public class SimpleSharedPreferencesFacade extends Object implements SharedPreferencesFacade
SharedPreferencesFacade which supports simple obtaining
and putting of values persisted in SharedPreferences with which is facade created
via SimpleSharedPreferencesFacade(SharedPreferences) constructor.| Constructor and Description |
|---|
SimpleSharedPreferencesFacade(android.content.SharedPreferences preferences)
Creates a new instance of SimpleSharedPreferencesFacade for the specified preferences.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(String key)
Checks whether the
SharedPreferences hidden behind this facade contain value for the
specified key or not. |
boolean |
getBoolean(String key,
boolean defValue)
Retrieves the boolean value for the specified key from
SharedPreferences
hidden behind this facade. |
float |
getFloat(String key,
float defValue)
Retrieves the float value for the specified key from
SharedPreferences
hidden behind this facade. |
int |
getInt(String key,
int defValue)
Retrieves the integer value for the specified key from
SharedPreferences
hidden behind this facade. |
long |
getLong(String key,
long defValue)
Retrieves the long value for the specified key from
SharedPreferences
hidden behind this facade. |
android.content.SharedPreferences |
getPreferences()
Returns the
SharedPreferences that are hidden behind this facade. |
String |
getString(String key,
String defValue)
Retrieves the string value for the specified key from
SharedPreferences
hidden behind this facade. |
Set<String> |
getStringSet(String key,
Set<String> defValues)
Note, that for pre
HONEYCOMB Android versions
this method does nothing and always returns null. |
boolean |
putBoolean(String key,
boolean value)
Puts the given boolean value for the specified key into
SharedPreferences
hidden behind this facade. |
boolean |
putFloat(String key,
float value)
Puts the given float value for the specified key into
SharedPreferences
hidden behind this facade. |
boolean |
putInt(String key,
int value)
Puts the given integer value for the specified key into
SharedPreferences
hidden behind this facade. |
boolean |
putLong(String key,
long value)
Puts the given long value for the specified key into
SharedPreferences
hidden behind this facade. |
boolean |
putString(String key,
String value)
Puts the given string value for the specified key into
SharedPreferences
hidden behind this facade. |
boolean |
putStringSet(String key,
Set<String> values)
Note, that for pre
HONEYCOMB Android versions
this method does nothing and always returns false. |
void |
registerOnSharedPreferenceChangeListener(android.content.SharedPreferences.OnSharedPreferenceChangeListener listener)
Registers a listener in order to receive a callback whenever a value of preference persisted
within the
SharedPreferences hidden behind this facade changes. |
boolean |
remove(String key)
Removes a value for the specified key from the
SharedPreferences hidden
behind this facade. |
int |
removeAll()
Removes all values from the
SharedPreferences hidden behind this facade. |
void |
unregisterOnSharedPreferenceChangeListener(android.content.SharedPreferences.OnSharedPreferenceChangeListener listener)
Un-registers a previously registered listener in order to not receive further any callbacks
about preference changes.
|
public SimpleSharedPreferencesFacade(android.content.SharedPreferences preferences)
preferences - The instance of shared preferences to hide behind the new facade.public final android.content.SharedPreferences getPreferences()
SharedPreferences that are hidden behind this facade.SimpleSharedPreferencesFacade(SharedPreferences)public void registerOnSharedPreferenceChangeListener(android.content.SharedPreferences.OnSharedPreferenceChangeListener listener)
SharedPreferencesFacadeSharedPreferences hidden behind this facade changes.registerOnSharedPreferenceChangeListener in interface SharedPreferencesFacadelistener - The desired listener to be registered.SharedPreferencesFacade.unregisterOnSharedPreferenceChangeListener(SharedPreferences.OnSharedPreferenceChangeListener),
SharedPreferences.registerOnSharedPreferenceChangeListener(SharedPreferences.OnSharedPreferenceChangeListener)public void unregisterOnSharedPreferenceChangeListener(android.content.SharedPreferences.OnSharedPreferenceChangeListener listener)
SharedPreferencesFacadeunregisterOnSharedPreferenceChangeListener in interface SharedPreferencesFacadelistener - The desired listener to be un-registered.SharedPreferencesFacade.registerOnSharedPreferenceChangeListener(SharedPreferences.OnSharedPreferenceChangeListener),
SharedPreferences.unregisterOnSharedPreferenceChangeListener(SharedPreferences.OnSharedPreferenceChangeListener)public boolean contains(String key)
SharedPreferencesFacadeSharedPreferences hidden behind this facade contain value for the
specified key or not.contains in interface SharedPreferencesFacadekey - The key of which value's presence to check.True if there is value contained for the specified key, false otherwise.SharedPreferencesFacade.remove(String),
SharedPreferences.contains(String)public boolean putString(String key, String value)
SharedPreferencesFacadeSharedPreferences
hidden behind this facade.putString in interface SharedPreferencesFacadekey - The key for which to put the value into preferences.value - The desired value to put into preferences.True if put has been successful, false otherwise.SharedPreferences.edit(),
SharedPreferences.Editor#putString(String, String)public String getString(String key, String defValue)
SharedPreferencesFacadeSharedPreferences
hidden behind this facade.getString in interface SharedPreferencesFacadekey - The key for which to retrieve its associated value.defValue - Default value to be returned in case when there is no value persisted for
the specified key.SharedPreferencesFacade.contains(String),
SharedPreferences.getString(String, String)public boolean putStringSet(String key, Set<String> values)
HONEYCOMB Android versions
this method does nothing and always returns false.putStringSet in interface SharedPreferencesFacadekey - The key for which to put the values into preferences.values - The desired values to put into preferences.True if put has been successful, false otherwise.SharedPreferences.edit(),
SharedPreferences.Editor#putStringSet(String, Set)public Set<String> getStringSet(String key, Set<String> defValues)
HONEYCOMB Android versions
this method does nothing and always returns null.getStringSet in interface SharedPreferencesFacadekey - The key for which to retrieve its associated values.defValues - Default values to be returned in case when there are no values persisted for
the specified key.SharedPreferencesFacade.contains(String),
SharedPreferences.getStringSet(String, Set)public boolean putInt(String key, int value)
SharedPreferencesFacadeSharedPreferences
hidden behind this facade.putInt in interface SharedPreferencesFacadekey - The key for which to put the value into preferences.value - The desired value to put into preferences.True if put has been successful, false otherwise.SharedPreferences.edit(),
SharedPreferences.Editor#putInt(String, int)public int getInt(String key, int defValue)
SharedPreferencesFacadeSharedPreferences
hidden behind this facade.getInt in interface SharedPreferencesFacadekey - The key for which to retrieve its associated value.defValue - Default value to be returned in case when there is no value persisted for
the specified key.SharedPreferencesFacade.contains(String),
SharedPreferences.getInt(String, int)public boolean putFloat(String key, float value)
SharedPreferencesFacadeSharedPreferences
hidden behind this facade.putFloat in interface SharedPreferencesFacadekey - The key for which to put the value into preferences.value - The desired value to put into preferences.True if put has been successful, false otherwise.SharedPreferences.edit(),
SharedPreferences.Editor#putFloat(String, float)public float getFloat(String key, float defValue)
SharedPreferencesFacadeSharedPreferences
hidden behind this facade.getFloat in interface SharedPreferencesFacadekey - The key for which to retrieve its associated value.defValue - Default value to be returned in case when there is no value persisted for
the specified key.SharedPreferencesFacade.contains(String),
SharedPreferences.getFloat(String, float)public boolean putLong(String key, long value)
SharedPreferencesFacadeSharedPreferences
hidden behind this facade.putLong in interface SharedPreferencesFacadekey - The key for which to put the value into preferences.value - The desired value to put into preferences.True if put has been successful, false otherwise.SharedPreferences.edit(),
SharedPreferences.Editor#putLong(String, long)public long getLong(String key, long defValue)
SharedPreferencesFacadeSharedPreferences
hidden behind this facade.getLong in interface SharedPreferencesFacadekey - The key for which to retrieve its associated value.defValue - Default value to be returned in case when there is no value persisted for
the specified key.SharedPreferencesFacade.contains(String),
SharedPreferences.getLong(String, long)public boolean putBoolean(String key, boolean value)
SharedPreferencesFacadeSharedPreferences
hidden behind this facade.putBoolean in interface SharedPreferencesFacadekey - The key for which to put the value into preferences.value - The desired value to put into preferences.True if put has been successful, false otherwise.SharedPreferences.edit(),
SharedPreferences.Editor#putBoolean(String, boolean)public boolean getBoolean(String key, boolean defValue)
SharedPreferencesFacadeSharedPreferences
hidden behind this facade.getBoolean in interface SharedPreferencesFacadekey - The key for which to retrieve its associated value.defValue - Default value to be returned in case when there is no value persisted for
the specified key.SharedPreferencesFacade.contains(String),
SharedPreferences.getBoolean(String, boolean)public boolean remove(String key)
SharedPreferencesFacadeSharedPreferences hidden
behind this facade.remove in interface SharedPreferencesFacadekey - The key for which to remove its associated value.True if removal has been successful, false otherwise.SharedPreferencesFacade.removeAll(),
SharedPreferencesFacade.contains(String),
SharedPreferences.edit(),
SharedPreferences.Editor#remove(String)public int removeAll()
SharedPreferencesFacadeSharedPreferences hidden behind this facade.removeAll in interface SharedPreferencesFacade0
if there are no values persisted.SharedPreferencesFacade.remove(String),
SharedPreferences.getAll(),
SharedPreferences.edit(),
SharedPreferences.Editor#remove(String)