forked from upstream-mirrors/OpenTracks
Move handling of sensor removal (from settings) in BluetoothConnectionManager.BluetoothConnectionManager.
This commit is contained in:
@@ -28,21 +28,11 @@ public final class SensorDataSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void set(SensorData data) {
|
public void set(SensorData data) {
|
||||||
if (data instanceof SensorDataHeartRate) {
|
set(data, data);
|
||||||
this.heartRate = (SensorDataHeartRate) data;
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data instanceof SensorDataCycling.Cadence) {
|
public void remove(SensorData type) {
|
||||||
this.cyclingCadence = (SensorDataCycling.Cadence) data;
|
set(type, null);
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (data instanceof SensorDataCycling.Speed) {
|
|
||||||
this.cyclingSpeed = (SensorDataCycling.Speed) data;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
@@ -72,4 +62,22 @@ public final class SensorDataSet {
|
|||||||
+ (getCyclingCadence() != null ? " " + getCyclingCadence() : "")
|
+ (getCyclingCadence() != null ? " " + getCyclingCadence() : "")
|
||||||
+ (getCyclingSpeed() != null ? " " + getCyclingSpeed() : "");
|
+ (getCyclingSpeed() != null ? " " + getCyclingSpeed() : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void set(SensorData type, SensorData data) {
|
||||||
|
if (type instanceof SensorDataHeartRate) {
|
||||||
|
this.heartRate = (SensorDataHeartRate) data;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type instanceof SensorDataCycling.Cadence) {
|
||||||
|
this.cyclingCadence = (SensorDataCycling.Cadence) data;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (type instanceof SensorDataCycling.Speed) {
|
||||||
|
this.cyclingSpeed = (SensorDataCycling.Speed) data;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -418,10 +418,7 @@ public class StatisticsRecordingFragment extends Fragment implements TrackDataLi
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setHeartRateSensorData(SensorDataSet sensorDataSet) {
|
private void setHeartRateSensorData(SensorDataSet sensorDataSet) {
|
||||||
int isVisible = View.VISIBLE;
|
int isVisible = sensorDataSet != null ? View.VISIBLE : View.GONE;
|
||||||
if (PreferencesUtils.isBluetoothHeartRateSensorAddressNone(getContext())) {
|
|
||||||
isVisible = View.GONE;
|
|
||||||
}
|
|
||||||
heartRateGroup.setVisibility(isVisible);
|
heartRateGroup.setVisibility(isVisible);
|
||||||
setVisibilitySensorHorizontalLine();
|
setVisibilitySensorHorizontalLine();
|
||||||
|
|
||||||
@@ -441,10 +438,7 @@ public class StatisticsRecordingFragment extends Fragment implements TrackDataLi
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setCadenceSensorData(SensorDataSet sensorDataSet) {
|
private void setCadenceSensorData(SensorDataSet sensorDataSet) {
|
||||||
int isVisible = View.VISIBLE;
|
int isVisible = sensorDataSet != null ? View.VISIBLE : View.GONE;
|
||||||
if (PreferencesUtils.isBluetoothCyclingCadenceSensorAddressNone(getContext())) {
|
|
||||||
isVisible = View.GONE;
|
|
||||||
}
|
|
||||||
cadenceGroup.setVisibility(isVisible);
|
cadenceGroup.setVisibility(isVisible);
|
||||||
setVisibilitySensorHorizontalLine();
|
setVisibilitySensorHorizontalLine();
|
||||||
|
|
||||||
@@ -522,13 +516,8 @@ public class StatisticsRecordingFragment extends Fragment implements TrackDataLi
|
|||||||
|
|
||||||
// Set activity type
|
// Set activity type
|
||||||
{
|
{
|
||||||
activityLabel.setVisibility(trackIconValue != null ? View.VISIBLE : View.GONE);
|
|
||||||
|
|
||||||
activitySpinner.setVisibility(trackIconValue != null ? View.VISIBLE : View.GONE);
|
|
||||||
activitySpinner.setEnabled(isRecording);
|
activitySpinner.setEnabled(isRecording);
|
||||||
if (trackIconValue != null) {
|
TrackIconUtils.setIconSpinner(activitySpinner, trackIconValue);
|
||||||
TrackIconUtils.setIconSpinner(activitySpinner, trackIconValue);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set time
|
// Set time
|
||||||
|
|||||||
+8
-5
@@ -118,7 +118,7 @@ public abstract class BluetoothConnectionManager {
|
|||||||
Log.d(TAG, "Connecting to: " + device);
|
Log.d(TAG, "Connecting to: " + device);
|
||||||
|
|
||||||
bluetoothGatt = device.connectGatt(context, true, connectCallback);
|
bluetoothGatt = device.connectGatt(context, true, connectCallback);
|
||||||
SensorData sensorData = createPreConnectSensorData(bluetoothGatt.getDevice().getAddress());
|
SensorData sensorData = createEmptySensorData(bluetoothGatt.getDevice().getAddress());
|
||||||
observer.onChanged(sensorData);
|
observer.onChanged(sensorData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,6 +128,8 @@ public abstract class BluetoothConnectionManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bluetoothGatt.close();
|
bluetoothGatt.close();
|
||||||
|
observer.onDisconnecting(createEmptySensorData(bluetoothGatt.getDevice().getAddress()));
|
||||||
|
|
||||||
bluetoothGatt = null;
|
bluetoothGatt = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +141,7 @@ public abstract class BluetoothConnectionManager {
|
|||||||
return address.equals(bluetoothGatt.getDevice().getAddress());
|
return address.equals(bluetoothGatt.getDevice().getAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract SensorData createPreConnectSensorData(String address);
|
protected abstract SensorData createEmptySensorData(String address);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return null if data could not be parsed.
|
* @return null if data could not be parsed.
|
||||||
@@ -153,7 +155,7 @@ public abstract class BluetoothConnectionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SensorData createPreConnectSensorData(String address) {
|
protected SensorData createEmptySensorData(String address) {
|
||||||
return new SensorDataHeartRate(address);
|
return new SensorDataHeartRate(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +174,7 @@ public abstract class BluetoothConnectionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SensorData createPreConnectSensorData(String address) {
|
protected SensorData createEmptySensorData(String address) {
|
||||||
return new SensorDataCycling.Cadence(address);
|
return new SensorDataCycling.Cadence(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,7 +205,7 @@ public abstract class BluetoothConnectionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SensorData createPreConnectSensorData(String address) {
|
protected SensorData createEmptySensorData(String address) {
|
||||||
return new SensorDataCycling.Speed(address);
|
return new SensorDataCycling.Speed(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,5 +223,6 @@ public abstract class BluetoothConnectionManager {
|
|||||||
|
|
||||||
void onChanged(SensorData sensorData);
|
void onChanged(SensorData sensorData);
|
||||||
|
|
||||||
|
void onDisconnecting(SensorData sensorData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -121,6 +121,7 @@ public class BluetoothRemoteSensorManager implements BluetoothConnectionManager.
|
|||||||
|
|
||||||
if (PreferencesUtils.isBluetoothSensorAddressNone(context, address)) {
|
if (PreferencesUtils.isBluetoothSensorAddressNone(context, address)) {
|
||||||
Log.w(TAG, "No Bluetooth address.");
|
Log.w(TAG, "No Bluetooth address.");
|
||||||
|
connectionManager.disconnect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,4 +169,9 @@ public class BluetoothRemoteSensorManager implements BluetoothConnectionManager.
|
|||||||
|
|
||||||
sensorDataSet.set(sensorData);
|
sensorDataSet.set(sensorData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisconnecting(SensorData sensorData) {
|
||||||
|
sensorDataSet.remove(sensorData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -245,29 +245,14 @@ public class PreferencesUtils {
|
|||||||
return getBluetoothSensorAddressNone(context).equals(currentValue);
|
return getBluetoothSensorAddressNone(context).equals(currentValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static boolean isBluetoothHeartRateSensorAddressNone(Context context) {
|
|
||||||
return isBluetoothSensorAddressNone(context, getBluetoothHeartRateSensorAddress(context));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getBluetoothHeartRateSensorAddress(Context context) {
|
public static String getBluetoothHeartRateSensorAddress(Context context) {
|
||||||
return getString(context, R.string.settings_sensor_bluetooth_heart_rate_key, getBluetoothSensorAddressNone(context));
|
return getString(context, R.string.settings_sensor_bluetooth_heart_rate_key, getBluetoothSensorAddressNone(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static boolean isBluetoothCyclingCadenceSensorAddressNone(Context context) {
|
|
||||||
return isBluetoothSensorAddressNone(context, getBluetoothCyclingCadenceSensorAddress(context));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getBluetoothCyclingCadenceSensorAddress(Context context) {
|
public static String getBluetoothCyclingCadenceSensorAddress(Context context) {
|
||||||
return getString(context, R.string.settings_sensor_bluetooth_cycling_cadence_key, getBluetoothSensorAddressNone(context));
|
return getString(context, R.string.settings_sensor_bluetooth_cycling_cadence_key, getBluetoothSensorAddressNone(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static boolean isBluetoothCyclingSpeedSensorAddressNone(Context context) {
|
|
||||||
return isBluetoothSensorAddressNone(context, getBluetoothCyclingSpeedSensorAddress(context));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getBluetoothCyclingSpeedSensorAddress(Context context) {
|
public static String getBluetoothCyclingSpeedSensorAddress(Context context) {
|
||||||
return getString(context, R.string.settings_sensor_bluetooth_cycling_speed_key, getBluetoothSensorAddressNone(context));
|
return getString(context, R.string.settings_sensor_bluetooth_cycling_speed_key, getBluetoothSensorAddressNone(context));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user