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
Modifier and TypeFieldDescriptionstatic final String
Bundle key to store the context changes.static final String
Bundle key to store the density changes.static final String
Bundle key to store the font scale changes.static final String
Bundle key to store the locale changes.static final String
Bundle key to store the orientation changes.static final String
Bundle key to store the power save mode changes.static final String
Bundle key to store the recreate changes.static final String
Bundle key to store the UI mode changes.static final String
Bundle key to store the dynamic color changes.static final int
Message constant to post the auto theme changes.static final int
Message constant to post the dynamic theme changes.static final int
Message constant to post the dynamic color changes.static final int
Message constant to post the dynamic configuration changes.static final int
Message constant to post the navigation bar theme changes.static final int
Message constant to post the power save mode changes. -
Constructor Summary
ConstructorDescriptionDynamicThemeHandler
(Looper looper, List<DynamicListener> listeners) Constructor to initialize an object of this class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(DynamicListener listener) Add a dynamic listener to receive the various callbacks.void
Remove all the dynamic listener.Returns the context used by this listener.int
getDefaultColor
(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.int
This method will be called to get the intended theme styles version for this listener.int
This method will be called to return the theme style resource for this listener.int
getThemeRes
(AppTheme<?> theme) This method will be called to return the theme style resource for this listener.void
handleMessage
(Message msg) boolean
Returns whether to apply the dynamic colors for this listener.boolean
Returns whether the dynamic colors are enabled for this listener.boolean
isListener
(DynamicListener listener) Checks whether a dynamic listener is already registered.boolean
isNightMode
(boolean resolve) Checks whether the night mode is enabled for this listener.boolean
Returns whether to register a shared preferences listener for this listener.boolean
Returns whether the dynamic colors should be extracted from the system for this listener.boolean
Returns whether the dynamic colors should be extracted from the wallpaper for this listener.void
onAutoThemeChanged
(boolean context) This method will be called when the auto theme change event occurs according to the time.void
onDynamicChanged
(boolean context, boolean recreate) This method will be called when the dynamic change event occurs (like theme, locale, etc.).void
onDynamicColorsChanged
(DynamicColors colors, boolean context) This method will be called when the dynamic color change event occurs according to the wallpaper.void
onDynamicConfigurationChanged
(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.).void
This method will be called when the navigation bar theme has been changed.void
onPowerSaveModeChanged
(boolean powerSaveMode) This method will be called when the power save mode has been changed.void
removeListener
(DynamicListener listener) Remove a dynamic listener.resolveListener
(boolean latest) Returns the latest listener added to the theme.boolean
Returns 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:
handleMessage
in 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
-true
to 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:
getProductFlavor
in interfaceDynamicProductFlavor
-
getContext
Description copied from interface:DynamicListener
Returns the context used by this listener.- Specified by:
getContext
in interfaceDynamicListener
- Returns:
- The context used by this listener.
-
getRequiredThemeVersion
public int getRequiredThemeVersion()Description copied from interface:DynamicListener
This method will be called to get the intended theme styles version for this listener.- Specified by:
getRequiredThemeVersion
in interfaceDynamicListener
- Returns:
- The intended theme styles version for this listener.
-
isNightMode
public boolean isNightMode(boolean resolve) Description copied from interface:DynamicListener
Checks whether the night mode is enabled for this listener.- Specified by:
isNightMode
in interfaceDynamicListener
- Parameters:
resolve
-true
to resolve based on the theme data.- Returns:
true
if the night mode is enabled for this listener.
-
getThemeRes
Description copied from interface:DynamicListener
This method will be called to return the theme style resource for this listener.Override this method to supply your own customised style.
- Specified by:
getThemeRes
in interfaceDynamicListener
- Returns:
- The theme style resource for this listener.
- See Also:
-
getDynamicTheme
Description copied from interface:DynamicListener
This method will be called to return the dynamic app theme for this listener.Override this method to supply your own customised theme.
- Specified by:
getDynamicTheme
in interfaceDynamicListener
- Returns:
- The dynamic app theme for this listener.
-
isDynamicColors
public boolean isDynamicColors()Description copied from interface:DynamicListener
Returns whether the dynamic colors are enabled for this listener.- Specified by:
isDynamicColors
in interfaceDynamicListener
- Returns:
true
if the dynamic colors are enabled for this listener.
-
isDynamicColor
public boolean isDynamicColor()Description copied from interface:DynamicListener
Returns whether to apply the dynamic colors for this listener.- Specified by:
isDynamicColor
in interfaceDynamicListener
- Returns:
true
if the dynamic colors should be applied for this listener.
-
isSystemColor
public boolean isSystemColor()Description copied from interface:DynamicListener
Returns whether the dynamic colors should be extracted from the system for this listener.- Specified by:
isSystemColor
in interfaceDynamicListener
- Returns:
true
if the dynamic colors should be extracted from the system for this listener
-
isWallpaperColor
public boolean isWallpaperColor()Description copied from interface:DynamicListener
Returns whether the dynamic colors should be extracted from the wallpaper for this listener.- Specified by:
isWallpaperColor
in interfaceDynamicListener
- Returns:
true
if the dynamic colors should be extracted from the wallpaper for this listener
-
getDefaultColor
Description copied from interface:DynamicListener
This 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:
getDefaultColor
in 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:DynamicListener
This 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:
onDynamicChanged
in interfaceDynamicListener
- Parameters:
context
-true
if there is a context change and it must be reinitialized.recreate
-true
if 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:DynamicListener
This 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:
onDynamicConfigurationChanged
in interfaceDynamicListener
- Parameters:
locale
-true
if locale is changed.fontScale
-true
if font scale is changed.orientation
-true
if there is an orientation change.uiMode
-true
if ui mode is changed.density
-true
if configuration density is changed.- See Also:
-
onAutoThemeChanged
public void onAutoThemeChanged(boolean context) Description copied from interface:DynamicListener
This 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:
onAutoThemeChanged
in interfaceDynamicListener
- Parameters:
context
-true
if there is a context change and it must be reinitialized.
-
onPowerSaveModeChanged
public void onPowerSaveModeChanged(boolean powerSaveMode) Description copied from interface:DynamicListener
This method will be called when the power save mode has been changed.It will be called only on API 21 and above.
- Specified by:
onPowerSaveModeChanged
in interfaceDynamicListener
- Parameters:
powerSaveMode
-true
if the device is in power save mode.
-