forked from upstream-mirrors/OpenTracks
PreferenceList: let summary be set by Android.
Some preferences used customized summaries - these were also removed.
This commit is contained in:
@@ -66,50 +66,29 @@ public class AbstractSettingsActivity extends PreferenceActivity {
|
||||
* Configures a list 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[] options, final String[] values, String value,
|
||||
final OnPreferenceChangeListener listener) {
|
||||
listPreference.setEntryValues(values);
|
||||
listPreference.setEntries(options);
|
||||
listPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference pref, Object newValue) {
|
||||
updatePreferenceSummary(pref, summary, values, (String) newValue);
|
||||
if (listener != null) {
|
||||
listener.onPreferenceChange(pref, newValue);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
updatePreferenceSummary(listPreference, summary, values, value);
|
||||
if (listener != null) {
|
||||
listener.onPreferenceChange(listPreference, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the preference summary.
|
||||
*
|
||||
* @param preference the preference
|
||||
* @param summary the summary array
|
||||
* @param values the values array
|
||||
* @param value the value
|
||||
*/
|
||||
private void updatePreferenceSummary(Preference preference, String[] summary, String[] values, String value) {
|
||||
int index = getIndex(values, value);
|
||||
if (index == -1) {
|
||||
preference.setSummary(R.string.value_unknown);
|
||||
} else {
|
||||
preference.setSummary(summary[index]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array index for a value.
|
||||
*
|
||||
|
||||
@@ -60,6 +60,6 @@ public class ChartSettingsActivity extends AbstractSettingsActivity {
|
||||
this, R.string.chart_x_axis_key, PreferencesUtils.CHART_X_AXIS_DEFAULT);
|
||||
String[] values = getResources().getStringArray(R.array.chart_x_axis_values);
|
||||
String[] options = getResources().getStringArray(R.array.chart_x_axis_options);
|
||||
configureListPreference(listPreference, options, options, values, value, null);
|
||||
configureListPreference(listPreference, options, values, value, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ public class RecordingSettingsActivity extends AbstractSettingsActivity
|
||||
int value = PreferencesUtils.getInt(this, key, defaultValue);
|
||||
String[] values = getResources().getStringArray(valueArray);
|
||||
String[] options = StringUtils.getFrequencyOptions(this, metricUnits);
|
||||
configureListPreference(preference, options, options, values, String.valueOf(value), null);
|
||||
configureListPreference(preference, options, values, String.valueOf(value), null);
|
||||
}
|
||||
|
||||
private void configTrackName() {
|
||||
@@ -95,7 +95,7 @@ public class RecordingSettingsActivity extends AbstractSettingsActivity
|
||||
this, R.string.track_name_key, PreferencesUtils.TRACK_NAME_DEFAULT);
|
||||
String[] values = getResources().getStringArray(R.array.track_name_values);
|
||||
String[] options = getResources().getStringArray(R.array.track_name_options);
|
||||
configureListPreference(preference, options, options, values, value, null);
|
||||
configureListPreference(preference, options, values, value, null);
|
||||
}
|
||||
|
||||
private void configDefaultActivity() {
|
||||
@@ -146,7 +146,7 @@ public class RecordingSettingsActivity extends AbstractSettingsActivity
|
||||
default:
|
||||
return;
|
||||
}
|
||||
configureListPreference(preference, summary, options, values, String.valueOf(value), null);
|
||||
configureListPreference(preference, options, values, String.valueOf(value), null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -319,8 +319,7 @@ public class RecordingSettingsActivity extends AbstractSettingsActivity
|
||||
* @param options the options
|
||||
* @param values the values
|
||||
*/
|
||||
private void setAutoResumeTrackTimeoutSummaryAndOptions(
|
||||
String[] summary, String[] options, String[] values) {
|
||||
private void setAutoResumeTrackTimeoutSummaryAndOptions(String[] summary, String[] options, String[] values) {
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
int value = Integer.parseInt(values[i]);
|
||||
switch (value) {
|
||||
|
||||
@@ -85,6 +85,6 @@ public class SensorSettingsActivity extends AbstractSettingsActivity {
|
||||
|
||||
String[] options = devicesNameList.toArray(new String[0]);
|
||||
String[] values = devicesAddressList.toArray(new String[0]);
|
||||
configureListPreference(preference, options, options, values, value, null);
|
||||
configureListPreference(preference, options, values, value, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class StatsSettingsActivity extends AbstractSettingsActivity {
|
||||
this, R.string.stats_units_key, PreferencesUtils.STATS_UNITS_DEFAULT);
|
||||
String[] values = getResources().getStringArray(R.array.stats_units_values);
|
||||
String[] options = getResources().getStringArray(R.array.stats_units_options);
|
||||
configureListPreference(listPreference, options, options, values, value, listener);
|
||||
configureListPreference(listPreference, options, values, value, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,6 +78,6 @@ public class StatsSettingsActivity extends AbstractSettingsActivity {
|
||||
String[] values = getResources().getStringArray(R.array.stats_rate_values);
|
||||
String[] options = getResources().getStringArray(
|
||||
metricUnits ? R.array.stats_rate_metric_options : R.array.stats_rate_imperial_options);
|
||||
configureListPreference(listPreference, options, options, values, value, null);
|
||||
configureListPreference(listPreference, options, values, value, null);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user