Update sensor settings

This commit is contained in:
Jimmy Shih
2013-01-17 17:41:50 -08:00
parent 7ad1c4fdf2
commit ab1d6d8582
5 changed files with 95 additions and 179 deletions
@@ -161,26 +161,26 @@ limitations under the License.
<item>5000</item>
</string-array>
<string-array name="sensor_type_all_options">
<item>@string/value_none</item>
<item>@string/settings_sensor_type_ant</item>
<item>@string/settings_sensor_type_polar</item>
<item>@string/settings_sensor_type_zephyr</item>
<item>@string/settings_sensor_type_ant</item>
<item>@string/value_none</item>
</string-array>
<string-array name="sensor_type_all_values">
<item>@string/sensor_type_value_none</item>
<item>@string/sensor_type_value_ant</item>
<item>@string/sensor_type_value_polar</item>
<item>@string/sensor_type_value_zephyr</item>
<item>@string/sensor_type_value_ant</item>
<item>@string/sensor_type_value_none</item>
</string-array>
<string-array name="sensor_type_bluetooth_options">
<item>@string/value_none</item>
<item>@string/settings_sensor_type_polar</item>
<item>@string/settings_sensor_type_zephyr</item>
<item>@string/value_none</item>
</string-array>
<string-array name="sensor_type_bluetooth_values">
<item>@string/sensor_type_value_none</item>
<item>@string/sensor_type_value_polar</item>
<item>@string/sensor_type_value_zephyr</item>
<item>@string/sensor_type_value_none</item>
</string-array>
<string-array name="track_color_mode_options">
<item>@string/settings_map_track_color_mode_single</item>
+36 -53
View File
@@ -1968,128 +1968,111 @@ limitations under the License.
<!-- Settings Sensor -->
<string name="settings_sensor"
translation_description="In the 'Settings' page, the option to change the sensor related
settings.
translation_description="In the 'Settings' page, the option to change the sensor settings.
Character limit: ~26 (1 line)">
Sensor
</string>
<string name="settings_sensor_ant_options"
translation_description="In the 'Sensor' settings, the section header to configure the ANT+
options. Note that ANT+ is a radio standard.
Character limit: ~26 (1 line)">
ANT+ options
<string name="settings_sensor_ant_not_connected"
translation_description="In the 'Sensor' settings, the summary to indicate that an ANT+ sensor
is not connected.">
Not connected
</string>
<string name="settings_sensor_ant_paired"
translation_description="In the 'Sensor' settings, the summary to indicate the paired ANT+
device. Note that ANT+ is a radio standard.
translation_description="In the 'Sensor' settings, the summary to indicate that an ANT+ sensor
is paired. Note that ANT+ is a radio standard.
%1$d: device id number. E.g., '1'.">
Paired with: %1$d
Paired with %1$d
</string>
<string name="settings_sensor_ant_reset_bike_cadence_sensor"
translation_description="In the 'Sensor' settings, under the 'ANT+ options', the option to reset
translation_description="In the 'Sensor' settings, under the 'ANT+' section, the option to reset
an ANT+ bike cadence sensor. Note that ANT+ is a radio standard.
Character limit: ~26 (1 line)">
Reset bike cadence
</string>
<string name="settings_sensor_ant_reset_combined_bike_sensor"
translation_description="In the 'Sensor' settings, under the 'ANT+ options', the option to reset
translation_description="In the 'Sensor' settings, under the 'ANT+' section, the option to reset
an ANT+ combined bike cadence and speed sensor. Note that ANT+ is a radio standard.
Character limit: ~26 (1 line)">
Reset combined bike
</string>
<string name="settings_sensor_ant_reset_heart_rate_monitor"
translation_description="In the 'Sensor' settings, under the 'ANT+ options', the option to reset
translation_description="In the 'Sensor' settings, under the 'ANT+' section, the option to reset
an ANT+ heart rate monitor. Note that ANT+ is a radio standard.
Character limit: ~26 (1 line)">
Reset heart rate
</string>
<string name="settings_sensor_ant_reset_speed_distance_monitor"
translation_description="In the 'Sensor' settings, under the 'ANT+ options', the option to reset
translation_description="In the 'Sensor' settings, under the 'ANT+' section, the option to reset
an ANT+ stride based speed distance monitor, also known as foot pod. Note that ANT+ is a radio
standard.
Character limit: ~26 (1 line)">
Reset foot pod
</string>
<string name="settings_sensor_bluetooth_options"
translation_description="In the 'Sensor' settings, the section header to configure the Bluetooth
options.
<string name="settings_sensor_bluetooth"
translation_description="In the 'Sensor' settings, the section to configure the Bluetooth
settings.
Character limit: ~26 (1 line)">
Bluetooth options
Bluetooth
</string>
<string name="settings_sensor_bluetooth_pairing"
translation_description="In the 'Sensor' settings, under the 'Bluetooth options' configurations,
the option to pair with a Bluetooth device.
translation_description="In the 'Sensor' settings, under the 'Bluetooth' section, the option to
pair with a Bluetooth sensor.
Character limit: ~26 (1 line)">
Bluetooth pairing
</string>
<string name="settings_sensor_bluetooth_pairing_summary"
translation_description="In the 'Sensor' settings, under the 'Bluetooth options' configurations,
the summary for the 'Bluetooth pairing' option explaining that it will open the Android's
Bluetooth settings to pair a device.">
Open Android\'s Bluetooth settings to pair a device.
translation_description="In the 'Sensor' settings, under the 'Bluetooth' section, the summary
for the 'Bluetooth pairing' option explaining that it will open the Android's Bluetooth
settings to pair a sensor.">
Open Android\'s Bluetooth settings to pair a sensor
</string>
<string name="settings_sensor_bluetooth_sensor"
translation_description="In the 'Sensor' settings, under the 'Bluetooth options' configurations,
the dropdown option to pick a Bluetooth sensor.
translation_description="In the 'Sensor' settings, under the 'Bluetooth' section, the picker to
choose a Bluetooth sensor.
Character limit: ~23 (1 line)">
Bluetooth sensor
</string>
<string name="settings_sensor_bluetooth_sensor_summary"
translation_description="In the 'Sensor' settings, under the 'Bluetooth options' configurations,
the summary for the 'Bluetooth sensor' dropdown option explaining it is to pick a Bluetooth
sensor to connect to.">
The Bluetooth sensor to connect to.
</string>
<string name="settings_sensor_connected"
translation_description="The message when connected to a sensor.
translation_description="A message when a sensor is connected.
%1$s: sensor name. E.g., 'polar bluetooth'.">
%1$s: sensor name. E.g., 'Polar Bluetooth'.">
Connected to %1$s
</string>
<string name="settings_sensor_not_connected"
translation_description="The message when not connected to a sensor.">
Not connected.
</string>
<string name="settings_sensor_type"
translation_description="In the 'Sensor' settings, the dropdown option to choose a sensor type.
translation_description="In the 'Sensor' settings, the picker to choose a sensor type.
Character limit: ~23 (1 line)">
Sensor type
</string>
<string name="settings_sensor_type_ant"
translation_description="In the 'Sensor' settings, for the 'Sensor type' dropdown, the option to
connect to an ANT+ sensor. Note that ANT+ is a radio standard.
translation_description="In the 'Sensor' settings, the option in the 'Sensor type' picker to
choose an ANT+ sensor. Note that ANT+ is a radio standard.
Character limit: ~20 (1 line)">
ANT+
</string>
<string name="settings_sensor_type_polar"
translation_description="In the 'Sensor' settings, for the 'Sensor type' dropdown, the option to
connect to a Polar bluetooth sensor. Do not translate Polar, the company name, but can
translate Bluetooth, the radio standard.
translation_description="In the 'Sensor' settings, the option in the 'Sensor type' picker to
choose a Polar bluetooth sensor. Do not translate Polar, the company name, but can translate
Bluetooth, the radio standard.
Character limit: ~20 (1 line)">
Polar Bluetooth
</string>
<string name="settings_sensor_type_summary"
translation_description="In the 'Sensor' settings, the summary for the 'Sensor type' option
explaining that it is to configure the type of sensor to connect to.">
The type of sensor to connect to.
</string>
<string name="settings_sensor_type_zephyr"
translation_description="In the 'Sensor' settings, for the 'Sensor type' dropdown, the option to
connect to a Zephyr bluetooth sensor. Do not translate Zephyr, the company name, but can
translate Bluetooth, the radio standard.
translation_description="In the 'Sensor' settings, the option in the 'Sensor type' picker to
choose a Zephyr bluetooth sensor. Do not translate Zephyr, the company name, but can translate
Bluetooth, the radio standard.
Character limit: ~20 (1 line)">
Zephyr Bluetooth
+2 -2
View File
@@ -23,7 +23,7 @@ limitations under the License.
android:title="@string/settings_sensor_type" />
<PreferenceCategory
android:key="@string/settings_sensor_bluetooth_key"
android:title="@string/settings_sensor_bluetooth_options" >
android:title="@string/settings_sensor_bluetooth" >
<Preference
android:key="@string/settings_sensor_bluetooth_pairing_key"
android:persistent="false"
@@ -36,7 +36,7 @@ limitations under the License.
</PreferenceCategory>
<PreferenceCategory
android:key="@string/settings_sensor_ant_key"
android:title="@string/settings_sensor_ant_options" >
android:title="@string/settings_sensor_type_ant" >
<Preference
android:key="@string/settings_sensor_ant_reset_heart_rate_monitor_key"
android:persistent="false"
@@ -52,7 +52,7 @@ public class AbstractSettingsActivity extends PreferenceActivity {
preferenceManager.setSharedPreferencesMode(Context.MODE_PRIVATE);
// Set up automatic preferences backup
backupPreferencesListener = new BackupPreferencesListener(this);
backupPreferencesListener = new BackupPreferencesListener(this);
preferenceManager.getSharedPreferences()
.registerOnSharedPreferenceChangeListener(backupPreferencesListener);
@@ -79,15 +79,15 @@ public class AbstractSettingsActivity extends PreferenceActivity {
/**
* Configures a list preference.
*
* @param listPreference the preference
* @param listPreference the list preference
* @param summary the summary array
* @param options the options array
* @param values the values array
* @param value the value
* @param listener optional listener
*/
protected void configureListPreference(ListPreference listPreference,
final String[] summary, final String[] options, final String[] values, String value,
protected void configureListPreference(ListPreference listPreference, final String[] summary,
final String[] options, final String[] values, String value,
final OnPreferenceChangeListener listener) {
listPreference.setEntryValues(values);
listPreference.setEntries(options);
@@ -106,95 +106,17 @@ public class AbstractSettingsActivity extends PreferenceActivity {
listener.onPreferenceChange(listPreference, value);
}
}
/**
* Configures a preference.
*
* @param preference the preference
* @param options the list of displayed options
* @param values the list of stored values
* @param summaryId the summary id
* @param value the stored value
* @param listener listener to invoke
*/
@Deprecated
protected void configurePreference(final Preference preference, final String[] options,
final String[] values, final int summaryId, String value,
final OnPreferenceChangeListener listener) {
if (options != null) {
((ListPreference) preference).setEntries(options);
}
if (values != null) {
((ListPreference) preference).setEntryValues(values);
}
preference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference pref, Object newValue) {
updatePreferenceSummary(pref, options, values, summaryId, (String) newValue);
if (listener != null) {
listener.onPreferenceChange(pref, newValue);
}
return true;
}
});
updatePreferenceSummary(preference, options, values, summaryId, value);
if (listener != null) {
listener.onPreferenceChange(preference, value);
}
}
/**
* Updates a preference when a stored value changes.
*
* @param preference the preference
* @param options the list of displayed options
* @param values the list of stored values
* @param summaryId the summary id
* @param value the stored value
*/
@Deprecated
private void updatePreferenceSummary(
Preference preference, String[] options, String[] values, int summaryId, String value) {
String option;
if (options != null && values != null) {
option = getOption(options, values, value);
if (option == null) {
option = getString(R.string.value_unknown);
}
} else {
option = value != null && value.length() != 0 ? value : getString(R.string.value_unknown);
}
String summary = getString(summaryId, option);
preference.setSummary(summary);
}
/**
* Gets the display option for a stored value.
*
* @param options the list of the display options
* @param values the list of the stored values
* @param value the store value
*/
@Deprecated
private String getOption(String[] options, String[] values, String value) {
for (int i = 0; i < values.length; i++) {
if (value.equals(values[i])) {
return options[i];
}
}
return null;
}
/**
* Update the preference summary.
*
* @param preference the preference
* @param summary the summary array
* @param values the value array
* @param values the values array
* @param value the value
*/
private void updatePreferenceSummary(
Preference preference, String[] summary, String[] values, String value) {
Preference preference, String[] summary, String[] values, String value) {
int index = getIndex(values, value);
if (index == -1) {
preference.setSummary(R.string.value_unknown);
@@ -49,23 +49,8 @@ public class SensorSettingsActivity extends AbstractSettingsActivity {
addPreferencesFromResource(R.xml.sensor_settings);
boolean hasAntSupport = AntInterface.hasAntSupport(this);
ListPreference sensorTypeListPreference = (ListPreference) findPreference(
getString(R.string.sensor_type_key));
String[] sensorTypeOptions = getResources().getStringArray(
hasAntSupport ? R.array.sensor_type_all_options : R.array.sensor_type_bluetooth_options);
String[] sensorTypeValues = getResources().getStringArray(
hasAntSupport ? R.array.sensor_type_all_values : R.array.sensor_type_bluetooth_values);
String sensorTypeValue = PreferencesUtils.getString(
this, R.string.sensor_type_key, PreferencesUtils.SENSOR_TYPE_DEFAULT);
OnPreferenceChangeListener listener = new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
updateUiBySensorType((String) newValue);
return true;
}
};
configurePreference(sensorTypeListPreference, sensorTypeOptions, sensorTypeValues,
R.string.settings_sensor_type_summary, sensorTypeValue, listener);
configSensorType(hasAntSupport);
findPreference(getString(R.string.settings_sensor_bluetooth_pairing_key))
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@@ -84,6 +69,31 @@ public class SensorSettingsActivity extends AbstractSettingsActivity {
}
}
private void configSensorType(boolean hasAntSupport) {
ListPreference preference = (ListPreference) findPreference(
getString(R.string.sensor_type_key));
String value = PreferencesUtils.getString(
this, R.string.sensor_type_key, PreferencesUtils.SENSOR_TYPE_DEFAULT);
String[] options = getResources().getStringArray(
hasAntSupport ? R.array.sensor_type_all_options : R.array.sensor_type_bluetooth_options);
String[] values = getResources().getStringArray(
hasAntSupport ? R.array.sensor_type_all_values : R.array.sensor_type_bluetooth_values);
if (!hasAntSupport && value.equals(R.string.sensor_type_value_ant)) {
value = PreferencesUtils.SENSOR_TYPE_DEFAULT;
PreferencesUtils.setString(this, R.string.sensor_type_key, value);
}
OnPreferenceChangeListener listener = new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference pref, Object newValue) {
updateUiBySensorType((String) newValue);
return true;
}
};
configureListPreference(preference, options, options, values, value, listener);
}
/**
* Updates the UI based on the sensor type.
*
@@ -120,7 +130,7 @@ public class SensorSettingsActivity extends AbstractSettingsActivity {
preference.setEnabled(enabled);
int deviceId = PreferencesUtils.getInt(this, valueKey, AntSensorManager.WILDCARD);
if (deviceId == AntSensorManager.WILDCARD) {
preference.setSummary(R.string.settings_sensor_not_connected);
preference.setSummary(R.string.settings_sensor_ant_not_connected);
} else {
preference.setSummary(getString(R.string.settings_sensor_ant_paired, deviceId));
}
@@ -128,7 +138,7 @@ public class SensorSettingsActivity extends AbstractSettingsActivity {
@Override
public boolean onPreferenceClick(Preference pref) {
PreferencesUtils.setInt(SensorSettingsActivity.this, valueKey, AntSensorManager.WILDCARD);
pref.setSummary(R.string.settings_sensor_not_connected);
pref.setSummary(R.string.settings_sensor_ant_not_connected);
return true;
}
});
@@ -138,14 +148,20 @@ public class SensorSettingsActivity extends AbstractSettingsActivity {
@Override
protected void onResume() {
super.onResume();
updateBluetoothSensorListPreference();
// Update each time in case the list of bluetooth sensors has changed
configBluetoothSensor();
}
/**
* Updates the bluetooth sensor list preference.
* Configures the bluetooth sensor.
*/
@SuppressWarnings("deprecation")
private void updateBluetoothSensorListPreference() {
private void configBluetoothSensor() {
ListPreference preference = (ListPreference) findPreference(
getString(R.string.bluetooth_sensor_key));
String value = PreferencesUtils.getString(
this, R.string.bluetooth_sensor_key, PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT);
List<String> optionsList = new ArrayList<String>();
List<String> valuesList = new ArrayList<String>();
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
@@ -155,22 +171,17 @@ public class SensorSettingsActivity extends AbstractSettingsActivity {
String[] options = optionsList.toArray(new String[optionsList.size()]);
String[] values = valuesList.toArray(new String[valuesList.size()]);
String bluetoothSensorValue = PreferencesUtils.getString(
this, R.string.bluetooth_sensor_key, PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT);
ListPreference bluetoothSensorListPreference = (ListPreference) findPreference(
getString(R.string.bluetooth_sensor_key));
if (valuesList.size() == 1) {
if (!valuesList.get(0).equals(bluetoothSensorValue)) {
bluetoothSensorValue = valuesList.get(0);
PreferencesUtils.setString(this, R.string.bluetooth_sensor_key, bluetoothSensorValue);
if (!valuesList.get(0).equals(value)) {
value = valuesList.get(0);
PreferencesUtils.setString(this, R.string.bluetooth_sensor_key, value);
}
} else {
if (!valuesList.contains(bluetoothSensorValue)) {
bluetoothSensorValue = PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT;
PreferencesUtils.setString(this, R.string.bluetooth_sensor_key, bluetoothSensorValue);
if (!valuesList.contains(value)) {
value = PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT;
PreferencesUtils.setString(this, R.string.bluetooth_sensor_key, value);
}
}
configurePreference(bluetoothSensorListPreference, options, values,
R.string.settings_sensor_bluetooth_sensor_summary, bluetoothSensorValue, null);
configureListPreference(preference, options, options, values, value, null);
}
}