Skip to content

Commit

Permalink
Provide context via constructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
IvBaranov committed Nov 27, 2015
1 parent efad0ca commit cccd677
Showing 1 changed file with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@
*/
public class RxBluetooth {
private BluetoothAdapter mBluetoothAdapter;
private Context context;

public RxBluetooth() {
public RxBluetooth(Context context) {
this.mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
this.context = context;
}

/**
Expand Down Expand Up @@ -138,10 +140,9 @@ public void enableDiscoverability(Activity activity, int requestCode, int durati
/**
* Observes Bluetooth devices found while discovering.
*
* @param context Context of the activity or an application
* @return RxJava Observable with BluetoothDevice found
*/
public Observable<BluetoothDevice> observeDevices(final Context context) {
public Observable<BluetoothDevice> observeDevices() {
final IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);

return Observable.create(new Observable.OnSubscribe<BluetoothDevice>() {
Expand Down Expand Up @@ -172,10 +173,9 @@ public Observable<BluetoothDevice> observeDevices(final Context context) {
* Observes DiscoveryState, which can be ACTION_DISCOVERY_STARTED or ACTION_DISCOVERY_FINISHED
* from {@link BluetoothAdapter}.
*
* @param context Context of the activity or an application
* @return RxJava Observable with DiscoveryState
*/
public Observable<String> observeDiscovery(final Context context) {
public Observable<String> observeDiscovery() {
final IntentFilter filter = new IntentFilter();
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
Expand Down Expand Up @@ -207,10 +207,9 @@ public Observable<String> observeDiscovery(final Context context) {
* {@link BluetoothAdapter#STATE_ON},
* {@link BluetoothAdapter#STATE_TURNING_OFF},
*
* @param context Context of the activity or an application
* @return RxJava Observable with BluetoothState
*/
public Observable<Integer> observeBluetoothState(final Context context) {
public Observable<Integer> observeBluetoothState() {
final IntentFilter filter = new IntentFilter();
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);

Expand Down Expand Up @@ -240,10 +239,9 @@ public Observable<Integer> observeBluetoothState(final Context context) {
* {@link BluetoothAdapter#SCAN_MODE_CONNECTABLE},
* {@link BluetoothAdapter#SCAN_MODE_CONNECTABLE_DISCOVERABLE}
*
* @param context Context of the activity or an application
* @return RxJava Observable with scan mode
*/
public Observable<Integer> observeScanMode(final Context context) {
public Observable<Integer> observeScanMode() {
final IntentFilter filter = new IntentFilter();
filter.addAction(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);

Expand All @@ -270,14 +268,12 @@ public Observable<Integer> observeScanMode(final Context context) {
/**
* Observes connection to specified profile. See also {@link BluetoothProfile.ServiceListener}.
*
* @param context Context of the activity or an application
* @param bluetoothProfile bluetooth profile to connect to. Can be either {@link
* BluetoothProfile#HEALTH},{@link BluetoothProfile#HEADSET}, {@link BluetoothProfile#A2DP},
* {@link BluetoothProfile#GATT} or {@link BluetoothProfile#GATT_SERVER}.
* @return RxJava Observable with {@link ServiceEvent}
*/
public Observable<ServiceEvent> observeBluetoothProfile(final Context context,
final int bluetoothProfile) {
public Observable<ServiceEvent> observeBluetoothProfile(final int bluetoothProfile) {
return Observable.create(new Observable.OnSubscribe<ServiceEvent>() {
@Override public void call(final Subscriber<? super ServiceEvent> subscriber) {
if (!mBluetoothAdapter.getProfileProxy(context, new BluetoothProfile.ServiceListener() {
Expand Down

0 comments on commit cccd677

Please sign in to comment.