-
Notifications
You must be signed in to change notification settings - Fork 582
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#165] Added support for native BluetoothGattCallback usage in custom…
… operations. (#237)
- Loading branch information
Showing
7 changed files
with
291 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
.../src/main/java/com/polidea/rxandroidble/internal/connection/NativeCallbackDispatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.polidea.rxandroidble.internal.connection; | ||
|
||
import android.annotation.TargetApi; | ||
import android.bluetooth.BluetoothGatt; | ||
import android.bluetooth.BluetoothGattCallback; | ||
import android.bluetooth.BluetoothGattCharacteristic; | ||
import android.bluetooth.BluetoothGattDescriptor; | ||
import android.os.Build; | ||
|
||
import javax.inject.Inject; | ||
|
||
class NativeCallbackDispatcher { | ||
|
||
private BluetoothGattCallback nativeCallback; | ||
|
||
@Inject | ||
NativeCallbackDispatcher() { | ||
|
||
} | ||
|
||
public void notifyNativeChangedCallback(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { | ||
if (nativeCallback != null) { | ||
nativeCallback.onCharacteristicChanged(gatt, characteristic); | ||
} | ||
} | ||
|
||
public void notifyNativeConnectionStateCallback(BluetoothGatt gatt, int status, int newState) { | ||
if (nativeCallback != null) { | ||
nativeCallback.onConnectionStateChange(gatt, status, newState); | ||
} | ||
} | ||
|
||
public void notifyNativeDescriptorReadCallback(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) { | ||
if (nativeCallback != null) { | ||
nativeCallback.onDescriptorRead(gatt, descriptor, status); | ||
} | ||
} | ||
|
||
public void notifyNativeDescriptorWriteCallback(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) { | ||
if (nativeCallback != null) { | ||
nativeCallback.onDescriptorWrite(gatt, descriptor, status); | ||
} | ||
} | ||
|
||
@TargetApi(Build.VERSION_CODES.LOLLIPOP) | ||
public void notifyNativeMtuChangedCallback(BluetoothGatt gatt, int mtu, int status) { | ||
if (nativeCallback != null) { | ||
nativeCallback.onMtuChanged(gatt, mtu, status); | ||
} | ||
} | ||
|
||
public void notifyNativeReadRssiCallback(BluetoothGatt gatt, int rssi, int status) { | ||
if (nativeCallback != null) { | ||
nativeCallback.onReadRemoteRssi(gatt, rssi, status); | ||
} | ||
} | ||
|
||
public void notifyNativeReliableWriteCallback(BluetoothGatt gatt, int status) { | ||
if (nativeCallback != null) { | ||
nativeCallback.onReliableWriteCompleted(gatt, status); | ||
} | ||
} | ||
|
||
public void notifyNativeServicesDiscoveredCallback(BluetoothGatt gatt, int status) { | ||
if (nativeCallback != null) { | ||
nativeCallback.onServicesDiscovered(gatt, status); | ||
} | ||
} | ||
|
||
public void notifyNativeWriteCallback(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { | ||
if (nativeCallback != null) { | ||
nativeCallback.onCharacteristicWrite(gatt, characteristic, status); | ||
} | ||
} | ||
|
||
void setNativeCallback(BluetoothGattCallback callback) { | ||
this.nativeCallback = callback; | ||
} | ||
|
||
void notifyNativeReadCallback(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { | ||
if (nativeCallback != null) { | ||
nativeCallback.onCharacteristicRead(gatt, characteristic, status); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.