com.todoroo.andlib.utility
Class Preferences

java.lang.Object
  extended by com.todoroo.andlib.utility.Preferences

public class Preferences
extends java.lang.Object

Helper class for reading and writing SharedPreferences

Author:
Tim Su

Constructor Summary
Preferences()
           
 
Method Summary
static void clear(java.lang.String key)
          Clears a preference
static boolean getBoolean(int keyResources, boolean defValue)
          Gets a boolean preference (e.g.
static boolean getBoolean(java.lang.String key, boolean defValue)
          Gets a boolean preference (e.g.
static java.lang.Float getFloatFromString(int keyResource)
          Gets an float value from a string preference.
static int getInt(java.lang.String key, int defValue)
          Gets a int preference
static int getIntegerFromString(int keyResource, int defaultValue)
          Gets an integer value from a string preference.
static long getLong(java.lang.String key, long defValue)
          Gets a long preference
static android.content.SharedPreferences getPrefs(android.content.Context context)
          Get preferences object from the context
static java.lang.String getStringValue(int keyResource)
          Gets an string value from a string preference.
static java.lang.String getStringValue(java.lang.String key)
          Gets an string value from a string preference.
static boolean isSet(java.lang.String key)
           
static void setBoolean(int keyResource, boolean value)
          Sets boolean preference
static void setBoolean(java.lang.String key, boolean value)
          Sets boolean preference
static void setIfUnset(android.content.SharedPreferences prefs, android.content.SharedPreferences.Editor editor, android.content.res.Resources r, int keyResource, boolean value)
          Helper to write to editor if key specified is null
static void setIfUnset(android.content.SharedPreferences prefs, android.content.SharedPreferences.Editor editor, android.content.res.Resources r, int keyResource, int value)
          Helper to write to editor if key specified is null.
static void setInt(java.lang.String key, int value)
          Sets int preference
static void setLong(java.lang.String key, long value)
          Sets long preference
static void setString(int keyResource, java.lang.String newValue)
          Sets string preference
static void setString(java.lang.String key, java.lang.String newValue)
          Sets string preference
static void setStringFromInteger(int keyResource, int newValue)
          Sets string preference from integer value
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Preferences

public Preferences()
Method Detail

setIfUnset

public static void setIfUnset(android.content.SharedPreferences prefs,
                              android.content.SharedPreferences.Editor editor,
                              android.content.res.Resources r,
                              int keyResource,
                              int value)
Helper to write to editor if key specified is null. Writes a String property with the given integer

Parameters:
prefs -
editor -
r -
keyResource -
value -

setIfUnset

public static void setIfUnset(android.content.SharedPreferences prefs,
                              android.content.SharedPreferences.Editor editor,
                              android.content.res.Resources r,
                              int keyResource,
                              boolean value)
Helper to write to editor if key specified is null

Parameters:
prefs -
editor -
r -
keyResource -
value -

getPrefs

public static android.content.SharedPreferences getPrefs(android.content.Context context)
Get preferences object from the context


isSet

public static boolean isSet(java.lang.String key)
Returns:
true if given preference is set

getStringValue

public static java.lang.String getStringValue(java.lang.String key)
Gets an string value from a string preference. Returns null if the value is not set

Parameters:
context -
key -
Returns:
integer value, or null on error

getStringValue

public static java.lang.String getStringValue(int keyResource)
Gets an string value from a string preference. Returns null if the value is not set

Parameters:
context -
key -
Returns:
integer value, or null on error

getIntegerFromString

public static int getIntegerFromString(int keyResource,
                                       int defaultValue)
Gets an integer value from a string preference. Returns null if the value is not set or not an integer.

Parameters:
keyResource - resource from string.xml
Returns:
integer value, or null on error

getFloatFromString

public static java.lang.Float getFloatFromString(int keyResource)
Gets an float value from a string preference. Returns null if the value is not set or not an flat.

Parameters:
keyResource - resource from string.xml
Returns:

setString

public static void setString(int keyResource,
                             java.lang.String newValue)
Sets string preference


setString

public static void setString(java.lang.String key,
                             java.lang.String newValue)
Sets string preference


setStringFromInteger

public static void setStringFromInteger(int keyResource,
                                        int newValue)
Sets string preference from integer value


getBoolean

public static boolean getBoolean(java.lang.String key,
                                 boolean defValue)
Gets a boolean preference (e.g. a CheckBoxPreference setting)

Parameters:
key -
defValue -
Returns:
default if value is unset otherwise the value

getBoolean

public static boolean getBoolean(int keyResources,
                                 boolean defValue)
Gets a boolean preference (e.g. a CheckBoxPreference setting)

Parameters:
keyResource -
defValue -
Returns:
default if value is unset otherwise the value

setBoolean

public static void setBoolean(int keyResource,
                              boolean value)
Sets boolean preference

Parameters:
key -
value -

setBoolean

public static void setBoolean(java.lang.String key,
                              boolean value)
Sets boolean preference

Parameters:
key -
value -

getInt

public static int getInt(java.lang.String key,
                         int defValue)
Gets a int preference

Parameters:
key -
defValue -
Returns:
default if value is unset otherwise the value

setInt

public static void setInt(java.lang.String key,
                          int value)
Sets int preference

Parameters:
key -
value -

getLong

public static long getLong(java.lang.String key,
                           long defValue)
Gets a long preference

Parameters:
key -
defValue -
Returns:
default if value is unset otherwise the value

setLong

public static void setLong(java.lang.String key,
                           long value)
Sets long preference

Parameters:
key -
value -

clear

public static void clear(java.lang.String key)
Clears a preference

Parameters:
key -