Adopting to BLE lib changes, part 1

This commit is contained in:
Aleksander Nowakowski
2018-04-13 08:53:37 +02:00
parent 27c491f633
commit 0627f29ec9
7 changed files with 43 additions and 2 deletions

View File

@@ -307,6 +307,11 @@ public abstract class BleProfileActivity extends AppCompatActivity implements Bl
showToast(R.string.bonded); showToast(R.string.bonded);
} }
@Override
public void onBondingFailed(final BluetoothDevice device) {
showToast(R.string.bonding_failed);
}
@Override @Override
public boolean shouldEnableBatteryLevelNotifications(final BluetoothDevice device) { public boolean shouldEnableBatteryLevelNotifications(final BluetoothDevice device) {
// Yes, we want battery level updates // Yes, we want battery level updates

View File

@@ -307,6 +307,11 @@ public abstract class BleProfileExpandableListActivity extends ExpandableListAct
showToast(R.string.bonded); showToast(R.string.bonded);
} }
@Override
public void onBondingFailed(final BluetoothDevice device) {
showToast(R.string.bonding_failed);
}
@Override @Override
public boolean shouldEnableBatteryLevelNotifications(final BluetoothDevice device) { public boolean shouldEnableBatteryLevelNotifications(final BluetoothDevice device) {
// Yes, we want battery level updates // Yes, we want battery level updates

View File

@@ -268,7 +268,7 @@ public abstract class BleProfileService extends Service implements BleManagerCal
// When we are connected, but the application is not open, we are not really interested in battery level notifications. But we will still be receiving other values, if enabled. // When we are connected, but the application is not open, we are not really interested in battery level notifications. But we will still be receiving other values, if enabled.
if (!mActivityIsChangingConfiguration && mBleManager.isConnected()) if (!mActivityIsChangingConfiguration && mBleManager.isConnected())
mBleManager.setBatteryNotifications(false); mBleManager.disableBatteryLevelNotifications();
// We want the onRebind method be called if anything else binds to it again // We want the onRebind method be called if anything else binds to it again
return true; return true;
@@ -518,6 +518,16 @@ public abstract class BleProfileService extends Service implements BleManagerCal
LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast); LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);
} }
@Override
public void onBondingFailed(final BluetoothDevice device) {
showToast(no.nordicsemi.android.nrftoolbox.common.R.string.bonding_failed);
final Intent broadcast = new Intent(BROADCAST_BOND_STATE);
broadcast.putExtra(EXTRA_DEVICE, mBluetoothDevice);
broadcast.putExtra(EXTRA_BOND_STATE, BluetoothDevice.BOND_NONE);
LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);
}
@Override @Override
public void onError(final BluetoothDevice device, final String message, final int errorCode) { public void onError(final BluetoothDevice device, final String message, final int errorCode) {
final Intent broadcast = new Intent(BROADCAST_ERROR); final Intent broadcast = new Intent(BROADCAST_ERROR);

View File

@@ -548,6 +548,11 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
// empty default implementation // empty default implementation
} }
@Override
public void onBondingFailed(final BluetoothDevice device) {
// empty default implementation
}
@Override @Override
public final boolean shouldEnableBatteryLevelNotifications(final BluetoothDevice device) { public final boolean shouldEnableBatteryLevelNotifications(final BluetoothDevice device) {
// This method will never be called. // This method will never be called.

View File

@@ -286,7 +286,7 @@ public abstract class BleMulticonnectProfileService extends Service implements B
// But we will still be receiving other values, if enabled. // But we will still be receiving other values, if enabled.
for (final BleManager<BleManagerCallbacks> manager : mBleManagers.values()) { for (final BleManager<BleManagerCallbacks> manager : mBleManagers.values()) {
if (manager.isConnected()) if (manager.isConnected())
manager.setBatteryNotifications(false); manager.disableBatteryLevelNotifications();
} }
} else { } else {
// The last activity has disconnected from the service and there are no devices to manage. The service may be stopped. // The last activity has disconnected from the service and there are no devices to manage. The service may be stopped.
@@ -535,6 +535,16 @@ public abstract class BleMulticonnectProfileService extends Service implements B
LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast); LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);
} }
@Override
public void onBondingFailed(final BluetoothDevice device) {
showToast(no.nordicsemi.android.nrftoolbox.common.R.string.bonding_failed);
final Intent broadcast = new Intent(BROADCAST_BOND_STATE);
broadcast.putExtra(EXTRA_DEVICE, device);
broadcast.putExtra(EXTRA_BOND_STATE, BluetoothDevice.BOND_NONE);
LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);
}
@Override @Override
public void onError(final BluetoothDevice device, final String message, final int errorCode) { public void onError(final BluetoothDevice device, final String message, final int errorCode) {
final Intent broadcast = new Intent(BROADCAST_ERROR); final Intent broadcast = new Intent(BROADCAST_ERROR);

View File

@@ -437,6 +437,11 @@ public abstract class BleMulticonnectProfileServiceReadyActivity<E extends BleMu
// empty default implementation // empty default implementation
} }
@Override
public void onBondingFailed(final BluetoothDevice device) {
// empty default implementation
}
@Override @Override
public void onDeviceNotSupported(final BluetoothDevice device) { public void onDeviceNotSupported(final BluetoothDevice device) {
showToast(R.string.not_supported); showToast(R.string.not_supported);

View File

@@ -23,6 +23,7 @@
<resources> <resources>
<string name="bonding">Bonding with the device&#8230;</string> <string name="bonding">Bonding with the device&#8230;</string>
<string name="bonded">The device is now bonded.</string> <string name="bonded">The device is now bonded.</string>
<string name="bonding_failed">Bonding failed.</string>
<string name="channel_connected_devices_title">Background connections</string> <string name="channel_connected_devices_title">Background connections</string>
<string name="channel_connected_devices_description">Shows a notification when a device is connected in background.</string> <string name="channel_connected_devices_description">Shows a notification when a device is connected in background.</string>