Annotation Type Preference
-
@Target({}) @Retention(CLASS) public @interface PreferenceDefines a preference. The preference key is the value of the string resource
withR.string.${preference_group_prefix}${name}${preference_group_suffix}${preference_group_prefix}and${preference_group_suffix}being the prefix and suffix defined in the enclosingPreferenceGroup-Annotation.
For each preference with atype()other thanvoid.classa getter
and a setterpublic ${type} ${name}()
will be generated in the preference group. Additionally, a key accessorpublic void ${name}(${type} value)
is generated in thepublic String ${name}()Keysclass of the preference group for each preference (includingvoid).- See Also:
Preferences,PreferenceGroup
-
-
Field Summary
Fields Modifier and Type Fields Description static java.lang.StringNO_DEFAULT_VALUE
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description java.lang.StringdefaultValueThe default value for the preference.java.lang.StringdescriptionA description that will be used as documentation for the preference accessors in the generated class.java.lang.Class<? extends PreferenceSerializer>serializerA serializer used for converting the preference type to a type supported bySharedPreferencesand back.
-
-
-
Element Detail
-
name
java.lang.String name
The name of the preference. Must be a valid Java identifier on its own and when combined with the preference gropusPreferenceGroup.prefix()andPreferenceGroup.suffix().
-
-
-
type
java.lang.Class<?> type
The type of the preference.If no serializer is provided this must be one of
byte.class,char.class,short.class,int.class,long.class,float.class,double.class,boolean.class,String.class,void.class,Set.classor any subtype ofEnum.class.If a serializer is provided the type declared here will serve as type-argument and/or constructor argument for the serializer. The actual preference type will be the serializers source type and may differ.
Since
SharedPreferencesonly supportint,long,float,boolean,StringandSet<String>the other natively supported types must be converted into one of those types:byte,charandshortare stored as anint-
doubleis stored as alongviaDouble.doubleToRawLongBits(double)andDouble.longBitsToDouble(long) -
enumis stored as aStringviaEnum.name()andEnum.valueOf(Class, String) -
Setis interpreted asSet<String> -
voidis not stored
- See Also:
serializer()
-
-
-
defaultValue
java.lang.String defaultValue
The default value for the preference. If no default value is provided the default value will befalseforbooleanpreferences,0forbyte,short,char,int,long,floatanddoublepreferences andnullforString,enumandSet<String>preferences
voidpreferences. If thetype()isString, then the default value is automatically escaped and quoted, otherwise it will be copied into the generated class source code as is. If aserializer()is used, the default value must be provided in serialized form, i.e. it must be a valid argument to the serializersPreferenceSerializer.deserialize(Object)method.- Implementation Note:
- it is possibly to inject code into the generated classes by misusing this field. Just don't.
- Default:
- "__NO_DEFAULT_VALUE__"
-
-
-
serializer
java.lang.Class<? extends PreferenceSerializer> serializer
A serializer used for converting the preference type to a type supported by
SharedPreferencesand back.A serializer must have at most one type argument
T- the declared preference type - and must either have a default constructor or a constructor taking exactly one argument of typeClass<? extends T>. If both constructors are present it is not defined which one will be used. Furthermore the serializers target type must be a primitive wrapper orString. If the target type is a primitive wrapper the argument ofPreferenceSerializer.deserialize(Object)is guaranteed to be non-nulland the return value ofPreferenceSerializer.serialize(Object)must be non-null.The actual preference type will be the serializers source type. Therefore a preference
{@code- Default:
- eu.jonahbauer.android.preference.annotations.serializer.PreferenceSerializer.class
-
-