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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user