Class DynamicThemeHandler
java.lang.Object
android.os.Handler
com.pranavpandey.android.dynamic.support.theme.DynamicThemeHandler
- All Implemented Interfaces:
DynamicListener,DynamicProductFlavor
A
Handler to handle theme updates on the main thread.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class android.os.Handler
Handler.Callback -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringBundle key to store the context changes.static final StringBundle key to store the density changes.static final StringBundle key to store the font scale changes.static final StringBundle key to store the locale changes.static final StringBundle key to store the orientation changes.static final StringBundle key to store the power save mode changes.static final StringBundle key to store the recreate changes.static final StringBundle key to store the UI mode changes.static final StringBundle key to store the dynamic color changes.static final intMessage constant to post the auto theme changes.static final intMessage constant to post the dynamic theme changes.static final intMessage constant to post the dynamic color changes.static final intMessage constant to post the dynamic configuration changes.static final intMessage constant to post the navigation bar theme changes.static final intMessage constant to post the power save mode changes. -
Constructor Summary
ConstructorsConstructorDescriptionDynamicThemeHandler(Looper looper, List<DynamicListener> listeners) Constructor to initialize an object of this class. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(DynamicListener listener) Add a dynamic listener to receive the various callbacks.voidRemove all the dynamic listener.Returns the context used by this listener.intgetDefaultColor(int colorType) This method will be called to resolve the default color according to it's type.AppTheme<?>This method will be called to return the dynamic app theme for this listener.Returns the list of listeners handled by this handler.intThis method will be called to get the intended theme styles version for this listener.intThis method will be called to return the theme style resource for this listener.intgetThemeRes(AppTheme<?> theme) This method will be called to return the theme style resource for this listener.voidhandleMessage(Message msg) booleanReturns whether to apply the dynamic colors for this listener.booleanReturns whether the dynamic colors are enabled for this listener.booleanisListener(DynamicListener listener) Checks whether a dynamic listener is already registered.booleanisNightMode(boolean resolve) Checks whether the night mode is enabled for this listener.booleanReturns whether to register a shared preferences listener for this listener.booleanReturns whether the dynamic colors should be extracted from the system for this listener.booleanReturns whether the dynamic colors should be extracted from the wallpaper for this listener.voidonAutoThemeChanged(boolean context) This method will be called when the auto theme change event occurs according to the time.voidonDynamicChanged(boolean context, boolean recreate) This method will be called when the dynamic change event occurs (like theme, locale, etc.).voidonDynamicColorsChanged(DynamicColors colors, boolean context) This method will be called when the dynamic color change event occurs according to the wallpaper.voidonDynamicConfigurationChanged(boolean locale, boolean fontScale, boolean orientation, boolean uiMode, boolean density) This method will be called when the dynamic configuration change event occurs (like locale, font scale, orientation, ui mode, etc.).voidThis method will be called when the navigation bar theme has been changed.voidonPowerSaveModeChanged(boolean powerSaveMode) This method will be called when the power save mode has been changed.voidremoveListener(DynamicListener listener) Remove a dynamic listener.resolveListener(boolean latest) Returns the latest listener added to the theme.booleanReturns whether the navigation bar theme should be applied for the activity.Methods inherited from class android.os.Handler
createAsync, createAsync, dispatchMessage, dump, getLooper, getMessageName, hasCallbacks, hasMessages, hasMessages, obtainMessage, obtainMessage, obtainMessage, obtainMessage, obtainMessage, post, postAtFrontOfQueue, postAtTime, postAtTime, postDelayed, postDelayed, removeCallbacks, removeCallbacks, removeCallbacksAndMessages, removeMessages, removeMessages, sendEmptyMessage, sendEmptyMessageAtTime, sendEmptyMessageDelayed, sendMessage, sendMessageAtFrontOfQueue, sendMessageAtTime, sendMessageDelayed, toString
-
Field Details
-
MESSAGE_POST_DYNAMIC
public static final int MESSAGE_POST_DYNAMICMessage constant to post the dynamic theme changes. -
MESSAGE_POST_DYNAMIC_CONFIGURATION
public static final int MESSAGE_POST_DYNAMIC_CONFIGURATIONMessage constant to post the dynamic configuration changes. -
MESSAGE_POST_DYNAMIC_COLOR
public static final int MESSAGE_POST_DYNAMIC_COLORMessage constant to post the dynamic color changes. -
MESSAGE_POST_AUTO_THEME
public static final int MESSAGE_POST_AUTO_THEMEMessage constant to post the auto theme changes. -
MESSAGE_POST_POWER_SAVE_MODE
public static final int MESSAGE_POST_POWER_SAVE_MODEMessage constant to post the power save mode changes. -
MESSAGE_POST_NAVIGATION_BAR_THEME
public static final int MESSAGE_POST_NAVIGATION_BAR_THEMEMessage constant to post the navigation bar theme changes. -
DATA_BOOLEAN_CONTEXT
Bundle key to store the context changes.- See Also:
-
DATA_BOOLEAN_RECREATE
Bundle key to store the recreate changes.- See Also:
-
DATA_BOOLEAN_LOCALE
Bundle key to store the locale changes.- See Also:
-
DATA_BOOLEAN_FONT_SCALE
Bundle key to store the font scale changes.- See Also:
-
DATA_BOOLEAN_ORIENTATION
Bundle key to store the orientation changes.- See Also:
-
DATA_BOOLEAN_UI_MODE
Bundle key to store the UI mode changes.- See Also:
-
DATA_BOOLEAN_DENSITY
Bundle key to store the density changes.- See Also:
-
DATA_BOOLEAN_POWER_SAVE_MODE
Bundle key to store the power save mode changes.- See Also:
-
DATA_PARCELABLE_COLORS
Bundle key to store the dynamic color changes.- See Also:
-
-
Constructor Details
-
DynamicThemeHandler
Constructor to initialize an object of this class.- Parameters:
looper- The looper to be used.listeners- The list of listeners to receive the callbacks.
-
-
Method Details
-
handleMessage
- Overrides:
handleMessagein classHandler
-
getListeners
Returns the list of listeners handled by this handler.- Returns:
- The list of listeners handled by this handler.
-
resolveListener
Returns the latest listener added to the theme.- Parameters:
latest-trueto resolve the latest listener.- Returns:
- The latest listener added to the theme.
-
clearListeners
public void clearListeners()Remove all the dynamic listener.- See Also:
-
getProductFlavor
- Specified by:
getProductFlavorin interfaceDynamicProductFlavor
-
getContext
Description copied from interface:DynamicListenerReturns the context used by this listener.- Specified by:
getContextin interfaceDynamicListener- Returns:
- The context used by this listener.
-
getRequiredThemeVersion
public int getRequiredThemeVersion()Description copied from interface:DynamicListenerThis method will be called to get the intended theme styles version for this listener.- Specified by:
getRequiredThemeVersionin interfaceDynamicListener- Returns:
- The intended theme styles version for this listener.
-
isNightMode
public boolean isNightMode(boolean resolve) Description copied from interface:DynamicListenerChecks whether the night mode is enabled for this listener.- Specified by:
isNightModein interfaceDynamicListener- Parameters:
resolve-trueto resolve based on the theme data.- Returns:
trueif the night mode is enabled for this listener.
-
getThemeRes
Description copied from interface:DynamicListenerThis method will be called to return the theme style resource for this listener.Override this method to supply your own customised style.
- Specified by:
getThemeResin interfaceDynamicListener- Returns:
- The theme style resource for this listener.
- See Also:
-
getDynamicTheme
Description copied from interface:DynamicListenerThis method will be called to return the dynamic app theme for this listener.Override this method to supply your own customised theme.
- Specified by:
getDynamicThemein interfaceDynamicListener- Returns:
- The dynamic app theme for this listener.
-
isDynamicColors
public boolean isDynamicColors()Description copied from interface:DynamicListenerReturns whether the dynamic colors are enabled for this listener.- Specified by:
isDynamicColorsin interfaceDynamicListener- Returns:
trueif the dynamic colors are enabled for this listener.
-
isDynamicColor
public boolean isDynamicColor()Description copied from interface:DynamicListenerReturns whether to apply the dynamic colors for this listener.- Specified by:
isDynamicColorin interfaceDynamicListener- Returns:
trueif the dynamic colors should be applied for this listener.
-
isSystemColor
public boolean isSystemColor()Description copied from interface:DynamicListenerReturns whether the dynamic colors should be extracted from the system for this listener.- Specified by:
isSystemColorin interfaceDynamicListener- Returns:
trueif the dynamic colors should be extracted from the system for this listener
-
isWallpaperColor
public boolean isWallpaperColor()Description copied from interface:DynamicListenerReturns whether the dynamic colors should be extracted from the wallpaper for this listener.- Specified by:
isWallpaperColorin interfaceDynamicListener- Returns:
trueif the dynamic colors should be extracted from the wallpaper for this listener
-
getDefaultColor
Description copied from interface:DynamicListenerThis method will be called to resolve the default color according to it's type.It is useful in resolving the color if the default theme also has auto values.
- Specified by:
getDefaultColorin interfaceDynamicListener- Parameters:
colorType- The color type to be resolved.- Returns:
- The resolved default color according to the color type.
- See Also:
-
onDynamicChanged
public void onDynamicChanged(boolean context, boolean recreate) Description copied from interface:DynamicListenerThis method will be called when the dynamic change event occurs (like theme, locale, etc.).Recreate the activity or application here to adapt changes.
- Specified by:
onDynamicChangedin interfaceDynamicListener- Parameters:
context-trueif there is a context change and it must be reinitialized.recreate-trueif listener must be recreated to adapt the changes.
-
onDynamicConfigurationChanged
public void onDynamicConfigurationChanged(boolean locale, boolean fontScale, boolean orientation, boolean uiMode, boolean density) Description copied from interface:DynamicListenerThis method will be called when the dynamic configuration change event occurs (like locale, font scale, orientation, ui mode, etc.).It will provide more control on
DynamicListener.onDynamicChanged(boolean, boolean)method call.- Specified by:
onDynamicConfigurationChangedin interfaceDynamicListener- Parameters:
locale-trueif locale is changed.fontScale-trueif font scale is changed.orientation-trueif there is an orientation change.uiMode-trueif ui mode is changed.density-trueif configuration density is changed.- See Also:
-
onAutoThemeChanged
public void onAutoThemeChanged(boolean context) Description copied from interface:DynamicListenerThis method will be called when the auto theme change event occurs according to the time.Recreate the activity or application here to adapt changes.
- Specified by:
onAutoThemeChangedin interfaceDynamicListener- Parameters:
context-trueif there is a context change and it must be reinitialized.
-
onPowerSaveModeChanged
public void onPowerSaveModeChanged(boolean powerSaveMode) Description copied from interface:DynamicListenerThis method will be called when the power save mode has been changed.It will be called only on API 21 and above.
- Specified by:
onPowerSaveModeChangedin interfaceDynamicListener- Parameters:
powerSaveMode-trueif the device is in power save mode.
-