Class ContextWrapper

java.lang.Object
icyllis.modernui.core.Context
icyllis.modernui.core.ContextWrapper
Direct Known Subclasses:
ContextThemeWrapper

public class ContextWrapper extends Context
Proxying implementation of Context that simply delegates all of its calls to another Context. Can be subclassed to modify behavior without changing the original Context.
  • Constructor Details

    • ContextWrapper

      public ContextWrapper(Context base)
  • Method Details

    • attachBaseContext

      protected void attachBaseContext(Context base)
      Set the base context for this ContextWrapper. All calls will then be delegated to the base context. Throws IllegalStateException if a base context has already been set.
      Parameters:
      base - The new base context for this wrapper.
    • getBaseContext

      public Context getBaseContext()
      Returns:
      the base context as set by the constructor or setBaseContext
    • getResources

      public Resources 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.

      Specified by:
      getResources in class Context
      Returns:
      a Resources instance for the application's environment
    • setTheme

      public void setTheme(@Nullable @StyleRes ResourceId resId)
      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.
      Specified by:
      setTheme in class Context
      Parameters:
      resId - The style resource describing the theme.
    • getTheme

      public Resources.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 with Context.getResources(). Calling this method is not particularly fast, so it is recommended to cache it in a local variable.

      Specified by:
      getTheme in class Context
    • getSystemService

      @Nullable public Object getSystemService(@NonNull String name)
      Specified by:
      getSystemService in class Context