-
Notifications
You must be signed in to change notification settings - Fork 1
SettingsAPI
The Preferences of user should be persistent between usage and customizable.
To better portability an external
csv
file associated with a profile can be saved and loaded anytime.
For incode settings, the annotation @ACCLSetting can be used with category and a description in any field of your Activity, Fragment or Service. These Annotated fields will be loaded and updated uppon need on the onResume() methods of Activity and Fragment and on the constructor of Service.
There are 4 types supported: Boolean, Integer, String and a set of Strings; if you annotate another type it will be treated as a String obtained from the Java
toString()
method; the set of Strings allow you to have a String setting with a fixed static set of possibilities, the first (index[0]) will be considered the default value.
The name and value of the setting will be the field's.
On the absence on the Annotation of category, other category will be used.
On the absence on the Annotation of description an empty String "" will be used.
Both settings created via the csv file and through the java @ACCLSetting annotation can be acessed globally in any component of the application through the
Settings
class via the corresponding type associated method:
getInt(key,default value)getBoolean(key,default value)getString(key,default value)
The second argument `default value` will be returned if no setting with that `key` exists and thus can be used as a debug measure.
In order to inittially copy the default_settings.csv file from assets and load its values if none exist yet. You should call the method Settings.initSettings(getBaseContext()); on the initiallization of your application by extending the Android's
Application class.
Check the Settings Example.