Class ColorStateListDrawable

java.lang.Object
icyllis.modernui.graphics.drawable.Drawable
icyllis.modernui.graphics.drawable.ColorStateListDrawable
All Implemented Interfaces:
Drawable.Callback

public class ColorStateListDrawable extends Drawable implements Drawable.Callback
A Drawable that manages a ColorDrawable to make it stateful and backed by a ColorStateList.
  • Constructor Details

    • ColorStateListDrawable

      public ColorStateListDrawable()
    • ColorStateListDrawable

      public ColorStateListDrawable(@NonNull ColorStateList colorStateList)
  • Method Details

    • draw

      public void draw(@NonNull Canvas canvas)
      Description copied from class: Drawable
      Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha).
      Specified by:
      draw in class Drawable
      Parameters:
      canvas - The canvas to draw into
    • getAlpha

      public int getAlpha()
      Description copied from class: Drawable
      Gets the current alpha value for the drawable. 0 means fully transparent, 255 means fully opaque. This method is implemented by Drawable subclasses and the value returned is specific to how that class treats alpha. The default return value is 255 if the class does not override this method to return a value specific to its use of alpha.
      Overrides:
      getAlpha in class Drawable
    • isStateful

      public boolean isStateful()
      Description copied from class: Drawable
      Indicates whether this drawable will change its appearance based on state. Clients can use this to determine whether it is necessary to calculate their state and call setState.
      Overrides:
      isStateful in class Drawable
      Returns:
      True if this drawable changes its appearance based on state, false otherwise.
      See Also:
    • hasFocusStateSpecified

      public boolean hasFocusStateSpecified()
      Description copied from class: Drawable
      Indicates whether this drawable has at least one state spec explicitly specifying state_focused.

      Note: A View uses a Drawable instance as its background and it changes its appearance based on a state. On keyboard devices, it should specify its state_focused to make sure the user knows which view is holding the focus.

      Overrides:
      hasFocusStateSpecified in class Drawable
      Returns:
      true if state_focused is specified for this drawable.
    • getCurrent

      @NonNull public Drawable getCurrent()
      Overrides:
      getCurrent in class Drawable
      Returns:
      The current drawable that will be used by this drawable. For simple drawables, this is just the drawable itself. For drawables that change state like StateListDrawable and LevelListDrawable this will be the child drawable currently in use.
    • setAlpha

      public void setAlpha(int alpha)
      Description copied from class: Drawable
      Specify an alpha value for the drawable. 0 means fully transparent, and 255 means fully opaque.
      Overrides:
      setAlpha in class Drawable
    • clearAlpha

      public void clearAlpha()
      Remove the alpha override, reverting to the alpha defined on each color in the ColorStateList.
    • setTintList

      public void setTintList(@Nullable ColorStateList tint)
      Description copied from class: Drawable
      Specifies tint color for this drawable as a color state list.

      A Drawable's drawing content will be blended together with its tint before it is drawn to the screen.

      Note: Setting a color filter via Drawable.setColorFilter(ColorFilter) overrides tint.

      Overrides:
      setTintList in class Drawable
      Parameters:
      tint - Color state list to use for tinting this drawable, or null to clear the tint
      See Also:
    • setTintBlendMode

      public void setTintBlendMode(@NonNull BlendMode blendMode)
      Description copied from class: Drawable
      Specifies a tint blending mode for this drawable.

      Defines how this drawable's tint color should be blended into the drawable before it is drawn to screen. Default tint mode is BlendMode.SRC_IN.

      Note: Setting a color filter via Drawable.setColorFilter(ColorFilter)

      Overrides:
      setTintBlendMode in class Drawable
      Parameters:
      blendMode - BlendMode to apply to the drawable, a value of null sets the default blend mode value of BlendMode.SRC_IN
      See Also:
    • onBoundsChange

      protected void onBoundsChange(@NonNull Rect bounds)
      Description copied from class: Drawable
      Override this in your subclass to change appearance if you vary based on the bounds.
      Overrides:
      onBoundsChange in class Drawable
    • onStateChange

      protected boolean onStateChange(@NonNull int[] state)
      Description copied from class: Drawable
      Override this in your subclass to change appearance if you recognize the specified state.
      Overrides:
      onStateChange in class Drawable
      Returns:
      Returns true if the state change has caused the appearance of the Drawable to change (that is, it needs to be drawn), else false if it looks the same and there is no need to redraw it since its last state.
    • invalidateDrawable

      public void invalidateDrawable(@NonNull Drawable who)
      Description copied from interface: Drawable.Callback
      Called when the drawable needs to be redrawn. A view at this point should invalidate itself (or at least the part of itself where the drawable appears).
      Specified by:
      invalidateDrawable in interface Drawable.Callback
      Parameters:
      who - The drawable that is requesting the update.
    • scheduleDrawable

      public void scheduleDrawable(@NonNull Drawable who, @NonNull Runnable what, long when)
      Description copied from interface: Drawable.Callback
      A Drawable can call this to schedule the next frame of its animation. An implementation can generally simply call Handler.postAtTime(Runnable, Object, long) with the parameters (what, who, when) to perform the scheduling.
      Specified by:
      scheduleDrawable in interface Drawable.Callback
      Parameters:
      who - The drawable being scheduled.
      what - The action to execute.
      when - The time (in milliseconds) to run. The timebase is Core.timeMillis()
    • unscheduleDrawable

      public void unscheduleDrawable(@NonNull Drawable who, @NonNull Runnable what)
      Description copied from interface: Drawable.Callback
      A Drawable can call this to unschedule an action previously scheduled with Drawable.Callback.scheduleDrawable(icyllis.modernui.graphics.drawable.Drawable, java.lang.Runnable, long). An implementation can generally simply call Handler.removeCallbacks(Runnable, Object) with the parameters (what, who) to unschedule the drawable.
      Specified by:
      unscheduleDrawable in interface Drawable.Callback
      Parameters:
      who - The drawable being unscheduled.
      what - The action being unscheduled.
    • getConstantState

      @NonNull public Drawable.ConstantState getConstantState()
      Description copied from class: Drawable
      Return a Drawable.ConstantState instance that holds the shared state of this Drawable.
      Overrides:
      getConstantState in class Drawable
      Returns:
      The ConstantState associated to that Drawable.
      See Also:
    • getColorStateList

      @NonNull public ColorStateList getColorStateList()
      Returns the ColorStateList backing this Drawable, or a new ColorStateList of the default ColorDrawable color if one hasn't been defined yet.
      Returns:
      a ColorStateList
    • mutate

      @NonNull public Drawable mutate()
      Description copied from class: Drawable
      Make this drawable mutable. This operation cannot be reversed. A mutable drawable is guaranteed to not share its state with any other drawable. This is especially useful when you need to modify properties of drawables loaded from resources. By default, all drawables instances loaded from the same resource share a common state; if you modify the state of one instance, all the other instances will receive the same modification.

      Calling this method on a mutable Drawable will have no effect.

      Overrides:
      mutate in class Drawable
      Returns:
      This drawable.
      See Also:
    • clearMutated

      public void clearMutated()
      Description copied from class: Drawable
      Clears the mutated state, allowing this drawable to be cached and mutated again.
      Overrides:
      clearMutated in class Drawable
    • setColorStateList

      public void setColorStateList(@NonNull ColorStateList colorStateList)
      Replace this Drawable's ColorStateList. It is not copied, so changes will propagate on the next call to Drawable.setState(int[]).
      Parameters:
      colorStateList - A color state list to attach.