Class Resources.Theme

java.lang.Object
icyllis.modernui.resources.Resources.Theme
Enclosing class:
Resources

@ThreadSafe public final class Resources.Theme extends Object
  • Constructor Details

    • Theme

      public Theme()
  • Method Details

    • applyStyle

      public void applyStyle(@NonNull @StyleRes ResourceId resId, boolean force)
      Place new attribute values into the theme. The style resource specified by resId will be retrieved from this Theme's resources, its values placed into the Theme object.

      The semantics of this function depends on the force argument: If false, only values that are not already defined in the theme will be copied from the system resource; otherwise, if any of the style's attributes are already defined in the theme, the current values in the theme will be overwritten.

      Parameters:
      resId - The resource ID of a style resource from which to obtain attribute values.
      force - If true, values in the style resource will always be used in the theme; otherwise, they will only be used if not already defined in the theme.
      Throws:
      IllegalArgumentException - if the resId is not a style or not found
    • obtainStyledAttributes

      @NonNull public TypedArray obtainStyledAttributes(@NonNull @StyleableRes String[] attrs)
      Return a TypedArray holding the values defined by Theme which are listed in attrs.

      Be sure to call TypedArray.recycle() when you are done with the array.

      Parameters:
      attrs - The desired attributes to be retrieved. See StyleableRes for requirements.
      Returns:
      Returns a TypedArray holding an array of the attribute values. Be sure to call TypedArray.recycle() when done with it.
      See Also:
    • obtainStyledAttributes

      @NonNull public TypedArray obtainStyledAttributes(@Nullable @StyleRes ResourceId resId, @NonNull @StyleableRes String[] attrs)
      Return a TypedArray holding the values defined by the resId resource which are listed in attrs.

      Be sure to call TypedArray.recycle() when you are done with the array.

      Parameters:
      resId - The desired style resource.
      attrs - The desired attributes to be retrieved. See StyleableRes for requirements.
      Returns:
      Returns a TypedArray holding an array of the attribute values. Be sure to call TypedArray.recycle() when done with it.
      See Also:
    • obtainStyledAttributes

      @NonNull public TypedArray obtainStyledAttributes(@Nullable AttributeSet set, @Nullable @AttrRes ResourceId defStyleAttr, @Nullable @StyleRes ResourceId defStyleRes, @NonNull @StyleableRes String[] attrs)
      Return a TypedArray holding the attribute values in set that are listed in attrs. In addition, if the given AttributeSet specifies a style class (through the "style" attribute), that style will be applied on top of the base attributes it defines.

      Be sure to call TypedArray.recycle() when you are done with the array.

      When determining the final value of a particular attribute, there are four inputs that come into play:

      1. Any attribute values in the given AttributeSet.
      2. The style resource specified in the AttributeSet (named "style").
      3. The default style specified by defStyleAttr and defStyleRes
      4. The base values in this theme.

      Each of these inputs is considered in-order, with the first listed taking precedence over the following ones. In other words, if in the AttributeSet you have supplied <Button textColor="#ff000000">, then the button's text will always be black, regardless of what is specified in any of the styles.

      Parameters:
      set - The base set of attribute values. May be null.
      defStyleAttr - An attribute in the current theme that contains a reference to a style resource that supplies defaults values for the TypedArray. Can be null to not look for defaults.
      defStyleRes - A resource identifier of a style resource that supplies default values for the TypedArray, used only if defStyleAttr is null or can not be found in the theme. Can be null to not look for defaults.
      attrs - The desired attributes to be retrieved. See StyleableRes for requirements.
      Returns:
      Returns a TypedArray holding an array of the attribute values. Be sure to call TypedArray.recycle() when done with it.
      See Also:
    • resolveAttribute

      public boolean resolveAttribute(@NonNull @AttrRes ResourceId resId, @NonNull TypedValue outValue, boolean resolveRefs)
      Retrieve the value of an attribute in the Theme. The contents of outValue are ultimately filled in by Resources.getValue(icyllis.modernui.resources.ResourceId, icyllis.modernui.resources.TypedValue, boolean).
      Parameters:
      resId - The resource identifier of the desired theme attribute.
      outValue - Filled in with the ultimate resource value supplied by the attribute.
      resolveRefs - If true, resource references will be walked; if false, outValue may be a TYPE_REFERENCE. In either case, it will never be a TYPE_ATTRIBUTE.
      Returns:
      boolean Returns true if the attribute was found and outValue is valid, else false.
    • resolveAttribute

      public boolean resolveAttribute(@NonNull String namespace, @NonNull String attribute, @NonNull TypedValue outValue, boolean resolveRefs)
      Retrieve the value of an attribute in the Theme. The contents of outValue are ultimately filled in by Resources.getValue(icyllis.modernui.resources.ResourceId, icyllis.modernui.resources.TypedValue, boolean).
      Parameters:
      outValue - Filled in with the ultimate resource value supplied by the attribute.
      resolveRefs - If true, resource references will be walked; if false, outValue may be a TYPE_REFERENCE. In either case, it will never be a TYPE_ATTRIBUTE.
      Returns:
      boolean Returns true if the attribute was found and outValue is valid, else false.
    • getResources

      public Resources getResources()
      Returns the resources to which this theme belongs.
      Returns:
      Resources to which this theme belongs.
    • setTo

      public void setTo(@NonNull Resources.Theme other)
    • clear

      public void clear()
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(@Nullable Object o)
      Overrides:
      equals in class Object
    • toString

      @NonNull public String toString()
      Overrides:
      toString in class Object