Class ActionMode

java.lang.Object
icyllis.modernui.view.ActionMode

public abstract class ActionMode extends Object
Represents a contextual mode of the user interface. Action modes can be used to provide alternative interaction modes and replace parts of the normal UI until finished. Examples of good action modes include text selection and contextual actions.

Developer Guides

For information about how to provide contextual actions with ActionMode, read the Menus developer guide.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Callback interface for action modes.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Default value to hide the action mode for
    invalid reference
    ViewConfiguration#getDefaultActionModeHideDuration()
    .
    static final int
    The action mode is treated as a Floating Toolbar.
    static final int
    The action mode is treated as a Primary mode.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract void
    Finish and close this action mode.
    abstract View
    Returns the current custom view for this action mode.
    abstract Menu
    Returns the menu of actions that this action mode presents.
    abstract CharSequence
    Returns the current subtitle of this action mode.
    Retrieve the tag object associated with this ActionMode.
    abstract CharSequence
    Returns the current title of this action mode.
    boolean
     
    int
    Returns the type for this action mode.
    void
    hide(long duration)
    Hide the action mode view from obstructing the content below for a short duration.
    abstract void
    Invalidate the action mode and refresh menu content.
    void
    Invalidate the content rect associated to this ActionMode.
    boolean
     
    boolean
    Returns whether the UI presenting this action mode can take focus or not.
    void
    onWindowFocusChanged(boolean hasWindowFocus)
    Called when the window containing the view that started this action mode gains or loses focus.
    abstract void
    Set a custom view for this action mode.
    abstract void
    Set the subtitle of the action mode.
    void
    Set a tag object associated with this ActionMode.
    abstract void
    Set the title of the action mode.
    void
    setTitleOptionalHint(boolean titleOptional)
    Set whether or not the title/subtitle display for this action mode is optional.
    void
    setType(int type)
    Set a type for this action mode.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • TYPE_PRIMARY

      public static final int TYPE_PRIMARY
      The action mode is treated as a Primary mode. This is the default. Use with setType(int).
      See Also:
    • TYPE_FLOATING

      public static final int TYPE_FLOATING
      The action mode is treated as a Floating Toolbar. Use with setType(int).
      See Also:
    • DEFAULT_HIDE_DURATION

      public static final int DEFAULT_HIDE_DURATION
      Default value to hide the action mode for
      invalid reference
      ViewConfiguration#getDefaultActionModeHideDuration()
      .
      See Also:
  • Constructor Details

    • ActionMode

      public ActionMode()
  • Method Details

    • setTag

      public void setTag(Object tag)
      Set a tag object associated with this ActionMode.

      Like the tag available to views, this allows applications to associate arbitrary data with an ActionMode for later reference.

      Parameters:
      tag - Tag to associate with this ActionMode
      See Also:
    • getTag

      public Object getTag()
      Retrieve the tag object associated with this ActionMode.

      Like the tag available to views, this allows applications to associate arbitrary data with an ActionMode for later reference.

      Returns:
      Tag associated with this ActionMode
      See Also:
    • setTitle

      public abstract void setTitle(CharSequence title)
      Set the title of the action mode. This method will have no visible effect if a custom view has been set.
      Parameters:
      title - Title string to set
      See Also:
    • setSubtitle

      public abstract void setSubtitle(CharSequence subtitle)
      Set the subtitle of the action mode. This method will have no visible effect if a custom view has been set.
      Parameters:
      subtitle - Subtitle string to set
      See Also:
    • setTitleOptionalHint

      public void setTitleOptionalHint(boolean titleOptional)
      Set whether or not the title/subtitle display for this action mode is optional.

      In many cases the supplied title for an action mode is merely meant to add context and is not strictly required for the action mode to be useful. If the title is optional, the system may choose to hide the title entirely rather than truncate it due to a lack of available space.

      Note that this is merely a hint; the underlying implementation may choose to ignore this setting under some circumstances.

      Parameters:
      titleOptional - true if the title only presents optional information.
    • getTitleOptionalHint

      public boolean getTitleOptionalHint()
      Returns:
      true if this action mode has been given a hint to consider the title/subtitle display to be optional.
      See Also:
    • isTitleOptional

      public boolean isTitleOptional()
      Returns:
      true if this action mode considers the title and subtitle fields as optional. Optional titles may not be displayed to the user.
    • setCustomView

      public abstract void setCustomView(View view)
      Set a custom view for this action mode. The custom view will take the place of the title and subtitle. Useful for things like search boxes.
      Parameters:
      view - Custom view to use in place of the title/subtitle.
      See Also:
    • setType

      public void setType(int type)
      Set a type for this action mode. This will affect how the system renders the action mode if it has to.
      Parameters:
      type - One of TYPE_PRIMARY or TYPE_FLOATING.
    • getType

      public int getType()
      Returns the type for this action mode.
      Returns:
      One of TYPE_PRIMARY or TYPE_FLOATING.
    • invalidate

      public abstract void invalidate()
      Invalidate the action mode and refresh menu content. The mode's ActionMode.Callback will have its ActionMode.Callback.onPrepareActionMode(ActionMode, Menu) method called. If it returns true the menu will be scanned for updated content and any relevant changes will be reflected to the user.
    • invalidateContentRect

      public void invalidateContentRect()
      Invalidate the content rect associated to this ActionMode. This only makes sense for action modes that support dynamic positioning on the screen, and provides a more efficient way to reposition it without invalidating the whole action mode.
      See Also:
    • hide

      public void hide(long duration)
      Hide the action mode view from obstructing the content below for a short duration. This only makes sense for action modes that support dynamic positioning on the screen. If this method is called again before the hide duration expires, the later hide call will cancel the former and then take effect. NOTE that there is an internal limit to how long the mode can be hidden for. It's typically about a few seconds.
      Parameters:
      duration - The number of milliseconds to hide for.
      See Also:
    • finish

      public abstract void finish()
      Finish and close this action mode. The action mode's ActionMode.Callback will have its ActionMode.Callback.onDestroyActionMode(ActionMode) method called.
    • getMenu

      public abstract Menu getMenu()
      Returns the menu of actions that this action mode presents.
      Returns:
      The action mode's menu.
    • getTitle

      public abstract CharSequence getTitle()
      Returns the current title of this action mode.
      Returns:
      Title text
    • getSubtitle

      public abstract CharSequence getSubtitle()
      Returns the current subtitle of this action mode.
      Returns:
      Subtitle text
    • getCustomView

      public abstract View getCustomView()
      Returns the current custom view for this action mode.
      Returns:
      The current custom view
    • onWindowFocusChanged

      public void onWindowFocusChanged(boolean hasWindowFocus)
      Called when the window containing the view that started this action mode gains or loses focus.
      Parameters:
      hasWindowFocus - True if the window containing the view that started this action mode now has focus, false otherwise.
    • isUiFocusable

      @Internal public boolean isUiFocusable()
      Returns whether the UI presenting this action mode can take focus or not. This is used by internal components within the framework that would otherwise present an action mode UI that requires focus, such as an EditText as a custom view.
      Returns:
      true if the UI used to show this action mode can take focus