diff --git a/MyTracks/AndroidManifest.xml b/MyTracks/AndroidManifest.xml
index a60d7ea5f..6f53e9dc1 100755
--- a/MyTracks/AndroidManifest.xml
+++ b/MyTracks/AndroidManifest.xml
@@ -209,6 +209,7 @@ limitations under the License.
+
diff --git a/MyTracks/res/values/arrays_do_not_translate.xml b/MyTracks/res/values/arrays_do_not_translate.xml
index 9f62b977a..aa43cb8fb 100644
--- a/MyTracks/res/values/arrays_do_not_translate.xml
+++ b/MyTracks/res/values/arrays_do_not_translate.xml
@@ -168,24 +168,30 @@ limitations under the License.
- -50
- -100
-
- - @string/sensor_type_value_ant
- - @string/sensor_type_value_srm_ant_bridge
-
-
+
- @string/settings_sensor_type_none
- @string/settings_sensor_type_ant
- @string/settings_sensor_type_srm
- @string/settings_sensor_type_polar
- @string/settings_sensor_type_zephyr
-
+
- @string/sensor_type_value_none
- @string/sensor_type_value_ant
- @string/sensor_type_value_srm_ant_bridge
- @string/sensor_type_value_polar
- @string/sensor_type_value_zephyr
+
+ - @string/settings_sensor_type_none
+ - @string/settings_sensor_type_polar
+ - @string/settings_sensor_type_zephyr
+
+
+ - @string/sensor_type_value_none
+ - @string/sensor_type_value_polar
+ - @string/sensor_type_value_zephyr
+
- @string/settings_recording_track_name_date_local_option
- @string/settings_recording_track_name_date_iso_8601_option
diff --git a/MyTracks/res/values/keys.xml b/MyTracks/res/values/keys.xml
index 68fef8646..e7598eb0b 100644
--- a/MyTracks/res/values/keys.xml
+++ b/MyTracks/res/values/keys.xml
@@ -24,7 +24,6 @@ limitations under the License.
antSRMBridgeSensorId
autoResumeTrackCurrentRetry
autoResumeTrackTimeout
- bluetoothPairing
bluetoothSensor
defaultActivity
defaultMapPublic
@@ -60,13 +59,16 @@ limitations under the License.
trackName
- antOptions
backupToSd
resetToDefaults
restoreFromSd
- sensorOptions
settingsBackup
settingsRecording
+ settingsSensor
+ settingsSensorAnt
+ settingsSensorBluetooth
+ settingsSensorBluetoothPairing
+ settingsSensorRoot
settingsSharing
trackColorModeFixedOptions
\ No newline at end of file
diff --git a/MyTracks/res/xml/preferences.xml b/MyTracks/res/xml/preferences.xml
index a7852614e..6608193d6 100644
--- a/MyTracks/res/xml/preferences.xml
+++ b/MyTracks/res/xml/preferences.xml
@@ -86,53 +86,18 @@ limitations under the License.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/MyTracks/src/com/google/android/apps/mytracks/services/sensors/BluetoothSensorManager.java b/MyTracks/src/com/google/android/apps/mytracks/services/sensors/BluetoothSensorManager.java
index 11a4e3db1..759e4daa4 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/services/sensors/BluetoothSensorManager.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/services/sensors/BluetoothSensorManager.java
@@ -19,12 +19,12 @@ import static com.google.android.apps.mytracks.Constants.TAG;
import com.google.android.apps.mytracks.Constants;
import com.google.android.apps.mytracks.content.Sensor;
+import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.maps.mytracks.R;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
-import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
@@ -127,16 +127,20 @@ public class BluetoothSensorManager extends SensorManager {
Log.w(Constants.TAG, "Disabled manager onStartTrack");
return;
}
- SharedPreferences prefs = context.getSharedPreferences(
- Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
- String address =
- prefs.getString(context.getString(R.string.bluetooth_sensor_key), "");
- if (address == null || address.equals("")) {
+ String address = PreferencesUtils.getString(
+ context, R.string.bluetooth_sensor_key, PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT);
+ if (PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT.equals(address)) {
return;
}
Log.w(Constants.TAG, "Connecting to bluetooth sensor: " + address);
// Get the BluetoothDevice object
- BluetoothDevice device = bluetoothAdapter.getRemoteDevice(address);
+ BluetoothDevice device;
+ try {
+ device = bluetoothAdapter.getRemoteDevice(address);
+ } catch (IllegalArgumentException e) {
+ Log.d(Constants.TAG, "Invalid address " + address, e);
+ return;
+ }
// Attempt to connect to the device
connectionManager.connect(device);
diff --git a/MyTracks/src/com/google/android/apps/mytracks/services/sensors/SensorManagerFactory.java b/MyTracks/src/com/google/android/apps/mytracks/services/sensors/SensorManagerFactory.java
index 9d98410bc..c76b0bade 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/services/sensors/SensorManagerFactory.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/services/sensors/SensorManagerFactory.java
@@ -61,33 +61,35 @@ public class SensorManagerFactory {
context = context.getApplicationContext();
- String sensor = prefs.getString(context.getString(R.string.sensor_type_key), null);
- Log.i(Constants.TAG, "Creating sensor of type: " + sensor);
+ String sensorTypeValueNone = context.getString(R.string.sensor_type_value_none);
+ String sensorType = prefs.getString(
+ context.getString(R.string.sensor_type_key), sensorTypeValueNone);
+ Log.i(Constants.TAG, "Creating sensor of type: " + sensorType);
- if (sensor == null) {
+ if (sensorTypeValueNone.equals(sensorType)) {
reset();
return null;
}
- if (sensor.equals(activeSensorType)) {
+ if (sensorType.equals(activeSensorType)) {
Log.i(Constants.TAG, "Returning existing sensor manager.");
refCount++;
return activeSensorManager;
}
reset();
- if (sensor.equals(context.getString(R.string.sensor_type_value_ant))) {
+ if (sensorType.equals(context.getString(R.string.sensor_type_value_ant))) {
activeSensorManager = new AntDirectSensorManager(context);
- } else if (sensor.equals(context.getString(R.string.sensor_type_value_srm_ant_bridge))) {
+ } else if (sensorType.equals(context.getString(R.string.sensor_type_value_srm_ant_bridge))) {
activeSensorManager = new AntSrmBridgeSensorManager(context);
- } else if (sensor.equals(context.getString(R.string.sensor_type_value_zephyr))) {
+ } else if (sensorType.equals(context.getString(R.string.sensor_type_value_zephyr))) {
activeSensorManager = new ZephyrSensorManager(context);
- } else if (sensor.equals(context.getString(R.string.sensor_type_value_polar))) {
+ } else if (sensorType.equals(context.getString(R.string.sensor_type_value_polar))) {
activeSensorManager = new PolarSensorManager(context);
} else {
- Log.w(Constants.TAG, "Unable to find sensor type: " + sensor);
+ Log.w(Constants.TAG, "Unable to find sensor type: " + sensorType);
return null;
}
- activeSensorType = sensor;
+ activeSensorType = sensorType;
refCount = 1;
activeSensorManager.onStartTrack();
return activeSensorManager;
diff --git a/MyTracks/src/com/google/android/apps/mytracks/services/sensors/ant/AntDirectSensorManager.java b/MyTracks/src/com/google/android/apps/mytracks/services/sensors/ant/AntDirectSensorManager.java
index 5cf6c14ca..669c8b040 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/services/sensors/ant/AntDirectSensorManager.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/services/sensors/ant/AntDirectSensorManager.java
@@ -20,13 +20,11 @@ import static com.google.android.apps.mytracks.Constants.TAG;
import com.dsi.ant.AntDefine;
import com.dsi.ant.AntMesg;
import com.dsi.ant.exception.AntInterfaceException;
-import com.google.android.apps.mytracks.Constants;
import com.google.android.apps.mytracks.content.Sensor;
-import com.google.android.apps.mytracks.util.ApiAdapterFactory;
+import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.maps.mytracks.R;
import android.content.Context;
-import android.content.SharedPreferences;
import android.util.Log;
/**
@@ -107,11 +105,7 @@ public class AntDirectSensorManager extends AntSensorManager
}
Log.i(TAG, "Found ANT device id: " + deviceNumber + " on channel: " + channel);
- SharedPreferences prefs = context.getSharedPreferences(
- Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
- SharedPreferences.Editor editor = prefs.edit();
- editor.putInt(context.getString(sensorIdKeys[channel]), deviceNumber);
- ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
+ PreferencesUtils.setInt(context, sensorIdKeys[channel], deviceNumber);
return deviceNumber;
}
@@ -171,12 +165,8 @@ public class AntDirectSensorManager extends AntSensorManager
protected void setupAntSensorChannels() {
short devIds[] = new short[sensorIdKeys.length];
- SharedPreferences prefs = context.getSharedPreferences(
- Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
- if (prefs != null) {
- for (int i = 0; i < sensorIdKeys.length; ++i) {
- devIds[i] = (short) prefs.getInt(context.getString(sensorIdKeys[i]), WILDCARD);
- }
+ for (int i = 0; i < sensorIdKeys.length; ++i) {
+ devIds[i] = (short) PreferencesUtils.getInt(context, sensorIdKeys[i], WILDCARD);
}
sensors = new AntSensorBase[] {
diff --git a/MyTracks/src/com/google/android/apps/mytracks/services/sensors/ant/AntSrmBridgeSensorManager.java b/MyTracks/src/com/google/android/apps/mytracks/services/sensors/ant/AntSrmBridgeSensorManager.java
index 2a16fb743..3f9cb8e8c 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/services/sensors/ant/AntSrmBridgeSensorManager.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/services/sensors/ant/AntSrmBridgeSensorManager.java
@@ -22,7 +22,7 @@ import com.dsi.ant.AntMesg;
import com.dsi.ant.exception.AntInterfaceException;
import com.google.android.apps.mytracks.Constants;
import com.google.android.apps.mytracks.content.Sensor;
-import com.google.android.apps.mytracks.util.ApiAdapterFactory;
+import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.maps.mytracks.BuildConfig;
import com.google.android.maps.mytracks.R;
@@ -71,9 +71,8 @@ public class AntSrmBridgeSensorManager extends AntSensorManager {
SharedPreferences prefs = context.getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
if (prefs != null) {
- deviceNumber =
- (short) prefs.getInt(context.getString(
- R.string.ant_srm_bridge_sensor_id_key), 0);
+ deviceNumber = (short) PreferencesUtils.getInt(
+ context, R.string.ant_srm_bridge_sensor_id_key, WILDCARD);
}
Log.i(TAG, "Will pair with device: " + deviceNumber);
}
@@ -194,12 +193,7 @@ public class AntSrmBridgeSensorManager extends AntSensorManager {
AntChannelIdMessage message = new AntChannelIdMessage(rawMessage);
deviceNumber = message.getDeviceNumber();
Log.d(TAG, "Found device id: " + deviceNumber);
-
- SharedPreferences prefs = context.getSharedPreferences(
- Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
- SharedPreferences.Editor editor = prefs.edit();
- editor.putInt(context.getString(R.string.ant_srm_bridge_sensor_id_key), deviceNumber);
- ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
+ PreferencesUtils.setInt(context, R.string.ant_srm_bridge_sensor_id_key, deviceNumber);
}
private void handleMessageResponse(byte[] rawMessage) {
diff --git a/MyTracks/src/com/google/android/apps/mytracks/settings/SensorSettingsActivity.java b/MyTracks/src/com/google/android/apps/mytracks/settings/SensorSettingsActivity.java
new file mode 100644
index 000000000..88f9b14e7
--- /dev/null
+++ b/MyTracks/src/com/google/android/apps/mytracks/settings/SensorSettingsActivity.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright 2012 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
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.google.android.apps.mytracks.settings;
+
+import com.google.android.apps.mytracks.services.sensors.ant.AntUtils;
+import com.google.android.apps.mytracks.util.BluetoothDeviceUtils;
+import com.google.android.maps.mytracks.R;
+
+import android.bluetooth.BluetoothAdapter;
+import android.content.Intent;
+import android.os.Bundle;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.preference.Preference.OnPreferenceChangeListener;
+import android.preference.Preference.OnPreferenceClickListener;
+import android.preference.PreferenceScreen;
+import android.provider.Settings;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * An activity for accessing sensor settings.
+ *
+ * @author Jimmy Shih
+ */
+public class SensorSettingsActivity extends AbstractSettingsActivity {
+
+ @SuppressWarnings("deprecation")
+ @Override
+ protected void onCreate(Bundle bundle) {
+ super.onCreate(bundle);
+ addPreferencesFromResource(R.xml.sensor_settings);
+
+ ListPreference sensorTypeListPreference = (ListPreference) findPreference(
+ getString(R.string.sensor_type_key));
+ List sensorTypeEntries = Arrays.asList(getResources().getStringArray(
+ AntUtils.hasAntSupport(this) ? R.array.sensor_type_all_options
+ : R.array.sensor_type_bluetooth_options));
+ List sensorTypeEntryValues = Arrays.asList(getResources().getStringArray(
+ AntUtils.hasAntSupport(this) ? R.array.sensor_type_all_values
+ : R.array.sensor_type_bluetooth_values));
+ sensorTypeListPreference.setEntries(sensorTypeEntries.toArray(
+ new CharSequence[sensorTypeEntries.size()]));
+ sensorTypeListPreference.setEntryValues(
+ sensorTypeEntryValues.toArray(new CharSequence[sensorTypeEntryValues.size()]));
+ sensorTypeListPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ updateUiBySensorType((String) newValue);
+ return true;
+ }
+ });
+
+ updateUiBySensorType(sensorTypeListPreference.getValue());
+
+ findPreference(getString(R.string.settings_sensor_bluetooth_pairing_key))
+ .setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ public boolean onPreferenceClick(Preference preference) {
+ Intent settingsIntent = new Intent(Settings.ACTION_BLUETOOTH_SETTINGS);
+ startActivity(settingsIntent);
+ return true;
+ }
+ });
+
+ if (!AntUtils.hasAntSupport(this)) {
+ PreferenceScreen rootPreferenceScreen = (PreferenceScreen) findPreference(
+ getString(R.string.settings_sensor_root_key));
+ rootPreferenceScreen.removePreference(
+ findPreference(getString(R.string.settings_sensor_ant_key)));
+ }
+ }
+
+ /**
+ * Updates the UI based on the sensor type.
+ *
+ * @param sensorType the sensor type
+ */
+ @SuppressWarnings("deprecation")
+ private void updateUiBySensorType(String sensorType) {
+ boolean isBluetooth = getString(R.string.sensor_type_value_polar).equals(sensorType)
+ || getString(R.string.sensor_type_value_zephyr).equals(sensorType);
+ findPreference(getString(R.string.settings_sensor_bluetooth_key)).setEnabled(isBluetooth);
+
+ Preference antHeartRateSensorId = findPreference(
+ getString(R.string.ant_heart_rate_sensor_id_key));
+ if (antHeartRateSensorId != null) {
+ antHeartRateSensorId.setEnabled(getString(R.string.sensor_type_value_ant).equals(sensorType));
+ }
+
+ Preference antSrmBridgetSensorId = findPreference(
+ getString(R.string.ant_srm_bridge_sensor_id_key));
+ if (antSrmBridgetSensorId != null) {
+ antSrmBridgetSensorId.setEnabled(
+ getString(R.string.sensor_type_value_srm_ant_bridge).equals(sensorType));
+ }
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ updateBluetoothSensorListPreference();
+ }
+
+ /**
+ * Updates the bluetooth sensor list preference.
+ */
+ private void updateBluetoothSensorListPreference() {
+ @SuppressWarnings("deprecation")
+ ListPreference bluetoothSensorListPreference = (ListPreference) findPreference(
+ getString(R.string.bluetooth_sensor_key));
+ List entries = new ArrayList();
+ List entryValues = new ArrayList();
+ BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+
+ if (bluetoothAdapter != null) {
+ BluetoothDeviceUtils.populateDeviceLists(bluetoothAdapter, entries, entryValues);
+ }
+ bluetoothSensorListPreference.setEntries(entries.toArray(new CharSequence[entries.size()]));
+ bluetoothSensorListPreference.setEntryValues(entryValues.toArray(
+ new CharSequence[entryValues.size()]));
+ if (entries.size() == 1) {
+ bluetoothSensorListPreference.setValueIndex(0);
+ }
+ }
+}
diff --git a/MyTracks/src/com/google/android/apps/mytracks/settings/SettingsActivity.java b/MyTracks/src/com/google/android/apps/mytracks/settings/SettingsActivity.java
index 606b21276..4859d8a1c 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/settings/SettingsActivity.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/settings/SettingsActivity.java
@@ -19,9 +19,7 @@ package com.google.android.apps.mytracks.settings;
import static com.google.android.apps.mytracks.Constants.TAG;
import com.google.android.apps.mytracks.Constants;
-import com.google.android.apps.mytracks.services.sensors.ant.AntUtils;
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
-import com.google.android.apps.mytracks.util.BluetoothDeviceUtils;
import com.google.android.apps.mytracks.util.DialogUtils;
import com.google.android.apps.mytracks.util.IntentUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils;
@@ -29,7 +27,6 @@ import com.google.android.apps.mytracks.util.UnitConversions;
import com.google.android.maps.mytracks.R;
import android.app.Dialog;
-import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
@@ -42,16 +39,9 @@ import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceCategory;
-import android.preference.PreferenceScreen;
-import android.provider.Settings;
import android.util.Log;
import android.widget.Toast;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
/**
* An activity for accessing settings.
*
@@ -67,7 +57,6 @@ public class SettingsActivity extends AbstractSettingsActivity {
super.onCreate(bundle);
addPreferencesFromResource(R.xml.preferences);
- customizeSensorOptionsPreferences();
customizeTrackColorModePreferences();
Preference recordingPreference = findPreference(getString(R.string.settings_recording_key));
@@ -90,6 +79,16 @@ public class SettingsActivity extends AbstractSettingsActivity {
return true;
}
});
+
+ Preference sensorPreference = findPreference(getString(R.string.settings_sensor_key));
+ sensorPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ Intent intent = IntentUtils.newIntent(SettingsActivity.this, SensorSettingsActivity.class);
+ startActivity(intent);
+ return true;
+ }
+ });
Preference backupPreference = findPreference(getString(R.string.settings_backup_key));
backupPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@@ -128,53 +127,6 @@ public class SettingsActivity extends AbstractSettingsActivity {
}
}
- private void customizeSensorOptionsPreferences() {
- ListPreference sensorTypePreference =
- (ListPreference) findPreference(getString(R.string.sensor_type_key));
- sensorTypePreference.setOnPreferenceChangeListener(
- new OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(Preference preference,
- Object newValue) {
- updateSensorSettings((String) newValue);
- return true;
- }
- });
- updateSensorSettings(sensorTypePreference.getValue());
-
- if (!AntUtils.hasAntSupport(this)) {
- // The sensor options screen has a few ANT-specific options which we
- // need to remove. First, we need to remove the ANT sensor types.
- // Second, we need to remove the ANT unpairing options.
-
- Set toRemove = new HashSet();
-
- String[] antValues = getResources().getStringArray(R.array.sensor_type_ant_values);
- for (String antValue : antValues) {
- toRemove.add(sensorTypePreference.findIndexOfValue(antValue));
- }
-
- CharSequence[] entries = sensorTypePreference.getEntries();
- CharSequence[] entryValues = sensorTypePreference.getEntryValues();
-
- CharSequence[] filteredEntries = new CharSequence[entries.length - toRemove.size()];
- CharSequence[] filteredEntryValues = new CharSequence[filteredEntries.length];
- for (int i = 0, last = 0; i < entries.length; i++) {
- if (!toRemove.contains(i)) {
- filteredEntries[last] = entries[i];
- filteredEntryValues[last++] = entryValues[i];
- }
- }
-
- sensorTypePreference.setEntries(filteredEntries);
- sensorTypePreference.setEntryValues(filteredEntryValues);
-
- PreferenceScreen sensorOptionsScreen =
- (PreferenceScreen) findPreference(getString(R.string.sensor_options_key));
- sensorOptionsScreen.removePreference(findPreference(getString(R.string.ant_options_key)));
- }
- }
-
private void customizeTrackColorModePreferences() {
ListPreference trackColorModePreference =
(ListPreference) findPreference(getString(R.string.track_color_mode_key));
@@ -203,7 +155,6 @@ public class SettingsActivity extends AbstractSettingsActivity {
@Override
protected void onResume() {
super.onResume();
- configureBluetoothPreferences();
Preference resetPreference = findPreference(getString(R.string.reset_key));
boolean recording = PreferencesUtils.getLong(this, R.string.recording_track_id_key) != -1;
resetPreference.setEnabled(!recording);
@@ -212,27 +163,6 @@ public class SettingsActivity extends AbstractSettingsActivity {
: R.string.settings_reset_summary);
}
- private void updateSensorSettings(String sensorType) {
- boolean usesBluetooth =
- getString(R.string.sensor_type_value_zephyr).equals(sensorType)
- || getString(R.string.sensor_type_value_polar).equals(sensorType);
- findPreference(
- getString(R.string.bluetooth_sensor_key)).setEnabled(usesBluetooth);
- findPreference(
- getString(R.string.bluetooth_pairing_key)).setEnabled(usesBluetooth);
-
- // Update the ANT+ sensors.
- // TODO: Only enable on phones that have ANT+.
- Preference antHrm = findPreference(getString(R.string.ant_heart_rate_sensor_id_key));
- Preference antSrm = findPreference(getString(R.string.ant_srm_bridge_sensor_id_key));
- if (antHrm != null && antSrm != null) {
- antHrm
- .setEnabled(getString(R.string.sensor_type_value_ant).equals(sensorType));
- antSrm
- .setEnabled(getString(R.string.sensor_type_value_srm_ant_bridge).equals(sensorType));
- }
- }
-
private void updateTrackColorModeSettings(String trackColorMode) {
boolean usesFixedSpeed =
trackColorMode.equals(getString(R.string.display_track_color_value_fixed));
@@ -247,45 +177,6 @@ public class SettingsActivity extends AbstractSettingsActivity {
.setEnabled(usesDynamicSpeed);
}
- /**
- * Configures preference actions related to bluetooth.
- */
- private void configureBluetoothPreferences() {
- // Populate the list of bluetooth devices
- populateBluetoothDeviceList();
- // Make the pair devices preference go to the system preferences
- findPreference(getString(R.string.bluetooth_pairing_key)).setOnPreferenceClickListener(
- new OnPreferenceClickListener() {
- public boolean onPreferenceClick(Preference preference) {
- Intent settingsIntent = new Intent(Settings.ACTION_BLUETOOTH_SETTINGS);
- startActivity(settingsIntent);
- return false;
- }
- });
- }
-
- /**
- * Populates the list preference with all available bluetooth devices.
- */
- private void populateBluetoothDeviceList() {
- // Build the list of entries and their values
- List entries = new ArrayList();
- List entryValues = new ArrayList();
-
- // The actual devices
- BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
- if (bluetoothAdapter != null) {
- BluetoothDeviceUtils.populateDeviceLists(bluetoothAdapter, entries, entryValues);
- }
-
- CharSequence[] entriesArray = entries.toArray(new CharSequence[entries.size()]);
- CharSequence[] entryValuesArray = entryValues.toArray(new CharSequence[entryValues.size()]);
- ListPreference devicesPreference =
- (ListPreference) findPreference(getString(R.string.bluetooth_sensor_key));
- devicesPreference.setEntryValues(entryValuesArray);
- devicesPreference.setEntries(entriesArray);
- }
-
/** Callback for when user confirms resetting all settings. */
private void onResetPreferencesConfirmed() {
// Change preferences in a separate thread.
diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/BluetoothDeviceUtils.java b/MyTracks/src/com/google/android/apps/mytracks/util/BluetoothDeviceUtils.java
index 548d873c7..ed1631070 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/util/BluetoothDeviceUtils.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/util/BluetoothDeviceUtils.java
@@ -24,17 +24,17 @@ import java.util.Set;
/**
* Utilities for dealing with bluetooth devices.
- *
+ *
* @author Rodrigo Damazio
*/
public class BluetoothDeviceUtils {
private 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
diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/PreferencesUtils.java b/MyTracks/src/com/google/android/apps/mytracks/util/PreferencesUtils.java
index 10e4e680b..413c8ec9d 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/util/PreferencesUtils.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/util/PreferencesUtils.java
@@ -41,6 +41,7 @@ public class PreferencesUtils {
public static final int AUTO_RESUME_TRACK_TIMEOUT_DEFAULT = 10;
public static final int AUTO_RESUME_TRACK_TIMEOUT_NEVER = 0;
+ public static final String BLUETOOTH_SENSOR_DEFAULT = "";
public static final String DEFAULT_ACTIVITY_DEFAULT = "";
public static final boolean DEFAULT_MAP_PUBLIC_DEFAULT = true;
public static final int MAX_RECORDING_DISTANCE_DEFAULT = 200;
@@ -168,4 +169,19 @@ public class PreferencesUtils {
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getString(getKey(context, keyId), defaultValue);
}
+
+ /**
+ * Sets a string preference value.
+ *
+ * @param context the context
+ * @param keyId the key id
+ * @param value the value
+ */
+ public static void setString(Context context, int keyId, String value) {
+ SharedPreferences sharedPreferences = context.getSharedPreferences(
+ Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
+ Editor editor = sharedPreferences.edit();
+ editor.putString(getKey(context, keyId), value);
+ ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
+ }
}
diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/services/TrackRecordingServiceTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/services/TrackRecordingServiceTest.java
index d4557bfdf..89b00d750 100644
--- a/MyTracksTest/src/com/google/android/apps/mytracks/services/TrackRecordingServiceTest.java
+++ b/MyTracksTest/src/com/google/android/apps/mytracks/services/TrackRecordingServiceTest.java
@@ -647,14 +647,17 @@ public class TrackRecordingServiceTest extends ServiceTestCase c, int i) {
- sharedPreferences.edit()
- .putString(getContext().getString(R.string.sensor_type_key),
- getContext().getString(i))
- .apply();
+ PreferencesUtils.setString(getContext(), R.string.sensor_type_key, getContext().getString(i));
SensorManager sm = SensorManagerFactory.getInstance().getSensorManager(getContext());
assertNotNull(sm);
assertTrue(c.isInstance(sm));
diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/services/sensors/ant/AntDirectSensorManagerTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/services/sensors/ant/AntDirectSensorManagerTest.java
index ed5e2c83e..2b167e15d 100644
--- a/MyTracksTest/src/com/google/android/apps/mytracks/services/sensors/ant/AntDirectSensorManagerTest.java
+++ b/MyTracksTest/src/com/google/android/apps/mytracks/services/sensors/ant/AntDirectSensorManagerTest.java
@@ -18,6 +18,7 @@ package com.google.android.apps.mytracks.services.sensors.ant;
import com.dsi.ant.AntMesg;
import com.google.android.apps.mytracks.Constants;
import com.google.android.apps.mytracks.content.Sensor;
+import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.maps.mytracks.R;
import android.content.Context;
@@ -87,9 +88,8 @@ public class AntDirectSensorManagerTest extends AndroidTestCase {
manager.handleMessage(AntMesg.MESG_CHANNEL_ID_ID, buff);
assertEquals(43, heartRateSensor.getDeviceNumber());
- assertEquals(43,
- sharedPreferences.getInt(
- getContext().getString(R.string.ant_heart_rate_sensor_id_key), -1));
+ assertEquals(43, PreferencesUtils.getInt(
+ getContext(), R.string.ant_heart_rate_sensor_id_key, AntSensorManager.WILDCARD));
assertNull(manager.getSensorDataSet());
}