01 Implementation details - michael-rapp/AndroidMaterialPreferences GitHub Wiki
The preferences, which are provided by this library, are implemented as custom preferences within the classes EditTextPreference
, ListPreference
, MultiChoiceListPreference
, SeekBarPreference
, NumberPickerPreference
, DigitPickerPreference
, ResolutionPreference
, ColorPalettePreference
, SwitchPreference
and ActionPreference
. Except for the SwitchPreference
and ActionPreference
, all of these preferences show a dialog when clicked by the user. For this reason, all of these classes are extended from the class DialogPreference
. Preferences, which support validation, such like the EditTextPreference
, are extended from the class AbstractValidateableDialogPreference
.
All preference implementations provide multiple constructors. The one of them, which only expects an instance of the class Context
as a parameter, can be used instantiate the appropriate preference programmatically, the others are implicitly used by the Android SDK, when the preference is defined by using a XML resource file. Furthermore, all preference implementations override the method onSaveInstanceState():Parceable
to store the preference's current state when the preference is destroyed, e.g. when the activity it belongs to is finished. This method is implicitly called by the Android SDK. For restoring a saved state afterwards, the method ??onRestoreInstanceState(Parceable):void
, which is also implicitly called, is overridden.
Most of the preferences, which are provided by the library show a dialog when the respective preference is clicked. The theme, which should be used for the dialogs, can be specified by using the theme attribute preferenceDialogTheme
. The library comes with a predefined dark and light theme. When no theme is specified, the light theme is used by default. It can be referenced by using the resource id @style/MaterialDialog.Light
, the dark theme corresponds to the id @style/MaterialDialog
instead. In order specify the theme, which should be used, the attribute preferenceDialogTheme
has to be overwritten in the theme of your app. If the theme of one of the preferences used in the app should differ from those used by the other ones, the attribute custom:dialogThemeResource
can be used when specifying the preference as a XML resource.