Java Code Examples for com.polidea.rxandroidble2.RxBleClient#State
The following examples show how to use
com.polidea.rxandroidble2.RxBleClient#State .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java From Mi365Locker with GNU General Public License v3.0 | 6 votes |
@NeedsPermission(Manifest.permission.ACCESS_COARSE_LOCATION) void startScan() { this.scanning = true; if (this.mBTAdapter != null) { RxBleClient client = this.rxBleClient; RxBleClient.State state = client.getState(); if(state == RxBleClient.State.READY) { bluetoothLeScanner.startScan(this.mLeScanCallback); } else { Toast.makeText(this, "Enable bluetooth", Toast.LENGTH_LONG).show(); stopScan(); } } this.updateStatus(); }
Example 2
Source File: ClientStateObservable.java From RxAndroidBle with Apache License 2.0 | 5 votes |
@NonNull static Observable<RxBleClient.State> checkAdapterAndServicesState( RxBleAdapterWrapper rxBleAdapterWrapper, Observable<RxBleAdapterStateObservable.BleAdapterState> rxBleAdapterStateObservable, final Observable<Boolean> locationServicesOkObservable ) { return rxBleAdapterStateObservable .startWith(rxBleAdapterWrapper.isBluetoothEnabled() ? RxBleAdapterStateObservable.BleAdapterState.STATE_ON /* * Actual RxBleAdapterStateObservable.BleAdapterState does not really matter - because in the .switchMap() below * we only check if it is STATE_ON or not */ : RxBleAdapterStateObservable.BleAdapterState.STATE_OFF) .switchMap(new Function<RxBleAdapterStateObservable.BleAdapterState, Observable<RxBleClient.State>>() { @Override public Observable<RxBleClient.State> apply( RxBleAdapterStateObservable.BleAdapterState bleAdapterState) { if (bleAdapterState != RxBleAdapterStateObservable.BleAdapterState.STATE_ON) { return Observable.just(RxBleClient.State.BLUETOOTH_NOT_ENABLED); } else { return locationServicesOkObservable.map(new Function<Boolean, RxBleClient.State>() { @Override public RxBleClient.State apply(Boolean locationServicesOk) { return locationServicesOk ? RxBleClient.State.READY : RxBleClient.State.LOCATION_SERVICES_NOT_ENABLED; } }); } } }); }
Example 3
Source File: ClientStateObservable.java From RxAndroidBle with Apache License 2.0 | 5 votes |
@Override protected void subscribeActual(Observer<? super RxBleClient.State> observer) { if (!rxBleAdapterWrapper.hasBluetoothAdapter()) { observer.onSubscribe(Disposables.empty()); observer.onComplete(); return; } checkPermissionUntilGranted(locationServicesStatus, timerScheduler) .flatMapObservable(new Function<Boolean, Observable<RxBleClient.State>>() { @Override public Observable<RxBleClient.State> apply(Boolean permissionWasInitiallyGranted) { Observable<RxBleClient.State> stateObservable = checkAdapterAndServicesState( rxBleAdapterWrapper, bleAdapterStateObservable, locationServicesOkObservable ) .distinctUntilChanged(); return permissionWasInitiallyGranted /* * If permission was granted from the beginning then the first value is not a change. The above Observable * does emit value at the moment of subscription. */ ? stateObservable.skip(1) : stateObservable; } }) .subscribe(observer); }