mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2026-01-23 08:34:20 +01:00
Migration to BLE Library 2.0-beta5
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user