public final class Prefs
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Prefs.Builder
Builder class for the EasyPrefs instance.
|
| Constructor and Description |
|---|
Prefs() |
| Modifier and Type | Method and Description |
|---|---|
static android.content.SharedPreferences.Editor |
clear()
Removed all the stored keys and values.
|
static boolean |
contains(java.lang.String key)
Checks if a value is stored for the given key.
|
static android.content.SharedPreferences.Editor |
edit()
Returns the Editor of the underlying SharedPreferences instance.
|
static java.util.Map<java.lang.String,?> |
getAll() |
static boolean |
getBoolean(java.lang.String key,
boolean defValue)
Retrieves a stored boolean value.
|
static double |
getDouble(java.lang.String key,
double defValue)
Returns the double that has been saved as a long raw bits value in the long preferences.
|
static float |
getFloat(java.lang.String key,
float defValue)
Retrieves a stored float value.
|
static int |
getInt(java.lang.String key,
int defValue)
Retrieves a stored int value.
|
static long |
getLong(java.lang.String key,
long defValue)
Retrieves a stored long value.
|
static java.util.Set<java.lang.String> |
getOrderedStringSet(java.lang.String key,
java.util.Set<java.lang.String> defValue)
Retrieves a Set of Strings as stored by
putOrderedStringSet(String, Set),
preserving the original order. |
static android.content.SharedPreferences |
getPreferences()
Returns the underlying SharedPreference instance
|
static java.lang.String |
getString(java.lang.String key,
java.lang.String defValue)
Retrieves a stored String value.
|
static java.util.Set<java.lang.String> |
getStringSet(java.lang.String key,
java.util.Set<java.lang.String> defValue)
Retrieves a Set of Strings as stored by
putStringSet(String, Set). |
static void |
initPrefs(android.content.Context context)
Deprecated.
|
static void |
putBoolean(java.lang.String key,
boolean value)
Stores a boolean value.
|
static void |
putDouble(java.lang.String key,
double value)
Stores a double value as a long raw bits value.
|
static void |
putFloat(java.lang.String key,
float value)
Stores a float value.
|
static void |
putInt(java.lang.String key,
int value)
Stores an integer value.
|
static void |
putLong(java.lang.String key,
long value)
Stores a long value.
|
static void |
putOrderedStringSet(java.lang.String key,
java.util.Set<java.lang.String> value)
Stores a Set of Strings, preserving the order.
|
static void |
putString(java.lang.String key,
java.lang.String value)
Stores a String value.
|
static void |
putStringSet(java.lang.String key,
java.util.Set<java.lang.String> value)
Stores a Set of Strings.
|
static void |
remove(java.lang.String key)
Removes a preference value.
|
@Deprecated public static void initPrefs(android.content.Context context)
context - the Application context.public static android.content.SharedPreferences getPreferences()
java.lang.RuntimeException - if SharedPreference instance has not been instantiated yet.public static java.util.Map<java.lang.String,?> getAll()
SharedPreferences.getAll()public static int getInt(java.lang.String key,
int defValue)
key - The name of the preference to retrieve.defValue - Value to return if this preference does not exist.java.lang.ClassCastException - if there is a preference with this name that is not
an int.SharedPreferences.getInt(String, int)public static boolean getBoolean(java.lang.String key,
boolean defValue)
key - The name of the preference to retrieve.defValue - Value to return if this preference does not exist.java.lang.ClassCastException - if there is a preference with this name that is not a boolean.SharedPreferences.getBoolean(String, boolean)public static long getLong(java.lang.String key,
long defValue)
key - The name of the preference to retrieve.defValue - Value to return if this preference does not exist.java.lang.ClassCastException - if there is a preference with this name that is not a long.SharedPreferences.getLong(String, long)public static double getDouble(java.lang.String key,
double defValue)
key - The name of the preference to retrieve.defValue - the double Value to return if this preference does not exist.java.lang.ClassCastException - if there is a preference with this name that is not a long.SharedPreferences.getLong(String, long)public static float getFloat(java.lang.String key,
float defValue)
key - The name of the preference to retrieve.defValue - Value to return if this preference does not exist.java.lang.ClassCastException - if there is a preference with this name that is not a float.SharedPreferences.getFloat(String, float)public static java.lang.String getString(java.lang.String key,
java.lang.String defValue)
key - The name of the preference to retrieve.defValue - Value to return if this preference does not exist.java.lang.ClassCastException - if there is a preference with this name that is not a String.SharedPreferences.getString(String, String)public static java.util.Set<java.lang.String> getStringSet(java.lang.String key,
java.util.Set<java.lang.String> defValue)
putStringSet(String, Set). On Honeycomb and
later this will call the native implementation in SharedPreferences, on older SDKs this will
call getOrderedStringSet(String, Set).
Note that the native implementation of SharedPreferences.getStringSet(String,
Set) does not reliably preserve the order of the Strings in the Set.key - The name of the preference to retrieve.defValue - Value to return if this preference does not exist.java.lang.ClassCastException - if there is a preference with this name that is not a Set.SharedPreferences.getStringSet(String, java.util.Set),
getOrderedStringSet(String, Set)public static java.util.Set<java.lang.String> getOrderedStringSet(java.lang.String key,
java.util.Set<java.lang.String> defValue)
putOrderedStringSet(String, Set),
preserving the original order. Note that this implementation is heavier than the native
getStringSet(String, Set) method (which does not guarantee to preserve order).key - The name of the preference to retrieve.defValue - Value to return if this preference does not exist.java.lang.ClassCastException - if there is a preference with this name that is not a Set of
Strings.getStringSet(String, Set)public static void putLong(java.lang.String key,
long value)
key - The name of the preference to modify.value - The new value for the preference.SharedPreferences.Editor.putLong(String, long)public static void putInt(java.lang.String key,
int value)
key - The name of the preference to modify.value - The new value for the preference.SharedPreferences.Editor.putInt(String, int)public static void putDouble(java.lang.String key,
double value)
key - The name of the preference to modify.value - The double value to be save in the preferences.SharedPreferences.Editor.putLong(String, long)public static void putFloat(java.lang.String key,
float value)
key - The name of the preference to modify.value - The new value for the preference.SharedPreferences.Editor.putFloat(String, float)public static void putBoolean(java.lang.String key,
boolean value)
key - The name of the preference to modify.value - The new value for the preference.SharedPreferences.Editor.putBoolean(String, boolean)public static void putString(java.lang.String key,
java.lang.String value)
key - The name of the preference to modify.value - The new value for the preference.SharedPreferences.Editor.putString(String, String)public static void putStringSet(java.lang.String key,
java.util.Set<java.lang.String> value)
putOrderedStringSet(String,
Set).
Note that the native implementation of SharedPreferences.Editor.putStringSet(String,
Set) does not reliably preserve the order of the Strings in the Set.key - The name of the preference to modify.value - The new value for the preference.SharedPreferences.Editor.putStringSet(String, java.util.Set),
putOrderedStringSet(String, Set)public static void putOrderedStringSet(java.lang.String key,
java.util.Set<java.lang.String> value)
putStringSet(String,
Set) (which does not reliably preserve the order of the Set). To preserve the order of the
items in the Set, the Set implementation must be one that as an iterator with predictable
order, such as LinkedHashSet.key - The name of the preference to modify.value - The new value for the preference.putStringSet(String, Set),
getOrderedStringSet(String, Set)public static void remove(java.lang.String key)
key - The name of the preference to remove.SharedPreferences.Editor.remove(String)public static boolean contains(java.lang.String key)
key - The name of the preference to check.true if the storage contains this key value, false otherwise.SharedPreferences.contains(String)public static android.content.SharedPreferences.Editor clear()
SharedPreferences.Editor for chaining. The changes have already been committed/applied
through the execution of this method.SharedPreferences.Editor.clear()public static android.content.SharedPreferences.Editor edit()