mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2026-01-08 09:14:23 +01:00
#47 fixed
This commit is contained in:
@@ -115,7 +115,7 @@ public class CGMSActivity extends BleProfileServiceReadyActivity<CGMService.CGMS
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onServiceBinded(final CGMService.CGMSBinder binder) {
|
||||
protected void onServiceBound(final CGMService.CGMSBinder binder) {
|
||||
mBinder = binder;
|
||||
final SparseArray<CGMSRecord> cgmsRecords = binder.getRecords();
|
||||
if (cgmsRecords != null && cgmsRecords.size() > 0) {
|
||||
@@ -128,7 +128,7 @@ public class CGMSActivity extends BleProfileServiceReadyActivity<CGMService.CGMS
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onServiceUnbinded() {
|
||||
protected void onServiceUnbound() {
|
||||
mBinder = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -167,12 +167,12 @@ public class CSCActivity extends BleProfileServiceReadyActivity<CSCService.CSCBi
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onServiceBinded(final CSCService.CSCBinder binder) {
|
||||
protected void onServiceBound(final CSCService.CSCBinder binder) {
|
||||
// not used
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onServiceUnbinded() {
|
||||
protected void onServiceUnbound() {
|
||||
// not used
|
||||
}
|
||||
|
||||
|
||||
@@ -128,12 +128,12 @@ public class HTSActivity extends BleProfileServiceReadyActivity<HTSService.RSCBi
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onServiceBinded(final HTSService.RSCBinder binder) {
|
||||
protected void onServiceBound(final HTSService.RSCBinder binder) {
|
||||
// not used
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onServiceUnbinded() {
|
||||
protected void onServiceUnbound() {
|
||||
// not used
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ public class HTSService extends BleProfileService implements HTSManagerCallbacks
|
||||
broadcast.putExtra(EXTRA_TEMPERATURE, value);
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);
|
||||
|
||||
if (!mBinded) {
|
||||
if (!mBound) {
|
||||
// Here we may update the notification to display the current temperature.
|
||||
// TODO modify the notification here
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ public abstract class BleProfileActivity extends AppCompatActivity implements Bl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLinklossOccur(final BluetoothDevice device) {
|
||||
public void onLinklossOccurred(final BluetoothDevice device) {
|
||||
mDeviceConnected = false;
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ public abstract class BleProfileActivity extends AppCompatActivity implements Bl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBonded(final BluetoothDevice device) {
|
||||
public void onBound(final BluetoothDevice device) {
|
||||
showToast(R.string.bonded);
|
||||
}
|
||||
|
||||
|
||||
@@ -278,7 +278,7 @@ public abstract class BleProfileExpandableListActivity extends ExpandableListAct
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLinklossOccur(final BluetoothDevice device) {
|
||||
public void onLinklossOccurred(final BluetoothDevice device) {
|
||||
mDeviceConnected = false;
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ public abstract class BleProfileExpandableListActivity extends ExpandableListAct
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBonded(final BluetoothDevice device) {
|
||||
public void onBound(final BluetoothDevice device) {
|
||||
showToast(R.string.bonded);
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ public abstract class BleProfileService extends Service implements BleManagerCal
|
||||
private BleManager<BleManagerCallbacks> mBleManager;
|
||||
private Handler mHandler;
|
||||
|
||||
protected boolean mBinded;
|
||||
protected boolean mBound;
|
||||
private boolean mActivityIsChangingConfiguration;
|
||||
private BluetoothDevice mBluetoothDevice;
|
||||
private String mDeviceName;
|
||||
@@ -234,13 +234,13 @@ public abstract class BleProfileService extends Service implements BleManagerCal
|
||||
|
||||
@Override
|
||||
public IBinder onBind(final Intent intent) {
|
||||
mBinded = true;
|
||||
mBound = true;
|
||||
return getBinder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onRebind(final Intent intent) {
|
||||
mBinded = true;
|
||||
mBound = true;
|
||||
|
||||
if (!mActivityIsChangingConfiguration)
|
||||
onRebind();
|
||||
@@ -257,7 +257,7 @@ public abstract class BleProfileService extends Service implements BleManagerCal
|
||||
|
||||
@Override
|
||||
public final boolean onUnbind(final Intent intent) {
|
||||
mBinded = false;
|
||||
mBound = false;
|
||||
|
||||
if (!mActivityIsChangingConfiguration)
|
||||
onUnbind();
|
||||
@@ -424,7 +424,7 @@ public abstract class BleProfileService extends Service implements BleManagerCal
|
||||
|
||||
// Note 2: if BleManager#shouldAutoConnect() for this device returned true, this callback will be
|
||||
// invoked ONLY when user requested disconnection (using Disconnect button). If the device
|
||||
// disconnects due to a link loss, the onLinklossOccur(BluetoothDevice) method will be called instead.
|
||||
// disconnects due to a link loss, the onLinklossOccurred(BluetoothDevice) method will be called instead.
|
||||
|
||||
final Intent broadcast = new Intent(BROADCAST_CONNECTION_STATE);
|
||||
broadcast.putExtra(EXTRA_DEVICE, mBluetoothDevice);
|
||||
@@ -442,7 +442,7 @@ public abstract class BleProfileService extends Service implements BleManagerCal
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLinklossOccur(final BluetoothDevice device) {
|
||||
public void onLinklossOccurred(final BluetoothDevice device) {
|
||||
final Intent broadcast = new Intent(BROADCAST_CONNECTION_STATE);
|
||||
broadcast.putExtra(EXTRA_DEVICE, mBluetoothDevice);
|
||||
broadcast.putExtra(EXTRA_CONNECTION_STATE, STATE_LINK_LOSS);
|
||||
@@ -495,7 +495,7 @@ public abstract class BleProfileService extends Service implements BleManagerCal
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBonded(final BluetoothDevice device) {
|
||||
public void onBound(final BluetoothDevice device) {
|
||||
showToast(no.nordicsemi.android.nrftoolbox.common.R.string.bonded);
|
||||
|
||||
final Intent broadcast = new Intent(BROADCAST_BOND_STATE);
|
||||
|
||||
@@ -112,7 +112,7 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
|
||||
break;
|
||||
}
|
||||
case BleProfileService.STATE_LINK_LOSS: {
|
||||
onLinklossOccur(bluetoothDevice);
|
||||
onLinklossOccurred(bluetoothDevice);
|
||||
break;
|
||||
}
|
||||
case BleProfileService.STATE_CONNECTING: {
|
||||
@@ -151,7 +151,7 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
|
||||
onBondingRequired(bluetoothDevice);
|
||||
break;
|
||||
case BluetoothDevice.BOND_BONDED:
|
||||
onBonded(bluetoothDevice);
|
||||
onBound(bluetoothDevice);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -180,7 +180,7 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
|
||||
mBluetoothDevice = bleService.getBluetoothDevice();
|
||||
mLogSession = mService.getLogSession();
|
||||
Logger.d(mLogSession, "Activity bound to the service");
|
||||
onServiceBinded(bleService);
|
||||
onServiceBound(bleService);
|
||||
|
||||
// Update UI
|
||||
mDeviceName = bleService.getDeviceName();
|
||||
@@ -211,7 +211,7 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
|
||||
mDeviceName = null;
|
||||
mBluetoothDevice = null;
|
||||
mLogSession = null;
|
||||
onServiceUnbinded();
|
||||
onServiceUnbound();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -277,7 +277,7 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
|
||||
mService = null;
|
||||
|
||||
Logger.d(mLogSession, "Activity unbound from the service");
|
||||
onServiceUnbinded();
|
||||
onServiceUnbound();
|
||||
mDeviceName = null;
|
||||
mBluetoothDevice = null;
|
||||
mLogSession = null;
|
||||
@@ -308,13 +308,13 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
|
||||
* Called when activity binds to the service. The parameter is the object returned in {@link Service#onBind(Intent)} method in your service. The method is
|
||||
* called when device gets connected or is created while sensor was connected before. You may use the binder as a sensor interface.
|
||||
*/
|
||||
protected abstract void onServiceBinded(E binder);
|
||||
protected abstract void onServiceBound(E binder);
|
||||
|
||||
/**
|
||||
* Called when activity unbinds from the service. You may no longer use this binder because the sensor was disconnected. This method is also called when you
|
||||
* leave the activity being connected to the sensor in the background.
|
||||
*/
|
||||
protected abstract void onServiceUnbinded();
|
||||
protected abstract void onServiceUnbound();
|
||||
|
||||
/**
|
||||
* Returns the service class for sensor communication. The service class must derive from {@link BleProfileService} in order to operate with this class.
|
||||
@@ -511,7 +511,7 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
|
||||
mService = null;
|
||||
|
||||
Logger.d(mLogSession, "Activity unbound from the service");
|
||||
onServiceUnbinded();
|
||||
onServiceUnbound();
|
||||
mDeviceName = null;
|
||||
mBluetoothDevice = null;
|
||||
mLogSession = null;
|
||||
@@ -521,7 +521,7 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLinklossOccur(final BluetoothDevice device) {
|
||||
public void onLinklossOccurred(final BluetoothDevice device) {
|
||||
// empty default implementation
|
||||
}
|
||||
|
||||
@@ -541,7 +541,7 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBonded(final BluetoothDevice device) {
|
||||
public void onBound(final BluetoothDevice device) {
|
||||
// empty default implementation
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ public abstract class BleMulticonnectProfileService extends Service implements B
|
||||
private List<BluetoothDevice> mManagedDevices;
|
||||
private Handler mHandler;
|
||||
|
||||
protected boolean mBinded;
|
||||
protected boolean mBound;
|
||||
private boolean mActivityIsChangingConfiguration;
|
||||
|
||||
private final BroadcastReceiver mBluetoothStateBroadcastReceiver = new BroadcastReceiver() {
|
||||
@@ -251,13 +251,13 @@ public abstract class BleMulticonnectProfileService extends Service implements B
|
||||
|
||||
@Override
|
||||
public IBinder onBind(final Intent intent) {
|
||||
mBinded = true;
|
||||
mBound = true;
|
||||
return getBinder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onRebind(final Intent intent) {
|
||||
mBinded = true;
|
||||
mBound = true;
|
||||
|
||||
if (!mActivityIsChangingConfiguration) {
|
||||
onRebind();
|
||||
@@ -275,7 +275,7 @@ public abstract class BleMulticonnectProfileService extends Service implements B
|
||||
|
||||
@Override
|
||||
public final boolean onUnbind(final Intent intent) {
|
||||
mBinded = false;
|
||||
mBound = false;
|
||||
|
||||
if (!mActivityIsChangingConfiguration) {
|
||||
if (!mManagedDevices.isEmpty()) {
|
||||
@@ -435,7 +435,7 @@ public abstract class BleMulticonnectProfileService extends Service implements B
|
||||
public void onDeviceDisconnected(final BluetoothDevice device) {
|
||||
// Note: if BleManager#shouldAutoConnect() for this device returned true, this callback will be
|
||||
// invoked ONLY when user requested disconnection (using Disconnect button). If the device
|
||||
// disconnects due to a link loss, the onLinklossOccur(BluetoothDevice) method will be called instead.
|
||||
// disconnects due to a link loss, the onLinklossOccurred(BluetoothDevice) method will be called instead.
|
||||
|
||||
// We no longer want to keep the device in the service
|
||||
mManagedDevices.remove(device);
|
||||
@@ -449,13 +449,13 @@ public abstract class BleMulticonnectProfileService extends Service implements B
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);
|
||||
|
||||
// When user disconnected the last device while the activity was not bound the service can be stopped
|
||||
if (!mBinded && mManagedDevices.isEmpty()) {
|
||||
if (!mBound && mManagedDevices.isEmpty()) {
|
||||
stopSelf();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLinklossOccur(final BluetoothDevice device) {
|
||||
public void onLinklossOccurred(final BluetoothDevice device) {
|
||||
final Intent broadcast = new Intent(BROADCAST_CONNECTION_STATE);
|
||||
broadcast.putExtra(EXTRA_DEVICE, device);
|
||||
broadcast.putExtra(EXTRA_CONNECTION_STATE, STATE_LINK_LOSS);
|
||||
@@ -512,7 +512,7 @@ public abstract class BleMulticonnectProfileService extends Service implements B
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBonded(final BluetoothDevice device) {
|
||||
public void onBound(final BluetoothDevice device) {
|
||||
showToast(no.nordicsemi.android.nrftoolbox.common.R.string.bonded);
|
||||
|
||||
final Intent broadcast = new Intent(BROADCAST_BOND_STATE);
|
||||
|
||||
@@ -99,7 +99,7 @@ public abstract class BleMulticonnectProfileServiceReadyActivity<E extends BleMu
|
||||
break;
|
||||
}
|
||||
case BleMulticonnectProfileService.STATE_LINK_LOSS: {
|
||||
onLinklossOccur(bluetoothDevice);
|
||||
onLinklossOccurred(bluetoothDevice);
|
||||
break;
|
||||
}
|
||||
case BleMulticonnectProfileService.STATE_CONNECTING: {
|
||||
@@ -138,7 +138,7 @@ public abstract class BleMulticonnectProfileServiceReadyActivity<E extends BleMu
|
||||
onBondingRequired(bluetoothDevice);
|
||||
break;
|
||||
case BluetoothDevice.BOND_BONDED:
|
||||
onBonded(bluetoothDevice);
|
||||
onBound(bluetoothDevice);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -166,7 +166,7 @@ public abstract class BleMulticonnectProfileServiceReadyActivity<E extends BleMu
|
||||
final E bleService = mService = (E) service;
|
||||
bleService.log(LogContract.Log.Level.DEBUG, "Activity bound to the service");
|
||||
mManagedDevices.addAll(bleService.getManagedDevices());
|
||||
onServiceBinded(bleService);
|
||||
onServiceBound(bleService);
|
||||
|
||||
// and notify user if device is connected
|
||||
for (final BluetoothDevice device : mManagedDevices) {
|
||||
@@ -178,7 +178,7 @@ public abstract class BleMulticonnectProfileServiceReadyActivity<E extends BleMu
|
||||
@Override
|
||||
public void onServiceDisconnected(final ComponentName name) {
|
||||
mService = null;
|
||||
onServiceUnbinded();
|
||||
onServiceUnbound();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -238,7 +238,7 @@ public abstract class BleMulticonnectProfileServiceReadyActivity<E extends BleMu
|
||||
unbindService(mServiceConnection);
|
||||
mService = null;
|
||||
|
||||
onServiceUnbinded();
|
||||
onServiceUnbound();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -263,12 +263,12 @@ public abstract class BleMulticonnectProfileServiceReadyActivity<E extends BleMu
|
||||
* Called when activity binds to the service. The parameter is the object returned in {@link Service#onBind(Intent)} method in your service.
|
||||
* It is safe to obtain managed devices now.
|
||||
*/
|
||||
protected abstract void onServiceBinded(E binder);
|
||||
protected abstract void onServiceBound(E binder);
|
||||
|
||||
/**
|
||||
* Called when activity unbinds from the service. You may no longer use this binder methods.
|
||||
*/
|
||||
protected abstract void onServiceUnbinded();
|
||||
protected abstract void onServiceUnbound();
|
||||
|
||||
/**
|
||||
* Returns the service class for sensor communication. The service class must derive from {@link BleMulticonnectProfileService} in order to operate with this class.
|
||||
@@ -415,7 +415,7 @@ public abstract class BleMulticonnectProfileServiceReadyActivity<E extends BleMu
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLinklossOccur(final BluetoothDevice device) {
|
||||
public void onLinklossOccurred(final BluetoothDevice device) {
|
||||
// empty default implementation
|
||||
}
|
||||
|
||||
@@ -435,7 +435,7 @@ public abstract class BleMulticonnectProfileServiceReadyActivity<E extends BleMu
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBonded(final BluetoothDevice device) {
|
||||
public void onBound(final BluetoothDevice device) {
|
||||
// empty default implementation
|
||||
}
|
||||
|
||||
|
||||
@@ -78,12 +78,12 @@ public class ProximityActivity extends BleMulticonnectProfileServiceReadyActivit
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onServiceBinded(final ProximityService.ProximityBinder binder) {
|
||||
protected void onServiceBound(final ProximityService.ProximityBinder binder) {
|
||||
mDevicesView.setAdapter(mAdapter = new DeviceAdapter(binder));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onServiceUnbinded() {
|
||||
protected void onServiceUnbound() {
|
||||
mDevicesView.setAdapter(mAdapter = null);
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ public class ProximityActivity extends BleMulticonnectProfileServiceReadyActivit
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLinklossOccur(final BluetoothDevice device) {
|
||||
public void onLinklossOccurred(final BluetoothDevice device) {
|
||||
if (mAdapter != null)
|
||||
mAdapter.onDeviceStateChanged(device);
|
||||
|
||||
|
||||
@@ -262,7 +262,7 @@ public class ProximityService extends BleMulticonnectProfileService implements P
|
||||
public void onDeviceConnected(final BluetoothDevice device) {
|
||||
super.onDeviceConnected(device);
|
||||
|
||||
if (!mBinded) {
|
||||
if (!mBound) {
|
||||
createBackgroundNotification();
|
||||
}
|
||||
}
|
||||
@@ -274,12 +274,12 @@ public class ProximityService extends BleMulticonnectProfileService implements P
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLinklossOccur(final BluetoothDevice device) {
|
||||
public void onLinklossOccurred(final BluetoothDevice device) {
|
||||
mServerManager.cancelConnection(device);
|
||||
stopAlarm(device);
|
||||
super.onLinklossOccur(device);
|
||||
super.onLinklossOccurred(device);
|
||||
|
||||
if (!mBinded) {
|
||||
if (!mBound) {
|
||||
createBackgroundNotification();
|
||||
if (BluetoothAdapter.getDefaultAdapter().isEnabled())
|
||||
createLinklossNotification(device);
|
||||
@@ -294,7 +294,7 @@ public class ProximityService extends BleMulticonnectProfileService implements P
|
||||
stopAlarm(device);
|
||||
super.onDeviceDisconnected(device);
|
||||
|
||||
if (!mBinded) {
|
||||
if (!mBound) {
|
||||
cancelNotification(device);
|
||||
createBackgroundNotification();
|
||||
}
|
||||
|
||||
@@ -167,12 +167,12 @@ public class RSCActivity extends BleProfileServiceReadyActivity<RSCService.RSCBi
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onServiceBinded(final RSCService.RSCBinder binder) {
|
||||
protected void onServiceBound(final RSCService.RSCBinder binder) {
|
||||
// not used
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onServiceUnbinded() {
|
||||
protected void onServiceUnbound() {
|
||||
// not used
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ public class RSCService extends BleProfileService implements RSCManagerCallbacks
|
||||
private final LocalBinder mBinder = new RSCBinder();
|
||||
|
||||
/**
|
||||
* This local binder is an interface for the binded activity to operate with the RSC sensor
|
||||
* This local binder is an interface for the bound activity to operate with the RSC sensor
|
||||
*/
|
||||
public class RSCBinder extends LocalBinder {
|
||||
// empty
|
||||
|
||||
@@ -56,8 +56,10 @@ import no.nordicsemi.android.support.v18.scanner.ScanResult;
|
||||
import no.nordicsemi.android.support.v18.scanner.ScanSettings;
|
||||
|
||||
/**
|
||||
* ScannerFragment class scan required BLE devices and shows them in a list. This class scans and filter devices with standard BLE Service UUID and devices with custom BLE Service UUID. It contains a
|
||||
* list and a button to scan/cancel. There is a interface {@link OnDeviceSelectedListener} which is implemented by activity in order to receive selected device. The scanning will continue to scan
|
||||
* ScannerFragment class scan required BLE devices and shows them in a list. This class scans and filter
|
||||
* devices with standard BLE Service UUID and devices with custom BLE Service UUID. It contains a
|
||||
* list and a button to scan/cancel. There is a interface {@link OnDeviceSelectedListener} which is
|
||||
* implemented by activity in order to receive selected device. The scanning will continue to scan
|
||||
* for 5 seconds and then stop.
|
||||
*/
|
||||
public class ScannerFragment extends DialogFragment {
|
||||
@@ -100,8 +102,9 @@ public class ScannerFragment extends DialogFragment {
|
||||
* @param device
|
||||
* the device to connect to
|
||||
* @param name
|
||||
* the device name. Unfortunately on some devices {@link BluetoothDevice#getName()} always returns <code>null</code>, f.e. Sony Xperia Z1 (C6903) with Android 4.3. The name has to
|
||||
* be parsed manually form the Advertisement packet.
|
||||
* the device name. Unfortunately on some devices {@link BluetoothDevice#getName()}
|
||||
* always returns <code>null</code>, i.e. Sony Xperia Z1 (C6903) with Android 4.3.
|
||||
* The name has to be parsed manually form the Advertisement packet.
|
||||
*/
|
||||
void onDeviceSelected(final BluetoothDevice device, final String name);
|
||||
|
||||
@@ -129,12 +132,14 @@ public class ScannerFragment extends DialogFragment {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
final Bundle args = getArguments();
|
||||
if (args.containsKey(PARAM_UUID)) {
|
||||
if (args != null && args.containsKey(PARAM_UUID)) {
|
||||
mUuid = args.getParcelable(PARAM_UUID);
|
||||
}
|
||||
|
||||
final BluetoothManager manager = (BluetoothManager) getActivity().getSystemService(Context.BLUETOOTH_SERVICE);
|
||||
mBluetoothAdapter = manager.getAdapter();
|
||||
final BluetoothManager manager = (BluetoothManager) requireContext().getSystemService(Context.BLUETOOTH_SERVICE);
|
||||
if (manager != null) {
|
||||
mBluetoothAdapter = manager.getAdapter();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -146,7 +151,7 @@ public class ScannerFragment extends DialogFragment {
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(final Bundle savedInstanceState) {
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
|
||||
final View dialogView = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_device_selection, null);
|
||||
final ListView listview = dialogView.findViewById(android.R.id.list);
|
||||
|
||||
@@ -175,7 +180,7 @@ public class ScannerFragment extends DialogFragment {
|
||||
}
|
||||
});
|
||||
|
||||
addBondedDevices();
|
||||
addBoundDevices();
|
||||
if (savedInstanceState == null)
|
||||
startScan();
|
||||
return dialog;
|
||||
@@ -205,16 +210,17 @@ public class ScannerFragment extends DialogFragment {
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan for 5 seconds and then stop scanning when a BluetoothLE device is found then mLEScanCallback is activated This will perform regular scan for custom BLE Service UUID and then filter out.
|
||||
* Scan for 5 seconds and then stop scanning when a BluetoothLE device is found then mLEScanCallback
|
||||
* is activated This will perform regular scan for custom BLE Service UUID and then filter out.
|
||||
* using class ScannerServiceParser
|
||||
*/
|
||||
private void startScan() {
|
||||
// Since Android 6.0 we need to obtain either Manifest.permission.ACCESS_COARSE_LOCATION or Manifest.permission.ACCESS_FINE_LOCATION to be able to scan for
|
||||
// Bluetooth LE devices. This is related to beacons as proximity devices.
|
||||
// On API older than Marshmallow the following code does nothing.
|
||||
if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
if (ContextCompat.checkSelfPermission(requireContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
// When user pressed Deny and still wants to use this functionality, show the rationale
|
||||
if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) && mPermissionRationale.getVisibility() == View.GONE) {
|
||||
if (ActivityCompat.shouldShowRequestPermissionRationale(requireActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) && mPermissionRationale.getVisibility() == View.GONE) {
|
||||
mPermissionRationale.setVisibility(View.VISIBLE);
|
||||
return;
|
||||
}
|
||||
@@ -276,7 +282,7 @@ public class ScannerFragment extends DialogFragment {
|
||||
}
|
||||
};
|
||||
|
||||
private void addBondedDevices() {
|
||||
private void addBoundDevices() {
|
||||
final Set<BluetoothDevice> devices = mBluetoothAdapter.getBondedDevices();
|
||||
mAdapter.addBondedDevices(devices);
|
||||
}
|
||||
|
||||
@@ -80,12 +80,12 @@ public class TemplateActivity extends BleProfileServiceReadyActivity<TemplateSer
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onServiceBinded(final TemplateService.TemplateBinder binder) {
|
||||
protected void onServiceBound(final TemplateService.TemplateBinder binder) {
|
||||
// not used
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onServiceUnbinded() {
|
||||
protected void onServiceUnbound() {
|
||||
// not used
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ public class TemplateService extends BleProfileService implements TemplateManage
|
||||
broadcast.putExtra(EXTRA_DATA, value);
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);
|
||||
|
||||
if (!mBinded) {
|
||||
if (!mBound) {
|
||||
// Here we may update the notification to display the current value.
|
||||
// TODO modify the notification here
|
||||
}
|
||||
|
||||
@@ -160,12 +160,12 @@ public class UARTActivity extends BleProfileServiceReadyActivity<UARTService.UAR
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onServiceBinded(final UARTService.UARTBinder binder) {
|
||||
protected void onServiceBound(final UARTService.UARTBinder binder) {
|
||||
mServiceBinder = binder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onServiceUnbinded() {
|
||||
protected void onServiceUnbound() {
|
||||
mServiceBinder = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ package no.nordicsemi.android.nrftoolbox.uart;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Color;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.SparseIntArray;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -49,7 +50,7 @@ public class UARTLogAdapter extends CursorAdapter {
|
||||
mColors.put(Level.ERROR, Color.RED);
|
||||
}
|
||||
|
||||
public UARTLogAdapter(Context context) {
|
||||
UARTLogAdapter(@NonNull final Context context) {
|
||||
super(context, null, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import android.content.ServiceConnection;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.CursorLoader;
|
||||
@@ -57,19 +58,27 @@ public class UARTLogFragment extends ListFragment implements LoaderManager.Loade
|
||||
private static final int LOG_SCROLLED_TO_BOTTOM = -2;
|
||||
|
||||
private static final int LOG_REQUEST_ID = 1;
|
||||
private static final String[] LOG_PROJECTION = { LogContract.Log._ID, LogContract.Log.TIME, LogContract.Log.LEVEL, LogContract.Log.DATA };
|
||||
private static final String[] LOG_PROJECTION = {LogContract.Log._ID, LogContract.Log.TIME, LogContract.Log.LEVEL, LogContract.Log.DATA};
|
||||
|
||||
/** The service UART interface that may be used to send data to the target. */
|
||||
/**
|
||||
* The service UART interface that may be used to send data to the target.
|
||||
*/
|
||||
private UARTInterface mUARTInterface;
|
||||
/** The adapter used to populate the list with log entries. */
|
||||
/**
|
||||
* The adapter used to populate the list with log entries.
|
||||
*/
|
||||
private CursorAdapter mLogAdapter;
|
||||
/** The log session created to log events related with the target device. */
|
||||
/**
|
||||
* The log session created to log events related with the target device.
|
||||
*/
|
||||
private ILogSession mLogSession;
|
||||
|
||||
private EditText mField;
|
||||
private Button mSendButton;
|
||||
|
||||
/** The last list view position. */
|
||||
/**
|
||||
* The last list view position.
|
||||
*/
|
||||
private int mLogScrollPosition;
|
||||
|
||||
/**
|
||||
@@ -128,7 +137,7 @@ public class UARTLogFragment extends ListFragment implements LoaderManager.Loade
|
||||
public void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mCommonBroadcastReceiver, makeIntentFilter());
|
||||
LocalBroadcastManager.getInstance(requireContext()).registerReceiver(mCommonBroadcastReceiver, makeIntentFilter());
|
||||
|
||||
// Load the last log list view scroll position
|
||||
if (savedInstanceState != null) {
|
||||
@@ -141,11 +150,11 @@ public class UARTLogFragment extends ListFragment implements LoaderManager.Loade
|
||||
super.onStart();
|
||||
|
||||
/*
|
||||
* If the service has not been started before the following lines will not start it. However, if it's running, the Activity will be binded to it
|
||||
* If the service has not been started before the following lines will not start it. However, if it's running, the Activity will be bound to it
|
||||
* and notified via mServiceConnection.
|
||||
*/
|
||||
final Intent service = new Intent(getActivity(), UARTService.class);
|
||||
getActivity().bindService(service, mServiceConnection, 0); // we pass 0 as a flag so the service will not be created if not exists
|
||||
requireActivity().bindService(service, mServiceConnection, 0); // we pass 0 as a flag so the service will not be created if not exists
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -153,7 +162,7 @@ public class UARTLogFragment extends ListFragment implements LoaderManager.Loade
|
||||
super.onStop();
|
||||
|
||||
try {
|
||||
getActivity().unbindService(mServiceConnection);
|
||||
requireActivity().unbindService(mServiceConnection);
|
||||
mUARTInterface = null;
|
||||
} catch (final IllegalArgumentException e) {
|
||||
// do nothing, we were not connected to the sensor
|
||||
@@ -161,7 +170,7 @@ public class UARTLogFragment extends ListFragment implements LoaderManager.Loade
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(final Bundle outState) {
|
||||
public void onSaveInstanceState(@NonNull final Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
|
||||
// Save the last log list view scroll position
|
||||
@@ -172,9 +181,8 @@ public class UARTLogFragment extends ListFragment implements LoaderManager.Loade
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
LocalBroadcastManager.getInstance(requireContext()).unregisterReceiver(mCommonBroadcastReceiver);
|
||||
super.onDestroy();
|
||||
|
||||
LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mCommonBroadcastReceiver);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -196,26 +204,27 @@ public class UARTLogFragment extends ListFragment implements LoaderManager.Loade
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(final View view, final Bundle savedInstanceState) {
|
||||
public void onViewCreated(@NonNull final View view, final Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
// Create the log adapter, initially with null cursor
|
||||
mLogAdapter = new UARTLogAdapter(getActivity());
|
||||
mLogAdapter = new UARTLogAdapter(requireContext());
|
||||
setListAdapter(mLogAdapter);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Loader<Cursor> onCreateLoader(final int id, final Bundle args) {
|
||||
switch (id) {
|
||||
case LOG_REQUEST_ID: {
|
||||
return new CursorLoader(getActivity(), mLogSession.getSessionEntriesUri(), LOG_PROJECTION, null, null, LogContract.Log.TIME);
|
||||
case LOG_REQUEST_ID: {
|
||||
return new CursorLoader(requireContext(), mLogSession.getSessionEntriesUri(), LOG_PROJECTION, null, null, LogContract.Log.TIME);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
throw new UnsupportedOperationException("Could not create loader with ID " + id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(final Loader<Cursor> loader, final Cursor data) {
|
||||
public void onLoadFinished(@NonNull final Loader<Cursor> loader, final Cursor data) {
|
||||
// Here we have to restore the old saved scroll position, or scroll to the bottom if before adding new events it was scrolled to the bottom.
|
||||
final ListView list = getListView();
|
||||
final int position = mLogScrollPosition;
|
||||
@@ -233,7 +242,7 @@ public class UARTLogFragment extends ListFragment implements LoaderManager.Loade
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(final Loader<Cursor> loader) {
|
||||
public void onLoaderReset(@NonNull final Loader<Cursor> loader) {
|
||||
mLogAdapter.swapCursor(null);
|
||||
}
|
||||
|
||||
@@ -253,15 +262,17 @@ public class UARTLogFragment extends ListFragment implements LoaderManager.Loade
|
||||
public void onServiceStarted() {
|
||||
// The service has been started, bind to it
|
||||
final Intent service = new Intent(getActivity(), UARTService.class);
|
||||
getActivity().bindService(service, mServiceConnection, 0);
|
||||
requireActivity().bindService(service, mServiceConnection, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when user closes the pane in horizontal orientation. The EditText is no longer visible so we need to close the soft keyboard here.
|
||||
*/
|
||||
public void onFragmentHidden() {
|
||||
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(mField.getWindowToken(), 0);
|
||||
final InputMethodManager imm = (InputMethodManager) requireContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
if (imm != null) {
|
||||
imm.hideSoftInputFromWindow(mField.getWindowToken(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -156,8 +156,8 @@ public class UARTService extends BleProfileService implements UARTManagerCallbac
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLinklossOccur(final BluetoothDevice device) {
|
||||
super.onLinklossOccur(device);
|
||||
public void onLinklossOccurred(final BluetoothDevice device) {
|
||||
super.onLinklossOccurred(device);
|
||||
sendMessageToWearables(Constants.UART.DEVICE_LINKLOSS, notNull(getDeviceName()));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user