forked from upstream-mirrors/OpenTracks
Use a PrefereneList to select preferred units.
This commit is contained in:
@@ -182,6 +182,14 @@ limitations under the License.
|
|||||||
<item>@string/sensor_type_value_zephyr</item>
|
<item>@string/sensor_type_value_zephyr</item>
|
||||||
<item>@string/sensor_type_value_none</item>
|
<item>@string/sensor_type_value_none</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
<string-array name="stats_units_options">
|
||||||
|
<item>@string/settings_stats_units_metric</item>
|
||||||
|
<item>@string/settings_stats_units_imperial</item>
|
||||||
|
</string-array>
|
||||||
|
<string-array name="stats_units_values">
|
||||||
|
<item>@string/stats_units_metric</item>
|
||||||
|
<item>@string/stats_units_imperial</item>
|
||||||
|
</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>
|
||||||
<item>@string/settings_map_track_color_mode_fixed</item>
|
<item>@string/settings_map_track_color_mode_fixed</item>
|
||||||
|
|||||||
@@ -93,6 +93,8 @@ Google은 이용자에 대한 위치정보의 이용∙제공사실을 위치정
|
|||||||
<string name="settings_recording_track_name_date_local_value">DATE_LOCAL</string>
|
<string name="settings_recording_track_name_date_local_value">DATE_LOCAL</string>
|
||||||
<string name="settings_recording_track_name_location_value">LOCATION</string>
|
<string name="settings_recording_track_name_location_value">LOCATION</string>
|
||||||
<string name="settings_recording_track_name_number_value">NUMBER</string>
|
<string name="settings_recording_track_name_number_value">NUMBER</string>
|
||||||
|
<string name="stats_units_imperial">IMPERIAL</string>
|
||||||
|
<string name="stats_units_metric">METRIC</string>
|
||||||
<string name="track_action_end">com.google.android.apps.mytracks.END_CURRENT_TRACK</string>
|
<string name="track_action_end">com.google.android.apps.mytracks.END_CURRENT_TRACK</string>
|
||||||
<string name="track_action_pause">com.google.android.apps.mytracks.PAUSE_CURRENT_TRACK</string>
|
<string name="track_action_pause">com.google.android.apps.mytracks.PAUSE_CURRENT_TRACK</string>
|
||||||
<string name="track_action_resume">com.google.android.apps.mytracks.RESUME_CURRENT_TRACK</string>
|
<string name="track_action_resume">com.google.android.apps.mytracks.RESUME_CURRENT_TRACK</string>
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ limitations under the License.
|
|||||||
<string name="export_type_key">exportType</string>
|
<string name="export_type_key">exportType</string>
|
||||||
<string name="map_type_key">mapType</string>
|
<string name="map_type_key">mapType</string>
|
||||||
<string name="max_recording_distance_key">maxRecordingDistance</string>
|
<string name="max_recording_distance_key">maxRecordingDistance</string>
|
||||||
<string name="metric_units_key">metricUnits</string>
|
|
||||||
<string name="min_recording_distance_key">minRecordingDistance</string>
|
<string name="min_recording_distance_key">minRecordingDistance</string>
|
||||||
<string name="min_recording_interval_key">minRecordingInterval</string>
|
<string name="min_recording_interval_key">minRecordingInterval</string>
|
||||||
<string name="min_required_accuracy_key">minRequiredAccuracy</string>
|
<string name="min_required_accuracy_key">minRequiredAccuracy</string>
|
||||||
@@ -42,6 +41,7 @@ limitations under the License.
|
|||||||
<string name="split_frequency_key">splitFrequency</string>
|
<string name="split_frequency_key">splitFrequency</string>
|
||||||
<string name="stats_show_coordinate_key">statsShowCoordinate</string>
|
<string name="stats_show_coordinate_key">statsShowCoordinate</string>
|
||||||
<string name="stats_show_grade_elevation_key">statsShowGradeElevation</string>
|
<string name="stats_show_grade_elevation_key">statsShowGradeElevation</string>
|
||||||
|
<string name="stats_units_key">statsdUnits</string>
|
||||||
<string name="track_color_mode_medium_key">trackColorModeMedium</string>
|
<string name="track_color_mode_medium_key">trackColorModeMedium</string>
|
||||||
<string name="track_color_mode_percentage_key">trackColorModePercentage</string>
|
<string name="track_color_mode_percentage_key">trackColorModePercentage</string>
|
||||||
<string name="track_color_mode_slow_key">trackColorModeSlow</string>
|
<string name="track_color_mode_slow_key">trackColorModeSlow</string>
|
||||||
|
|||||||
@@ -16,11 +16,9 @@ limitations under the License.
|
|||||||
-->
|
-->
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:title="@string/track_detail_stats_tab" >
|
android:title="@string/track_detail_stats_tab" >
|
||||||
<CheckBoxPreference
|
<ListPreference
|
||||||
android:defaultValue="true"
|
android:defaultValue="@string/stats_units_metric"
|
||||||
android:key="@string/metric_units_key"
|
android:key="@string/stats_units_key"
|
||||||
android:summaryOff="@string/settings_stats_units_imperial"
|
|
||||||
android:summaryOn="@string/settings_stats_units_metric"
|
|
||||||
android:title="@string/settings_stats_units_title" />
|
android:title="@string/settings_stats_units_title" />
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:defaultValue="true"
|
android:defaultValue="true"
|
||||||
|
|||||||
@@ -99,9 +99,8 @@ public class SearchListActivity extends AbstractSendToGoogleActivity
|
|||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||||
if (key == null || key.equals(
|
if (key == null || key.equals(
|
||||||
PreferencesUtils.getKey(SearchListActivity.this, R.string.metric_units_key))) {
|
PreferencesUtils.getKey(SearchListActivity.this, R.string.stats_units_key))) {
|
||||||
metricUnits = PreferencesUtils.getBoolean(SearchListActivity.this,
|
metricUnits = PreferencesUtils.isMetricUnits(SearchListActivity.this);
|
||||||
R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
|
||||||
}
|
}
|
||||||
if (key == null || key.equals(
|
if (key == null || key.equals(
|
||||||
PreferencesUtils.getKey(SearchListActivity.this, R.string.recording_track_id_key))) {
|
PreferencesUtils.getKey(SearchListActivity.this, R.string.recording_track_id_key))) {
|
||||||
@@ -177,7 +176,7 @@ public class SearchListActivity extends AbstractSendToGoogleActivity
|
|||||||
private SearchRecentSuggestions searchRecentSuggestions;
|
private SearchRecentSuggestions searchRecentSuggestions;
|
||||||
private ArrayAdapter<Map<String, Object>> arrayAdapter;
|
private ArrayAdapter<Map<String, Object>> arrayAdapter;
|
||||||
|
|
||||||
private boolean metricUnits = PreferencesUtils.METRIC_UNITS_DEFAULT;
|
private boolean metricUnits = true;
|
||||||
private long recordingTrackId = PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
private long recordingTrackId = PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
||||||
private boolean recordingTrackPaused = PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT;
|
private boolean recordingTrackPaused = PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT;
|
||||||
|
|
||||||
|
|||||||
@@ -166,9 +166,8 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
|||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||||
if (key == null || key.equals(
|
if (key == null || key.equals(
|
||||||
PreferencesUtils.getKey(TrackListActivity.this, R.string.metric_units_key))) {
|
PreferencesUtils.getKey(TrackListActivity.this, R.string.stats_units_key))) {
|
||||||
metricUnits = PreferencesUtils.getBoolean(TrackListActivity.this,
|
metricUnits = PreferencesUtils.isMetricUnits(TrackListActivity.this);
|
||||||
R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
|
||||||
}
|
}
|
||||||
if (key == null || key.equals(
|
if (key == null || key.equals(
|
||||||
PreferencesUtils.getKey(TrackListActivity.this, R.string.recording_track_id_key))) {
|
PreferencesUtils.getKey(TrackListActivity.this, R.string.recording_track_id_key))) {
|
||||||
@@ -286,7 +285,7 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
|||||||
private SectionResourceCursorAdapter sectionResourceCursorAdapter;
|
private SectionResourceCursorAdapter sectionResourceCursorAdapter;
|
||||||
|
|
||||||
// Preferences
|
// Preferences
|
||||||
private boolean metricUnits = PreferencesUtils.METRIC_UNITS_DEFAULT;
|
private boolean metricUnits = true;
|
||||||
private long recordingTrackId = PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
private long recordingTrackId = PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
||||||
private boolean recordingTrackPaused = PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT;
|
private boolean recordingTrackPaused = PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT;
|
||||||
private boolean driveSync = PreferencesUtils.DRIVE_SYNC_DEFAULT;
|
private boolean driveSync = PreferencesUtils.DRIVE_SYNC_DEFAULT;
|
||||||
|
|||||||
@@ -270,9 +270,8 @@ public class TrackDataHub implements DataSourceListener {
|
|||||||
PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT);
|
PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT);
|
||||||
}
|
}
|
||||||
if (key == null
|
if (key == null
|
||||||
|| key.equals(PreferencesUtils.getKey(context, R.string.metric_units_key))) {
|
|| key.equals(PreferencesUtils.getKey(context, R.string.stats_units_key))) {
|
||||||
metricUnits = PreferencesUtils.getBoolean(
|
metricUnits = PreferencesUtils.isMetricUnits(context);
|
||||||
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
for (TrackDataListener trackDataListener :
|
for (TrackDataListener trackDataListener :
|
||||||
trackDataManager.getListeners(TrackDataType.PREFERENCE)) {
|
trackDataManager.getListeners(TrackDataType.PREFERENCE)) {
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
private TripStatisticsUpdater tripStatisticsUpdater;
|
private TripStatisticsUpdater tripStatisticsUpdater;
|
||||||
private long startTime;
|
private long startTime;
|
||||||
|
|
||||||
private boolean metricUnits = PreferencesUtils.METRIC_UNITS_DEFAULT;
|
private boolean metricUnits = true;
|
||||||
private boolean reportSpeed = PreferencesUtils.REPORT_SPEED_DEFAULT;
|
private boolean reportSpeed = PreferencesUtils.REPORT_SPEED_DEFAULT;
|
||||||
private int minRecordingDistance = PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT;
|
private int minRecordingDistance = PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT;
|
||||||
|
|
||||||
|
|||||||
@@ -120,8 +120,10 @@ public class EulaDialogFragment extends DialogFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
EulaUtils.setAcceptEula(fragmentActivity);
|
EulaUtils.setAcceptEula(fragmentActivity);
|
||||||
PreferencesUtils.setBoolean(
|
String statsUnits = fragmentActivity.getString(
|
||||||
fragmentActivity, R.string.metric_units_key, !Locale.US.equals(Locale.getDefault()));
|
Locale.US.equals(Locale.getDefault()) ? R.string.stats_units_imperial
|
||||||
|
: R.string.stats_units_metric);
|
||||||
|
PreferencesUtils.setString(fragmentActivity, R.string.stats_units_key, statsUnits);
|
||||||
caller.onEulaDone();
|
caller.onEulaDone();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
+1
-2
@@ -80,8 +80,7 @@ public class FrequencyDialogFragment extends DialogFragment {
|
|||||||
* Gets the frequency display options.
|
* Gets the frequency display options.
|
||||||
*/
|
*/
|
||||||
private String[] getFrequencyDisplayOptions() {
|
private String[] getFrequencyDisplayOptions() {
|
||||||
boolean metricUnits = PreferencesUtils.getBoolean(
|
boolean metricUnits = PreferencesUtils.isMetricUnits(fragmentActivity);
|
||||||
fragmentActivity, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
|
||||||
return StringUtils.getFrequencyOptions(fragmentActivity, metricUnits);
|
return StringUtils.getFrequencyOptions(fragmentActivity, metricUnits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -241,8 +241,7 @@ public class SendSpreadsheetsAsyncTask extends AbstractSendAsyncTask {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
TripStatistics tripStatistics = track.getTripStatistics();
|
TripStatistics tripStatistics = track.getTripStatistics();
|
||||||
boolean metricUnits = PreferencesUtils.getBoolean(
|
boolean metricUnits = PreferencesUtils.isMetricUnits(context);
|
||||||
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
|
||||||
String distanceUnit = context.getString(
|
String distanceUnit = context.getString(
|
||||||
metricUnits ? R.string.unit_kilometer : R.string.unit_mile);
|
metricUnits ? R.string.unit_kilometer : R.string.unit_mile);
|
||||||
String speedUnit = context.getString(
|
String speedUnit = context.getString(
|
||||||
|
|||||||
@@ -156,9 +156,8 @@ public class TrackRecordingService extends Service {
|
|||||||
PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT);
|
PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT);
|
||||||
}
|
}
|
||||||
if (key == null
|
if (key == null
|
||||||
|| key.equals(PreferencesUtils.getKey(context, R.string.metric_units_key))) {
|
|| key.equals(PreferencesUtils.getKey(context, R.string.stats_units_key))) {
|
||||||
boolean metricUnits = PreferencesUtils.getBoolean(
|
boolean metricUnits = PreferencesUtils.isMetricUnits(context);
|
||||||
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
|
||||||
voiceExecutor.setMetricUnits(metricUnits);
|
voiceExecutor.setMetricUnits(metricUnits);
|
||||||
splitExecutor.setMetricUnits(metricUnits);
|
splitExecutor.setMetricUnits(metricUnits);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -227,8 +227,7 @@ public class AnnouncementPeriodicTask implements PeriodicTask {
|
|||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected String getAnnouncement(TripStatistics tripStatistics) {
|
protected String getAnnouncement(TripStatistics tripStatistics) {
|
||||||
boolean metricUnits = PreferencesUtils.getBoolean(
|
boolean metricUnits = PreferencesUtils.isMetricUnits(context);
|
||||||
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
|
||||||
boolean reportSpeed = PreferencesUtils.getBoolean(
|
boolean reportSpeed = PreferencesUtils.getBoolean(
|
||||||
context, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
|
context, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
|
||||||
double distance = tripStatistics.getTotalDistance() * UnitConversions.M_TO_KM;
|
double distance = tripStatistics.getTotalDistance() * UnitConversions.M_TO_KM;
|
||||||
|
|||||||
@@ -218,11 +218,10 @@ public class MapSettingsActivity extends AbstractSettingsActivity {
|
|||||||
* @param defaultValue the default value
|
* @param defaultValue the default value
|
||||||
*/
|
*/
|
||||||
private void updateSpeedSummary(Preference preference, int keyId, int defaultValue) {
|
private void updateSpeedSummary(Preference preference, int keyId, int defaultValue) {
|
||||||
boolean metric = PreferencesUtils.getBoolean(
|
boolean metricUnits = PreferencesUtils.isMetricUnits(this);
|
||||||
this, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
|
||||||
int displayValue = getSpeedDisplayValue(keyId, defaultValue);
|
int displayValue = getSpeedDisplayValue(keyId, defaultValue);
|
||||||
preference.setSummary(getString(
|
preference.setSummary(getString(
|
||||||
metric ? R.string.value_integer_kilometer_hour : R.string.value_integer_mile_hour,
|
metricUnits ? R.string.value_integer_kilometer_hour : R.string.value_integer_mile_hour,
|
||||||
displayValue));
|
displayValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,8 +248,7 @@ public class MapSettingsActivity extends AbstractSettingsActivity {
|
|||||||
int value;
|
int value;
|
||||||
try {
|
try {
|
||||||
value = Integer.parseInt(displayValue);
|
value = Integer.parseInt(displayValue);
|
||||||
if (!PreferencesUtils.getBoolean(
|
if (!PreferencesUtils.isMetricUnits(this)) {
|
||||||
this, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT)) {
|
|
||||||
value = (int) (value * UnitConversions.MI_TO_KM);
|
value = (int) (value * UnitConversions.MI_TO_KM);
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
@@ -276,8 +274,7 @@ public class MapSettingsActivity extends AbstractSettingsActivity {
|
|||||||
*/
|
*/
|
||||||
private int getSpeedDisplayValue(int keyId, int defaultValue) {
|
private int getSpeedDisplayValue(int keyId, int defaultValue) {
|
||||||
int value = PreferencesUtils.getInt(this, keyId, defaultValue);
|
int value = PreferencesUtils.getInt(this, keyId, defaultValue);
|
||||||
if (!PreferencesUtils.getBoolean(
|
if (!PreferencesUtils.isMetricUnits(this)) {
|
||||||
this, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT)) {
|
|
||||||
value = (int) (value * UnitConversions.KM_TO_MI);
|
value = (int) (value * UnitConversions.KM_TO_MI);
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
|
|||||||
+1
-2
@@ -38,8 +38,7 @@ public class RecordingSettingsActivity extends AbstractSettingsActivity {
|
|||||||
super.onCreate(bundle);
|
super.onCreate(bundle);
|
||||||
addPreferencesFromResource(R.xml.recording_settings);
|
addPreferencesFromResource(R.xml.recording_settings);
|
||||||
|
|
||||||
boolean metricUnits = PreferencesUtils.getBoolean(
|
boolean metricUnits = PreferencesUtils.isMetricUnits(this);
|
||||||
this, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
|
||||||
|
|
||||||
configFrequencyPreference(R.string.voice_frequency_key,
|
configFrequencyPreference(R.string.voice_frequency_key,
|
||||||
PreferencesUtils.VOICE_FREQUENCY_DEFAULT, R.array.frequency_values, metricUnits);
|
PreferencesUtils.VOICE_FREQUENCY_DEFAULT, R.array.frequency_values, metricUnits);
|
||||||
|
|||||||
@@ -16,15 +16,14 @@
|
|||||||
|
|
||||||
package com.google.android.apps.mytracks.settings;
|
package com.google.android.apps.mytracks.settings;
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.Constants;
|
|
||||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.CheckBoxPreference;
|
||||||
|
import android.preference.ListPreference;
|
||||||
|
import android.preference.Preference;
|
||||||
|
import android.preference.Preference.OnPreferenceChangeListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An activity for accessing stats settings.
|
* An activity for accessing stats settings.
|
||||||
@@ -33,64 +32,44 @@ import android.preference.CheckBoxPreference;
|
|||||||
*/
|
*/
|
||||||
public class StatsSettingsActivity extends AbstractSettingsActivity {
|
public class StatsSettingsActivity extends AbstractSettingsActivity {
|
||||||
|
|
||||||
/*
|
private String statsUnits;
|
||||||
* Note that sharedPreferenceChangeListenr cannot be an anonymous inner class.
|
|
||||||
* Anonymous inner class will get garbage collected.
|
|
||||||
*/
|
|
||||||
private final OnSharedPreferenceChangeListener
|
|
||||||
sharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
|
|
||||||
@Override
|
|
||||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
|
||||||
if (key == null || key.equals(
|
|
||||||
PreferencesUtils.getKey(StatsSettingsActivity.this, R.string.metric_units_key))) {
|
|
||||||
metricUnits = PreferencesUtils.getBoolean(StatsSettingsActivity.this,
|
|
||||||
R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
|
||||||
}
|
|
||||||
if (key != null) {
|
|
||||||
runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateUi();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private SharedPreferences sharedPreferences;
|
|
||||||
private boolean metricUnits = PreferencesUtils.METRIC_UNITS_DEFAULT;
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle bundle) {
|
protected void onCreate(Bundle bundle) {
|
||||||
super.onCreate(bundle);
|
super.onCreate(bundle);
|
||||||
addPreferencesFromResource(R.xml.stats_settings);
|
addPreferencesFromResource(R.xml.stats_settings);
|
||||||
sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
ListPreference preference = (ListPreference) findPreference(
|
||||||
protected void onStart() {
|
getString(R.string.stats_units_key));
|
||||||
super.onStart();
|
OnPreferenceChangeListener listener = new OnPreferenceChangeListener() {
|
||||||
sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
@Override
|
||||||
sharedPreferenceChangeListener.onSharedPreferenceChanged(null, null);
|
public boolean onPreferenceChange(Preference pref, Object newValue) {
|
||||||
|
statsUnits = (String) newValue;
|
||||||
|
updateUi();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
String value = PreferencesUtils.getString(
|
||||||
|
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(preference, options, options, values, value, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
statsUnits = PreferencesUtils.getString(
|
||||||
|
this, R.string.stats_units_key, PreferencesUtils.STATS_UNITS_DEFAULT);
|
||||||
updateUi();
|
updateUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStop() {
|
|
||||||
super.onStop();
|
|
||||||
sharedPreferences.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
private void updateUi() {
|
private void updateUi() {
|
||||||
CheckBoxPreference reportSpeedCheckBoxPreference = (CheckBoxPreference) findPreference(
|
CheckBoxPreference reportSpeedCheckBoxPreference = (CheckBoxPreference) findPreference(
|
||||||
getString(R.string.report_speed_key));
|
getString(R.string.report_speed_key));
|
||||||
|
boolean metricUnits = PreferencesUtils.STATS_UNITS_DEFAULT.equals(statsUnits);
|
||||||
reportSpeedCheckBoxPreference.setSummaryOn(
|
reportSpeedCheckBoxPreference.setSummaryOn(
|
||||||
metricUnits ? getString(R.string.description_speed_metric)
|
metricUnits ? getString(R.string.description_speed_metric)
|
||||||
: getString(R.string.description_speed_imperial));
|
: getString(R.string.description_speed_imperial));
|
||||||
|
|||||||
@@ -46,8 +46,7 @@ public class ChartURLGenerator {
|
|||||||
*/
|
*/
|
||||||
public static String getChartUrl(
|
public static String getChartUrl(
|
||||||
Vector<Double> distances, Vector<Double> elevations, Track track, Context context) {
|
Vector<Double> distances, Vector<Double> elevations, Track track, Context context) {
|
||||||
boolean metricUnits = PreferencesUtils.getBoolean(
|
boolean metricUnits = PreferencesUtils.isMetricUnits(context);
|
||||||
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
|
||||||
return getChartUrl(
|
return getChartUrl(
|
||||||
distances, elevations, track, context.getString(R.string.stats_elevation), metricUnits);
|
distances, elevations, track, context.getString(R.string.stats_elevation), metricUnits);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import com.google.android.apps.mytracks.Constants;
|
|||||||
import com.google.android.apps.mytracks.fragments.ExportDialogFragment.ExportType;
|
import com.google.android.apps.mytracks.fragments.ExportDialogFragment.ExportType;
|
||||||
import com.google.android.apps.mytracks.io.file.TrackFileFormat;
|
import com.google.android.apps.mytracks.io.file.TrackFileFormat;
|
||||||
import com.google.android.gms.location.DetectedActivity;
|
import com.google.android.gms.location.DetectedActivity;
|
||||||
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -76,7 +77,6 @@ public class PreferencesUtils {
|
|||||||
public static final String GOOGLE_ACCOUNT_DEFAULT = "";
|
public static final String GOOGLE_ACCOUNT_DEFAULT = "";
|
||||||
public static final int MAP_TYPE_DEFAUlT = 1;
|
public static final int MAP_TYPE_DEFAUlT = 1;
|
||||||
public static final int MAX_RECORDING_DISTANCE_DEFAULT = 200;
|
public static final int MAX_RECORDING_DISTANCE_DEFAULT = 200;
|
||||||
public static final boolean METRIC_UNITS_DEFAULT = true;
|
|
||||||
public static final int MIN_RECORDING_DISTANCE_DEFAULT = 5;
|
public static final int MIN_RECORDING_DISTANCE_DEFAULT = 5;
|
||||||
|
|
||||||
// Values for min_recording_interval_key
|
// Values for min_recording_interval_key
|
||||||
@@ -104,6 +104,7 @@ public class PreferencesUtils {
|
|||||||
// Stats
|
// Stats
|
||||||
public static final boolean STATS_SHOW_COORDINATE_DEFAULT = false;
|
public static final boolean STATS_SHOW_COORDINATE_DEFAULT = false;
|
||||||
public static final boolean STATS_SHOW_GRADE_ELEVATION_DEFAULT = false;
|
public static final boolean STATS_SHOW_GRADE_ELEVATION_DEFAULT = false;
|
||||||
|
public static final String STATS_UNITS_DEFAULT = "METRIC";
|
||||||
|
|
||||||
// Track color
|
// Track color
|
||||||
public static final String TRACK_COLOR_MODE_DEFAULT = "SINGLE";
|
public static final String TRACK_COLOR_MODE_DEFAULT = "SINGLE";
|
||||||
@@ -246,4 +247,14 @@ public class PreferencesUtils {
|
|||||||
editor.putString(getKey(context, keyId), value);
|
editor.putString(getKey(context, keyId), value);
|
||||||
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
|
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if metric units.
|
||||||
|
*
|
||||||
|
* @param context the context
|
||||||
|
*/
|
||||||
|
public static boolean isMetricUnits(Context context) {
|
||||||
|
return PreferencesUtils.STATS_UNITS_DEFAULT.equals(
|
||||||
|
getString(context, R.string.stats_units_key, PreferencesUtils.STATS_UNITS_DEFAULT));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,8 +49,7 @@ public class StatsUtils {
|
|||||||
* @param isRecording true if recording
|
* @param isRecording true if recording
|
||||||
*/
|
*/
|
||||||
public static void setLocationValues(Activity activity, Location location, boolean isRecording) {
|
public static void setLocationValues(Activity activity, Location location, boolean isRecording) {
|
||||||
boolean metricUnits = PreferencesUtils.getBoolean(
|
boolean metricUnits = PreferencesUtils.isMetricUnits(activity);
|
||||||
activity, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
|
||||||
boolean reportSpeed = PreferencesUtils.getBoolean(
|
boolean reportSpeed = PreferencesUtils.getBoolean(
|
||||||
activity, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
|
activity, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
|
||||||
|
|
||||||
@@ -109,8 +108,7 @@ public class StatsUtils {
|
|||||||
* @param tripStatistics the trip statistics
|
* @param tripStatistics the trip statistics
|
||||||
*/
|
*/
|
||||||
public static void setTripStatisticsValues(Activity activity, TripStatistics tripStatistics) {
|
public static void setTripStatisticsValues(Activity activity, TripStatistics tripStatistics) {
|
||||||
boolean metricUnits = PreferencesUtils.getBoolean(
|
boolean metricUnits = PreferencesUtils.isMetricUnits(activity);
|
||||||
activity, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
|
||||||
boolean reportSpeed = PreferencesUtils.getBoolean(
|
boolean reportSpeed = PreferencesUtils.getBoolean(
|
||||||
activity, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
|
activity, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
|
||||||
|
|
||||||
|
|||||||
@@ -195,8 +195,7 @@ public class TrackWidgetProvider extends AppWidgetProvider {
|
|||||||
boolean isRecording = recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
boolean isRecording = recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
||||||
boolean isPaused = PreferencesUtils.getBoolean(context, R.string.recording_track_paused_key,
|
boolean isPaused = PreferencesUtils.getBoolean(context, R.string.recording_track_paused_key,
|
||||||
PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT);
|
PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT);
|
||||||
boolean metricUnits = PreferencesUtils.getBoolean(
|
boolean metricUnits = PreferencesUtils.isMetricUnits(context);
|
||||||
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
|
||||||
boolean reportSpeed = PreferencesUtils.getBoolean(
|
boolean reportSpeed = PreferencesUtils.getBoolean(
|
||||||
context, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
|
context, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
|
||||||
int item1 = PreferencesUtils.getInt(
|
int item1 = PreferencesUtils.getInt(
|
||||||
|
|||||||
@@ -527,7 +527,8 @@ public class TrackDataHubTest extends AndroidTestCase {
|
|||||||
|
|
||||||
// Register two listeners
|
// Register two listeners
|
||||||
PreferencesUtils.setBoolean(context, R.string.report_speed_key, true);
|
PreferencesUtils.setBoolean(context, R.string.report_speed_key, true);
|
||||||
PreferencesUtils.setBoolean(context, R.string.metric_units_key, true);
|
PreferencesUtils.setString(
|
||||||
|
context, R.string.stats_units_key, PreferencesUtils.STATS_UNITS_DEFAULT);
|
||||||
PreferencesUtils.setInt(context, R.string.min_required_accuracy_key,
|
PreferencesUtils.setInt(context, R.string.min_required_accuracy_key,
|
||||||
PreferencesUtils.MIN_REQUIRED_ACCURACY_DEFAULT);
|
PreferencesUtils.MIN_REQUIRED_ACCURACY_DEFAULT);
|
||||||
PreferencesUtils.setInt(context, R.string.min_recording_distance_key,
|
PreferencesUtils.setInt(context, R.string.min_recording_distance_key,
|
||||||
@@ -571,9 +572,10 @@ public class TrackDataHubTest extends AndroidTestCase {
|
|||||||
expect(trackDataListener2.onMetricUnitsChanged(false)).andReturn(false);
|
expect(trackDataListener2.onMetricUnitsChanged(false)).andReturn(false);
|
||||||
replay();
|
replay();
|
||||||
|
|
||||||
PreferencesUtils.setBoolean(context, R.string.metric_units_key, false);
|
String imperialUnits = context.getString(R.string.stats_units_imperial);
|
||||||
|
PreferencesUtils.setString(context, R.string.stats_units_key, imperialUnits);
|
||||||
listener.onSharedPreferenceChanged(
|
listener.onSharedPreferenceChanged(
|
||||||
sharedPreferences, PreferencesUtils.getKey(context, R.string.metric_units_key));
|
sharedPreferences, PreferencesUtils.getKey(context, R.string.stats_units_key));
|
||||||
verifyAndReset();
|
verifyAndReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -762,15 +764,17 @@ public class TrackDataHubTest extends AndroidTestCase {
|
|||||||
* the key is R.string.metric_units_key.
|
* the key is R.string.metric_units_key.
|
||||||
*/
|
*/
|
||||||
public void testNotifyPreferenceChanged_metricUnitsNoNotify() {
|
public void testNotifyPreferenceChanged_metricUnitsNoNotify() {
|
||||||
boolean value = false;
|
String imperialUnits = context.getString(R.string.stats_units_imperial);
|
||||||
PreferencesUtils.setBoolean(context, R.string.metric_units_key, value);
|
|
||||||
trackDataHub.notifyPreferenceChanged(PreferencesUtils
|
PreferencesUtils.setString(context, R.string.stats_units_key, imperialUnits);
|
||||||
.getKey(context, R.string.metric_units_key));
|
trackDataHub.notifyPreferenceChanged(
|
||||||
assertEquals(value, trackDataHub.isMetricUnits());
|
PreferencesUtils.getKey(context, R.string.stats_units_key));
|
||||||
PreferencesUtils.setBoolean(context, R.string.metric_units_key, !value);
|
assertEquals(false, trackDataHub.isMetricUnits());
|
||||||
trackDataHub.notifyPreferenceChanged(PreferencesUtils
|
PreferencesUtils.setString(
|
||||||
.getKey(context, R.string.metric_units_key));
|
context, R.string.stats_units_key, PreferencesUtils.STATS_UNITS_DEFAULT);
|
||||||
assertEquals(!value, trackDataHub.isMetricUnits());
|
trackDataHub.notifyPreferenceChanged(
|
||||||
|
PreferencesUtils.getKey(context, R.string.stats_units_key));
|
||||||
|
assertEquals(true, trackDataHub.isMetricUnits());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -642,14 +642,15 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
|||||||
|
|
||||||
@MediumTest
|
@MediumTest
|
||||||
public void testWithProperties_metricUnitsDefault() throws Exception {
|
public void testWithProperties_metricUnitsDefault() throws Exception {
|
||||||
PreferencesUtils.setBoolean(
|
PreferencesUtils.setString(
|
||||||
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
context, R.string.stats_units_key, PreferencesUtils.STATS_UNITS_DEFAULT);
|
||||||
fullRecordingSession();
|
fullRecordingSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
@MediumTest
|
@MediumTest
|
||||||
public void testWithProperties_metricUnitsDisabled() throws Exception {
|
public void testWithProperties_metricUnitsDisabled() throws Exception {
|
||||||
PreferencesUtils.setBoolean(context, R.string.metric_units_key, false);
|
PreferencesUtils.setString(
|
||||||
|
context, R.string.stats_units_key, context.getString(R.string.stats_units_imperial));
|
||||||
fullRecordingSession();
|
fullRecordingSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user