public final class EncryptedPreferences
extends java.lang.Object
| 限定符和类型 | 类和说明 |
|---|---|
static class |
EncryptedPreferences.Builder
Class for configuring a new
EncryptedPreferences instance. |
class |
EncryptedPreferences.EncryptedEditor
Class used for modifying values in a
EncryptedPreferences object. |
static interface |
EncryptedPreferences.OnSharedPreferenceChangeListener
Interface definition for a callback to be invoked when a shared
preference is changed.
|
class |
EncryptedPreferences.Utils
A class for several utility methods.
|
| 限定符和类型 | 方法和说明 |
|---|---|
boolean |
contains(java.lang.String key)
Checks whether the preferences contains a preference.
|
EncryptedPreferences.EncryptedEditor |
edit()
Get the Editor for these preferences, through which you can make modifications to the data in the preferences and atomically commit those changes
back to
the SharedPreferences object.
|
void |
forceDeleteExistingPreferences()
Deletes all existing preference entries stored in its underlying SharedPreferences instance.
|
java.util.Set<java.lang.String> |
getAllKeys()
Retrieve a Set
|
java.util.Set<java.lang.String> |
getAllKeys(boolean decrypt)
Retrieve a Set
|
boolean |
getBoolean(java.lang.String key,
boolean defaultValue)
Retrieve a boolean value from the preferences
|
float |
getFloat(java.lang.String key,
float defaultValue)
Retrieve a float value from the preferences
|
static EncryptedPreferences |
getInstance(android.content.Context context)
已过时。
Due to security reasons it's recommended to use
EncryptedPreferences.Builder for instance creation instead. |
int |
getInt(java.lang.String key,
int defaultValue)
Retrieve an int value from the preferences.
|
long |
getLong(java.lang.String key,
long defaultValue)
Retrieve a long value from the preferences.
|
static EncryptedPreferences |
getSingletonInstance()
Retrieve the configured
EncryptedPreferences instance. |
java.lang.String |
getString(java.lang.String key,
java.lang.String defaultValue)
Retrieve a String value from the preferences
|
EncryptedPreferences.Utils |
getUtils()
Get the
EncryptedPreferences.Utils instance for this EncryptedPreferences configuration. |
void |
importSharedPreferences(android.content.SharedPreferences sharedPreferences,
boolean override)
Allows you to import your unencrypted SharedPreferences.
|
void |
importSharedPreferences(android.content.SharedPreferences sharedPreferences,
boolean override,
boolean removeAfter)
Allows you to import your unencrypted SharedPreferences.
|
void |
registerOnSharedPreferenceChangeListener(EncryptedPreferences.OnSharedPreferenceChangeListener listener)
Registers a callback to be invoked when a change happens to a preference.
|
void |
unregisterOnSharedPreferenceChangeListener(EncryptedPreferences.OnSharedPreferenceChangeListener listener)
Unregisters a previous callback.
|
@Deprecated public static EncryptedPreferences getInstance(android.content.Context context)
EncryptedPreferences.Builder for instance creation instead.EncryptedPreferences instance with all default settings.context - EncryptedPreferencespublic static EncryptedPreferences getSingletonInstance()
EncryptedPreferences instance.
Make sure to call EncryptedPreferences.Builder.withSaveAsSingleton(boolean) to initialize the singleton, otherwise a RuntimeException will be thrown.EncryptedPreferences instance.public int getInt(java.lang.String key,
int defaultValue)
key - - The name of the preference to retrievedefaultValue - - Value to return if this preference does not existpublic long getLong(java.lang.String key,
long defaultValue)
key - - The name of the preference to retrievedefaultValue - - Value to return if this preference does not existpublic boolean getBoolean(java.lang.String key,
boolean defaultValue)
key - - The name of the preference to retrievedefaultValue - - Value to return if this preference does not existpublic float getFloat(java.lang.String key,
float defaultValue)
key - - The name of the preference to retrievedefaultValue - - Value to return if this preference does not existpublic java.lang.String getString(java.lang.String key,
java.lang.String defaultValue)
key - - The name of the preference to retrievedefaultValue - - Value to return if this preference does not existpublic java.util.Set<java.lang.String> getAllKeys(boolean decrypt)
decrypt - - Whether to decrypt stored keys before returning them or not.public java.util.Set<java.lang.String> getAllKeys()
public boolean contains(java.lang.String key)
key - - The name of the preference to checkpublic EncryptedPreferences.EncryptedEditor edit()
public EncryptedPreferences.Utils getUtils()
EncryptedPreferences.Utils instance for this EncryptedPreferences configuration.EncryptedPreferences.Utils instance for this EncryptedPreferences configuration.public void importSharedPreferences(android.content.SharedPreferences sharedPreferences,
boolean override)
sharedPreferences - - The unencrypted SharedPreferences instanceoverride - - Whether to override existing keys (and their values) or notpublic void importSharedPreferences(android.content.SharedPreferences sharedPreferences,
boolean override,
boolean removeAfter)
sharedPreferences - - The unencrypted SharedPreferences instanceoverride - - Whether to override existing keys (and their values) or notremoveAfter - - Whether to remove the old unencrypted entries after encrypting or notpublic void forceDeleteExistingPreferences()
EncryptedPreferences won't respect non-encrypted values during deletion.
The operation is completely key-based, therefore no encryption key is required.
Removed values cannot be restored!SharedPreferences#getAll()}public void registerOnSharedPreferenceChangeListener(EncryptedPreferences.OnSharedPreferenceChangeListener listener)
listener - The callback that will run.unregisterOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener)public void unregisterOnSharedPreferenceChangeListener(EncryptedPreferences.OnSharedPreferenceChangeListener listener)
listener - The callback that should be unregistered.registerOnSharedPreferenceChangeListener(com.pddstudio.preferences.encrypted.EncryptedPreferences.OnSharedPreferenceChangeListener)