Package icyllis.modernui.view.menu

# Class MenuPopupHelper

java.lang.Object
icyllis.modernui.view.menu.MenuPopupHelper

All Implemented Interfaces:
  `MenuHelper`

public class MenuPopupHelper extends Object implements MenuHelper

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `MenuPopupHelper(Context context, MenuBuilder menu)`
  `MenuPopupHelper(Context context, MenuBuilder menu, View anchorView)`
  `MenuPopupHelper(Context context, MenuBuilder menu, View anchorView, boolean overflowOnly)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `dismiss()`
  Dismisses the popup, if showing.
  `int`
  `getGravity()`
  `MenuPopup`
  `getPopup()`
  `boolean`
  `isShowing()`
  `protected void`
  `onDismiss()`
  Called after the popup has been dismissed.
  `void`
  `setAnchorView(View anchor)`
  Sets the view to which the popup window is anchored.
  `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 alignment of the popup window relative to the anchor view.
  `void`
  `setOnDismissListener(PopupWindow.OnDismissListener listener)`
  `void`
  `setPresenterCallback(MenuPresenter.Callback cb)`
  `void`
  `show()`
  `void`
  `show(int x, int y)`
  `boolean`
  `tryShow()`
  Attempts to show the popup anchored to the view specified by `setAnchorView(View)`.
  `boolean`
  `tryShow(int x, int y)`
  Shows the popup menu and makes a best-effort to anchor it to the specified (x,y) coordinate relative to the anchor view.

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

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

- ## Constructor Details

  - ### MenuPopupHelper

    public MenuPopupHelper(@NonNull Context context, @NonNull MenuBuilder menu)

  - ### MenuPopupHelper

    public MenuPopupHelper(@NonNull Context context, @NonNull MenuBuilder menu, View anchorView)

  - ### MenuPopupHelper

    public MenuPopupHelper(@NonNull Context context, @NonNull MenuBuilder menu, View anchorView, boolean overflowOnly)

- ## Method Details

  - ### setOnDismissListener

    public void setOnDismissListener(@Nullable PopupWindow.OnDismissListener listener)

  - ### setAnchorView

    public void setAnchorView(@NonNull View anchor)
    Sets the view to which the popup window is anchored.

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

    Parameters:
      `anchor` - the view to which the popup window should be anchored

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

    This method should not be accessed directly outside the framework, please use `PopupMenu.setForceShowIcon(boolean)` instead.

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

  - ### setGravity

    public void setGravity(int gravity)
    Sets the alignment of the popup window relative to the anchor view.

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

    Parameters:
      `gravity` - alignment of the popup relative to the anchor

  - ### getGravity

    public int getGravity()
    Returns:
      alignment of the popup relative to the anchor

  - ### show

    public void show()

  - ### show

    public void show(int x, int y)

  - ### getPopup

    @NonNull public MenuPopup getPopup()

  - ### tryShow

    public boolean tryShow()
    Attempts to show the popup anchored to the view specified by `setAnchorView(View)`.
    Returns:
      `true` if the popup was shown or was already showing prior to calling this method, `false` otherwise

  - ### tryShow

    public boolean tryShow(int x, int y)
    Shows the popup menu and makes a best-effort to anchor it to the specified (x,y) coordinate relative to the anchor view.

    Additionally, the popup's transition epicenter (see `PopupWindow.setEpicenterBounds(Rect)` will be centered on the specified coordinate, rather than using the bounds of the anchor view.

    If the popup's resolved gravity is `Gravity.LEFT`, this will display the popup with its top-left corner at (x,y) relative to the anchor view. If the resolved gravity is `Gravity.RIGHT`, the popup's top-right corner will be at (x,y).

    If the popup cannot be displayed fully on-screen, this method will attempt to scroll the anchor view's ancestors and/or offset the popup such that it may be displayed fully on-screen.

    Parameters:
      `x` - x coordinate relative to the anchor view
      `y` - y coordinate relative to the anchor view
    Returns:
      `true` if the popup was shown or was already showing prior to calling this method, `false` otherwise

  - ### dismiss

    public void dismiss()
    Dismisses the popup, if showing.
    Specified by:
      `dismiss` in interface `MenuHelper`

  - ### onDismiss

    protected void onDismiss()
    Called after the popup has been dismissed.

    Note: Subclasses should call the super implementation last to ensure that any necessary tear down has occurred before the listener specified by `setOnDismissListener(PopupWindow.OnDismissListener)` is called.

  - ### isShowing

    public boolean isShowing()

  - ### setPresenterCallback

    public void setPresenterCallback(@Nullable MenuPresenter.Callback cb)
    Specified by:
      `setPresenterCallback` in interface `MenuHelper`