Package icyllis.modernui.graphics.drawable

# Class DrawableContainer

java.lang.Object
icyllis.modernui.graphics.drawable.Drawable
icyllis.modernui.graphics.drawable.DrawableContainer

All Implemented Interfaces:
  `Drawable.Callback`

Direct Known Subclasses:
  `LevelListDrawable`, `StateListDrawable`

public class DrawableContainer extends Drawable implements Drawable.Callback
A helper class that contains several `Drawable`s and selects which one to use.

You can extend it to create your own DrawableContainers or directly use one its child classes.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `protected static class`
  `DrawableContainer.DrawableContainerState`
  A ConstantState that can contain several `Drawable`s.

  ## Nested classes/interfaces inherited from class icyllis.modernui.graphics.drawable.Drawable

  `Drawable.Callback, Drawable.ConstantState`

- ## Field Summary

  ### Fields inherited from class icyllis.modernui.graphics.drawable.Drawable

  `MAX_LEVEL`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DrawableContainer()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `clearMutated()`
  Clears the mutated state, allowing this drawable to be cached and mutated again.
  `void`
  `draw(Canvas canvas)`
  Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha).
  `int`
  `getAlpha()`
  Gets the current alpha value for the drawable.
  `Drawable.ConstantState`
  `getConstantState()`
  Return a `Drawable.ConstantState` instance that holds the shared state of this Drawable.
  `Drawable`
  `getCurrent()`
  `int`
  `getCurrentIndex()`
  `void`
  `getHotspotBounds(Rect outRect)`
  Populates `outRect` with the hotspot bounds.
  `int`
  `getIntrinsicHeight()`
  Returns the drawable's intrinsic height.
  `int`
  `getIntrinsicWidth()`
  Returns the drawable's intrinsic width.
  `int`
  `getMinimumHeight()`
  Returns the minimum height suggested by this Drawable.
  `int`
  `getMinimumWidth()`
  Returns the minimum width suggested by this Drawable.
  `boolean`
  `getPadding(Rect padding)`
  Return in padding the insets suggested by this Drawable for placing content inside the drawable's bounds.
  `boolean`
  `hasFocusStateSpecified()`
  Indicates whether this drawable has at least one state spec explicitly specifying state_focused.
  `void`
  `invalidateDrawable(Drawable who)`
  Called when the drawable needs to be redrawn.
  `boolean`
  `isAutoMirrored()`
  Tells if this Drawable will be automatically mirrored when its layout direction is RTL right-to-left.
  `boolean`
  `isStateful()`
  Indicates whether this drawable will change its appearance based on state.
  `void`
  `jumpToCurrentState()`
  If this Drawable does transition animations between states, ask that it immediately jump to the current state and skip any active animations.
  `Drawable`
  `mutate()`
  Make this drawable mutable.
  `protected void`
  `onBoundsChange(Rect bounds)`
  Override this in your subclass to change appearance if you vary based on the bounds.
  `protected boolean`
  `onLayoutDirectionChanged(int layoutDirection)`
  Called when the drawable's resolved layout direction changes.
  `protected boolean`
  `onLevelChange(int level)`
  Override this in your subclass to change appearance if you vary based on level.
  `protected boolean`
  `onStateChange(int[] state)`
  Override this in your subclass to change appearance if you recognize the specified state.
  `void`
  `scheduleDrawable(Drawable who, Runnable what, long when)`
  A Drawable can call this to schedule the next frame of its animation.
  `boolean`
  `selectDrawable(int index)`
  Sets the currently displayed drawable by index.
  `void`
  `setAlpha(int alpha)`
  Specify an alpha value for the drawable.
  `void`
  `setAutoMirrored(boolean mirrored)`
  Set whether this Drawable is automatically mirrored when its layout direction is RTL (right-to left).
  `protected void`
  `setConstantState(DrawableContainer.DrawableContainerState state)`
  `void`
  `setEnterFadeDuration(int ms)`
  Change the global fade duration when a new drawable is entering the scene.
  `void`
  `setExitFadeDuration(int ms)`
  Change the global fade duration when a new drawable is leaving the scene.
  `void`
  `setHotspot(float x, float y)`
  Specifies the hotspot's location within the drawable.
  `void`
  `setHotspotBounds(int left, int top, int right, int bottom)`
  Sets the bounds to which the hotspot is constrained, if they should be different from the drawable bounds.
  `void`
  `setTintBlendMode(BlendMode blendMode)`
  Specifies a tint blending mode for this drawable.
  `void`
  `setTintList(ColorStateList tint)`
  Specifies tint color for this drawable as a color state list.
  `boolean`
  `setVisible(boolean visible, boolean restart)`
  Set whether this Drawable is visible.
  `void`
  `unscheduleDrawable(Drawable who, Runnable what)`
  A Drawable can call this to unschedule an action previously scheduled with `Drawable.Callback.scheduleDrawable(icyllis.modernui.graphics.drawable.Drawable, java.lang.Runnable, long)`.

  ### Methods inherited from class icyllis.modernui.graphics.drawable.Drawable

  `applyTheme, canApplyTheme, copyBounds, copyBounds, getBounds, getCallback, getChangingConfigurations, getColorFilter, getLayoutDirection, getLevel, getState, invalidateSelf, isVisible, scaleFromDensity, scaleFromDensity, scheduleSelf, setBounds, setBounds, setCallback, setChangingConfigurations, setColorFilter, setLayoutDirection, setLevel, setState, setTint, unscheduleSelf`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### DrawableContainer

    public DrawableContainer()

