2 * Copyright (C) 2011 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package android
.support
.v7
.view
.menu
;
19 import android
.content
.Context
;
20 import android
.os
.Parcelable
;
21 import android
.support
.annotation
.RestrictTo
;
22 import android
.view
.ViewGroup
;
24 import static android
.support
.annotation
.RestrictTo
.Scope
.GROUP_ID
;
27 * A MenuPresenter is responsible for building views for a Menu object. It takes over some
28 * responsibility from the old style monolithic MenuBuilder class.
33 public interface MenuPresenter
{
36 * Called by menu implementation to notify another component of open/close events.
40 * Called when a menu is closing.
42 * @param allMenusAreClosing
44 void onCloseMenu(MenuBuilder menu
, boolean allMenusAreClosing
);
47 * Called when a submenu opens. Useful for notifying the application
48 * of menu state so that it does not attempt to hide the action bar
49 * while a submenu is open or similar.
51 * @param subMenu Submenu currently being opened
52 * @return true if the Callback will handle presenting the submenu, false if
53 * the presenter should attempt to do so.
55 boolean onOpenSubMenu(MenuBuilder subMenu
);
59 * Initialize this presenter for the given context and menu.
60 * This method is called by MenuBuilder when a presenter is
61 * added. See {@link MenuBuilder#addMenuPresenter(MenuPresenter)}
63 * @param context Context for this presenter; used for view creation and resource management
64 * @param menu Menu to host
66 void initForMenu(Context context
, MenuBuilder menu
);
69 * Retrieve a MenuView to display the menu specified in
70 * {@link #initForMenu(Context, MenuBuilder)}.
72 * @param root Intended parent of the MenuView.
73 * @return A freshly created MenuView.
75 MenuView
getMenuView(ViewGroup root
);
78 * Update the menu UI in response to a change. Called by
79 * MenuBuilder during the normal course of operation.
81 * @param cleared true if the menu was entirely cleared
83 void updateMenuView(boolean cleared
);
86 * Set a callback object that will be notified of menu events
87 * related to this specific presentation.
88 * @param cb Callback that will be notified of future events
90 void setCallback(Callback cb
);
93 * Called by Menu implementations to indicate that a submenu item
94 * has been selected. An active Callback should be notified, and
95 * if applicable the presenter should present the submenu.
97 * @param subMenu SubMenu being opened
98 * @return true if the the event was handled, false otherwise.
100 boolean onSubMenuSelected(SubMenuBuilder subMenu
);
103 * Called by Menu implementations to indicate that a menu or submenu is
104 * closing. Presenter implementations should close the representation
105 * of the menu indicated as necessary and notify a registered callback.
107 * @param menu Menu or submenu that is closing.
108 * @param allMenusAreClosing True if all associated menus are closing.
110 void onCloseMenu(MenuBuilder menu
, boolean allMenusAreClosing
);
113 * Called by Menu implementations to flag items that will be shown as actions.
114 * @return true if this presenter changed the action status of any items.
116 boolean flagActionItems();
119 * Called when a menu item with a collapsible action view should expand its action view.
121 * @param menu Menu containing the item to be expanded
122 * @param item Item to be expanded
123 * @return true if this presenter expanded the action view, false otherwise.
125 boolean expandItemActionView(MenuBuilder menu
, MenuItemImpl item
);
128 * Called when a menu item with a collapsible action view should collapse its action view.
130 * @param menu Menu containing the item to be collapsed
131 * @param item Item to be collapsed
132 * @return true if this presenter collapsed the action view, false otherwise.
134 boolean collapseItemActionView(MenuBuilder menu
, MenuItemImpl item
);
137 * Returns an ID for determining how to save/restore instance state.
138 * @return a valid ID value.
143 * Returns a Parcelable describing the current state of the presenter.
144 * It will be passed to the {@link #onRestoreInstanceState(Parcelable)}
145 * method of the presenter sharing the same ID later.
146 * @return The saved instance state
148 Parcelable
onSaveInstanceState();
151 * Supplies the previously saved instance state to be restored.
152 * @param state The previously saved instance state
154 void onRestoreInstanceState(Parcelable state
);