Package icyllis.modernui.widget

# Class PopupMenu

java.lang.Object
icyllis.modernui.widget.PopupMenu

public class PopupMenu extends Object
A PopupMenu displays a `Menu` in a modal popup window anchored to a `View`. The popup will appear below the anchor view if there is room, or above it if there is not. If the IME is visible the popup will not overlap it until it is touched. Touching outside of the popup will dismiss it.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static interface`
  `PopupMenu.OnDismissListener`
  Callback interface used to notify the application that the menu has closed.
  `static interface`
  `PopupMenu.OnMenuItemClickListener`
  Interface responsible for receiving menu item click events if the items themselves do not have individual item click listeners.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PopupMenu(Context context, View anchor)`
  Constructor to create a new popup menu with an anchor view.
  `PopupMenu(Context context, View anchor, int gravity)`
  Constructor to create a new popup menu with an anchor view and alignment gravity.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `dismiss()`
  Dismiss the menu popup.
  `View.OnTouchListener`
  `getDragToOpenListener()`
  Returns an `View.OnTouchListener` that can be added to the anchor view to implement drag-to-open behavior.
  `int`
  `getGravity()`
  `Menu`
  `getMenu()`
  Returns the `Menu` associated with this popup.
  `ListView`
  `getMenuListView()`
  Returns the `ListView` representing the list of menu items in the currently showing menu.
  `void`
  `setForceShowIcon(boolean forceShowIcon)`
  Sets whether the popup menu's adapter is forced to show icons in the menu item views.
  `void`
  `setGravity(int gravity)`
  Sets the gravity used to align the popup window to its anchor view.
  `void`
  `setOnDismissListener(PopupMenu.OnDismissListener listener)`
  Sets a listener that will be notified when this menu is dismissed.
  `void`
  `setOnMenuItemClickListener(PopupMenu.OnMenuItemClickListener listener)`
  Sets a listener that will be notified when the user selects an item from the menu.
  `void`
  `show()`
  Show the menu popup anchored to the view specified during construction.

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

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

- ## Constructor Details

  - ### PopupMenu

    public PopupMenu(Context context, View anchor)
    Constructor to create a new popup menu with an anchor view.
    Parameters:
      `anchor` - Anchor view for this popup. The popup will appear below the anchor if there is room, or above it if there is not.

  - ### PopupMenu

    public PopupMenu(Context context, View anchor, int gravity)
    Constructor to create a new popup menu with an anchor view and alignment gravity.
    Parameters:
      `anchor` - Anchor view for this popup. The popup will appear below the anchor if there is room, or above it if there is not.
      `gravity` - The `Gravity` value for aligning the popup with its anchor.

- ## Method Details

  - ### setGravity

    public void setGravity(int gravity)
    Sets the gravity used to align the popup window to its anchor view.

    If the popup is showing, calling this method will take effect only the next time the popup is shown.

    Parameters:
      `gravity` - the gravity used to align the popup window
    See Also:
      - `getGravity()`

  - ### getGravity

    public int getGravity()
    Returns:
      the gravity used to align the popup window to its anchor view
    See Also:
      - `setGravity(int)`

  - ### getDragToOpenListener

    public View.OnTouchListener getDragToOpenListener()
    Returns an `View.OnTouchListener` that can be added to the anchor view to implement drag-to-open behavior.

    When the listener is set on a view, touching that view and dragging outside of its bounds will open the popup window. Lifting will select the currently touched list item.

    Example usage:

         PopupMenu myPopup = new PopupMenu(myAnchor);
         myAnchor.setOnTouchListener(myPopup.getDragToOpenListener());

    Returns:
      a touch listener that controls drag-to-open behavior

  - ### getMenu

    public Menu getMenu()
    Returns the `Menu` associated with this popup. Populate the returned Menu with items before calling `show()`.
    Returns:
      the `Menu` associated with this popup
    See Also:
      - `show()`

  - ### show

    public void show()
    Show the menu popup anchored to the view specified during construction.
    See Also:
      - `dismiss()`

  - ### dismiss

    public void dismiss()
    Dismiss the menu popup.
    See Also:
      - `show()`

  - ### setOnMenuItemClickListener

    public void setOnMenuItemClickListener(PopupMenu.OnMenuItemClickListener listener)
    Sets a listener that will be notified when the user selects an item from the menu.
    Parameters:
      `listener` - the listener to notify

  - ### setOnDismissListener

    public void setOnDismissListener(PopupMenu.OnDismissListener listener)
    Sets a listener that will be notified when this menu is dismissed.
    Parameters:
      `listener` - the listener to notify

  - ### setForceShowIcon

    public void setForceShowIcon(boolean forceShowIcon)
    Sets whether the popup menu's adapter is forced to show icons in the menu item views.

    Changes take effect on the next call to show().

    Parameters:
      `forceShowIcon` - `true` to force icons to be shown, or `false` for icons to be optionally shown

  - ### getMenuListView

    public ListView getMenuListView()
    Returns the `ListView` representing the list of menu items in the currently showing menu.
    Returns:
      The view representing the list of menu items.