T - Type of items within a collection of which values should be persisted by CollectionPreference.public final class CollectionPreference<T> extends SharedPreference<Collection<T>>
SharedPreference implementation that may be used to persist a Collection of values
via SharedPreferences.ArrayPreferenceSharedPreference.PreferenceChangeCallback<P>| Constructor and Description |
|---|
CollectionPreference(String key,
Class<T> componentType,
Collection<T> defValue)
Creates a new instance of ListPreference with the specified key and defValue.
|
| Modifier and Type | Method and Description |
|---|---|
static <T> Collection<T> |
getFromPreferences(android.content.SharedPreferences preferences,
String key,
Collection<T> defValue)
Obtains the array persisted within the given shared preferences for the
specified key.
|
protected Collection<T> |
onGetFromPreferences(android.content.SharedPreferences preferences)
Invoked to retrieve the actual value of this preference from the given shared preferences.
|
protected boolean |
onPutIntoPreferences(android.content.SharedPreferences preferences)
Invoked to persist the actual value into the given shared preferences.
|
static <T> boolean |
putIntoPreferences(android.content.SharedPreferences preferences,
String key,
Collection<T> value,
Class<T> componentType)
Persists the given collection value for the specified key into the given
shared preferences.
|
createOnChangeListener, getDefaultValue, getKey, getValue, putIntoPreferences, updateValuepublic CollectionPreference(@NonNull
String key,
@NonNull
Class<T> componentType,
@Nullable
Collection<T> defValue)
componentType - Class of components that can be presented within a collection that is to
by persisted by the new collection preference.SharedPreference.SharedPreference(String, Object)@CheckResult
protected boolean onPutIntoPreferences(@NonNull
android.content.SharedPreferences preferences)
SharedPreferenceonPutIntoPreferences in class SharedPreference<Collection<T>>preferences - The instance of shared preferences into which should be the current value
of this preference persisted.True if put has been successful, false otherwise.putIntoPreferences(SharedPreferences, String, Collection, Class)@CheckResult
public static <T> boolean putIntoPreferences(@NonNull
android.content.SharedPreferences preferences,
@NonNull
String key,
@Nullable
Collection<T> value,
@NonNull
Class<T> componentType)
T - Type of the component.preferences - The instance of shared preferences into which should be the given collection
persisted.key - The key for which should be the collection mapped in the shared preferences.value - The desired collection value to be persisted.componentType - Class of components presented within the given collection.True if put has been successful, false otherwise.@Nullable protected Collection<T> onGetFromPreferences(@NonNull android.content.SharedPreferences preferences)
SharedPreferenceonGetFromPreferences in class SharedPreference<Collection<T>>preferences - The instance of shared preferences into which was the value of this preference
before saved.getFromPreferences(SharedPreferences, String, Collection)public static <T> Collection<T> getFromPreferences(@NonNull android.content.SharedPreferences preferences, @NonNull String key, @Nullable Collection<T> defValue)
T - Type of items of the collection to obtain.preferences - The instance of shared preferences where is the desired collection persisted.key - The key for which is the desired collection mapped in the shared preferences.defValue - Default collection value to return in case when there is no collection value
persisted for the specified key yet.ClassCastException - If value stored for the specified key does not represent a
collection (more specifically an array).IllegalArgumentException - If type of items of the requested collection is not supported
by this library.IllegalStateException - If the requested collection was not stored by means of this
library.