forked from upstream-mirrors/OpenTracks
Update sensor settings to include current value in the summary.
This commit is contained in:
@@ -18,17 +18,14 @@ limitations under the License.
|
||||
android:title="@string/settings_recording" >
|
||||
<com.google.android.apps.mytracks.IntegerListPreference
|
||||
android:defaultValue="0"
|
||||
android:entryValues="@array/frequency_values"
|
||||
android:key="@string/voice_frequency_key"
|
||||
android:title="@string/menu_voice_frequency" />
|
||||
<com.google.android.apps.mytracks.IntegerListPreference
|
||||
android:defaultValue="0"
|
||||
android:entryValues="@array/frequency_values"
|
||||
android:key="@string/split_frequency_key"
|
||||
android:title="@string/menu_split_frequency" />
|
||||
<ListPreference
|
||||
android:defaultValue="@string/settings_recording_track_name_location_value"
|
||||
android:entryValues="@array/track_name_values"
|
||||
android:key="@string/track_name_key"
|
||||
android:title="@string/settings_recording_track_name_title" />
|
||||
<com.google.android.apps.mytracks.AutoCompleteTextPreference
|
||||
@@ -38,27 +35,22 @@ limitations under the License.
|
||||
android:title="@string/settings_recording_default_activity_title" />
|
||||
<com.google.android.apps.mytracks.IntegerListPreference
|
||||
android:defaultValue="0"
|
||||
android:entryValues="@array/min_recording_interval_values"
|
||||
android:key="@string/min_recording_interval_key"
|
||||
android:title="@string/settings_recording_min_recording_interval_title" />
|
||||
<com.google.android.apps.mytracks.IntegerListPreference
|
||||
android:defaultValue="5"
|
||||
android:entryValues="@array/min_recording_distance_values"
|
||||
android:key="@string/min_recording_distance_key"
|
||||
android:title="@string/settings_recording_min_recording_distance_title" />
|
||||
<com.google.android.apps.mytracks.IntegerListPreference
|
||||
android:defaultValue="200"
|
||||
android:entryValues="@array/max_recording_distance_values"
|
||||
android:key="@string/max_recording_distance_key"
|
||||
android:title="@string/settings_recording_max_recording_distance_title" />
|
||||
<com.google.android.apps.mytracks.IntegerListPreference
|
||||
android:defaultValue="200"
|
||||
android:entryValues="@array/min_required_accuracy_values"
|
||||
android:key="@string/min_required_accuracy_key"
|
||||
android:title="@string/settings_recording_min_required_accuracy_title" />
|
||||
<com.google.android.apps.mytracks.IntegerListPreference
|
||||
android:defaultValue="10"
|
||||
android:entryValues="@array/auto_resume_track_timeout_values"
|
||||
android:key="@string/auto_resume_track_timeout_key"
|
||||
android:title="@string/settings_recording_auto_resume_track_timeout_title" />
|
||||
</PreferenceScreen>
|
||||
@@ -20,7 +20,6 @@ limitations under the License.
|
||||
<ListPreference
|
||||
android:defaultValue="@string/sensor_type_value_none"
|
||||
android:key="@string/sensor_type_key"
|
||||
android:summary="@string/settings_sensor_type_summary"
|
||||
android:title="@string/settings_sensor_type" />
|
||||
<PreferenceCategory
|
||||
android:key="@string/settings_sensor_bluetooth_key"
|
||||
@@ -33,7 +32,6 @@ limitations under the License.
|
||||
<ListPreference
|
||||
android:defaultValue=""
|
||||
android:key="@string/bluetooth_sensor_key"
|
||||
android:summary="@string/settings_sensor_bluetooth_sensor_summary"
|
||||
android:title="@string/settings_sensor_bluetooth_sensor" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
|
||||
@@ -316,9 +316,9 @@ public class TrackDetailActivity extends AbstractMyTracksActivity implements Del
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
String sensorTypeValueNone = getString(R.string.sensor_type_value_none);
|
||||
boolean showSensorState = !sensorTypeValueNone.equals(
|
||||
PreferencesUtils.getString(this, R.string.sensor_type_key, sensorTypeValueNone));
|
||||
boolean showSensorState = !PreferencesUtils.SENSOR_TYPE_DEFAULT.equals(
|
||||
PreferencesUtils.getString(
|
||||
this, R.string.sensor_type_key, PreferencesUtils.SENSOR_TYPE_DEFAULT));
|
||||
menu.findItem(R.id.track_detail_sensor_state).setVisible(showSensorState);
|
||||
return super.onPrepareOptionsMenu(menu);
|
||||
}
|
||||
|
||||
+1
-2
@@ -93,9 +93,8 @@ public class SensorManagerFactory {
|
||||
* @param context the context
|
||||
*/
|
||||
private static SensorManager getSensorManager(Context context, boolean sendPageViews) {
|
||||
String sensorTypeValueNone = context.getString(R.string.sensor_type_value_none);
|
||||
String sensorType = PreferencesUtils.getString(
|
||||
context, R.string.sensor_type_key, sensorTypeValueNone);
|
||||
context, R.string.sensor_type_key, PreferencesUtils.SENSOR_TYPE_DEFAULT);
|
||||
|
||||
if (sensorType.equals(context.getString(R.string.sensor_type_value_ant))) {
|
||||
if (sendPageViews) {
|
||||
|
||||
@@ -19,9 +19,13 @@ package com.google.android.apps.mytracks.settings;
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.apps.mytracks.io.backup.BackupPreferencesListener;
|
||||
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.Preference.OnPreferenceChangeListener;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.speech.tts.TextToSpeech;
|
||||
@@ -71,4 +75,94 @@ public class AbstractSettingsActivity extends PreferenceActivity {
|
||||
preferenceManager.getSharedPreferences()
|
||||
.unregisterOnSharedPreferenceChangeListener(backupPreferencesListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
protected void configurePreference(final Preference preference, final String[] options,
|
||||
final String[] values, final int summaryId, String value) {
|
||||
configurePreference(preference, options, values, summaryId, value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
private void updatePreferenceSummary(
|
||||
Preference preference, String[] options, String[] values, int summaryId, String value) {
|
||||
String summary = getString(summaryId);
|
||||
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);
|
||||
}
|
||||
summary += "\n" + 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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,52 +123,6 @@ public class RecordingSettingsActivity extends AbstractSettingsActivity {
|
||||
String.valueOf(autoResumeTrackTimeoutValue));
|
||||
}
|
||||
|
||||
private void configurePreference(final Preference preference, final String[] options,
|
||||
final String[] values, final int summaryId, String value) {
|
||||
if (options != null) {
|
||||
((ListPreference) preference).setEntries(options);
|
||||
}
|
||||
preference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference pref, Object newValue) {
|
||||
updatePreferenceSummary(pref, options, values, summaryId, (String) newValue);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
updatePreferenceSummary(preference, options, values, summaryId, value);
|
||||
}
|
||||
|
||||
private void updatePreferenceSummary(
|
||||
Preference listPreference, String[] options, String[] values, int summaryId, String value) {
|
||||
String summary = getString(summaryId);
|
||||
String option;
|
||||
if (options != null && values != null) {
|
||||
option = getOption(options, values, value);
|
||||
} else {
|
||||
option = value != null && value.length() != 0 ? value : getString(R.string.value_unknown);
|
||||
}
|
||||
if (option != null) {
|
||||
summary += "\n" + option;
|
||||
}
|
||||
listPreference.setSummary(summary);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the display option for a stored value.
|
||||
*
|
||||
* @param options list of the display options
|
||||
* @param values list of the stored values
|
||||
* @param value the store value
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the min recording interval display options.
|
||||
*/
|
||||
|
||||
+34
-28
@@ -33,7 +33,6 @@ import android.preference.PreferenceScreen;
|
||||
import android.provider.Settings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -52,25 +51,21 @@ public class SensorSettingsActivity extends AbstractSettingsActivity {
|
||||
boolean hasAntSupport = AntInterface.hasAntSupport(this);
|
||||
ListPreference sensorTypeListPreference = (ListPreference) findPreference(
|
||||
getString(R.string.sensor_type_key));
|
||||
List<String> sensorTypeEntries = Arrays.asList(getResources().getStringArray(
|
||||
hasAntSupport ? R.array.sensor_type_all_options
|
||||
: R.array.sensor_type_bluetooth_options));
|
||||
List<String> sensorTypeEntryValues = Arrays.asList(getResources().getStringArray(
|
||||
hasAntSupport ? 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() {
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
||||
updateUiBySensorType(sensorTypeListPreference.getValue());
|
||||
};
|
||||
configurePreference(sensorTypeListPreference, sensorTypeOptions, sensorTypeValues,
|
||||
R.string.settings_sensor_type_summary, sensorTypeValue, listener);
|
||||
|
||||
findPreference(getString(R.string.settings_sensor_bluetooth_pairing_key))
|
||||
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||
@@ -110,7 +105,7 @@ public class SensorSettingsActivity extends AbstractSettingsActivity {
|
||||
updateAntSensor(R.string.settings_sensor_ant_reset_combined_bike_sensor_key,
|
||||
R.string.ant_combined_bike_sensor_id_key, isAnt);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates an ant sensor.
|
||||
*
|
||||
@@ -151,20 +146,31 @@ public class SensorSettingsActivity extends AbstractSettingsActivity {
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private void updateBluetoothSensorListPreference() {
|
||||
List<String> optionsList = new ArrayList<String>();
|
||||
List<String> valuesList = new ArrayList<String>();
|
||||
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if (bluetoothAdapter != null) {
|
||||
BluetoothDeviceUtils.populateDeviceLists(bluetoothAdapter, optionsList, valuesList);
|
||||
}
|
||||
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));
|
||||
List<String> entries = new ArrayList<String>();
|
||||
List<String> entryValues = new ArrayList<String>();
|
||||
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);
|
||||
if (valuesList.size() == 1) {
|
||||
if (!valuesList.get(0).equals(bluetoothSensorValue)) {
|
||||
bluetoothSensorValue = valuesList.get(0);
|
||||
PreferencesUtils.setString(this, R.string.bluetooth_sensor_key, bluetoothSensorValue);
|
||||
}
|
||||
} else {
|
||||
if (!valuesList.contains(bluetoothSensorValue)) {
|
||||
bluetoothSensorValue = PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT;
|
||||
PreferencesUtils.setString(this, R.string.bluetooth_sensor_key, bluetoothSensorValue);
|
||||
}
|
||||
}
|
||||
configurePreference(bluetoothSensorListPreference, options, values,
|
||||
R.string.settings_sensor_bluetooth_sensor_summary, bluetoothSensorValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +73,9 @@ public class PreferencesUtils {
|
||||
public static final boolean SEND_TO_DOCS_DEFAULT = true;
|
||||
public static final boolean SEND_TO_FUSION_TABLES_DEFAULT = true;
|
||||
public static final boolean SEND_TO_MAPS_DEFAULT = true;
|
||||
|
||||
public static final String SENSOR_TYPE_DEFAULT = "NONE";
|
||||
|
||||
public static final boolean SHOW_CONFIRM_SHARING_DIALOG_DEFAULT = true;
|
||||
public static final int SPLIT_FREQUENCY_DEFAULT = 0;
|
||||
|
||||
@@ -84,7 +87,7 @@ public class PreferencesUtils {
|
||||
public static final int TRACK_COLOR_MODE_MEDIUM_DEFAULT = 15;
|
||||
public static final int TRACK_COLOR_MODE_PERCENTAGE_DEFAULT = 25;
|
||||
public static final int TRACK_COLOR_MODE_SLOW_DEFAULT = 9;
|
||||
|
||||
|
||||
public static final String TRACK_NAME_DEFAULT = "LOCATION";
|
||||
|
||||
public static final int VOICE_FREQUENCY_DEFAULT = 0;
|
||||
@@ -183,7 +186,7 @@ public class PreferencesUtils {
|
||||
editor.putLong(getKey(context, keyId), value);
|
||||
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets a string preference value.
|
||||
*
|
||||
@@ -196,7 +199,7 @@ public class PreferencesUtils {
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
return sharedPreferences.getString(getKey(context, keyId), defaultValue);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets a string preference value.
|
||||
*
|
||||
|
||||
+1
-1
@@ -678,7 +678,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
@MediumTest
|
||||
public void testWithProperties_sensorTypeDefault() throws Exception {
|
||||
PreferencesUtils.setString(
|
||||
context, R.string.sensor_type_key, context.getString(R.string.sensor_type_value_none));
|
||||
context, R.string.sensor_type_key, PreferencesUtils.SENSOR_TYPE_DEFAULT);
|
||||
fullRecordingSession();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user