forked from upstream-mirrors/OpenTracks
Cleanup: mainly code formatting and made LocationIterator implement autoclosable.
This commit is contained in:
+11
-7
@@ -30,11 +30,11 @@ import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
||||
import de.dennisguse.opentracks.content.sensor.SensorState;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Manages connection to Bluetooth LE heart rate monitor.
|
||||
* TODO: shutdown connection.
|
||||
@@ -42,16 +42,20 @@ import java.util.UUID;
|
||||
public class BluetoothConnectionManager {
|
||||
|
||||
// Message types sent to handler
|
||||
public static final int MESSAGE_DEVICE_NAME = 1;
|
||||
public static final int MESSAGE_READ = 2;
|
||||
public static final String KEY_DEVICE_NAME = "device_name";
|
||||
static final int MESSAGE_DEVICE_NAME = 1;
|
||||
static final int MESSAGE_READ = 2;
|
||||
|
||||
static final String KEY_DEVICE_NAME = "device_name";
|
||||
|
||||
private static final UUID HEART_RATE_SERVICE_UUID = new UUID(0x180D00001000L, 0x800000805f9b34fbL);
|
||||
private static final UUID HEART_RATE_MEASUREMENT_CHAR_UUID = new UUID(0x2A3700001000L, 0x800000805f9b34fbL);
|
||||
private static final UUID CLIENT_CHARACTERISTIC_CONFIG_UUID = new UUID(0x290200001000L, 0x800000805f9b34fbL);
|
||||
|
||||
private static final String TAG = BluetoothConnectionManager.class.getSimpleName();
|
||||
|
||||
private final Context context;
|
||||
private final Handler handler;
|
||||
|
||||
private SensorState sensorState;
|
||||
|
||||
private BluetoothGattCallback connectCallback = new BluetoothGattCallback() {
|
||||
@@ -100,7 +104,7 @@ public class BluetoothConnectionManager {
|
||||
*
|
||||
* @param handler a handler for sending messages back to the UI activity
|
||||
*/
|
||||
public BluetoothConnectionManager(Context context, Handler handler) {
|
||||
BluetoothConnectionManager(Context context, Handler handler) {
|
||||
this.context = context;
|
||||
this.handler = handler;
|
||||
this.sensorState = SensorState.NONE;
|
||||
@@ -109,7 +113,7 @@ public class BluetoothConnectionManager {
|
||||
/**
|
||||
* Gets the sensor state.
|
||||
*/
|
||||
public synchronized SensorState getSensorState() {
|
||||
synchronized SensorState getSensorState() {
|
||||
return sensorState;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@ package de.dennisguse.opentracks.services.sensors;
|
||||
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
|
||||
public final class BluetoothLEUtils {
|
||||
final class BluetoothLEUtils {
|
||||
|
||||
private BluetoothLEUtils() {
|
||||
}
|
||||
|
||||
public static int parseHeartRate(BluetoothGattCharacteristic characteristic) {
|
||||
static int parseHeartRate(BluetoothGattCharacteristic characteristic) {
|
||||
//DOCUMENTATION https://www.bluetooth.com/specifications/gatt/characteristics/
|
||||
byte[] raw = characteristic.getValue();
|
||||
int index = ((raw[0] & 0x1) == 1) ? 2 : 1;
|
||||
|
||||
+7
-3
@@ -34,7 +34,6 @@ import de.dennisguse.opentracks.util.UnitConversions;
|
||||
|
||||
/**
|
||||
* Bluetooth sensor manager.
|
||||
* <p>
|
||||
* TODO: Handle a BluetoothGatt.STATE_DISCONNECTED
|
||||
*
|
||||
* @author Sandor Dornbush
|
||||
@@ -42,10 +41,15 @@ import de.dennisguse.opentracks.util.UnitConversions;
|
||||
public class BluetoothRemoteSensorManager extends RemoteSensorManager {
|
||||
|
||||
private static final String TAG = BluetoothConnectionManager.class.getSimpleName();
|
||||
|
||||
private static final BluetoothAdapter bluetoothAdapter = getDefaultBluetoothAdapter();
|
||||
|
||||
private final Context context;
|
||||
|
||||
private final BluetoothConnectionManager bluetoothConnectionManager;
|
||||
|
||||
private SensorDataSet sensorDataSet = null;
|
||||
|
||||
// Handler that gets information back from the bluetoothConnectionManager
|
||||
private final Handler messageHandler = new Handler(Looper.getMainLooper()) {
|
||||
@Override
|
||||
@@ -71,7 +75,7 @@ public class BluetoothRemoteSensorManager extends RemoteSensorManager {
|
||||
/**
|
||||
* @param context the context
|
||||
*/
|
||||
public BluetoothRemoteSensorManager(Context context) {
|
||||
BluetoothRemoteSensorManager(Context context) {
|
||||
this.context = context;
|
||||
bluetoothConnectionManager = new BluetoothConnectionManager(context, messageHandler);
|
||||
}
|
||||
@@ -109,7 +113,6 @@ public class BluetoothRemoteSensorManager extends RemoteSensorManager {
|
||||
|
||||
if (adapters.get(0) == null) {
|
||||
Log.w(TAG, "No bluetooth adapter found.");
|
||||
return null;
|
||||
}
|
||||
return adapters.get(0);
|
||||
}
|
||||
@@ -125,6 +128,7 @@ public class BluetoothRemoteSensorManager extends RemoteSensorManager {
|
||||
Log.w(TAG, "Bluetooth not enabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
String address = PreferencesUtils.getString(context, R.string.bluetooth_sensor_key, PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT);
|
||||
if (PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT.equals(address)) {
|
||||
Log.w(TAG, "No bluetooth address.");
|
||||
|
||||
@@ -78,13 +78,10 @@ public abstract class RemoteSensorManager {
|
||||
setUpChannel();
|
||||
}
|
||||
break;
|
||||
case NONE:
|
||||
case DISCONNECTED:
|
||||
setUpChannel();
|
||||
break;
|
||||
default:
|
||||
// CONNECTED or SENDING
|
||||
break;
|
||||
default: // NONE, CONNECTED or SENDING
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
+3
-1
@@ -26,6 +26,8 @@ import android.content.Context;
|
||||
public class RemoteSensorManagerFactory {
|
||||
|
||||
private static RemoteSensorManager remoteSensorManagerSystem = null;
|
||||
|
||||
//TODO Check if still needed? Is there a missing features?
|
||||
private static RemoteSensorManager remoteSensorManagerTemporary = null;
|
||||
|
||||
private RemoteSensorManagerFactory() {
|
||||
@@ -70,7 +72,7 @@ public class RemoteSensorManagerFactory {
|
||||
/**
|
||||
* Releases the temp sensor manager.
|
||||
*/
|
||||
public static void releaseSensorManagerTemporary() {
|
||||
private static void releaseSensorManagerTemporary() {
|
||||
if (remoteSensorManagerTemporary != null) {
|
||||
remoteSensorManagerTemporary.stopSensor();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user