diff --git a/src/main/java/com/google/android/apps/mytracks/services/sensors/BluetoothSensorManager.java b/src/main/java/com/google/android/apps/mytracks/services/sensors/BluetoothSensorManager.java index 26bc27fb0..c6840daf1 100644 --- a/src/main/java/com/google/android/apps/mytracks/services/sensors/BluetoothSensorManager.java +++ b/src/main/java/com/google/android/apps/mytracks/services/sensors/BluetoothSensorManager.java @@ -94,7 +94,6 @@ public class BluetoothSensorManager extends SensorManager { switch (message.what) { case BluetoothConnectionManager.MESSAGE_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; case BluetoothConnectionManager.MESSAGE_READ: if (!(message.obj instanceof SensorDataSet)) { diff --git a/src/main/java/com/google/android/apps/mytracks/settings/SensorSettingsActivity.java b/src/main/java/com/google/android/apps/mytracks/settings/SensorSettingsActivity.java index 524d049bf..346ca0b90 100644 --- a/src/main/java/com/google/android/apps/mytracks/settings/SensorSettingsActivity.java +++ b/src/main/java/com/google/android/apps/mytracks/settings/SensorSettingsActivity.java @@ -74,17 +74,10 @@ public class SensorSettingsActivity extends AbstractSettingsActivity { BluetoothDeviceUtils.populateDeviceLists(bluetoothAdapter, devicesNameList, devicesAddressList); } - //TODO Investigate why the settings are also written here? - if (devicesAddressList.size() == 1) { - if (!devicesAddressList.get(0).equals(value)) { - value = devicesAddressList.get(0); - 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); - } + // Was the previously configured device unpaired? Then forget it. + 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)); diff --git a/src/main/java/com/google/android/apps/mytracks/util/BluetoothDeviceUtils.java b/src/main/java/com/google/android/apps/mytracks/util/BluetoothDeviceUtils.java index f1db3fcb2..1feff7bbc 100644 --- a/src/main/java/com/google/android/apps/mytracks/util/BluetoothDeviceUtils.java +++ b/src/main/java/com/google/android/apps/mytracks/util/BluetoothDeviceUtils.java @@ -1,12 +1,12 @@ /* * Copyright 2010 Google Inc. - * + * * 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 * the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * 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. - * + * * @author Rodrigo Damazio */ public class BluetoothDeviceUtils { @@ -34,7 +34,7 @@ public class BluetoothDeviceUtils { /** * Populates the device names and the device addresses with all the suitable * bluetooth devices. - * + * * @param bluetoothAdapter the bluetooth adapter * @param deviceNames list of device names * @param deviceAddresses list of device addresses @@ -46,16 +46,9 @@ public class BluetoothDeviceUtils { Set pairedDevices = bluetoothAdapter.getBondedDevices(); for (BluetoothDevice device : pairedDevices) { BluetoothClass bluetoothClass = device.getBluetoothClass(); - if (bluetoothClass != null) { - //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: + if (bluetoothClass != null && (bluetoothClass.getDeviceClass() & BluetoothClass.Device.HEALTH_PULSE_RATE) != 0) { deviceAddresses.add(device.getAddress()); deviceNames.add(device.getName()); - } } } } diff --git a/src/main/java/com/google/android/apps/mytracks/util/StatsUtils.java b/src/main/java/com/google/android/apps/mytracks/util/StatsUtils.java index f7c4b34dd..ef5d0de27 100644 --- a/src/main/java/com/google/android/apps/mytracks/util/StatsUtils.java +++ b/src/main/java/com/google/android/apps/mytracks/util/StatsUtils.java @@ -97,7 +97,11 @@ public class StatsUtils { public static void setSensorData(Context context, Activity activity, SensorDataSet sensorDataSet, boolean isRecording) { { // 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 viewSensor = getView(activity, null, R.id.stats_sensor_heart_rate_sensor);