Annotation Type Preferences


  • @Target(TYPE)
    @Retention(CLASS)
    public @interface Preferences
    Defines a set of preferences. A preference class for easier and type-safe access to SharedPreferences is generated from this annotation.

    Example

    Source Code
    {@code @Preferences(name = "org.example.AppPreferences$Generated", r = R.class, value = {
    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element Description
      java.lang.String name
      The fully qualified class name of the generated preferences class.
      java.lang.Class<?> r
      The type of the app's R class.
      PreferenceGroup[] value
      A list of PreferenceGroups.
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      boolean editor
      Whether to generate an Editor class similar to SharedPreferences.Editor.
      boolean fluent
      Whether the generated code should use fluent accessors or stick to the traditional getter/setter prefixes.
      boolean makeFile
      Whether the generated class should be public final with a private constructor, or package-private non-final with a protected constructor.
    • Element Detail

      • name

        java.lang.String name
        The fully qualified class name of the generated preferences class.
      • r

        java.lang.Class<?> r
        The type of the app's R class.
      • makeFile

        boolean makeFile
        Whether the generated class should be public final with a private constructor, or package-private non-final with a protected constructor.
        Having the generated class be non-final allows the syntax
         @Preferences(name = "Prefs$Generated", ...)
         public class Prefs extends Prefs$Generated {}
        Either way the generated class will throw an exception on instantiation.
        Default:
        false
      • fluent

        boolean fluent
        Whether the generated code should use fluent accessors or stick to the traditional getter/setter prefixes. When interoperability with kotlin code is a concern this should probably be set to false.
        Default:
        true
      • editor

        boolean editor
        Whether to generate an Editor class similar to SharedPreferences.Editor.
        Default:
        false