TrackDetailActivity: only show heart rate if sensor is configured.

This commit is contained in:
Dennis Guse
2019-07-20 16:14:56 +02:00
parent 70eea7baea
commit 89a6b56a61
4 changed files with 15 additions and 26 deletions
@@ -94,7 +94,6 @@ public class BluetoothSensorManager extends SensorManager {
switch (message.what) { switch (message.what) {
case BluetoothConnectionManager.MESSAGE_DEVICE_NAME: case BluetoothConnectionManager.MESSAGE_DEVICE_NAME:
String deviceName = message.getData().getString(BluetoothConnectionManager.KEY_DEVICE_NAME); String deviceName = message.getData().getString(BluetoothConnectionManager.KEY_DEVICE_NAME);
Toast.makeText(context, context.getString(R.string.settings_sensor_connected, deviceName), Toast.LENGTH_LONG).show();
break; break;
case BluetoothConnectionManager.MESSAGE_READ: case BluetoothConnectionManager.MESSAGE_READ:
if (!(message.obj instanceof SensorDataSet)) { if (!(message.obj instanceof SensorDataSet)) {
@@ -74,17 +74,10 @@ public class SensorSettingsActivity extends AbstractSettingsActivity {
BluetoothDeviceUtils.populateDeviceLists(bluetoothAdapter, devicesNameList, devicesAddressList); BluetoothDeviceUtils.populateDeviceLists(bluetoothAdapter, devicesNameList, devicesAddressList);
} }
//TODO Investigate why the settings are also written here? // Was the previously configured device unpaired? Then forget it.
if (devicesAddressList.size() == 1) { if (!devicesAddressList.contains(value)) {
if (!devicesAddressList.get(0).equals(value)) { value = PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT;
value = devicesAddressList.get(0); PreferencesUtils.setString(this, R.string.bluetooth_sensor_key, value);
PreferencesUtils.setString(this, R.string.bluetooth_sensor_key, value);
}
} else {
if (!devicesAddressList.contains(value)) {
value = PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT;
PreferencesUtils.setString(this, R.string.bluetooth_sensor_key, value);
}
} }
devicesNameList.add(0, getString(R.string.value_none)); devicesNameList.add(0, getString(R.string.value_none));
@@ -46,16 +46,9 @@ public class BluetoothDeviceUtils {
Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices(); Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
for (BluetoothDevice device : pairedDevices) { for (BluetoothDevice device : pairedDevices) {
BluetoothClass bluetoothClass = device.getBluetoothClass(); BluetoothClass bluetoothClass = device.getBluetoothClass();
if (bluetoothClass != null) { if (bluetoothClass != null && (bluetoothClass.getDeviceClass() & BluetoothClass.Device.HEALTH_PULSE_RATE) != 0) {
//TODO Not really sure what we want, but I know what we don't want.
switch (bluetoothClass.getMajorDeviceClass()) {
case BluetoothClass.Device.Major.COMPUTER:
case BluetoothClass.Device.Major.PHONE:
break;
default:
deviceAddresses.add(device.getAddress()); deviceAddresses.add(device.getAddress());
deviceNames.add(device.getName()); deviceNames.add(device.getName());
}
} }
} }
} }
@@ -97,7 +97,11 @@ public class StatsUtils {
public static void setSensorData(Context context, Activity activity, SensorDataSet sensorDataSet, boolean isRecording) { public static void setSensorData(Context context, Activity activity, SensorDataSet sensorDataSet, boolean isRecording) {
{ {
// SensorDataSet: heart rate // SensorDataSet: heart rate
getView(activity, null, R.id.stats_sensor_container).setVisibility(isRecording ? View.VISIBLE : View.INVISIBLE); int isVisible = View.VISIBLE;
if (!isRecording || PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT.equals(PreferencesUtils.getString(context, R.string.bluetooth_sensor_key, PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT))) {
isVisible = View.INVISIBLE;
}
getView(activity, null, R.id.stats_sensor_container).setVisibility(isVisible);
View viewValue = getView(activity, null, R.id.stats_sensor_heart_rate_value); View viewValue = getView(activity, null, R.id.stats_sensor_heart_rate_value);
View viewSensor = getView(activity, null, R.id.stats_sensor_heart_rate_sensor); View viewSensor = getView(activity, null, R.id.stats_sensor_heart_rate_sensor);