Class ContextThemeWrapper
-
Field Summary
Fields inherited from class icyllis.modernui.core.Context
WINDOW_SERVICE
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new context wrapper with no theme and no base context.ContextThemeWrapper
(Context base, ResourceId themeResId) Creates a new context wrapper with the specified theme.ContextThemeWrapper
(Context base, Resources.Theme theme) Creates a new context wrapper with the specified theme. -
Method Summary
Modifier and TypeMethodDescriptionReturns a Resources instance for the application's environment.getTheme()
Return the Theme object associated with this Context.protected void
onApplyThemeResource
(Resources.Theme theme, ResourceId resId, boolean first) Called bysetTheme(icyllis.modernui.resources.ResourceId)
andgetTheme()
to apply a theme resource to the current Theme object.void
setTheme
(ResourceId resId) Reset the base theme for this context.Methods inherited from class icyllis.modernui.core.ContextWrapper
attachBaseContext, getBaseContext, getSystemService
Methods inherited from class icyllis.modernui.core.Context
obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes
-
Constructor Details
-
ContextThemeWrapper
public ContextThemeWrapper()Creates a new context wrapper with no theme and no base context.Note: A base context must be attached using
ContextWrapper.attachBaseContext(Context)
before calling any other method on the newly constructed context wrapper. -
ContextThemeWrapper
Creates a new context wrapper with the specified theme.The specified theme will be applied on top of the base context's theme. Any attributes not explicitly defined in the theme identified by themeResId will retain their original values.
- Parameters:
base
- the base contextthemeResId
- the resource ID of the theme to be applied on top of the base context's theme
-
ContextThemeWrapper
Creates a new context wrapper with the specified theme.Unlike
ContextThemeWrapper(Context, ResourceId)
, the theme passed to this constructor will completely replace the base context's theme and the Resources object.- Parameters:
base
- the base contexttheme
- the theme against which resources should be inflated
-
-
Method Details
-
getResources
Description copied from class:Context
Returns a Resources instance for the application's environment.Note: For a Context object, the implementation of this method should always return the same Resources object, even if a resource reload occurs.
- Overrides:
getResources
in classContextWrapper
- Returns:
- a Resources instance for the application's environment
-
setTheme
Description copied from class:Context
Reset the base theme for this context. Note that this should be called before any views are instantiated in the Context.- Overrides:
setTheme
in classContextWrapper
- Parameters:
resId
- The style resource describing the theme.
-
getTheme
Description copied from class:Context
Return the Theme object associated with this Context.Note: For a Context object, the implementation of this method should always return the same Theme object, even if a resource reload or theme reset occurs. And the object returned by
Resources.Theme.getResources()
should be consistent withContext.getResources()
. Calling this method is not particularly fast, so it is recommended to cache it in a local variable.- Overrides:
getTheme
in classContextWrapper
-
onApplyThemeResource
protected void onApplyThemeResource(@NonNull Resources.Theme theme, @Nullable @StyleRes ResourceId resId, boolean first) Called bysetTheme(icyllis.modernui.resources.ResourceId)
andgetTheme()
to apply a theme resource to the current Theme object. May be overridden to change the default (simple) behavior. This method will not be called in multiple threads simultaneously.- Parameters:
theme
- the theme being modifiedresId
- the style resource being applied to themefirst
-true
if this is the first time a style is being applied to theme
-