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.OnProvideAssistDataListenerNested classes/interfaces inherited from class android.content.Context
Context.BindServiceFlags -
Field Summary
FieldsFields 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_SERVICEFields 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_HIDDENFields inherited from interface com.pranavpandey.android.dynamic.locale.DynamicLocale
HINDI, INDONESIA, PORTUGUESE, RUSSIAN, SPANISH, SPLIT, SYSTEM, TURKISH -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidattachBaseContext(Context base) 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.getDefaultLocale(Context context) protected DynamicResolverReturns 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.floatintThis method will be called to get the intended theme styles version for this listener.String[]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.booleanReturns whether to apply the dynamic colors for this listener.booleanReturns whether the dynamic colors are 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.voidonConfigurationChanged(Configuration newConfig) voidonCreate()protected voidThis method will be called inside theonCreate()method after applying the theme.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.).protected abstract voidThis method will be called inside theonCreate()method before applying the theme.voidvoidThis 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.protected booleanThis method will be called before setting up the dynamic work to listen changes based on time.voidonSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) protected voidSet the dynamic app theme and style resource for this application.booleanReturns 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, unregisterOnProvideAssistDataListenerMethods 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, updateServiceGroupMethods inherited from class android.content.Context
bindIsolatedService, getColor, getColorStateList, getDrawable, getString, getString, getSystemService, getText, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, revokeSelfPermissionOnKill, sendBroadcastWithMultiplePermissionsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.pranavpandey.android.dynamic.support.listener.DynamicListener
isNightModeMethods 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:
attachBaseContextin classContextWrapper
-
onCreate
public void onCreate()- Overrides:
onCreatein classApplication
-
onConfigurationChanged
- Specified by:
onConfigurationChangedin interfaceComponentCallbacks- Overrides:
onConfigurationChangedin classApplication
-
onLowMemory
public void onLowMemory()- Specified by:
onLowMemoryin interfaceComponentCallbacks- Overrides:
onLowMemoryin 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 theautotheme while the app is in background.Return
falseto skip the dynamic work initialization.- Returns:
trueto setup the dynamic work.
-
setDynamicTheme
protected void setDynamicTheme()Set the dynamic app theme and style resource for this application. -
getWorkManagerConfiguration
- Specified by:
getWorkManagerConfigurationin interfaceConfiguration.Provider
-
getSupportedLocales
- Specified by:
getSupportedLocalesin interfaceDynamicLocale
-
getDefaultLocale
- Specified by:
getDefaultLocalein interfaceDynamicLocale
-
setLocale
- Specified by:
setLocalein interfaceDynamicLocale
-
getFontScale
public float getFontScale()- Specified by:
getFontScalein interfaceDynamicLocale
-
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.
-
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.
-