forked from upstream-mirrors/OpenTracks
Update sensor settings
This commit is contained in:
@@ -161,26 +161,26 @@ limitations under the License.
|
|||||||
<item>5000</item>
|
<item>5000</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="sensor_type_all_options">
|
<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_polar</item>
|
||||||
<item>@string/settings_sensor_type_zephyr</item>
|
<item>@string/settings_sensor_type_zephyr</item>
|
||||||
|
<item>@string/settings_sensor_type_ant</item>
|
||||||
|
<item>@string/value_none</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="sensor_type_all_values">
|
<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_polar</item>
|
||||||
<item>@string/sensor_type_value_zephyr</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>
|
||||||
<string-array name="sensor_type_bluetooth_options">
|
<string-array name="sensor_type_bluetooth_options">
|
||||||
<item>@string/value_none</item>
|
|
||||||
<item>@string/settings_sensor_type_polar</item>
|
<item>@string/settings_sensor_type_polar</item>
|
||||||
<item>@string/settings_sensor_type_zephyr</item>
|
<item>@string/settings_sensor_type_zephyr</item>
|
||||||
|
<item>@string/value_none</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="sensor_type_bluetooth_values">
|
<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_polar</item>
|
||||||
<item>@string/sensor_type_value_zephyr</item>
|
<item>@string/sensor_type_value_zephyr</item>
|
||||||
|
<item>@string/sensor_type_value_none</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="track_color_mode_options">
|
<string-array name="track_color_mode_options">
|
||||||
<item>@string/settings_map_track_color_mode_single</item>
|
<item>@string/settings_map_track_color_mode_single</item>
|
||||||
|
|||||||
@@ -1968,128 +1968,111 @@ limitations under the License.
|
|||||||
|
|
||||||
<!-- Settings Sensor -->
|
<!-- Settings Sensor -->
|
||||||
<string name="settings_sensor"
|
<string name="settings_sensor"
|
||||||
translation_description="In the 'Settings' page, the option to change the sensor related
|
translation_description="In the 'Settings' page, the option to change the sensor settings.
|
||||||
settings.
|
|
||||||
|
|
||||||
Character limit: ~26 (1 line)">
|
Character limit: ~26 (1 line)">
|
||||||
Sensor
|
Sensor
|
||||||
</string>
|
</string>
|
||||||
<string name="settings_sensor_ant_options"
|
<string name="settings_sensor_ant_not_connected"
|
||||||
translation_description="In the 'Sensor' settings, the section header to configure the ANT+
|
translation_description="In the 'Sensor' settings, the summary to indicate that an ANT+ sensor
|
||||||
options. Note that ANT+ is a radio standard.
|
is not connected.">
|
||||||
|
Not connected
|
||||||
Character limit: ~26 (1 line)">
|
|
||||||
ANT+ options
|
|
||||||
</string>
|
</string>
|
||||||
<string name="settings_sensor_ant_paired"
|
<string name="settings_sensor_ant_paired"
|
||||||
translation_description="In the 'Sensor' settings, the summary to indicate the paired ANT+
|
translation_description="In the 'Sensor' settings, the summary to indicate that an ANT+ sensor
|
||||||
device. Note that ANT+ is a radio standard.
|
is paired. Note that ANT+ is a radio standard.
|
||||||
|
|
||||||
%1$d: device id number. E.g., '1'.">
|
%1$d: device id number. E.g., '1'.">
|
||||||
Paired with: %1$d
|
Paired with %1$d
|
||||||
</string>
|
</string>
|
||||||
<string name="settings_sensor_ant_reset_bike_cadence_sensor"
|
<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.
|
an ANT+ bike cadence sensor. Note that ANT+ is a radio standard.
|
||||||
|
|
||||||
Character limit: ~26 (1 line)">
|
Character limit: ~26 (1 line)">
|
||||||
Reset bike cadence
|
Reset bike cadence
|
||||||
</string>
|
</string>
|
||||||
<string name="settings_sensor_ant_reset_combined_bike_sensor"
|
<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.
|
an ANT+ combined bike cadence and speed sensor. Note that ANT+ is a radio standard.
|
||||||
|
|
||||||
Character limit: ~26 (1 line)">
|
Character limit: ~26 (1 line)">
|
||||||
Reset combined bike
|
Reset combined bike
|
||||||
</string>
|
</string>
|
||||||
<string name="settings_sensor_ant_reset_heart_rate_monitor"
|
<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.
|
an ANT+ heart rate monitor. Note that ANT+ is a radio standard.
|
||||||
|
|
||||||
Character limit: ~26 (1 line)">
|
Character limit: ~26 (1 line)">
|
||||||
Reset heart rate
|
Reset heart rate
|
||||||
</string>
|
</string>
|
||||||
<string name="settings_sensor_ant_reset_speed_distance_monitor"
|
<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
|
an ANT+ stride based speed distance monitor, also known as foot pod. Note that ANT+ is a radio
|
||||||
standard.
|
standard.
|
||||||
|
|
||||||
Character limit: ~26 (1 line)">
|
Character limit: ~26 (1 line)">
|
||||||
Reset foot pod
|
Reset foot pod
|
||||||
</string>
|
</string>
|
||||||
<string name="settings_sensor_bluetooth_options"
|
<string name="settings_sensor_bluetooth"
|
||||||
translation_description="In the 'Sensor' settings, the section header to configure the Bluetooth
|
translation_description="In the 'Sensor' settings, the section to configure the Bluetooth
|
||||||
options.
|
settings.
|
||||||
|
|
||||||
Character limit: ~26 (1 line)">
|
Character limit: ~26 (1 line)">
|
||||||
Bluetooth options
|
Bluetooth
|
||||||
</string>
|
</string>
|
||||||
<string name="settings_sensor_bluetooth_pairing"
|
<string name="settings_sensor_bluetooth_pairing"
|
||||||
translation_description="In the 'Sensor' settings, under the 'Bluetooth options' configurations,
|
translation_description="In the 'Sensor' settings, under the 'Bluetooth' section, the option to
|
||||||
the option to pair with a Bluetooth device.
|
pair with a Bluetooth sensor.
|
||||||
|
|
||||||
Character limit: ~26 (1 line)">
|
Character limit: ~26 (1 line)">
|
||||||
Bluetooth pairing
|
Bluetooth pairing
|
||||||
</string>
|
</string>
|
||||||
<string name="settings_sensor_bluetooth_pairing_summary"
|
<string name="settings_sensor_bluetooth_pairing_summary"
|
||||||
translation_description="In the 'Sensor' settings, under the 'Bluetooth options' configurations,
|
translation_description="In the 'Sensor' settings, under the 'Bluetooth' section, the summary
|
||||||
the summary for the 'Bluetooth pairing' option explaining that it will open the Android's
|
for the 'Bluetooth pairing' option explaining that it will open the Android's Bluetooth
|
||||||
Bluetooth settings to pair a device.">
|
settings to pair a sensor.">
|
||||||
Open Android\'s Bluetooth settings to pair a device.
|
Open Android\'s Bluetooth settings to pair a sensor
|
||||||
</string>
|
</string>
|
||||||
<string name="settings_sensor_bluetooth_sensor"
|
<string name="settings_sensor_bluetooth_sensor"
|
||||||
translation_description="In the 'Sensor' settings, under the 'Bluetooth options' configurations,
|
translation_description="In the 'Sensor' settings, under the 'Bluetooth' section, the picker to
|
||||||
the dropdown option to pick a Bluetooth sensor.
|
choose a Bluetooth sensor.
|
||||||
|
|
||||||
Character limit: ~23 (1 line)">
|
Character limit: ~23 (1 line)">
|
||||||
Bluetooth sensor
|
Bluetooth sensor
|
||||||
</string>
|
</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"
|
<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
|
Connected to %1$s
|
||||||
</string>
|
</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"
|
<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)">
|
Character limit: ~23 (1 line)">
|
||||||
Sensor type
|
Sensor type
|
||||||
</string>
|
</string>
|
||||||
<string name="settings_sensor_type_ant"
|
<string name="settings_sensor_type_ant"
|
||||||
translation_description="In the 'Sensor' settings, for the 'Sensor type' dropdown, the option to
|
translation_description="In the 'Sensor' settings, the option in the 'Sensor type' picker to
|
||||||
connect to an ANT+ sensor. Note that ANT+ is a radio standard.
|
choose an ANT+ sensor. Note that ANT+ is a radio standard.
|
||||||
|
|
||||||
Character limit: ~20 (1 line)">
|
Character limit: ~20 (1 line)">
|
||||||
ANT+
|
ANT+
|
||||||
</string>
|
</string>
|
||||||
<string name="settings_sensor_type_polar"
|
<string name="settings_sensor_type_polar"
|
||||||
translation_description="In the 'Sensor' settings, for the 'Sensor type' dropdown, the option to
|
translation_description="In the 'Sensor' settings, the option in the 'Sensor type' picker to
|
||||||
connect to a Polar bluetooth sensor. Do not translate Polar, the company name, but can
|
choose a Polar bluetooth sensor. Do not translate Polar, the company name, but can translate
|
||||||
translate Bluetooth, the radio standard.
|
Bluetooth, the radio standard.
|
||||||
|
|
||||||
Character limit: ~20 (1 line)">
|
Character limit: ~20 (1 line)">
|
||||||
Polar Bluetooth
|
Polar Bluetooth
|
||||||
</string>
|
</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"
|
<string name="settings_sensor_type_zephyr"
|
||||||
translation_description="In the 'Sensor' settings, for the 'Sensor type' dropdown, the option to
|
translation_description="In the 'Sensor' settings, the option in the 'Sensor type' picker to
|
||||||
connect to a Zephyr bluetooth sensor. Do not translate Zephyr, the company name, but can
|
choose a Zephyr bluetooth sensor. Do not translate Zephyr, the company name, but can translate
|
||||||
translate Bluetooth, the radio standard.
|
Bluetooth, the radio standard.
|
||||||
|
|
||||||
Character limit: ~20 (1 line)">
|
Character limit: ~20 (1 line)">
|
||||||
Zephyr Bluetooth
|
Zephyr Bluetooth
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ limitations under the License.
|
|||||||
android:title="@string/settings_sensor_type" />
|
android:title="@string/settings_sensor_type" />
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="@string/settings_sensor_bluetooth_key"
|
android:key="@string/settings_sensor_bluetooth_key"
|
||||||
android:title="@string/settings_sensor_bluetooth_options" >
|
android:title="@string/settings_sensor_bluetooth" >
|
||||||
<Preference
|
<Preference
|
||||||
android:key="@string/settings_sensor_bluetooth_pairing_key"
|
android:key="@string/settings_sensor_bluetooth_pairing_key"
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
@@ -36,7 +36,7 @@ limitations under the License.
|
|||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="@string/settings_sensor_ant_key"
|
android:key="@string/settings_sensor_ant_key"
|
||||||
android:title="@string/settings_sensor_ant_options" >
|
android:title="@string/settings_sensor_type_ant" >
|
||||||
<Preference
|
<Preference
|
||||||
android:key="@string/settings_sensor_ant_reset_heart_rate_monitor_key"
|
android:key="@string/settings_sensor_ant_reset_heart_rate_monitor_key"
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
|
|||||||
+6
-84
@@ -52,7 +52,7 @@ public class AbstractSettingsActivity extends PreferenceActivity {
|
|||||||
preferenceManager.setSharedPreferencesMode(Context.MODE_PRIVATE);
|
preferenceManager.setSharedPreferencesMode(Context.MODE_PRIVATE);
|
||||||
|
|
||||||
// Set up automatic preferences backup
|
// Set up automatic preferences backup
|
||||||
backupPreferencesListener = new BackupPreferencesListener(this);
|
backupPreferencesListener = new BackupPreferencesListener(this);
|
||||||
|
|
||||||
preferenceManager.getSharedPreferences()
|
preferenceManager.getSharedPreferences()
|
||||||
.registerOnSharedPreferenceChangeListener(backupPreferencesListener);
|
.registerOnSharedPreferenceChangeListener(backupPreferencesListener);
|
||||||
@@ -79,15 +79,15 @@ public class AbstractSettingsActivity extends PreferenceActivity {
|
|||||||
/**
|
/**
|
||||||
* Configures a list preference.
|
* Configures a list preference.
|
||||||
*
|
*
|
||||||
* @param listPreference the preference
|
* @param listPreference the list preference
|
||||||
* @param summary the summary array
|
* @param summary the summary array
|
||||||
* @param options the options array
|
* @param options the options array
|
||||||
* @param values the values array
|
* @param values the values array
|
||||||
* @param value the value
|
* @param value the value
|
||||||
* @param listener optional listener
|
* @param listener optional listener
|
||||||
*/
|
*/
|
||||||
protected void configureListPreference(ListPreference listPreference,
|
protected void configureListPreference(ListPreference listPreference, final String[] summary,
|
||||||
final String[] summary, final String[] options, final String[] values, String value,
|
final String[] options, final String[] values, String value,
|
||||||
final OnPreferenceChangeListener listener) {
|
final OnPreferenceChangeListener listener) {
|
||||||
listPreference.setEntryValues(values);
|
listPreference.setEntryValues(values);
|
||||||
listPreference.setEntries(options);
|
listPreference.setEntries(options);
|
||||||
@@ -106,95 +106,17 @@ public class AbstractSettingsActivity extends PreferenceActivity {
|
|||||||
listener.onPreferenceChange(listPreference, value);
|
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.
|
* Update the preference summary.
|
||||||
*
|
*
|
||||||
* @param preference the preference
|
* @param preference the preference
|
||||||
* @param summary the summary array
|
* @param summary the summary array
|
||||||
* @param values the value array
|
* @param values the values array
|
||||||
* @param value the value
|
* @param value the value
|
||||||
*/
|
*/
|
||||||
private void updatePreferenceSummary(
|
private void updatePreferenceSummary(
|
||||||
Preference preference, String[] summary, String[] values, String value) {
|
Preference preference, String[] summary, String[] values, String value) {
|
||||||
int index = getIndex(values, value);
|
int index = getIndex(values, value);
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
preference.setSummary(R.string.value_unknown);
|
preference.setSummary(R.string.value_unknown);
|
||||||
|
|||||||
+45
-34
@@ -49,23 +49,8 @@ public class SensorSettingsActivity extends AbstractSettingsActivity {
|
|||||||
addPreferencesFromResource(R.xml.sensor_settings);
|
addPreferencesFromResource(R.xml.sensor_settings);
|
||||||
|
|
||||||
boolean hasAntSupport = AntInterface.hasAntSupport(this);
|
boolean hasAntSupport = AntInterface.hasAntSupport(this);
|
||||||
ListPreference sensorTypeListPreference = (ListPreference) findPreference(
|
|
||||||
getString(R.string.sensor_type_key));
|
configSensorType(hasAntSupport);
|
||||||
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);
|
|
||||||
|
|
||||||
findPreference(getString(R.string.settings_sensor_bluetooth_pairing_key))
|
findPreference(getString(R.string.settings_sensor_bluetooth_pairing_key))
|
||||||
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
.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.
|
* Updates the UI based on the sensor type.
|
||||||
*
|
*
|
||||||
@@ -120,7 +130,7 @@ public class SensorSettingsActivity extends AbstractSettingsActivity {
|
|||||||
preference.setEnabled(enabled);
|
preference.setEnabled(enabled);
|
||||||
int deviceId = PreferencesUtils.getInt(this, valueKey, AntSensorManager.WILDCARD);
|
int deviceId = PreferencesUtils.getInt(this, valueKey, AntSensorManager.WILDCARD);
|
||||||
if (deviceId == AntSensorManager.WILDCARD) {
|
if (deviceId == AntSensorManager.WILDCARD) {
|
||||||
preference.setSummary(R.string.settings_sensor_not_connected);
|
preference.setSummary(R.string.settings_sensor_ant_not_connected);
|
||||||
} else {
|
} else {
|
||||||
preference.setSummary(getString(R.string.settings_sensor_ant_paired, deviceId));
|
preference.setSummary(getString(R.string.settings_sensor_ant_paired, deviceId));
|
||||||
}
|
}
|
||||||
@@ -128,7 +138,7 @@ public class SensorSettingsActivity extends AbstractSettingsActivity {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(Preference pref) {
|
public boolean onPreferenceClick(Preference pref) {
|
||||||
PreferencesUtils.setInt(SensorSettingsActivity.this, valueKey, AntSensorManager.WILDCARD);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -138,14 +148,20 @@ public class SensorSettingsActivity extends AbstractSettingsActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.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")
|
@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> optionsList = new ArrayList<String>();
|
||||||
List<String> valuesList = new ArrayList<String>();
|
List<String> valuesList = new ArrayList<String>();
|
||||||
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
@@ -155,22 +171,17 @@ public class SensorSettingsActivity extends AbstractSettingsActivity {
|
|||||||
String[] options = optionsList.toArray(new String[optionsList.size()]);
|
String[] options = optionsList.toArray(new String[optionsList.size()]);
|
||||||
String[] values = valuesList.toArray(new String[valuesList.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.size() == 1) {
|
||||||
if (!valuesList.get(0).equals(bluetoothSensorValue)) {
|
if (!valuesList.get(0).equals(value)) {
|
||||||
bluetoothSensorValue = valuesList.get(0);
|
value = valuesList.get(0);
|
||||||
PreferencesUtils.setString(this, R.string.bluetooth_sensor_key, bluetoothSensorValue);
|
PreferencesUtils.setString(this, R.string.bluetooth_sensor_key, value);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!valuesList.contains(bluetoothSensorValue)) {
|
if (!valuesList.contains(value)) {
|
||||||
bluetoothSensorValue = PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT;
|
value = PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT;
|
||||||
PreferencesUtils.setString(this, R.string.bluetooth_sensor_key, bluetoothSensorValue);
|
PreferencesUtils.setString(this, R.string.bluetooth_sensor_key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
configurePreference(bluetoothSensorListPreference, options, values,
|
configureListPreference(preference, options, options, values, value, null);
|
||||||
R.string.settings_sensor_bluetooth_sensor_summary, bluetoothSensorValue, null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user