Migration to BLE Library 2.0-beta5

This commit is contained in:
Aleksander Nowakowski
2018-10-02 17:38:15 +02:00
parent 39cc4abc6e
commit 650092a9c4
8 changed files with 52 additions and 14 deletions

View File

@@ -48,7 +48,7 @@ dependencies {
implementation 'no.nordicsemi.android.support.v18:scanner:1.1.0'
// The DFU Library is imported automatically from jcenter:
implementation 'no.nordicsemi.android:dfu:1.6.1'
implementation 'no.nordicsemi.android:dfu:1.7.0'
// if you desire to build the DFU Library, clone the
// https://github.com/NordicSemiconductor/Android-DFU-Library project into DFULibrary folder,
// add it as a module into the project structure and uncomment the following line
@@ -57,7 +57,7 @@ dependencies {
// Import the BLE Common Library.
// The BLE Common Library depends on BLE Library. It is enough to include the first one.
implementation 'no.nordicsemi.android:ble-common:2.0-alpha5'
implementation 'no.nordicsemi.android:ble-common:2.0-beta5'
// The BLE Common Library may be included from jcenter. If you want to modify the code,
// clone both projects from GitHub and replace the line above with the following
// (and also the according lines in the settings.gradle):

View File

@@ -51,6 +51,7 @@ import no.nordicsemi.android.nrftoolbox.R;
import no.nordicsemi.android.nrftoolbox.scanner.ScannerFragment;
import no.nordicsemi.android.nrftoolbox.utility.DebugLogger;
@SuppressWarnings("unused")
public abstract class BleProfileActivity extends AppCompatActivity implements BleManagerCallbacks, ScannerFragment.OnDeviceSelectedListener {
private static final String TAG = "BaseProfileActivity";
@@ -228,6 +229,15 @@ public abstract class BleProfileActivity extends AppCompatActivity implements Bl
return null;
}
/**
* This method returns whether autoConnect option should be used.
*
* @return true to use autoConnect feature, false (default) otherwise.
*/
protected boolean shouldAutoConnect() {
return false;
}
@Override
public void onDeviceSelected(final BluetoothDevice device, final String name) {
final int titleId = getLoggerProfileTitle();
@@ -240,7 +250,10 @@ public abstract class BleProfileActivity extends AppCompatActivity implements Bl
}
mDeviceName = name;
mBleManager.setLogger(mLogSession);
mBleManager.connect(device).enqueue();
mBleManager.connect(device)
.useAutoConnect(shouldAutoConnect())
.retry(3, 100)
.enqueue();
}
@Override

View File

@@ -228,6 +228,15 @@ public abstract class BleProfileExpandableListActivity extends ExpandableListAct
return null;
}
/**
* This method returns whether autoConnect option should be used.
*
* @return true to use autoConnect feature, false (default) otherwise.
*/
protected boolean shouldAutoConnect() {
return false;
}
@Override
public void onDeviceSelected(final BluetoothDevice device, final String name) {
final int titleId = getLoggerProfileTitle();
@@ -240,7 +249,10 @@ public abstract class BleProfileExpandableListActivity extends ExpandableListAct
}
mDeviceName = name;
mBleManager.setLogger(mLogSession);
mBleManager.connect(device).enqueue();
mBleManager.connect(device)
.useAutoConnect(shouldAutoConnect())
.retry(3, 100)
.enqueue();
}
@Override

View File

@@ -313,6 +313,15 @@ public abstract class BleProfileService extends Service implements BleManagerCal
@SuppressWarnings("rawtypes")
protected abstract BleManager initializeManager();
/**
* This method returns whether autoConnect option should be used.
*
* @return true to use autoConnect feature, false (default) otherwise.
*/
protected boolean shouldAutoConnect() {
return false;
}
@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
if (intent == null || !intent.hasExtra(EXTRA_DEVICE_ADDRESS))
@@ -330,7 +339,10 @@ public abstract class BleProfileService extends Service implements BleManagerCal
mBleManager.setLogger(mLogSession);
onServiceStarted();
mBleManager.connect(mBluetoothDevice).enqueue();
mBleManager.connect(mBluetoothDevice)
.useAutoConnect(shouldAutoConnect())
.retry(3, 100)
.enqueue();
return START_REDELIVER_INTENT;
}

View File

@@ -69,6 +69,7 @@ import no.nordicsemi.android.nrftoolbox.utility.DebugLogger;
* listens for it. When entering back to the activity, activity will to bind to the service and refresh UI.
* </p>
*/
@SuppressWarnings("unused")
public abstract class BleProfileServiceReadyActivity<E extends BleProfileService.LocalBinder> extends AppCompatActivity implements
ScannerFragment.OnDeviceSelectedListener, BleManagerCallbacks {
private static final String TAG = "BleProfileServiceReadyActivity";

View File

@@ -117,11 +117,12 @@ public class UARTManager extends BleManager<UARTManagerCallbacks> {
}
};
@Override
// This has been moved to the service in BleManager v2.0.
/*@Override
protected boolean shouldAutoConnect() {
// We want the connection to be kept
return true;
}
}*/
/**
* Sends the given text to RX characteristic.

View File

@@ -95,6 +95,11 @@ public class UARTService extends BleProfileService implements UARTManagerCallbac
return mManager = new UARTManager(this);
}
@Override
protected boolean shouldAutoConnect() {
return true;
}
@Override
public void onCreate() {
super.onCreate();
@@ -132,12 +137,6 @@ public class UARTService extends BleProfileService implements UARTManagerCallbac
createNotification(R.string.uart_notification_connected_message, 0);
}
@Override
public boolean shouldEnableBatteryLevelNotifications(final BluetoothDevice device) {
// No UI in UART profile for Battery Level information
return false;
}
@Override
public void onDeviceConnected(final BluetoothDevice device) {
super.onDeviceConnected(device);

View File

@@ -24,7 +24,7 @@
<string name="dfu_feature_title">DFU</string>
<string name="dfu_service_title">nRF Toolbox DFU Proxy</string>
<string name="dfu_settings_title">DFU Settings</string>
<string name="dfu_lib_version">DFU Library version 1.6.1</string>
<string name="dfu_lib_version">DFU Library version 1.7.0</string>
<string name="dfu_feature_title_long">DEVICE FIRMWARE UPDATE</string>
<dimen name="dfu_feature_title_long_margin">-186dp</dimen>