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 com.actionbarsherlock.internal.view.menu;
19 import android.content.Context;
20 import android.os.Parcelable;
21 import android.view.ViewGroup;
24 * A MenuPresenter is responsible for building views for a Menu object.
25 * It takes over some responsibility from the old style monolithic MenuBuilder class.
27 public interface MenuPresenter {
29 * Called by menu implementation to notify another component of open/close events.
31 public interface Callback {
33 * Called when a menu is closing.
35 * @param allMenusAreClosing
37 public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing);
40 * Called when a submenu opens. Useful for notifying the application
41 * of menu state so that it does not attempt to hide the action bar
42 * while a submenu is open or similar.
44 * @param subMenu Submenu currently being opened
45 * @return true if the Callback will handle presenting the submenu, false if
46 * the presenter should attempt to do so.
48 public boolean onOpenSubMenu(MenuBuilder subMenu);
52 * Initialize this presenter for the given context and menu.
53 * This method is called by MenuBuilder when a presenter is
54 * added. See {@link MenuBuilder#addMenuPresenter(MenuPresenter)}
56 * @param context Context for this presenter; used for view creation and resource management
57 * @param menu Menu to host
59 public void initForMenu(Context context, MenuBuilder menu);
62 * Retrieve a MenuView to display the menu specified in
63 * {@link #initForMenu(Context, Menu)}.
65 * @param root Intended parent of the MenuView.
66 * @return A freshly created MenuView.
68 public MenuView getMenuView(ViewGroup root);
71 * Update the menu UI in response to a change. Called by
72 * MenuBuilder during the normal course of operation.
74 * @param cleared true if the menu was entirely cleared
76 public void updateMenuView(boolean cleared);
79 * Set a callback object that will be notified of menu events
80 * related to this specific presentation.
81 * @param cb Callback that will be notified of future events
83 public void setCallback(Callback cb);
86 * Called by Menu implementations to indicate that a submenu item
87 * has been selected. An active Callback should be notified, and
88 * if applicable the presenter should present the submenu.
90 * @param subMenu SubMenu being opened
91 * @return true if the the event was handled, false otherwise.
93 public boolean onSubMenuSelected(SubMenuBuilder subMenu);
96 * Called by Menu implementations to indicate that a menu or submenu is
97 * closing. Presenter implementations should close the representation
98 * of the menu indicated as necessary and notify a registered callback.
100 * @param menu Menu or submenu that is closing.
101 * @param allMenusAreClosing True if all associated menus are closing.
103 public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing);
106 * Called by Menu implementations to flag items that will be shown as actions.
107 * @return true if this presenter changed the action status of any items.
109 public boolean flagActionItems();
112 * Called when a menu item with a collapsable action view should expand its action view.
114 * @param menu Menu containing the item to be expanded
115 * @param item Item to be expanded
116 * @return true if this presenter expanded the action view, false otherwise.
118 public boolean expandItemActionView(MenuBuilder menu, MenuItemImpl item);
121 * Called when a menu item with a collapsable action view should collapse its action view.
123 * @param menu Menu containing the item to be collapsed
124 * @param item Item to be collapsed
125 * @return true if this presenter collapsed the action view, false otherwise.
127 public boolean collapseItemActionView(MenuBuilder menu, MenuItemImpl item);
130 * Returns an ID for determining how to save/restore instance state.
131 * @return a valid ID value.
136 * Returns a Parcelable describing the current state of the presenter.
137 * It will be passed to the {@link #onRestoreInstanceState(Parcelable)}
138 * method of the presenter sharing the same ID later.
139 * @return The saved instance state
141 public Parcelable onSaveInstanceState();
144 * Supplies the previously saved instance state to be restored.
145 * @param state The previously saved instance state
147 public void onRestoreInstanceState(Parcelable state);