Class StateSet

java.lang.Object
icyllis.modernui.util.StateSet

public final class StateSet extends Object
State sets are arrays of positive ints where each element represents the state of a View (e.g. focused, selected, visible, etc.). A View may be in one or more of those states.

A state spec is an array of signed ints where each element represents a required (if positive) or an undesired (if negative) View state.

Utils dealing with state sets.

In theory, we could encapsulate the state set and state spec arrays and not have static methods here but there is some concern about performance since these methods are called during view drawing.

Modified from Android, removes (hardware) accelerated state.

  • Field Details

    • WILD_CARD

      public static final int[] WILD_CARD
      A state specification that will be matched by all StateSets.
    • VIEW_STATE_WINDOW_FOCUSED

      public static final int VIEW_STATE_WINDOW_FOCUSED
      Called by View.
      See Also:
    • VIEW_STATE_SELECTED

      public static final int VIEW_STATE_SELECTED
      Called by View.
      See Also:
    • VIEW_STATE_FOCUSED

      public static final int VIEW_STATE_FOCUSED
      Called by View.
      See Also:
    • VIEW_STATE_ENABLED

      public static final int VIEW_STATE_ENABLED
      Called by View.
      See Also:
    • VIEW_STATE_PRESSED

      public static final int VIEW_STATE_PRESSED
      Called by View.
      See Also:
    • VIEW_STATE_ACTIVATED

      public static final int VIEW_STATE_ACTIVATED
      Called by View.
      See Also:
    • VIEW_STATE_HOVERED

      public static final int VIEW_STATE_HOVERED
      Called by View.
      See Also:
    • VIEW_STATE_DRAG_CAN_ACCEPT

      public static final int VIEW_STATE_DRAG_CAN_ACCEPT
      Called by View.
      See Also:
    • VIEW_STATE_DRAG_HOVERED

      public static final int VIEW_STATE_DRAG_HOVERED
      Called by View.
      See Also:
  • Method Details

    • get

      public static int[] get(int mask)
      Called by View.
    • isWildCard

      public static boolean isWildCard(@Nonnull int[] state)
      Return whether the state is matched by all StateSets.
      Parameters:
      state - a state set or state spec.
    • stateSetMatches

      public static boolean stateSetMatches(@Nonnull int[] stateSpec, @Nonnull int[] stateSet)
      Return whether the stateSet matches the desired stateSpec.
      Parameters:
      stateSpec - an array of required (if positive) or prohibited (if negative) View states.
      stateSet - an array of View states
    • stateSetMatches

      public static boolean stateSetMatches(@Nonnull int[] stateSpec, int state)
      Return whether the state matches the desired stateSpec.
      Parameters:
      stateSpec - an array of required (if positive) or prohibited (if negative) View states.
      state - a View state
    • containsAttribute

      public static boolean containsAttribute(@Nonnull int[][] stateSpecs, int attr)
      Check whether a list of state specs has an attribute specified.
      Parameters:
      stateSpecs - a list of state specs we're checking.
      attr - an attribute we're looking for.
      Returns:
      true if the attribute is contained in the state specs.
    • trimStateSet

      @Nonnull public static int[] trimStateSet(@Nonnull int[] states, int newSize)