org.solovyev.android.prefs
Interface Preference<T>

Type Parameters:
T - type of java object preference
All Known Implementing Classes:
AbstractPreference, BooleanPreference, CollectionSetPreference, CollectionToStringPreference, FloatPreference, HashSetPreference, IntegerPreference, LocalePreference, LongPreference, NumberIntervalPreference, NumberToStringPreference, StringPreference

public interface Preference<T>

Class for working with android preferences: can save and load preferences, convert them to custom java objects and use default value;


Method Summary
 T getDefaultValue()
           
 String getKey()
          Method returns key of preference used in android: the key with which current preference is saved in persistence
 T getPreference(android.content.SharedPreferences preferences)
          NOTE: this method can throw runtime exceptions if errors occurred while extracting preferences values
 T getPreferenceNoError(android.content.SharedPreferences preferences)
          NOTE: this method SHOULD not throw any runtime exceptions BUT return default value if any error occurred
 boolean isSameKey(String key)
           
 boolean isSet(android.content.SharedPreferences preferences)
           
 void putDefault(android.content.SharedPreferences preferences)
          Method saves default value in preferences container.
 void putPreference(android.content.SharedPreferences preferences, T value)
          Method puts (saves) preference represented by value in preferences container
 boolean tryPutDefault(android.content.SharedPreferences preferences)
          Method applies default value to preference only if explicit value is not set
 

Method Detail

getKey

@Nonnull
String getKey()
Method returns key of preference used in android: the key with which current preference is saved in persistence

Returns:
android preference key

getDefaultValue

T getDefaultValue()
Returns:
default preference value, may be null

getPreference

T getPreference(@Nonnull
                android.content.SharedPreferences preferences)
NOTE: this method can throw runtime exceptions if errors occurred while extracting preferences values

Parameters:
preferences - application preferences
Returns:
value from preference, default value if no value in preference was found

getPreferenceNoError

T getPreferenceNoError(@Nonnull
                       android.content.SharedPreferences preferences)
NOTE: this method SHOULD not throw any runtime exceptions BUT return default value if any error occurred

Parameters:
preferences - application preferences
Returns:
value from preference, default value if no value in preference was found or error occurred

putPreference

void putPreference(@Nonnull
                   android.content.SharedPreferences preferences,
                   @Nullable
                   T value)
Method puts (saves) preference represented by value in preferences container

Parameters:
preferences - preferences container
value - value to be saved

putDefault

void putDefault(@Nonnull
                android.content.SharedPreferences preferences)
Method saves default value in preferences container. Should behave exactly as p.putPreference(preferences, p.getDefaultValue())

Parameters:
preferences - preferences container

isSet

boolean isSet(@Nonnull
              android.content.SharedPreferences preferences)
Parameters:
preferences - preferences container
Returns:
true if any value is saved in preferences container, false - otherwise

tryPutDefault

boolean tryPutDefault(@Nonnull
                      android.content.SharedPreferences preferences)
Method applies default value to preference only if explicit value is not set

Parameters:
preferences - preferences container
Returns:
true if default values have been applied, false otherwise

isSameKey

boolean isSameKey(@Nonnull
                  String key)
Parameters:
key - preference key
Returns:
true if current preferences has the same key


Copyright © 2014 se.solovyev. All Rights Reserved.