mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
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_none</item>
|
||||
</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">
|
||||
<item>@string/settings_map_track_color_mode_single</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_location_value">LOCATION</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_pause">com.google.android.apps.mytracks.PAUSE_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="map_type_key">mapType</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_interval_key">minRecordingInterval</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="stats_show_coordinate_key">statsShowCoordinate</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_percentage_key">trackColorModePercentage</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"
|
||||
android:title="@string/track_detail_stats_tab" >
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="@string/metric_units_key"
|
||||
android:summaryOff="@string/settings_stats_units_imperial"
|
||||
android:summaryOn="@string/settings_stats_units_metric"
|
||||
<ListPreference
|
||||
android:defaultValue="@string/stats_units_metric"
|
||||
android:key="@string/stats_units_key"
|
||||
android:title="@string/settings_stats_units_title" />
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
|
||||
@@ -99,9 +99,8 @@ public class SearchListActivity extends AbstractSendToGoogleActivity
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||
if (key == null || key.equals(
|
||||
PreferencesUtils.getKey(SearchListActivity.this, R.string.metric_units_key))) {
|
||||
metricUnits = PreferencesUtils.getBoolean(SearchListActivity.this,
|
||||
R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
||||
PreferencesUtils.getKey(SearchListActivity.this, R.string.stats_units_key))) {
|
||||
metricUnits = PreferencesUtils.isMetricUnits(SearchListActivity.this);
|
||||
}
|
||||
if (key == null || key.equals(
|
||||
PreferencesUtils.getKey(SearchListActivity.this, R.string.recording_track_id_key))) {
|
||||
@@ -177,7 +176,7 @@ public class SearchListActivity extends AbstractSendToGoogleActivity
|
||||
private SearchRecentSuggestions searchRecentSuggestions;
|
||||
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 boolean recordingTrackPaused = PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT;
|
||||
|
||||
|
||||
@@ -166,9 +166,8 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||
if (key == null || key.equals(
|
||||
PreferencesUtils.getKey(TrackListActivity.this, R.string.metric_units_key))) {
|
||||
metricUnits = PreferencesUtils.getBoolean(TrackListActivity.this,
|
||||
R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
||||
PreferencesUtils.getKey(TrackListActivity.this, R.string.stats_units_key))) {
|
||||
metricUnits = PreferencesUtils.isMetricUnits(TrackListActivity.this);
|
||||
}
|
||||
if (key == null || key.equals(
|
||||
PreferencesUtils.getKey(TrackListActivity.this, R.string.recording_track_id_key))) {
|
||||
@@ -286,7 +285,7 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
||||
private SectionResourceCursorAdapter sectionResourceCursorAdapter;
|
||||
|
||||
// Preferences
|
||||
private boolean metricUnits = PreferencesUtils.METRIC_UNITS_DEFAULT;
|
||||
private boolean metricUnits = true;
|
||||
private long recordingTrackId = PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
||||
private boolean recordingTrackPaused = PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT;
|
||||
private boolean driveSync = PreferencesUtils.DRIVE_SYNC_DEFAULT;
|
||||
|
||||
@@ -270,9 +270,8 @@ public class TrackDataHub implements DataSourceListener {
|
||||
PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT);
|
||||
}
|
||||
if (key == null
|
||||
|| key.equals(PreferencesUtils.getKey(context, R.string.metric_units_key))) {
|
||||
metricUnits = PreferencesUtils.getBoolean(
|
||||
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
||||
|| key.equals(PreferencesUtils.getKey(context, R.string.stats_units_key))) {
|
||||
metricUnits = PreferencesUtils.isMetricUnits(context);
|
||||
if (key != null) {
|
||||
for (TrackDataListener trackDataListener :
|
||||
trackDataManager.getListeners(TrackDataType.PREFERENCE)) {
|
||||
|
||||
@@ -64,7 +64,7 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
||||
private TripStatisticsUpdater tripStatisticsUpdater;
|
||||
private long startTime;
|
||||
|
||||
private boolean metricUnits = PreferencesUtils.METRIC_UNITS_DEFAULT;
|
||||
private boolean metricUnits = true;
|
||||
private boolean reportSpeed = PreferencesUtils.REPORT_SPEED_DEFAULT;
|
||||
private int minRecordingDistance = PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT;
|
||||
|
||||
|
||||
@@ -120,8 +120,10 @@ public class EulaDialogFragment extends DialogFragment {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
EulaUtils.setAcceptEula(fragmentActivity);
|
||||
PreferencesUtils.setBoolean(
|
||||
fragmentActivity, R.string.metric_units_key, !Locale.US.equals(Locale.getDefault()));
|
||||
String statsUnits = fragmentActivity.getString(
|
||||
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();
|
||||
}
|
||||
});
|
||||
|
||||
+1
-2
@@ -80,8 +80,7 @@ public class FrequencyDialogFragment extends DialogFragment {
|
||||
* Gets the frequency display options.
|
||||
*/
|
||||
private String[] getFrequencyDisplayOptions() {
|
||||
boolean metricUnits = PreferencesUtils.getBoolean(
|
||||
fragmentActivity, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
||||
boolean metricUnits = PreferencesUtils.isMetricUnits(fragmentActivity);
|
||||
return StringUtils.getFrequencyOptions(fragmentActivity, metricUnits);
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -241,8 +241,7 @@ public class SendSpreadsheetsAsyncTask extends AbstractSendAsyncTask {
|
||||
return false;
|
||||
}
|
||||
TripStatistics tripStatistics = track.getTripStatistics();
|
||||
boolean metricUnits = PreferencesUtils.getBoolean(
|
||||
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
||||
boolean metricUnits = PreferencesUtils.isMetricUnits(context);
|
||||
String distanceUnit = context.getString(
|
||||
metricUnits ? R.string.unit_kilometer : R.string.unit_mile);
|
||||
String speedUnit = context.getString(
|
||||
|
||||
@@ -156,9 +156,8 @@ public class TrackRecordingService extends Service {
|
||||
PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT);
|
||||
}
|
||||
if (key == null
|
||||
|| key.equals(PreferencesUtils.getKey(context, R.string.metric_units_key))) {
|
||||
boolean metricUnits = PreferencesUtils.getBoolean(
|
||||
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
||||
|| key.equals(PreferencesUtils.getKey(context, R.string.stats_units_key))) {
|
||||
boolean metricUnits = PreferencesUtils.isMetricUnits(context);
|
||||
voiceExecutor.setMetricUnits(metricUnits);
|
||||
splitExecutor.setMetricUnits(metricUnits);
|
||||
}
|
||||
|
||||
+1
-2
@@ -227,8 +227,7 @@ public class AnnouncementPeriodicTask implements PeriodicTask {
|
||||
*/
|
||||
@VisibleForTesting
|
||||
protected String getAnnouncement(TripStatistics tripStatistics) {
|
||||
boolean metricUnits = PreferencesUtils.getBoolean(
|
||||
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
||||
boolean metricUnits = PreferencesUtils.isMetricUnits(context);
|
||||
boolean reportSpeed = PreferencesUtils.getBoolean(
|
||||
context, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
|
||||
double distance = tripStatistics.getTotalDistance() * UnitConversions.M_TO_KM;
|
||||
|
||||
@@ -218,11 +218,10 @@ public class MapSettingsActivity extends AbstractSettingsActivity {
|
||||
* @param defaultValue the default value
|
||||
*/
|
||||
private void updateSpeedSummary(Preference preference, int keyId, int defaultValue) {
|
||||
boolean metric = PreferencesUtils.getBoolean(
|
||||
this, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
||||
boolean metricUnits = PreferencesUtils.isMetricUnits(this);
|
||||
int displayValue = getSpeedDisplayValue(keyId, defaultValue);
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -249,8 +248,7 @@ public class MapSettingsActivity extends AbstractSettingsActivity {
|
||||
int value;
|
||||
try {
|
||||
value = Integer.parseInt(displayValue);
|
||||
if (!PreferencesUtils.getBoolean(
|
||||
this, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT)) {
|
||||
if (!PreferencesUtils.isMetricUnits(this)) {
|
||||
value = (int) (value * UnitConversions.MI_TO_KM);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -276,8 +274,7 @@ public class MapSettingsActivity extends AbstractSettingsActivity {
|
||||
*/
|
||||
private int getSpeedDisplayValue(int keyId, int defaultValue) {
|
||||
int value = PreferencesUtils.getInt(this, keyId, defaultValue);
|
||||
if (!PreferencesUtils.getBoolean(
|
||||
this, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT)) {
|
||||
if (!PreferencesUtils.isMetricUnits(this)) {
|
||||
value = (int) (value * UnitConversions.KM_TO_MI);
|
||||
}
|
||||
return value;
|
||||
|
||||
+1
-2
@@ -38,8 +38,7 @@ public class RecordingSettingsActivity extends AbstractSettingsActivity {
|
||||
super.onCreate(bundle);
|
||||
addPreferencesFromResource(R.xml.recording_settings);
|
||||
|
||||
boolean metricUnits = PreferencesUtils.getBoolean(
|
||||
this, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
||||
boolean metricUnits = PreferencesUtils.isMetricUnits(this);
|
||||
|
||||
configFrequencyPreference(R.string.voice_frequency_key,
|
||||
PreferencesUtils.VOICE_FREQUENCY_DEFAULT, R.array.frequency_values, metricUnits);
|
||||
|
||||
@@ -16,15 +16,14 @@
|
||||
|
||||
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.maps.mytracks.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.os.Bundle;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.Preference.OnPreferenceChangeListener;
|
||||
|
||||
/**
|
||||
* An activity for accessing stats settings.
|
||||
@@ -33,64 +32,44 @@ import android.preference.CheckBoxPreference;
|
||||
*/
|
||||
public class StatsSettingsActivity extends AbstractSettingsActivity {
|
||||
|
||||
/*
|
||||
* 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;
|
||||
private String statsUnits;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
addPreferencesFromResource(R.xml.stats_settings);
|
||||
sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
||||
sharedPreferenceChangeListener.onSharedPreferenceChanged(null, null);
|
||||
ListPreference preference = (ListPreference) findPreference(
|
||||
getString(R.string.stats_units_key));
|
||||
OnPreferenceChangeListener listener = new OnPreferenceChangeListener() {
|
||||
@Override
|
||||
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
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
statsUnits = PreferencesUtils.getString(
|
||||
this, R.string.stats_units_key, PreferencesUtils.STATS_UNITS_DEFAULT);
|
||||
updateUi();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
sharedPreferences.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void updateUi() {
|
||||
CheckBoxPreference reportSpeedCheckBoxPreference = (CheckBoxPreference) findPreference(
|
||||
getString(R.string.report_speed_key));
|
||||
boolean metricUnits = PreferencesUtils.STATS_UNITS_DEFAULT.equals(statsUnits);
|
||||
reportSpeedCheckBoxPreference.setSummaryOn(
|
||||
metricUnits ? getString(R.string.description_speed_metric)
|
||||
: getString(R.string.description_speed_imperial));
|
||||
|
||||
@@ -46,8 +46,7 @@ public class ChartURLGenerator {
|
||||
*/
|
||||
public static String getChartUrl(
|
||||
Vector<Double> distances, Vector<Double> elevations, Track track, Context context) {
|
||||
boolean metricUnits = PreferencesUtils.getBoolean(
|
||||
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
||||
boolean metricUnits = PreferencesUtils.isMetricUnits(context);
|
||||
return getChartUrl(
|
||||
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.io.file.TrackFileFormat;
|
||||
import com.google.android.gms.location.DetectedActivity;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
@@ -76,7 +77,6 @@ public class PreferencesUtils {
|
||||
public static final String GOOGLE_ACCOUNT_DEFAULT = "";
|
||||
public static final int MAP_TYPE_DEFAUlT = 1;
|
||||
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;
|
||||
|
||||
// Values for min_recording_interval_key
|
||||
@@ -104,6 +104,7 @@ public class PreferencesUtils {
|
||||
// Stats
|
||||
public static final boolean STATS_SHOW_COORDINATE_DEFAULT = false;
|
||||
public static final boolean STATS_SHOW_GRADE_ELEVATION_DEFAULT = false;
|
||||
public static final String STATS_UNITS_DEFAULT = "METRIC";
|
||||
|
||||
// Track color
|
||||
public static final String TRACK_COLOR_MODE_DEFAULT = "SINGLE";
|
||||
@@ -246,4 +247,14 @@ public class PreferencesUtils {
|
||||
editor.putString(getKey(context, keyId), value);
|
||||
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
|
||||
*/
|
||||
public static void setLocationValues(Activity activity, Location location, boolean isRecording) {
|
||||
boolean metricUnits = PreferencesUtils.getBoolean(
|
||||
activity, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
||||
boolean metricUnits = PreferencesUtils.isMetricUnits(activity);
|
||||
boolean reportSpeed = PreferencesUtils.getBoolean(
|
||||
activity, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
|
||||
|
||||
@@ -109,8 +108,7 @@ public class StatsUtils {
|
||||
* @param tripStatistics the trip statistics
|
||||
*/
|
||||
public static void setTripStatisticsValues(Activity activity, TripStatistics tripStatistics) {
|
||||
boolean metricUnits = PreferencesUtils.getBoolean(
|
||||
activity, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
||||
boolean metricUnits = PreferencesUtils.isMetricUnits(activity);
|
||||
boolean reportSpeed = PreferencesUtils.getBoolean(
|
||||
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 isPaused = PreferencesUtils.getBoolean(context, R.string.recording_track_paused_key,
|
||||
PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT);
|
||||
boolean metricUnits = PreferencesUtils.getBoolean(
|
||||
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
||||
boolean metricUnits = PreferencesUtils.isMetricUnits(context);
|
||||
boolean reportSpeed = PreferencesUtils.getBoolean(
|
||||
context, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
|
||||
int item1 = PreferencesUtils.getInt(
|
||||
|
||||
@@ -527,7 +527,8 @@ public class TrackDataHubTest extends AndroidTestCase {
|
||||
|
||||
// Register two listeners
|
||||
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.MIN_REQUIRED_ACCURACY_DEFAULT);
|
||||
PreferencesUtils.setInt(context, R.string.min_recording_distance_key,
|
||||
@@ -571,9 +572,10 @@ public class TrackDataHubTest extends AndroidTestCase {
|
||||
expect(trackDataListener2.onMetricUnitsChanged(false)).andReturn(false);
|
||||
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(
|
||||
sharedPreferences, PreferencesUtils.getKey(context, R.string.metric_units_key));
|
||||
sharedPreferences, PreferencesUtils.getKey(context, R.string.stats_units_key));
|
||||
verifyAndReset();
|
||||
}
|
||||
|
||||
@@ -762,15 +764,17 @@ public class TrackDataHubTest extends AndroidTestCase {
|
||||
* the key is R.string.metric_units_key.
|
||||
*/
|
||||
public void testNotifyPreferenceChanged_metricUnitsNoNotify() {
|
||||
boolean value = false;
|
||||
PreferencesUtils.setBoolean(context, R.string.metric_units_key, value);
|
||||
trackDataHub.notifyPreferenceChanged(PreferencesUtils
|
||||
.getKey(context, R.string.metric_units_key));
|
||||
assertEquals(value, trackDataHub.isMetricUnits());
|
||||
PreferencesUtils.setBoolean(context, R.string.metric_units_key, !value);
|
||||
trackDataHub.notifyPreferenceChanged(PreferencesUtils
|
||||
.getKey(context, R.string.metric_units_key));
|
||||
assertEquals(!value, trackDataHub.isMetricUnits());
|
||||
String imperialUnits = context.getString(R.string.stats_units_imperial);
|
||||
|
||||
PreferencesUtils.setString(context, R.string.stats_units_key, imperialUnits);
|
||||
trackDataHub.notifyPreferenceChanged(
|
||||
PreferencesUtils.getKey(context, R.string.stats_units_key));
|
||||
assertEquals(false, trackDataHub.isMetricUnits());
|
||||
PreferencesUtils.setString(
|
||||
context, R.string.stats_units_key, PreferencesUtils.STATS_UNITS_DEFAULT);
|
||||
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
|
||||
public void testWithProperties_metricUnitsDefault() throws Exception {
|
||||
PreferencesUtils.setBoolean(
|
||||
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
||||
PreferencesUtils.setString(
|
||||
context, R.string.stats_units_key, PreferencesUtils.STATS_UNITS_DEFAULT);
|
||||
fullRecordingSession();
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user