com.polidea.rxandroidble2.exceptions.BleAlreadyConnectedException Java Examples
The following examples show how to use
com.polidea.rxandroidble2.exceptions.BleAlreadyConnectedException.
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: RxBleDeviceImpl.java From RxAndroidBle with Apache License 2.0 | 6 votes |
public Observable<RxBleConnection> establishConnection(final ConnectionSetup options) { return Observable.defer(new Callable<ObservableSource<RxBleConnection>>() { @Override public ObservableSource<RxBleConnection> call() { if (isConnected.compareAndSet(false, true)) { return connector.prepareConnection(options) .doFinally(new Action() { @Override public void run() { isConnected.set(false); } }); } else { return Observable.error(new BleAlreadyConnectedException(bluetoothDevice.getAddress())); } } }); }
Example #2
Source File: RxBleDeviceMock.java From RxAndroidBle with Apache License 2.0 | 5 votes |
@Override public Observable<RxBleConnection> establishConnection(boolean autoConnect) { return Observable.defer(new Callable<Observable<RxBleConnection>>() { @Override public Observable<RxBleConnection> call() { if (isConnected.compareAndSet(false, true)) { return RxBleDeviceMock.this.emitConnectionWithoutCompleting() .doOnSubscribe(new Consumer<Disposable>() { @Override public void accept(Disposable disposable) throws Exception { connectionStateBehaviorSubject.onNext(CONNECTING); } }) .doOnNext(new Consumer<RxBleConnection>() { @Override public void accept(RxBleConnection rxBleConnection) throws Exception { connectionStateBehaviorSubject.onNext(CONNECTED); } }) .doFinally(new Action() { @Override public void run() { connectionStateBehaviorSubject.onNext(DISCONNECTED); isConnected.set(false); } }); } else { return Observable.error(new BleAlreadyConnectedException(macAddress)); } } }); }
Example #3
Source File: JamBaseBluetoothSequencer.java From xDrip with GNU General Public License v3.0 | 5 votes |
private void onConnectionFailure(Throwable throwable) { UserError.Log.d(TAG, "received: onConnectionFailure: " + throwable); if (throwable instanceof BleAlreadyConnectedException) { UserError.Log.d(TAG, "Already connected - advancing to next stage"); I.isConnected = true; changeNextState(); } else if (throwable instanceof BleDisconnectedException) { if (((BleDisconnectedException) throwable).state == 133) { if (I.retry133) { if (JoH.ratelimit(TAG + "133recon", 60)) { if (I.state.equals(CONNECT_NOW)) { UserError.Log.d(TAG, "Automatically retrying connection"); Inevitable.task(TAG + "133recon", 3000, new Runnable() { @Override public void run() { changeState(CONNECT_NOW); } }); } } } } else if (I.autoConnect) { UserError.Log.d(TAG, "Auto reconnect persist"); changeState(CONNECT_NOW); } } }
Example #4
Source File: JamBaseBluetoothSequencer.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
private void onConnectionFailure(Throwable throwable) { UserError.Log.d(TAG, "received: onConnectionFailure: " + throwable); if (throwable instanceof BleAlreadyConnectedException) { UserError.Log.d(TAG, "Already connected - advancing to next stage"); I.isConnected = true; changeNextState(); } else if (throwable instanceof BleDisconnectedException) { if (((BleDisconnectedException) throwable).state == 133) { if (I.retry133) { if (JoH.ratelimit(TAG + "133recon", 60)) { if (I.state.equals(CONNECT_NOW)) { UserError.Log.d(TAG, "Automatically retrying connection"); Inevitable.task(TAG + "133recon", 3000, new Runnable() { @Override public void run() { changeState(CONNECT_NOW); } }); } } } } else if (I.autoConnect) { UserError.Log.d(TAG, "Auto reconnect persist"); changeState(CONNECT_NOW); } } }