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));
@@ -1,12 +1,12 @@
/* /*
* Copyright 2010 Google Inc. * Copyright 2010 Google Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of * use this file except in compliance with the License. You may obtain a copy of
* the License at * the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -24,7 +24,7 @@ import java.util.Set;
/** /**
* Utilities for dealing with bluetooth devices. * Utilities for dealing with bluetooth devices.
* *
* @author Rodrigo Damazio * @author Rodrigo Damazio
*/ */
public class BluetoothDeviceUtils { public class BluetoothDeviceUtils {
@@ -34,7 +34,7 @@ public class BluetoothDeviceUtils {
/** /**
* Populates the device names and the device addresses with all the suitable * Populates the device names and the device addresses with all the suitable
* bluetooth devices. * bluetooth devices.
* *
* @param bluetoothAdapter the bluetooth adapter * @param bluetoothAdapter the bluetooth adapter
* @param deviceNames list of device names * @param deviceNames list of device names
* @param deviceAddresses list of device addresses * @param deviceAddresses list of device addresses
@@ -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);