Package icyllis.modernui.view.menu

# Interface MenuPresenter

All Known Implementing Classes:
  `CascadingMenuPopup`, `MenuPopup`, `StandardMenuPopup`

public interface MenuPresenter
A MenuPresenter is responsible for building views for a Menu object. It takes over some responsibility from the old style monolithic MenuBuilder class.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Interface
  Description
  `static interface`
  `MenuPresenter.Callback`
  Called by menu implementation to notify another component of open/close events.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `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.
  `boolean`
  `flagActionItems()`
  Called by Menu implementations to flag items that will be shown as actions.
  `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 `initForMenu(Context, MenuBuilder)`.
  `void`
  `initForMenu(Context context, MenuBuilder menu)`
  Initializes this presenter for the given context and menu.
  `void`
  `onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing)`
  Called by Menu implementations to indicate that a menu or submenu is closing.
  `boolean`
  `onSubMenuSelected(SubMenuBuilder subMenu)`
  Called by Menu implementations to indicate that a submenu item has been selected.
  `void`
  `setCallback(MenuPresenter.Callback cb)`
  Set a callback object that will be notified of menu events related to this specific presentation.
  `void`
  `updateMenuView(boolean cleared)`
  Update the menu UI in response to a change.

- ## Method Details

  - ### initForMenu

    void initForMenu(@NonNull Context context, @Nullable MenuBuilder menu)
    Initializes this presenter for the given context and menu.

    This method is called by MenuBuilder when a presenter is added. See `MenuBuilder.addMenuPresenter(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

    MenuView getMenuView(ViewGroup root)
    Retrieve a MenuView to display the menu specified in `initForMenu(Context, MenuBuilder)`.
    Parameters:
      `root` - Intended parent of the MenuView.
    Returns:
      A freshly created MenuView.

  - ### updateMenuView

    void updateMenuView(boolean cleared)
    Update the menu UI in response to a change. Called by MenuBuilder during the normal course of operation.
    Parameters:
      `cleared` - true if the menu was entirely cleared

  - ### setCallback

    void setCallback(MenuPresenter.Callback cb)
    Set a callback object that will be notified of menu events related to this specific presentation.
    Parameters:
      `cb` - Callback that will be notified of future events

  - ### onSubMenuSelected

    boolean onSubMenuSelected(SubMenuBuilder subMenu)
    Called by Menu implementations to indicate that a submenu item has been selected. An active Callback should be notified, and if applicable the presenter should present the submenu.
    Parameters:
      `subMenu` - SubMenu being opened
    Returns:
      true if the event was handled, false otherwise.

  - ### onCloseMenu

    void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing)
    Called by Menu implementations to indicate that a menu or submenu is closing. Presenter implementations should close the representation of the menu indicated as necessary and notify a registered callback.
    Parameters:
      `menu` - the menu or submenu that is closing
      `allMenusAreClosing` - `true` if all displayed menus and submenus are closing, `false` if only the specified menu is closing

  - ### flagActionItems

    boolean flagActionItems()
    Called by Menu implementations to flag items that will be shown as actions.
    Returns:
      true if this presenter changed the action status of any items.

  - ### expandItemActionView

    boolean expandItemActionView(MenuBuilder menu, MenuItemImpl item)
    Called when a menu item with a collapsable action view should expand its action view.
    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

    boolean collapseItemActionView(MenuBuilder menu, MenuItemImpl item)
    Called when a menu item with a collapsable action view should collapse its action view.
    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

    int getId()
    Returns an ID for determining how to save/restore instance state.
    Returns:
      a valid ID value.