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
-
Method Summary
Modifier and TypeMethodDescriptionabstract 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.int
getId()
Returns an ID for determining how to save/restore instance state.getMenuView
(ViewGroup root) Retrieve a MenuView to display the menu specified inMenuPresenter.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
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
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) -
setGravity
public abstract void setGravity(int dropDownGravity) -
setAnchorView
-
setHorizontalOffset
public abstract void setHorizontalOffset(int x) -
setVerticalOffset
public abstract void setVerticalOffset(int y) -
setEpicenterBounds
Specifies the anchor-relative bounds of the popup's transition epicenter.- Parameters:
bounds
- anchor-relative bounds
-
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
Set a listener to receive a callback when the popup is dismissed.- Parameters:
listener
- Listener that will be notified when the popup is dismissed.
-
getMenuView
Description copied from interface:MenuPresenter
Retrieve a MenuView to display the menu specified inMenuPresenter.initForMenu(Context, MenuBuilder)
.- Specified by:
getMenuView
in interfaceMenuPresenter
- Parameters:
root
- Intended parent of the MenuView.- Returns:
- A freshly created MenuView.
-
getId
public int getId()Description copied from interface:MenuPresenter
Returns an ID for determining how to save/restore instance state.- Specified by:
getId
in interfaceMenuPresenter
- Returns:
- a valid ID value.
-
onItemClick
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 interfaceAdapterView.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
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.)
-