- ## 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

  - ### getPadding

    public boolean getPadding(@NonNull Rect padding)
    Description copied from class: `Drawable`
    Return in padding the insets suggested by this Drawable for placing content inside the drawable's bounds. Positive values move toward the center of the Drawable (set `Rect.inset(int, int)`).
    Overrides:
      `getPadding` in class `Drawable`
    Returns:
      true if this drawable actually has a padding, else false. When false is returned, the padding is always set to 0.

  - ### 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`

  - ### 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`

  - ### setTintList

    public void setTintList(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:
      - `Drawable.setTint(int)`
      - `Drawable.setTintBlendMode(BlendMode)`

  - ### 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:
      - `Drawable.setTint(int)`
      - `Drawable.setTintList(ColorStateList)`

  - ### setEnterFadeDuration

    public void setEnterFadeDuration(int ms)
    Change the global fade duration when a new drawable is entering the scene.
    Parameters:
      `ms` - The amount of time to fade in milliseconds.

  - ### setExitFadeDuration

    public void setExitFadeDuration(int ms)
    Change the global fade duration when a new drawable is leaving the scene.
    Parameters:
      `ms` - The amount of time to fade in milliseconds.

  - ### 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`

  - ### 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:
      - `Drawable.setState(int[])`

  - ### 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.

  - ### setAutoMirrored

    public void setAutoMirrored(boolean mirrored)
    Description copied from class: `Drawable`
    Set whether this Drawable is automatically mirrored when its layout direction is RTL (right-to left). See `LayoutDirection`.
    Overrides:
      `setAutoMirrored` in class `Drawable`
    Parameters:
      `mirrored` - Set to true if the Drawable should be mirrored, false if not.

  - ### isAutoMirrored

    public boolean isAutoMirrored()
    Description copied from class: `Drawable`
    Tells if this Drawable will be automatically mirrored when its layout direction is RTL right-to-left. See `LayoutDirection`.
    Overrides:
      `isAutoMirrored` in class `Drawable`
    Returns:
      boolean Returns true if this Drawable will be automatically mirrored.

  - ### jumpToCurrentState

    public void jumpToCurrentState()
    Description copied from class: `Drawable`
    If this Drawable does transition animations between states, ask that it immediately jump to the current state and skip any active animations.
    Overrides:
      `jumpToCurrentState` in class `Drawable`

  - ### setHotspot

    public void setHotspot(float x, float y)
    Description copied from class: `Drawable`
    Specifies the hotspot's location within the drawable.
    Overrides:
      `setHotspot` in class `Drawable`
    Parameters:
      `x` - The X coordinate of the center of the hotspot
      `y` - The Y coordinate of the center of the hotspot

  - ### setHotspotBounds

    public void setHotspotBounds(int left, int top, int right, int bottom)
    Description copied from class: `Drawable`
    Sets the bounds to which the hotspot is constrained, if they should be different from the drawable bounds.
    Overrides:
      `setHotspotBounds` in class `Drawable`
    Parameters:
      `left` - position in pixels of the left bound
      `top` - position in pixels of the top bound
      `right` - position in pixels of the right bound
      `bottom` - position in pixels of the bottom bound
    See Also:
      - `Drawable.getHotspotBounds(Rect)`

  - ### getHotspotBounds

    public void getHotspotBounds(@NonNull Rect outRect)
    Description copied from class: `Drawable`
    Populates `outRect` with the hotspot bounds.
    Overrides:
      `getHotspotBounds` in class `Drawable`
    Parameters:
      `outRect` - the rect to populate with the hotspot bounds
    See Also:
      - `Drawable.setHotspotBounds(int, int, int, int)`

  - ### 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.

  - ### onLevelChange

    protected boolean onLevelChange(int level)
    Description copied from class: `Drawable`
    Override this in your subclass to change appearance if you vary based on level.
    Overrides:
      `onLevelChange` in class `Drawable`
    Returns:
      Returns true if the level 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 level.

  - ### onLayoutDirectionChanged

    protected boolean onLayoutDirectionChanged(int layoutDirection)
    Description copied from class: `Drawable`
    Called when the drawable's resolved layout direction changes.
    Overrides:
      `onLayoutDirectionChanged` in class `Drawable`
    Parameters:
      `layoutDirection` - the new resolved layout direction
    Returns:
      `true` if the layout direction change has caused the appearance of the drawable to change such that it needs to be re-drawn, `false` otherwise
    See Also:
      - `Drawable.setLayoutDirection(int)`

  - ### getIntrinsicWidth

    public int getIntrinsicWidth()
    Description copied from class: `Drawable`
    Returns the drawable's intrinsic width.

    Intrinsic width is the width at which the drawable would like to be laid out, including any inherent padding. If the drawable has no intrinsic width, such as a solid color, this method returns -1.

    Overrides:
      `getIntrinsicWidth` in class `Drawable`
    Returns:
      the intrinsic width, or -1 if no intrinsic width

  - ### getIntrinsicHeight

    public int getIntrinsicHeight()
    Description copied from class: `Drawable`
    Returns the drawable's intrinsic height.

    Intrinsic height is the height at which the drawable would like to be laid out, including any inherent padding. If the drawable has no intrinsic height, such as a solid color, this method returns -1.

    Overrides:
      `getIntrinsicHeight` in class `Drawable`
    Returns:
      the intrinsic height, or -1 if no intrinsic height

  - ### getMinimumWidth

    public int getMinimumWidth()
    Description copied from class: `Drawable`
    Returns the minimum width suggested by this Drawable. If a View uses this Drawable as a background, it is suggested that the View use at least this value for its width. (There will be some scenarios where this will not be possible.) This value should INCLUDE any padding.
    Overrides:
      `getMinimumWidth` in class `Drawable`
    Returns:
      The minimum width suggested by this Drawable. If this Drawable doesn't have a suggested minimum width, 0 is returned.

  - ### getMinimumHeight

    public int getMinimumHeight()
    Description copied from class: `Drawable`
    Returns the minimum height suggested by this Drawable. If a View uses this Drawable as a background, it is suggested that the View use at least this value for its height. (There will be some scenarios where this will not be possible.) This value should INCLUDE any padding.
    Overrides:
      `getMinimumHeight` in class `Drawable`
    Returns:
      The minimum height suggested by this Drawable. If this Drawable doesn't have a suggested minimum height, 0 is returned.

  - ### 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.

  - ### setVisible

    public boolean setVisible(boolean visible, boolean restart)
    Description copied from class: `Drawable`
    Set whether this Drawable is visible. This generally does not impact the Drawable's behavior, but is a hint that can be used by some Drawables, for example, to decide whether run animations.
    Overrides:
      `setVisible` in class `Drawable`
    Parameters:
      `visible` - Set to true if visible, false if not.
      `restart` - You can supply true here to force the drawable to behave as if it has just become visible, even if it had last been set visible. Used for example to force animations to restart.
    Returns:
      true if the new visibility is different from its previous state.

  - ### getCurrentIndex

    public int getCurrentIndex()

  - ### selectDrawable

    public boolean selectDrawable(int index)
    Sets the currently displayed drawable by index.

    If an invalid index is specified, the current drawable will be set to `null` and the index will be set to `-1`.

    Parameters:
      `index` - the index of the drawable to display
    Returns:
      `true` if the drawable changed, `false` otherwise

  - ### getCurrent

    @Nullable 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.

  - ### getConstantState

    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:
      - `Drawable.ConstantState`
      - `Drawable.mutate()`

  - ### 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:
      - `Drawable.ConstantState`
      - `Drawable.getConstantState()`

  - ### 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`

  - ### setConstantState

    protected void setConstantState(DrawableContainer.DrawableContainerState state)