Package icyllis.modernui.view.menu

# Class MenuPopup

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

All Implemented Interfaces:
  `MenuPresenter`, `ShowableListMenu`, `AdapterView.OnItemClickListener`

Direct Known Subclasses:
  `CascadingMenuPopup`, `StandardMenuPopup`

public abstract class MenuPopup extends Object implements ShowableListMenu, MenuPresenter, AdapterView.OnItemClickListener
Base class for a menu popup abstraction - i.e., some type of menu, housed in a popup window environment.

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from interface icyllis.modernui.view.menu.MenuPresenter

  `MenuPresenter.Callback`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `MenuPopup()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `abstract void`
  `addMenu(MenuBuilder menu)`
  Adds the given menu to the popup, if it is capable of displaying submenus within itself.
  `boolean`
  `collapseItemActionView(MenuBuilder menu, MenuItemImpl item)`
  Called when a menu item with a collapsable action view should collapse its action view.
  `boolean`
  `expandItemActionView(MenuBuilder menu, MenuItemImpl item)`
  Called when a menu item with a collapsable action view should expand its action view.
  `Rect`
  `getEpicenterBounds()`
  `int`
  `getId()`
  Returns an ID for determining how to save/restore instance state.
  `MenuView`
  `getMenuView(ViewGroup root)`
  Retrieve a MenuView to display the menu specified in `MenuPresenter.initForMenu(Context, MenuBuilder)`.
  `void`
  `initForMenu(Context context, MenuBuilder menu)`
  Initializes this presenter for the given context and menu.
  `protected static int`
  `measureIndividualMenuWidth(ListAdapter adapter, ViewGroup parent, Context context, int maxAllowedWidth)`
  Measures the width of the given menu view.
  `void`
  `onItemClick(AdapterView<?> parent, View view, int position, long id)`
  Callback method to be invoked when an item in this AdapterView has been clicked.
  `abstract void`
  `setAnchorView(View anchor)`
  `void`
  `setEpicenterBounds(Rect bounds)`
  Specifies the anchor-relative bounds of the popup's transition epicenter.
  `abstract void`
  `setForceShowIcon(boolean forceShow)`
  `abstract void`
  `setGravity(int dropDownGravity)`
  `abstract void`
  `setHorizontalOffset(int x)`
  `abstract void`
  `setOnDismissListener(PopupWindow.OnDismissListener listener)`
  Set a listener to receive a callback when the popup is dismissed.
  `abstract void`
  `setShowTitle(boolean showTitle)`
  Set whether a title entry should be shown in the popup menu (if a title exists for the menu).
  `abstract void`
  `setVerticalOffset(int y)`
  `protected static boolean`
  `shouldPreserveIconSpacing(MenuBuilder menu)`
  Returns whether icon spacing needs to be preserved for the given menu, based on whether any of its items contains an icon.
  `protected static MenuAdapter`
  `toMenuAdapter(ListAdapter adapter)`
  Converts the given ListAdapter originating from a menu, to a MenuAdapter, accounting for the possibility of the parameter adapter actually wrapping the MenuAdapter.

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

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

  ### Methods inherited from interface icyllis.modernui.view.menu.MenuPresenter

  `flagActionItems, onCloseMenu, onSubMenuSelected, setCallback, updateMenuView`

  ### Methods inherited from interface icyllis.modernui.view.menu.ShowableListMenu

  `dismiss, getListView, isShowing, show`

- ## Constructor Details

  - ### MenuPopup

    public MenuPopup()

- ## Method Details

  - ### setForceShowIcon

    public abstract void setForceShowIcon(boolean forceShow)

  - ### addMenu

    public abstract void addMenu(MenuBuilder menu)
    Adds the given menu to the popup, if it is capable of displaying submenus within itself. If menu is the first menu shown, it won't be displayed until show() is called. If the popup was already showing, adding a submenu via this method will cause that new submenu to be shown immediately (that is, if this MenuPopup implementation is capable of showing its own submenus).
    Parameters:
      `menu` - menu

  - ### setGravity

    public abstract void setGravity(int dropDownGravity)

  - ### setAnchorView

    public abstract void setAnchorView(View anchor)

  - ### setHorizontalOffset

    public abstract void setHorizontalOffset(int x)

  - ### setVerticalOffset

    public abstract void setVerticalOffset(int y)

  - ### setEpicenterBounds

    public void setEpicenterBounds(Rect bounds)
    Specifies the anchor-relative bounds of the popup's transition epicenter.
    Parameters:
      `bounds` - anchor-relative bounds

  - ### getEpicenterBounds

    public Rect getEpicenterBounds()
    Returns:
      anchor-relative bounds of the popup's transition epicenter

  - ### setShowTitle

    public abstract void setShowTitle(boolean showTitle)
    Set whether a title entry should be shown in the popup menu (if a title exists for the menu).
    Parameters:
      `showTitle` - show title

  - ### setOnDismissListener

    public abstract void setOnDismissListener(PopupWindow.OnDismissListener listener)
    Set a listener to receive a callback when the popup is dismissed.
    Parameters:
      `listener` - Listener that will be notified when the popup is dismissed.

  - ### initForMenu

    public void initForMenu(@NonNull Context context, @Nullable MenuBuilder menu)
    Description copied from interface: `MenuPresenter`
    Initializes this presenter for the given context and menu.

    This method is called by MenuBuilder when a presenter is added. See `MenuBuilder.addMenuPresenter(MenuPresenter)`.

    Specified by:
      `initForMenu` in interface `MenuPresenter`
    Parameters:
      `context` - the context for this presenter; used for view creation and resource management, must be non-`null`
      `menu` - the menu to host, or `null` to clear the hosted menu

  - ### getMenuView

    public MenuView getMenuView(ViewGroup root)
    Description copied from interface: `MenuPresenter`
    Retrieve a MenuView to display the menu specified in `MenuPresenter.initForMenu(Context, MenuBuilder)`.
    Specified by:
      `getMenuView` in interface `MenuPresenter`
    Parameters:
      `root` - Intended parent of the MenuView.
    Returns:
      A freshly created MenuView.

  - ### expandItemActionView

    public boolean expandItemActionView(MenuBuilder menu, MenuItemImpl item)
    Description copied from interface: `MenuPresenter`
    Called when a menu item with a collapsable action view should expand its action view.
    Specified by:
      `expandItemActionView` in interface `MenuPresenter`
    Parameters:
      `menu` - Menu containing the item to be expanded
      `item` - Item to be expanded
    Returns:
      true if this presenter expanded the action view, false otherwise.

  - ### collapseItemActionView

    public boolean collapseItemActionView(MenuBuilder menu, MenuItemImpl item)
    Description copied from interface: `MenuPresenter`
    Called when a menu item with a collapsable action view should collapse its action view.
    Specified by:
      `collapseItemActionView` in interface `MenuPresenter`
    Parameters:
      `menu` - Menu containing the item to be collapsed
      `item` - Item to be collapsed
    Returns:
      true if this presenter collapsed the action view, false otherwise.

  - ### getId

    public int getId()
    Description copied from interface: `MenuPresenter`
    Returns an ID for determining how to save/restore instance state.
    Specified by:
      `getId` in interface `MenuPresenter`
    Returns:
      a valid ID value.

  - ### onItemClick

    public void onItemClick(@NonNull AdapterView<?> parent, View view, int position, long id)
    Description copied from interface: `AdapterView.OnItemClickListener`
    Callback method to be invoked when an item in this AdapterView has been clicked.

    Implementers can call getItemAtPosition(position) if they need to access the data associated with the selected item.

    Specified by:
      `onItemClick` in interface `AdapterView.OnItemClickListener`
    Parameters:
      `parent` - The AdapterView where the click happened.
      `view` - The view within the AdapterView that was clicked (this will be a view provided by the adapter)
      `position` - The position of the view in the adapter.
      `id` - The row id of the item that was clicked.

  - ### measureIndividualMenuWidth

    protected static int measureIndividualMenuWidth(@NonNull ListAdapter adapter, @Nullable ViewGroup parent, Context context, int maxAllowedWidth)
    Measures the width of the given menu view.
    Returns:
      The width.

  - ### toMenuAdapter

    protected static MenuAdapter toMenuAdapter(ListAdapter adapter)
    Converts the given ListAdapter originating from a menu, to a MenuAdapter, accounting for the possibility of the parameter adapter actually wrapping the MenuAdapter. (That could happen if a header view was added on the menu.)

  - ### shouldPreserveIconSpacing

    protected static boolean shouldPreserveIconSpacing(@NonNull MenuBuilder menu)
    Returns whether icon spacing needs to be preserved for the given menu, based on whether any of its items contains an icon.

    NOTE: This should only be used for non-overflow-only menus, because this method does not take into account whether the menu items are being shown as part of the popup or or being shown as actions in the action bar.

    Returns:
      Whether to preserve icon spacing.