Package icyllis.modernui.graphics.drawable

# Class StateListDrawable

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

All Implemented Interfaces:
  `Drawable.Callback`

public class StateListDrawable extends DrawableContainer
Lets you assign a number of graphic images to a single Drawable and swap out the visible item by a string ID value.

- ## Nested Class Summary

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

  `DrawableContainer.DrawableContainerState`

  ## 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
  `StateListDrawable()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addState(int[] stateSet, Drawable drawable)`
  Add a new image/string ID to the set of images.
  `void`
  `clearMutated()`
  Clears the mutated state, allowing this drawable to be cached and mutated again.
  `int`
  `findStateDrawableIndex(int[] stateSet)`
  Gets the index of the drawable with the provided state set.
  `int`
  `getStateCount()`
  Gets the number of states contained in this drawable.
  `Drawable`
  `getStateDrawable(int index)`
  Gets the drawable at an index.
  `int[]`
  `getStateSet(int index)`
  Gets the state set at an index.
  `boolean`
  `hasFocusStateSpecified()`
  Indicates whether this drawable has at least one state spec explicitly specifying state_focused.
  `boolean`
  `isStateful()`
  Indicates whether this drawable will change its appearance based on state.
  `Drawable`
  `mutate()`
  Make this drawable mutable.
  `protected boolean`
  `onStateChange(int[] stateSet)`
  Override this in your subclass to change appearance if you recognize the specified state.
  `protected void`
  `setConstantState(DrawableContainer.DrawableContainerState state)`

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

  `draw, getAlpha, getConstantState, getCurrent, getCurrentIndex, getHotspotBounds, getIntrinsicHeight, getIntrinsicWidth, getMinimumHeight, getMinimumWidth, getPadding, invalidateDrawable, isAutoMirrored, jumpToCurrentState, onBoundsChange, onLayoutDirectionChanged, onLevelChange, scheduleDrawable, selectDrawable, setAlpha, setAutoMirrored, setEnterFadeDuration, setExitFadeDuration, setHotspot, setHotspotBounds, setTintBlendMode, setTintList, setVisible, unscheduleDrawable`

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

  - ### StateListDrawable

    public StateListDrawable()

- ## Method Details

  - ### addState

    public void addState(int[] stateSet, Drawable drawable)
    Add a new image/string ID to the set of images.
    Parameters:
      `stateSet` - An array of resource Ids to associate with the image. Switch to this image by calling setState().
      `drawable` - The image to show. Note this must be a unique Drawable that is not shared between any other View or Drawable otherwise the results are undefined and can lead to unexpected rendering behavior

  - ### 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 `DrawableContainer`
    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 `DrawableContainer`
    Returns:
      `true` if state_focused is specified for this drawable.

  - ### onStateChange

    protected boolean onStateChange(@NonNull int[] stateSet)
    Description copied from class: `Drawable`
    Override this in your subclass to change appearance if you recognize the specified state.
    Overrides:
      `onStateChange` in class `DrawableContainer`
    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.

  - ### getStateCount

    public int getStateCount()
    Gets the number of states contained in this drawable.
    Returns:
      The number of states contained in this drawable.
    See Also:
      - `getStateSet(int)`
      - `getStateDrawable(int)`

  - ### getStateSet

    @NonNull public int[] getStateSet(int index)
    Gets the state set at an index.
    Parameters:
      `index` - The index of the state set.
    Returns:
      The state set at the index.
    See Also:
      - `getStateCount()`
      - `getStateDrawable(int)`

  - ### getStateDrawable

    @Nullable public Drawable getStateDrawable(int index)
    Gets the drawable at an index.
    Parameters:
      `index` - The index of the drawable.
    Returns:
      The drawable at the index.
    See Also:
      - `getStateCount()`
      - `getStateSet(int)`

  - ### findStateDrawableIndex

    public int findStateDrawableIndex(@NonNull int[] stateSet)
    Gets the index of the drawable with the provided state set.
    Parameters:
      `stateSet` - the state set to look up
    Returns:
      the index of the provided state set, or -1 if not found
    See Also:
      - `getStateDrawable(int)`
      - `getStateSet(int)`

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

  - ### setConstantState

    protected void setConstantState(@NonNull DrawableContainer.DrawableContainerState state)
    Overrides:
      `setConstantState` in class `DrawableContainer`