Class DynamicApplication
java.lang.Object
android.content.Context
android.content.ContextWrapper
android.app.Application
com.pranavpandey.android.dynamic.support.DynamicApplication
- All Implemented Interfaces:
ComponentCallbacks
,ComponentCallbacks2
,SharedPreferences.OnSharedPreferenceChangeListener
,Configuration.Provider
,DynamicLocale
,DynamicListener
,DynamicProductFlavor
public abstract class DynamicApplication
extends Application
implements Configuration.Provider, DynamicProductFlavor, DynamicLocale, DynamicListener, SharedPreferences.OnSharedPreferenceChangeListener
Base
Application
class which can be extended to initialize the DynamicTheme
and to perform theme change operations.-
Nested Class Summary
Nested classes/interfaces inherited from class android.app.Application
Application.ActivityLifecycleCallbacks, Application.OnProvideAssistDataListener
Nested classes/interfaces inherited from class android.content.Context
Context.BindServiceFlags
-
Field Summary
Fields inherited from class android.content.Context
ACCESSIBILITY_SERVICE, ACCOUNT_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, APP_OPS_SERVICE, APP_SEARCH_SERVICE, APPWIDGET_SERVICE, AUDIO_SERVICE, BATTERY_SERVICE, BIND_ABOVE_CLIENT, BIND_ADJUST_WITH_ACTIVITY, BIND_ALLOW_ACTIVITY_STARTS, BIND_ALLOW_OOM_MANAGEMENT, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_EXTERNAL_SERVICE, BIND_EXTERNAL_SERVICE_LONG, BIND_IMPORTANT, BIND_INCLUDE_CAPABILITIES, BIND_NOT_FOREGROUND, BIND_NOT_PERCEPTIBLE, BIND_PACKAGE_ISOLATED_PROCESS, BIND_SHARED_ISOLATED_PROCESS, BIND_WAIVE_PRIORITY, BIOMETRIC_SERVICE, BLOB_STORE_SERVICE, BLUETOOTH_SERVICE, BUGREPORT_SERVICE, CAMERA_SERVICE, CAPTIONING_SERVICE, CARRIER_CONFIG_SERVICE, CLIPBOARD_SERVICE, COMPANION_DEVICE_SERVICE, CONNECTIVITY_DIAGNOSTICS_SERVICE, CONNECTIVITY_SERVICE, CONSUMER_IR_SERVICE, CONTACT_KEYS_SERVICE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_RESTRICTED, CREDENTIAL_SERVICE, CROSS_PROFILE_APPS_SERVICE, DEVICE_ID_DEFAULT, DEVICE_ID_INVALID, DEVICE_LOCK_SERVICE, DEVICE_POLICY_SERVICE, DISPLAY_HASH_SERVICE, DISPLAY_SERVICE, DOMAIN_VERIFICATION_SERVICE, DOWNLOAD_SERVICE, DROPBOX_SERVICE, EUICC_SERVICE, FILE_INTEGRITY_SERVICE, FINGERPRINT_SERVICE, GAME_SERVICE, GRAMMATICAL_INFLECTION_SERVICE, HARDWARE_PROPERTIES_SERVICE, HEALTHCONNECT_SERVICE, INPUT_METHOD_SERVICE, INPUT_SERVICE, IPSEC_SERVICE, JOB_SCHEDULER_SERVICE, KEYGUARD_SERVICE, LAUNCHER_APPS_SERVICE, LAYOUT_INFLATER_SERVICE, LOCALE_SERVICE, LOCATION_SERVICE, MEDIA_COMMUNICATION_SERVICE, MEDIA_METRICS_SERVICE, MEDIA_PROJECTION_SERVICE, MEDIA_ROUTER_SERVICE, MEDIA_SESSION_SERVICE, MIDI_SERVICE, MODE_APPEND, MODE_ENABLE_WRITE_AHEAD_LOGGING, MODE_MULTI_PROCESS, MODE_NO_LOCALIZED_COLLATORS, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NETWORK_STATS_SERVICE, NFC_SERVICE, NOTIFICATION_SERVICE, NSD_SERVICE, OVERLAY_SERVICE, PEOPLE_SERVICE, PERFORMANCE_HINT_SERVICE, PERSISTENT_DATA_BLOCK_SERVICE, POWER_SERVICE, PRINT_SERVICE, PROFILING_SERVICE, RECEIVER_EXPORTED, RECEIVER_NOT_EXPORTED, RECEIVER_VISIBLE_TO_INSTANT_APPS, RESTRICTIONS_SERVICE, ROLE_SERVICE, SEARCH_SERVICE, SECURITY_STATE_SERVICE, SENSOR_SERVICE, SHORTCUT_SERVICE, STATUS_BAR_SERVICE, STORAGE_SERVICE, STORAGE_STATS_SERVICE, SYSTEM_HEALTH_SERVICE, TELECOM_SERVICE, TELEPHONY_IMS_SERVICE, TELEPHONY_SERVICE, TELEPHONY_SUBSCRIPTION_SERVICE, TEXT_CLASSIFICATION_SERVICE, TEXT_SERVICES_MANAGER_SERVICE, TV_INPUT_SERVICE, TV_INTERACTIVE_APP_SERVICE, UI_MODE_SERVICE, USAGE_STATS_SERVICE, USB_SERVICE, USER_SERVICE, VIBRATOR_MANAGER_SERVICE, VIBRATOR_SERVICE, VIRTUAL_DEVICE_SERVICE, VPN_MANAGEMENT_SERVICE, WALLPAPER_SERVICE, WIFI_AWARE_SERVICE, WIFI_P2P_SERVICE, WIFI_RTT_RANGING_SERVICE, WIFI_SERVICE, WINDOW_SERVICE
Fields inherited from interface android.content.ComponentCallbacks2
TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_COMPLETE, TRIM_MEMORY_MODERATE, TRIM_MEMORY_RUNNING_CRITICAL, TRIM_MEMORY_RUNNING_LOW, TRIM_MEMORY_RUNNING_MODERATE, TRIM_MEMORY_UI_HIDDEN
Fields inherited from interface com.pranavpandey.android.dynamic.locale.DynamicLocale
HINDI, INDONESIA, PORTUGUESE, RUSSIAN, SPANISH, SPLIT, SYSTEM, TURKISH
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
attachBaseContext
(Context base) 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.getDefaultLocale
(Context context) protected DynamicResolver
Returns the resolver for the dynamic theme to provide implementation for conditions like auto and night themes.AppTheme<?>
This method will be called to return the dynamic app theme for this listener.float
int
This method will be called to get the intended theme styles version for this listener.String[]
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.boolean
Returns whether to apply the dynamic colors for this listener.boolean
Returns whether the dynamic colors are 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
onConfigurationChanged
(Configuration newConfig) void
onCreate()
protected void
This method will be called inside theonCreate()
method after applying the theme.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.).protected abstract void
This method will be called inside theonCreate()
method before applying the theme.void
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.protected boolean
This method will be called before setting up the dynamic work to listen changes based on time.void
onSharedPreferenceChanged
(SharedPreferences sharedPreferences, String key) protected void
Set the dynamic app theme and style resource for this application.boolean
Returns whether the navigation bar theme should be applied for the activity.Methods inherited from class android.app.Application
getProcessName, onTerminate, onTrimMemory, registerActivityLifecycleCallbacks, registerComponentCallbacks, registerOnProvideAssistDataListener, unregisterActivityLifecycleCallbacks, unregisterComponentCallbacks, unregisterOnProvideAssistDataListener
Methods inherited from class android.content.ContextWrapper
bindIsolatedService, bindService, bindService, bindService, bindService, bindServiceAsUser, bindServiceAsUser, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingOrSelfUriPermissions, checkCallingPermission, checkCallingUriPermission, checkCallingUriPermissions, checkContentUriPermissionFull, checkPermission, checkSelfPermission, checkUriPermission, checkUriPermission, checkUriPermissions, clearWallpaper, createAttributionContext, createConfigurationContext, createContext, createContextForSplit, createDeviceContext, createDeviceProtectedStorageContext, createDisplayContext, createPackageContext, createWindowContext, createWindowContext, databaseList, deleteDatabase, deleteFile, deleteSharedPreferences, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAssets, getAttributionSource, getAttributionTag, getBaseContext, getCacheDir, getClassLoader, getCodeCacheDir, getContentResolver, getDatabasePath, getDataDir, getDeviceId, getDir, getDisplay, getExternalCacheDir, getExternalCacheDirs, getExternalFilesDir, getExternalFilesDirs, getExternalMediaDirs, getFilesDir, getFileStreamPath, getMainExecutor, getMainLooper, getNoBackupFilesDir, getObbDir, getObbDirs, getOpPackageName, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getParams, getResources, getSharedPreferences, getSystemService, getSystemServiceName, getTheme, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isDeviceProtectedStorage, isRestricted, isUiContext, moveDatabaseFrom, moveSharedPreferencesFrom, openFileInput, openFileOutput, openOrCreateDatabase, openOrCreateDatabase, peekWallpaper, registerDeviceIdChangeListener, registerReceiver, registerReceiver, registerReceiver, registerReceiver, removeStickyBroadcast, removeStickyBroadcastAsUser, revokeSelfPermissionsOnKill, revokeUriPermission, revokeUriPermission, sendBroadcast, sendBroadcast, sendBroadcast, sendBroadcastAsUser, sendBroadcastAsUser, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcastAsUser, sendStickyBroadcast, sendStickyBroadcast, sendStickyBroadcastAsUser, sendStickyOrderedBroadcast, sendStickyOrderedBroadcastAsUser, setTheme, setWallpaper, setWallpaper, startActivities, startActivities, startActivity, startActivity, startForegroundService, startInstrumentation, startIntentSender, startIntentSender, startService, stopService, unbindService, unregisterDeviceIdChangeListener, unregisterReceiver, updateServiceGroup
Methods inherited from class android.content.Context
bindIsolatedService, getColor, getColorStateList, getDrawable, getString, getString, getSystemService, getText, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, revokeSelfPermissionOnKill, sendBroadcastWithMultiplePermissions
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.pranavpandey.android.dynamic.support.listener.DynamicListener
isNightMode
Methods inherited from interface com.pranavpandey.android.dynamic.locale.DynamicLocale
getLocale
-
Field Details
-
mContext
Dynamic context used by this application.
-
-
Constructor Details
-
DynamicApplication
public DynamicApplication()
-
-
Method Details
-
attachBaseContext
- Overrides:
attachBaseContext
in classContextWrapper
-
onCreate
public void onCreate()- Overrides:
onCreate
in classApplication
-
onConfigurationChanged
- Specified by:
onConfigurationChanged
in interfaceComponentCallbacks
- Overrides:
onConfigurationChanged
in classApplication
-
onLowMemory
public void onLowMemory()- Specified by:
onLowMemory
in interfaceComponentCallbacks
- Overrides:
onLowMemory
in classApplication
-
onInitialize
protected abstract void onInitialize()This method will be called inside theonCreate()
method before applying the theme.Do any initializations in this method.
-
getDynamicResolver
Returns the resolver for the dynamic theme to provide implementation for conditions like auto and night themes.Override this method to supply your own resolver implementation.
- Returns:
- The resolver for the dynamic theme.
-
onCustomiseTheme
protected void onCustomiseTheme()This method will be called inside theonCreate()
method after applying the theme.Override this method to customise the theme further.
-
onSetupDynamicWork
protected boolean onSetupDynamicWork()This method will be called before setting up the dynamic work to listen changes based on time. It will be useful in updating theauto
theme while the app is in background.Return
false
to skip the dynamic work initialization.- Returns:
true
to setup the dynamic work.
-
setDynamicTheme
protected void setDynamicTheme()Set the dynamic app theme and style resource for this application. -
getWorkManagerConfiguration
- Specified by:
getWorkManagerConfiguration
in interfaceConfiguration.Provider
-
getSupportedLocales
- Specified by:
getSupportedLocales
in interfaceDynamicLocale
-
getDefaultLocale
- Specified by:
getDefaultLocale
in interfaceDynamicLocale
-
setLocale
- Specified by:
setLocale
in interfaceDynamicLocale
-
getFontScale
public float getFontScale()- Specified by:
getFontScale
in interfaceDynamicLocale
-
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.
-
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.
-