forked from upstream-mirrors/OpenTracks
Inline methods in PreferencesUtils.
Donot want to have a pair of getter and setting for each preference.
This commit is contained in:
@@ -21,6 +21,7 @@ import com.google.android.apps.mytracks.io.file.GpxImporter;
|
||||
import com.google.android.apps.mytracks.util.FileUtils;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.apps.mytracks.util.SystemUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.os.PowerManager.WakeLock;
|
||||
@@ -82,7 +83,7 @@ public class ImportAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
||||
myTracksProviderUtils = MyTracksProviderUtils.Factory.get(importActivity);
|
||||
|
||||
// Get the wake lock if not recording
|
||||
if (PreferencesUtils.getRecordingTrackId(importActivity) == -1L) {
|
||||
if (PreferencesUtils.getLong(importActivity, R.string.recording_track_id_key) == -1L) {
|
||||
wakeLock = SystemUtils.acquireWakeLock(importActivity, wakeLock);
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ public class MarkerListActivity extends AbstractMyTracksActivity {
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||
// Note that key can be null
|
||||
if (PreferencesUtils.getRecordingTrackIdKey(MarkerListActivity.this).equals(key)) {
|
||||
if (PreferencesUtils.getKey(MarkerListActivity.this, R.string.recording_track_id_key).equals(key)) {
|
||||
updateMenu();
|
||||
}
|
||||
}
|
||||
@@ -188,7 +188,7 @@ public class MarkerListActivity extends AbstractMyTracksActivity {
|
||||
|
||||
private void updateMenu() {
|
||||
if (insertMarkerMenuItem != null) {
|
||||
insertMarkerMenuItem.setVisible(trackId == PreferencesUtils.getRecordingTrackId(this));
|
||||
insertMarkerMenuItem.setVisible(trackId == PreferencesUtils.getLong(this, R.string.recording_track_id_key));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ public class SaveAllAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
||||
myTracksProviderUtils = MyTracksProviderUtils.Factory.get(saveAllActivity);
|
||||
|
||||
// Get the wake lock if not recording
|
||||
if (PreferencesUtils.getRecordingTrackId(saveAllActivity) == -1L) {
|
||||
if (PreferencesUtils.getLong(saveAllActivity, R.string.recording_track_id_key) == -1L) {
|
||||
wakeLock = SystemUtils.acquireWakeLock(saveAllActivity, wakeLock);
|
||||
}
|
||||
success = false;
|
||||
|
||||
@@ -85,8 +85,8 @@ public class SearchListActivity extends AbstractMyTracksActivity {
|
||||
sharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||
if (PreferencesUtils.getRecordingTrackIdKey(SearchListActivity.this).equals(key)) {
|
||||
recordingTrackId = PreferencesUtils.getRecordingTrackId(SearchListActivity.this);
|
||||
if (PreferencesUtils.getKey(SearchListActivity.this, R.string.recording_track_id_key).equals(key)) {
|
||||
recordingTrackId = PreferencesUtils.getLong(SearchListActivity.this, R.string.recording_track_id_key);
|
||||
arrayAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
@@ -126,7 +126,7 @@ public class SearchListActivity extends AbstractMyTracksActivity {
|
||||
SharedPreferences sharedPreferences = getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
||||
recordingTrackId = PreferencesUtils.getRecordingTrackId(this);
|
||||
recordingTrackId = PreferencesUtils.getLong(this, R.string.recording_track_id_key);
|
||||
|
||||
listView = (ListView) findViewById(R.id.search_list);
|
||||
listView.setEmptyView(findViewById(R.id.search_list_empty));
|
||||
@@ -185,7 +185,7 @@ public class SearchListActivity extends AbstractMyTracksActivity {
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
metricUnits = PreferencesUtils.isMetricUnits(this);
|
||||
metricUnits = PreferencesUtils.getBoolean(this, R.string.metric_units_key, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -131,7 +131,7 @@ public class SettingsActivity extends PreferenceActivity {
|
||||
// Hook up switching of displayed list entries between metric and imperial
|
||||
// units
|
||||
CheckBoxPreference metricUnitsPreference =
|
||||
(CheckBoxPreference) findPreference(PreferencesUtils.getMetricUnitsKey(this));
|
||||
(CheckBoxPreference) findPreference(PreferencesUtils.getKey(this, R.string.metric_units_key));
|
||||
metricUnitsPreference.setOnPreferenceChangeListener(
|
||||
new OnPreferenceChangeListener() {
|
||||
@Override
|
||||
@@ -348,7 +348,7 @@ public class SettingsActivity extends PreferenceActivity {
|
||||
|
||||
// If recording, disable backup/restore/reset
|
||||
// (we don't want to get to inconsistent states)
|
||||
boolean recording = PreferencesUtils.getRecordingTrackId(this) != -1;
|
||||
boolean recording = PreferencesUtils.getLong(this, R.string.recording_track_id_key) != -1;
|
||||
backupNowPreference.setEnabled(!recording);
|
||||
restoreNowPreference.setEnabled(!recording);
|
||||
resetPreference.setEnabled(!recording);
|
||||
@@ -642,7 +642,7 @@ public class SettingsActivity extends PreferenceActivity {
|
||||
* If the units are not metric convert the value before displaying.
|
||||
*/
|
||||
private void viewTrackColorModeSettings(EditTextPreference preference, int id) {
|
||||
if (PreferencesUtils.isMetricUnits(this)) {
|
||||
if (PreferencesUtils.getBoolean(this, R.string.metric_units_key, true)) {
|
||||
return;
|
||||
}
|
||||
// Convert miles/h to km/h
|
||||
@@ -663,7 +663,7 @@ public class SettingsActivity extends PreferenceActivity {
|
||||
*/
|
||||
private void validateTrackColorModeSettings(String newValue, int id) {
|
||||
String metricspeed;
|
||||
if (PreferencesUtils.isMetricUnits(this)) {
|
||||
if (PreferencesUtils.getBoolean(this, R.string.metric_units_key, true)) {
|
||||
metricspeed = newValue;
|
||||
} else {
|
||||
// Convert miles/h to km/h
|
||||
|
||||
@@ -101,7 +101,7 @@ public class TrackDetailActivity extends AbstractMyTracksActivity
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||
// Note that key can be null
|
||||
if (PreferencesUtils.getRecordingTrackIdKey(TrackDetailActivity.this).equals(key)) {
|
||||
if (PreferencesUtils.getKey(TrackDetailActivity.this, R.string.recording_track_id_key).equals(key)) {
|
||||
updateMenu();
|
||||
}
|
||||
}
|
||||
@@ -438,7 +438,7 @@ public class TrackDetailActivity extends AbstractMyTracksActivity
|
||||
* Updates the menu.
|
||||
*/
|
||||
private void updateMenu() {
|
||||
updateMenuItems(trackId == PreferencesUtils.getRecordingTrackId(this));
|
||||
updateMenuItems(trackId == PreferencesUtils.getLong(this, R.string.recording_track_id_key));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -119,12 +119,12 @@ public class TrackListActivity extends FragmentActivity {
|
||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||
boolean updateList = false;
|
||||
// Note that key can be null
|
||||
if (PreferencesUtils.getMetricUnitsKey(TrackListActivity.this).equals(key)) {
|
||||
metricUnits = PreferencesUtils.isMetricUnits(TrackListActivity.this);
|
||||
if (PreferencesUtils.getKey(TrackListActivity.this, R.string.metric_units_key).equals(key)) {
|
||||
metricUnits = PreferencesUtils.getBoolean(TrackListActivity.this, R.string.metric_units_key, true);
|
||||
updateList = true;
|
||||
}
|
||||
if (PreferencesUtils.getRecordingTrackIdKey(TrackListActivity.this).equals(key)) {
|
||||
recordingTrackId = PreferencesUtils.getRecordingTrackId(TrackListActivity.this);
|
||||
if (PreferencesUtils.getKey(TrackListActivity.this, R.string.recording_track_id_key).equals(key)) {
|
||||
recordingTrackId = PreferencesUtils.getLong(TrackListActivity.this, R.string.recording_track_id_key);
|
||||
if (TrackRecordingServiceConnectionUtils.isRecording(
|
||||
TrackListActivity.this, trackRecordingServiceConnection)) {
|
||||
trackRecordingServiceConnection.startAndBind();
|
||||
@@ -176,8 +176,8 @@ public class TrackListActivity extends FragmentActivity {
|
||||
SharedPreferences sharedPreferences = getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
||||
metricUnits = PreferencesUtils.isMetricUnits(this);
|
||||
recordingTrackId = PreferencesUtils.getRecordingTrackId(this);
|
||||
metricUnits = PreferencesUtils.getBoolean(this, R.string.metric_units_key, true);
|
||||
recordingTrackId = PreferencesUtils.getLong(this, R.string.recording_track_id_key);
|
||||
|
||||
ImageButton recordImageButton = (ImageButton) findViewById(R.id.track_list_record_button);
|
||||
recordImageButton.setOnClickListener(new View.OnClickListener() {
|
||||
@@ -274,14 +274,14 @@ public class TrackListActivity extends FragmentActivity {
|
||||
EulaDialogFragment.newInstance(false)
|
||||
.show(getSupportFragmentManager(), EulaDialogFragment.EULA_DIALOG_TAG);
|
||||
}
|
||||
} else if (PreferencesUtils.isShowWelcomeDialog(this)) {
|
||||
} else if (PreferencesUtils.getBoolean(this, R.string.show_welcome_dialog_key, true)) {
|
||||
Fragment fragment = getSupportFragmentManager()
|
||||
.findFragmentByTag(WelcomeDialogFragment.WELCOME_DIALOG_TAG);
|
||||
if (fragment == null) {
|
||||
new WelcomeDialogFragment().show(
|
||||
getSupportFragmentManager(), WelcomeDialogFragment.WELCOME_DIALOG_TAG);
|
||||
}
|
||||
} else if (PreferencesUtils.isShowCheckUnitsDialog(this)) {
|
||||
} else if (PreferencesUtils.getBoolean(this, R.string.show_check_units_dialog_key, true)) {
|
||||
Fragment fragment = getSupportFragmentManager()
|
||||
.findFragmentByTag(CheckUnitsDialogFragment.CHECK_UNITS_DIALOG_TAG);
|
||||
if (fragment == null) {
|
||||
|
||||
@@ -294,9 +294,9 @@ public class TrackDataHub {
|
||||
}
|
||||
|
||||
private void loadSharedPreferences() {
|
||||
selectedTrackId = PreferencesUtils.getSelectedTrackId(context);
|
||||
metricUnits = PreferencesUtils.isMetricUnits(context);
|
||||
reportSpeed = PreferencesUtils.isReportSpeed(context);
|
||||
selectedTrackId = PreferencesUtils.getLong(context, R.string.selected_track_id_key);
|
||||
metricUnits = PreferencesUtils.getBoolean(context, R.string.metric_units_key, true);
|
||||
reportSpeed = PreferencesUtils.getBoolean(context, R.string.report_speed_key, true);
|
||||
minRequiredAccuracy = preferences.getInt(MIN_REQUIRED_ACCURACY_KEY,
|
||||
DEFAULT_MIN_REQUIRED_ACCURACY);
|
||||
}
|
||||
@@ -372,7 +372,7 @@ public class TrackDataHub {
|
||||
if (!isStarted()) {
|
||||
loadSharedPreferences();
|
||||
}
|
||||
long recordingTrackId = PreferencesUtils.getRecordingTrackId(context);
|
||||
long recordingTrackId = PreferencesUtils.getLong(context, R.string.recording_track_id_key);
|
||||
return recordingTrackId != -1L && recordingTrackId == selectedTrackId;
|
||||
}
|
||||
|
||||
@@ -391,7 +391,7 @@ public class TrackDataHub {
|
||||
|
||||
// Save the selection to memory and flush.
|
||||
selectedTrackId = trackId;
|
||||
PreferencesUtils.setSelectedTrackId(context, selectedTrackId);
|
||||
PreferencesUtils.setLong(context, R.string.selected_track_id_key, selectedTrackId);
|
||||
|
||||
// Force it to reload data from the beginning.
|
||||
Log.d(TAG, "Loading track");
|
||||
@@ -612,14 +612,14 @@ public class TrackDataHub {
|
||||
if (MIN_REQUIRED_ACCURACY_KEY.equals(key)) {
|
||||
minRequiredAccuracy = preferences.getInt(MIN_REQUIRED_ACCURACY_KEY,
|
||||
DEFAULT_MIN_REQUIRED_ACCURACY);
|
||||
} else if (PreferencesUtils.getMetricUnitsKey(context).equals(key)) {
|
||||
metricUnits = PreferencesUtils.isMetricUnits(context);
|
||||
} else if (PreferencesUtils.getKey(context, R.string.metric_units_key).equals(key)) {
|
||||
metricUnits = PreferencesUtils.getBoolean(context, R.string.metric_units_key, true);
|
||||
notifyUnitsChanged();
|
||||
} else if (PreferencesUtils.getReportSpeedKey(context).equals(key)) {
|
||||
reportSpeed = PreferencesUtils.isReportSpeed(context);
|
||||
} else if (PreferencesUtils.getKey(context, R.string.report_speed_key).equals(key)) {
|
||||
reportSpeed = PreferencesUtils.getBoolean(context, R.string.report_speed_key, true);
|
||||
notifySpeedReportingChanged();
|
||||
} else if (PreferencesUtils.getSelectedTrackIdKey(context).equals(key)) {
|
||||
loadTrack(PreferencesUtils.getSelectedTrackId(context));
|
||||
} else if (PreferencesUtils.getKey(context, R.string.selected_track_id_key).equals(key)) {
|
||||
loadTrack(PreferencesUtils.getLong(context, R.string.selected_track_id_key));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -46,7 +46,7 @@ public class CheckUnitsDialogFragment extends DialogFragment {
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
Locale defaultLocale = Locale.getDefault();
|
||||
boolean defaultMetric = !defaultLocale.equals(Locale.US) && !defaultLocale.equals(Locale.UK);
|
||||
PreferencesUtils.setMetricUnits(getActivity(), defaultMetric);
|
||||
PreferencesUtils.setBoolean(getActivity(), R.string.metric_units_key, defaultMetric);
|
||||
final String metric = getString(R.string.preferred_units_metric);
|
||||
final String imperial = getString(R.string.preferred_units_imperial);
|
||||
final CharSequence[] items = defaultMetric ? new CharSequence[] { metric, imperial }
|
||||
@@ -56,7 +56,7 @@ public class CheckUnitsDialogFragment extends DialogFragment {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
int position = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
|
||||
PreferencesUtils.setMetricUnits(getActivity(), items[position].equals(metric));
|
||||
PreferencesUtils.setBoolean(getActivity(), R.string.metric_units_key, items[position].equals(metric));
|
||||
onDone();
|
||||
}
|
||||
})
|
||||
@@ -68,7 +68,7 @@ public class CheckUnitsDialogFragment extends DialogFragment {
|
||||
* Tasks to perform when done.
|
||||
*/
|
||||
private void onDone() {
|
||||
PreferencesUtils.setShowCheckUnitsDialog(getActivity());
|
||||
PreferencesUtils.setBoolean(getActivity(), R.string.show_check_units_dialog_key, false);
|
||||
TrackListActivity trackListActivity = (TrackListActivity) getActivity();
|
||||
trackListActivity.showStartupDialogs();
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.d(TAG, "UI update thread started");
|
||||
while (PreferencesUtils.getRecordingTrackId(getActivity()) != -1L) {
|
||||
while (PreferencesUtils.getLong(getActivity(), R.string.recording_track_id_key) != -1L) {
|
||||
getActivity().runOnUiThread(updateTotalTime);
|
||||
try {
|
||||
Thread.sleep(1000L);
|
||||
|
||||
@@ -55,7 +55,7 @@ public class WelcomeDialogFragment extends DialogFragment {
|
||||
}
|
||||
|
||||
private void onDone() {
|
||||
PreferencesUtils.setShowWelcome(getActivity());
|
||||
PreferencesUtils.setBoolean(getActivity(), R.string.show_welcome_dialog_key, false);
|
||||
TrackListActivity trackListActivity = (TrackListActivity) getActivity();
|
||||
trackListActivity.showStartupDialogs();
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ public class SendDocsUtils {
|
||||
Track track, String spreadsheetId, String worksheetId, String authToken, Context context)
|
||||
throws IOException {
|
||||
String worksheetUri = String.format(GET_WORKSHEET_URI, spreadsheetId, worksheetId);
|
||||
boolean metricUnits = PreferencesUtils.isMetricUnits(context);
|
||||
boolean metricUnits = PreferencesUtils.getBoolean(context, R.string.metric_units_key, true);
|
||||
addRow(worksheetUri, getRowContent(track, metricUnits, context), authToken);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -205,7 +205,7 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
|
||||
private boolean uploadAllTrackPoints(Track track) {
|
||||
Cursor locationsCursor = null;
|
||||
try {
|
||||
boolean metricUnits = PreferencesUtils.isMetricUnits(context);
|
||||
boolean metricUnits = PreferencesUtils.getBoolean(context, R.string.metric_units_key, true);
|
||||
|
||||
locationsCursor = myTracksProviderUtils.getLocationsCursor(trackId, 0, -1, false);
|
||||
if (locationsCursor == null) {
|
||||
|
||||
@@ -258,7 +258,7 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
|
||||
boolean uploadAllTrackPoints(Track track) {
|
||||
Cursor locationsCursor = null;
|
||||
try {
|
||||
boolean metricUnits = PreferencesUtils.isMetricUnits(context);
|
||||
boolean metricUnits = PreferencesUtils.getBoolean(context, R.string.metric_units_key, true);
|
||||
|
||||
locationsCursor = myTracksProviderUtils.getLocationsCursor(trackId, 0, -1, false);
|
||||
if (locationsCursor == null) {
|
||||
|
||||
+1
-1
@@ -113,7 +113,7 @@ public class DynamicSpeedTrackPathDescriptor implements TrackPathDescriptor,
|
||||
|
||||
@Override
|
||||
public boolean needsRedraw() {
|
||||
long selectedTrackId = PreferencesUtils.getSelectedTrackId(context);
|
||||
long selectedTrackId = PreferencesUtils.getLong(context, R.string.selected_track_id_key);
|
||||
if (selectedTrackId == -1L) {
|
||||
// Could not find track.
|
||||
return false;
|
||||
|
||||
@@ -144,8 +144,8 @@ public class PreferenceManager implements OnSharedPreferenceChangeListener {
|
||||
autoResumeTrackTimeoutKey,
|
||||
Constants.DEFAULT_AUTO_RESUME_TRACK_TIMEOUT));
|
||||
}
|
||||
if (key == null || key.equals(PreferencesUtils.getRecordingTrackIdKey(service))) {
|
||||
long recordingTrackId = PreferencesUtils.getRecordingTrackId(service);
|
||||
if (key == null || key.equals(PreferencesUtils.getKey(service, R.string.recording_track_id_key))) {
|
||||
long recordingTrackId = PreferencesUtils.getLong(service, R.string.recording_track_id_key);
|
||||
// Only read the id if it is valid.
|
||||
// Setting it to -1 should only happen in
|
||||
// TrackRecordingService.endCurrentTrack()
|
||||
@@ -157,8 +157,8 @@ public class PreferenceManager implements OnSharedPreferenceChangeListener {
|
||||
service.setSplitFrequency(
|
||||
sharedPreferences.getInt(splitFrequencyKey, 0));
|
||||
}
|
||||
if (key == null || key.equals(PreferencesUtils.getMetricUnitsKey(service))) {
|
||||
service.setMetricUnits(PreferencesUtils.isMetricUnits(service));
|
||||
if (key == null || key.equals(PreferencesUtils.getKey(service, R.string.metric_units_key))) {
|
||||
service.setMetricUnits(PreferencesUtils.getBoolean(service, R.string.metric_units_key, true));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -271,7 +271,7 @@ public class TrackRecordingService extends Service {
|
||||
+ "Resetting an orphaned recording track = " + recordingTrackId);
|
||||
}
|
||||
recordingTrackId = -1L;
|
||||
PreferencesUtils.setRecordingTrackId(this, recordingTrackId);
|
||||
PreferencesUtils.setLong(this, R.string.recording_track_id_key, recordingTrackId);
|
||||
}
|
||||
showNotification();
|
||||
}
|
||||
@@ -328,7 +328,7 @@ public class TrackRecordingService extends Service {
|
||||
+ recordingTrack + ") doesn't exist or is too old");
|
||||
isRecording = false;
|
||||
recordingTrackId = -1L;
|
||||
PreferencesUtils.setRecordingTrackId(this, recordingTrackId);
|
||||
PreferencesUtils.setLong(this, R.string.recording_track_id_key, recordingTrackId);
|
||||
stopSelfResult(startId);
|
||||
return;
|
||||
}
|
||||
@@ -611,7 +611,7 @@ public class TrackRecordingService extends Service {
|
||||
// Reset the number of auto-resume retries.
|
||||
setAutoResumeTrackRetries(0);
|
||||
// Persist the current recording track.
|
||||
PreferencesUtils.setRecordingTrackId(this, recordingTrackId);
|
||||
PreferencesUtils.setLong(this, R.string.recording_track_id_key, recordingTrackId);
|
||||
|
||||
// Notify the world that we're now recording.
|
||||
sendTrackBroadcast(
|
||||
@@ -1054,7 +1054,7 @@ public class TrackRecordingService extends Service {
|
||||
showNotification();
|
||||
long recordedTrackId = recordingTrackId;
|
||||
recordingTrackId = -1L;
|
||||
PreferencesUtils.setRecordingTrackId(this, recordingTrackId);
|
||||
PreferencesUtils.setLong(this, R.string.recording_track_id_key, recordingTrackId);
|
||||
|
||||
if (sensorManager != null) {
|
||||
SensorManagerFactory.getInstance().releaseSensorManager(sensorManager);
|
||||
|
||||
+2
-2
@@ -150,8 +150,8 @@ public class StatusAnnouncerTask implements PeriodicTask {
|
||||
*/
|
||||
// @VisibleForTesting
|
||||
protected String getAnnouncement(TripStatistics stats) {
|
||||
boolean metricUnits = PreferencesUtils.isMetricUnits(context);
|
||||
boolean reportSpeed = PreferencesUtils.isReportSpeed(context);
|
||||
boolean metricUnits = PreferencesUtils.getBoolean(context, R.string.metric_units_key, true);
|
||||
boolean reportSpeed = PreferencesUtils.getBoolean(context, R.string.report_speed_key, true);
|
||||
double d = stats.getTotalDistance() * UnitConversions.M_TO_KM;
|
||||
double s = stats.getAverageMovingSpeed() * UnitConversions.MS_TO_KMH;
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public class ChartURLGenerator {
|
||||
*/
|
||||
public static String getChartUrl(
|
||||
Vector<Double> distances, Vector<Double> elevations, Track track, Context context) {
|
||||
boolean metricUnits = PreferencesUtils.isMetricUnits(context);
|
||||
boolean metricUnits = PreferencesUtils.getBoolean(context, R.string.metric_units_key, true);
|
||||
return getChartUrl(
|
||||
distances, elevations, track, context.getString(R.string.stats_elevation), metricUnits);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.google.android.apps.mytracks.util;
|
||||
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
@@ -32,161 +31,13 @@ public class PreferencesUtils {
|
||||
|
||||
private PreferencesUtils() {}
|
||||
|
||||
/**
|
||||
* Gets the metric units key.
|
||||
*
|
||||
* @param context the context
|
||||
*/
|
||||
public static String getMetricUnitsKey(Context context) {
|
||||
return getKey(context, R.string.metric_units_key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the metric units value.
|
||||
*
|
||||
* @param context the context
|
||||
*/
|
||||
public static boolean isMetricUnits(Context context) {
|
||||
return getBoolean(context, R.string.metric_units_key, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the metric units value.
|
||||
*
|
||||
* @param context the context
|
||||
* @param value the value
|
||||
*/
|
||||
public static void setMetricUnits(Context context, boolean value) {
|
||||
setBoolean(context, R.string.metric_units_key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the recording track id key.
|
||||
*
|
||||
* @param context the context
|
||||
*/
|
||||
public static String getRecordingTrackIdKey(Context context) {
|
||||
return getKey(context, R.string.recording_track_id_key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the recording track id.
|
||||
*
|
||||
* @param context the context
|
||||
*/
|
||||
public static long getRecordingTrackId(Context context) {
|
||||
return getLong(context, R.string.recording_track_id_key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the recording track id.
|
||||
*
|
||||
* @param context the context
|
||||
* @param trackId the track id
|
||||
*/
|
||||
public static void setRecordingTrackId(Context context, long trackId) {
|
||||
setLong(context, R.string.recording_track_id_key, trackId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the report speed key.
|
||||
*
|
||||
* @param context the context
|
||||
*/
|
||||
public static String getReportSpeedKey(Context context) {
|
||||
return getKey(context, R.string.report_speed_key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the report speed value.
|
||||
*
|
||||
* @param context the context
|
||||
*/
|
||||
public static boolean isReportSpeed(Context context) {
|
||||
return getBoolean(context, R.string.report_speed_key, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the report speed value.
|
||||
*
|
||||
* @param context the context
|
||||
* @param value the value
|
||||
*/
|
||||
public static void setReportSpeed(Context context, boolean value) {
|
||||
setBoolean(context, R.string.report_speed_key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the selected track id key.
|
||||
*
|
||||
* @param context the context
|
||||
*/
|
||||
public static String getSelectedTrackIdKey(Context context) {
|
||||
return getKey(context, R.string.selected_track_id_key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the selected track id.
|
||||
*
|
||||
* @param context the context
|
||||
*/
|
||||
public static long getSelectedTrackId(Context context) {
|
||||
return getLong(context, R.string.selected_track_id_key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the selected track id.
|
||||
*
|
||||
* @param context the context
|
||||
* @param trackId the track id
|
||||
*/
|
||||
public static void setSelectedTrackId(Context context, long trackId) {
|
||||
setLong(context, R.string.selected_track_id_key, trackId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the show check units dialog value.
|
||||
*
|
||||
* @param context the context
|
||||
*/
|
||||
public static boolean isShowCheckUnitsDialog(Context context) {
|
||||
return getBoolean(context, R.string.show_check_units_dialog_key, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the show check units dialog value to false.
|
||||
*
|
||||
* @param context the context
|
||||
*/
|
||||
public static void setShowCheckUnitsDialog(Context context) {
|
||||
setBoolean(context, R.string.show_check_units_dialog_key, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the show welcomes dialog value.
|
||||
*
|
||||
* @param context the context
|
||||
*/
|
||||
public static boolean isShowWelcomeDialog(Context context) {
|
||||
return getBoolean(context, R.string.show_welcome_dialog_key, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the show welcome dialog value to false.
|
||||
*
|
||||
* @param context the context
|
||||
*/
|
||||
public static void setShowWelcome(Context context) {
|
||||
setBoolean(context, R.string.show_welcome_dialog_key, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a preference key
|
||||
*
|
||||
* @param context the context
|
||||
* @param keyId the key id
|
||||
*/
|
||||
private static String getKey(Context context, int keyId) {
|
||||
public static String getKey(Context context, int keyId) {
|
||||
return context.getString(keyId);
|
||||
}
|
||||
|
||||
@@ -202,7 +53,7 @@ public class PreferencesUtils {
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
return sharedPreferences.getBoolean(getKey(context, keyId), defaultValue);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets a boolean preference value.
|
||||
*
|
||||
@@ -217,14 +68,14 @@ public class PreferencesUtils {
|
||||
editor.putBoolean(getKey(context, keyId), value);
|
||||
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets a long preference value.
|
||||
*
|
||||
* @param context the context
|
||||
* @param keyId the key id
|
||||
*/
|
||||
private static long getLong(Context context, int keyId) {
|
||||
public static long getLong(Context context, int keyId) {
|
||||
SharedPreferences sharedPreferences = context.getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
return sharedPreferences.getLong(getKey(context, keyId), -1L);
|
||||
@@ -237,7 +88,7 @@ public class PreferencesUtils {
|
||||
* @param keyId the key id
|
||||
* @param value the value
|
||||
*/
|
||||
private static void setLong(Context context, int keyId, long value) {
|
||||
public static void setLong(Context context, int keyId, long value) {
|
||||
SharedPreferences sharedPreferences = context.getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
Editor editor = sharedPreferences.edit();
|
||||
|
||||
+4
-4
@@ -86,7 +86,7 @@ public class TrackRecordingServiceConnectionUtils {
|
||||
Log.e(TAG, "Failed to check if service is recording", e);
|
||||
}
|
||||
}
|
||||
return PreferencesUtils.getRecordingTrackId(context) != -1L;
|
||||
return PreferencesUtils.getLong(context, R.string.recording_track_id_key) != -1L;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,7 +106,7 @@ public class TrackRecordingServiceConnectionUtils {
|
||||
* Need to remember the recordingTrackId before calling endCurrentTrack.
|
||||
* endCurrentTrack sets the value to -1L.
|
||||
*/
|
||||
long recordingTrackId = PreferencesUtils.getRecordingTrackId(context);
|
||||
long recordingTrackId = PreferencesUtils.getLong(context, R.string.recording_track_id_key);
|
||||
trackRecordingService.endCurrentTrack();
|
||||
if (recordingTrackId != -1L) {
|
||||
Intent intent = IntentUtils.newIntent(context, TrackEditActivity.class)
|
||||
@@ -118,7 +118,7 @@ public class TrackRecordingServiceConnectionUtils {
|
||||
Log.e(TAG, "Unable to stop recording.", e);
|
||||
}
|
||||
} else {
|
||||
PreferencesUtils.setRecordingTrackId(context, -1L);
|
||||
PreferencesUtils.setLong(context, R.string.recording_track_id_key, -1L);
|
||||
}
|
||||
trackRecordingServiceConnection.stop();
|
||||
}
|
||||
@@ -134,7 +134,7 @@ public class TrackRecordingServiceConnectionUtils {
|
||||
Context context, TrackRecordingServiceConnection trackRecordingServiceConnection) {
|
||||
trackRecordingServiceConnection.bindIfRunning();
|
||||
if (!isRecordingServiceRunning(context)) {
|
||||
PreferencesUtils.setRecordingTrackId(context, -1L);
|
||||
PreferencesUtils.setLong(context, R.string.recording_track_id_key, -1L);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -230,16 +230,16 @@ public class TrackWidgetProvider
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
||||
if (key == null || key.equals(PreferencesUtils.getMetricUnitsKey(context))) {
|
||||
metricUnits = PreferencesUtils.isMetricUnits(context);
|
||||
if (key == null || key.equals(PreferencesUtils.getKey(context, R.string.metric_units_key))) {
|
||||
metricUnits = PreferencesUtils.getBoolean(context, R.string.metric_units_key, true);
|
||||
}
|
||||
|
||||
if (key == null || key.equals(PreferencesUtils.getReportSpeedKey(context))) {
|
||||
reportSpeed = PreferencesUtils.isReportSpeed(context);
|
||||
if (key == null || key.equals(PreferencesUtils.getKey(context, R.string.report_speed_key))) {
|
||||
reportSpeed = PreferencesUtils.getBoolean(context, R.string.report_speed_key, true);
|
||||
}
|
||||
|
||||
if (key == null || key.equals(PreferencesUtils.getSelectedTrackIdKey(context))) {
|
||||
selectedTrackId = PreferencesUtils.getSelectedTrackId(context);
|
||||
if (key == null || key.equals(PreferencesUtils.getKey(context, R.string.selected_track_id_key))) {
|
||||
selectedTrackId = PreferencesUtils.getLong(context, R.string.selected_track_id_key);
|
||||
Log.d(TAG, "TrackWidgetProvider setting selecting track from preference: " + selectedTrackId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.google.android.apps.mytracks.content.TrackDataHub.ListenerDataType;
|
||||
import com.google.android.apps.mytracks.content.TrackDataListener.ProviderState;
|
||||
import com.google.android.apps.mytracks.services.TrackRecordingServiceTest.MockContext;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
import com.google.android.testing.mocking.AndroidMock;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -112,8 +113,8 @@ public class TrackDataHubTest extends AndroidTestCase {
|
||||
|
||||
listener1 = AndroidMock.createStrictMock("listener1", TrackDataListener.class);
|
||||
listener2 = AndroidMock.createStrictMock("listener2", TrackDataListener.class);
|
||||
PreferencesUtils.setRecordingTrackId(context, TRACK_ID);
|
||||
PreferencesUtils.setSelectedTrackId(context, TRACK_ID);
|
||||
PreferencesUtils.setLong(context, R.string.recording_track_id_key, TRACK_ID);
|
||||
PreferencesUtils.setLong(context, R.string.selected_track_id_key, TRACK_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -797,8 +798,8 @@ public class TrackDataHubTest extends AndroidTestCase {
|
||||
}
|
||||
|
||||
public void testDisplayPreferencesListen() throws Exception {
|
||||
String metricUnitsKey = PreferencesUtils.getMetricUnitsKey(context);
|
||||
String reportSpeedKey = PreferencesUtils.getReportSpeedKey(context);
|
||||
String metricUnitsKey = PreferencesUtils.getKey(context, R.string.metric_units_key);
|
||||
String reportSpeedKey = PreferencesUtils.getKey(context, R.string.report_speed_key);
|
||||
|
||||
prefs.edit()
|
||||
.putBoolean(metricUnitsKey, true)
|
||||
|
||||
+1
-1
@@ -145,7 +145,7 @@ public class DynamicSpeedTrackPathDescriptorTest extends AndroidTestCase {
|
||||
* id.
|
||||
*/
|
||||
public void testNeedsRedraw_WrongTrackId() {
|
||||
PreferencesUtils.setSelectedTrackId(context, -1L);
|
||||
PreferencesUtils.setLong(context, R.string.selected_track_id_key, -1L);
|
||||
DynamicSpeedTrackPathDescriptor dynamicSpeedTrackPathDescriptor = new DynamicSpeedTrackPathDescriptor(
|
||||
context);
|
||||
assertEquals(false, dynamicSpeedTrackPathDescriptor.needsRedraw());
|
||||
|
||||
+9
-9
@@ -167,7 +167,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
// Disable auto resume by default.
|
||||
updateAutoResumePrefs(0, -1);
|
||||
// No recording track.
|
||||
PreferencesUtils.setRecordingTrackId(context, -1L);
|
||||
PreferencesUtils.setLong(context, R.string.recording_track_id_key, -1L);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@@ -219,7 +219,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
assertTrue(service.isRecording());
|
||||
assertEquals(id, service.getRecordingTrackId());
|
||||
shutdownService();
|
||||
assertEquals(id, PreferencesUtils.getRecordingTrackId(context));
|
||||
assertEquals(id, PreferencesUtils.getLong(context, R.string.recording_track_id_key));
|
||||
|
||||
// Start the service in "resume" mode (simulates the on-reboot action).
|
||||
Intent startIntent = createStartIntent();
|
||||
@@ -315,7 +315,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
@MediumTest
|
||||
public void testRecording_orphanedRecordingTrack() throws Exception {
|
||||
// Just set recording track to a bogus value.
|
||||
PreferencesUtils.setRecordingTrackId(context, 256L);
|
||||
PreferencesUtils.setLong(context, R.string.recording_track_id_key, 256L);
|
||||
|
||||
// Make sure that the service will not start recording and will clear
|
||||
// the bogus track.
|
||||
@@ -389,7 +389,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
assertEquals(id, track.getId());
|
||||
assertEquals(sharedPreferences.getString(context.getString(R.string.default_activity_key), ""),
|
||||
track.getCategory());
|
||||
assertEquals(id, PreferencesUtils.getRecordingTrackId(context));
|
||||
assertEquals(id, PreferencesUtils.getLong(context, R.string.recording_track_id_key));
|
||||
assertEquals(id, service.getRecordingTrackId());
|
||||
|
||||
// Verify that the start broadcast was received.
|
||||
@@ -415,7 +415,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
long newTrack = service.startNewTrack();
|
||||
assertEquals(-1L, newTrack);
|
||||
|
||||
assertEquals(123L, PreferencesUtils.getRecordingTrackId(context));
|
||||
assertEquals(123L, PreferencesUtils.getLong(context, R.string.recording_track_id_key));
|
||||
assertEquals(123L, service.getRecordingTrackId());
|
||||
}
|
||||
|
||||
@@ -434,7 +434,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
// End the current track.
|
||||
service.endCurrentTrack();
|
||||
assertFalse(service.isRecording());
|
||||
assertEquals(-1L, PreferencesUtils.getRecordingTrackId(context));
|
||||
assertEquals(-1L, PreferencesUtils.getLong(context, R.string.recording_track_id_key));
|
||||
assertEquals(-1L, service.getRecordingTrackId());
|
||||
|
||||
// Verify that the stop broadcast was received.
|
||||
@@ -457,7 +457,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
// Ending the current track when there is no recording should not result in any error.
|
||||
service.endCurrentTrack();
|
||||
|
||||
assertEquals(-1L, PreferencesUtils.getRecordingTrackId(context));
|
||||
assertEquals(-1L, PreferencesUtils.getLong(context, R.string.recording_track_id_key));
|
||||
assertEquals(-1L, service.getRecordingTrackId());
|
||||
}
|
||||
|
||||
@@ -665,7 +665,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
assertTrue(track.getId() >= 0);
|
||||
providerUtils.insertTrack(track);
|
||||
assertEquals(track.getId(), providerUtils.getTrack(track.getId()).getId());
|
||||
PreferencesUtils.setRecordingTrackId(context, isRecording ? track.getId() : -1L);
|
||||
PreferencesUtils.setLong(context, R.string.recording_track_id_key, isRecording ? track.getId() : -1L);
|
||||
}
|
||||
|
||||
// TODO: We support multiple values for readability, however this test's
|
||||
@@ -706,7 +706,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
Track track = providerUtils.getTrack(id);
|
||||
assertNotNull(track);
|
||||
assertEquals(id, track.getId());
|
||||
assertEquals(id, PreferencesUtils.getRecordingTrackId(context));
|
||||
assertEquals(id, PreferencesUtils.getLong(context, R.string.recording_track_id_key));
|
||||
assertEquals(id, service.getRecordingTrackId());
|
||||
|
||||
// Insert a few points, markers and statistics.
|
||||
|
||||
Reference in New Issue
Block a user