[Android General] daxgirl:
Preferences - Part 1: Introduction

1. Major change in implementation:

1. For this release we made a major change in how preferences are handled. They are not handled anymore.

They handle themselves

.

2. For that to happen we needed to subclass ALL native android preferences except PreferenceScreen and PreferenceCategory.

3. What does it mean to subclass? That means we created java classses which extend (resemble) native android preferences and we wrote our own implementation of how they should behave, how they should load their values and write their values.

4. That being said - there is no more standard android preferences in this project.

No more SwitchPreference, no more CheckboxPreference, no ListPreference...

None of those.

5. Two reasons for that:

1. We didn't want you to get lost in special conditions anymore. We wanted you to be able to set if the preference should restart systemui from xml file when you declare preference. For that we needed to add custom xml attributes. For that we needed a preference class to be able to acknowledge that. So we needed a custom preference class.

2. We wanted the preference to manage itself in by reading and writing from and to database. Instead of fragment running endless iterations and conditions. When our new preferences are born (attached to the screen), they get their value from the database directly. No one needs to set values to them. When they are changed, they know to write into database directly. From their own class. Not containing fragment doing that for them.​

2. Types of preferences

1. Two state preferences:

MySwitchPreference

MyCheckboxPreference

FilePreference​

2. Dialog preferences:

MyListPreference

MyEditTextPreference

IntentDialogPreference

ThumbnailListPreference

ColorPickerPreference​

3. Native preferences(PreferenceGroup subclasses):

PreferenceScreen

PreferenceCategory​

4. Slider Preference:

MySeekBarPreference​

5. Special preferences:

OpenAppPreference

UriSelectionPreference

RunScriptPreference

ImageHeaderPreference​

3. Setting defaults:

It is ABSOLUTELY VITALLY IMPORTANT that you set

android:defaultValue

to all the preferences that change and read values. That means:

MySwitchPreference

MyCheckboxPreference

FilePreference

MyListPreference

MyEditTextPreference

ThumbnailListPreference

ColorPickerPreference

MySeekBarPreference
​

4. What happens if we use regular android preferences? Like SwitchPreference or ListPreference?

Nothing! Absolutely nothing will happen nor to this project, nor to your database and, MOST IMPORTANTLY, nor to your mods.

It will act like normal preference. It will not write to database. Your mods will not be affected and WILL NOT WORK.

​

5. Custom attributes for value changing preferences and RunScriptPreference

1. app: packageNameToKill

This attribute is of type string and you will need to provide which app you want to restart when this preference changes value.​

2. app:isSilent

This is a boolean type attribute, which is by default set to true. That means that if you don't set this attribute and you DO set the package name to kill, it will restart the app you want without warning as soon as the value has been changed. If it is set to "false", upon value change a dialog will appear with app icon and test informing user that for this action to take effect an app restart is required. They can then choose to kill app now or cancel the dialog and kill it later.​

3. app:rebootRequired

This is also a boolean type of preference which by default is set to false. If you set it to "true", upon preference value change a dialog will appear, informing the user that reboot is required for this action to take effect. good example for that is changing the default app intent to open on home button double click. That needs framework reload.

If rebootRequired is set to true and you ALSO set package name to kill, reboot takes preference. Package to kill will be ignored.​