151ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov/*
251ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov * Copyright (C) 2011 The Android Open Source Project
351ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov *
451ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov * Licensed under the Apache License, Version 2.0 (the "License");
551ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov * you may not use this file except in compliance with the License.
651ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov * You may obtain a copy of the License at
751ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov *
851ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov *      http://www.apache.org/licenses/LICENSE-2.0
951ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov *
1051ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov * Unless required by applicable law or agreed to in writing, software
1151ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov * distributed under the License is distributed on an "AS IS" BASIS,
1251ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1351ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov * See the License for the specific language governing permissions and
1451ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov * limitations under the License.
1551ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov */
1651ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov
1751ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganovpackage android.view;
1851ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov
1951ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganovimport android.content.Context;
2039d5c6172503620ac3761148adac5fd7fa20d02dAdam Powellimport android.util.Log;
2151ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov
2251ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov/**
239a1de308cea2d160778fd977825f10a07b49d738Adam Powell * An ActionProvider defines rich menu interaction in a single component.
249a1de308cea2d160778fd977825f10a07b49d738Adam Powell * ActionProvider can generate action views for use in the action bar,
259a1de308cea2d160778fd977825f10a07b49d738Adam Powell * dynamically populate submenus of a MenuItem, and handle default menu
269a1de308cea2d160778fd977825f10a07b49d738Adam Powell * item invocations.
279a1de308cea2d160778fd977825f10a07b49d738Adam Powell *
289a1de308cea2d160778fd977825f10a07b49d738Adam Powell * <p>An ActionProvider can be optionally specified for a {@link MenuItem} and will be
299a1de308cea2d160778fd977825f10a07b49d738Adam Powell * responsible for creating the action view that appears in the {@link android.app.ActionBar}
309a1de308cea2d160778fd977825f10a07b49d738Adam Powell * in place of a simple button in the bar. When the menu item is presented in a way that
319a1de308cea2d160778fd977825f10a07b49d738Adam Powell * does not allow custom action views, (e.g. in an overflow menu,) the ActionProvider
329a1de308cea2d160778fd977825f10a07b49d738Adam Powell * can perform a default action.</p>
339a1de308cea2d160778fd977825f10a07b49d738Adam Powell *
349a1de308cea2d160778fd977825f10a07b49d738Adam Powell * <p>There are two ways to use an action provider:
3551ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov * <ul>
3651ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov * <li>
379a1de308cea2d160778fd977825f10a07b49d738Adam Powell * Set the action provider on a {@link MenuItem} directly by calling
3851ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov * {@link MenuItem#setActionProvider(ActionProvider)}.
3951ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov * </li>
4051ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov * <li>
419a1de308cea2d160778fd977825f10a07b49d738Adam Powell * Declare the action provider in an XML menu resource. For example:
4251ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov * <pre>
4351ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov * <code>
4451ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov *   &lt;item android:id="@+id/my_menu_item"
4551ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov *     android:title="Title"
4651ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov *     android:icon="@drawable/my_menu_item_icon"
4751ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov *     android:showAsAction="ifRoom"
4851ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov *     android:actionProviderClass="foo.bar.SomeActionProvider" /&gt;
4951ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov * </code>
5051ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov * </pre>
5151ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov * </li>
5251ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov * </ul>
5351ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov * </p>
5451ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov *
5551ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov * @see MenuItem#setActionProvider(ActionProvider)
5651ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov * @see MenuItem#getActionProvider()
5751ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov */
5851ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganovpublic abstract class ActionProvider {
5939d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell    private static final String TAG = "ActionProvider";
60823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell    private SubUiVisibilityListener mSubUiVisibilityListener;
6139d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell    private VisibilityListener mVisibilityListener;
6251ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov
6351ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov    /**
64690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     * Creates a new instance. ActionProvider classes should always implement a
65690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     * constructor that takes a single Context parameter for inflating from menu XML.
6651ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     *
6751ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * @param context Context for accessing resources.
6851ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     */
6951ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov    public ActionProvider(Context context) {
7051ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov    }
7151ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov
7251ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov    /**
73690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     * Factory method called by the Android framework to create new action views.
74690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     *
75690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     * <p>This method has been deprecated in favor of {@link #onCreateActionView(MenuItem)}.
76690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     * Newer apps that wish to support platform versions prior to API 16 should also
77690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     * implement this method to return a valid action view.</p>
7851ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     *
7951ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * @return A new action view.
80690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     *
81690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     * @deprecated use {@link #onCreateActionView(MenuItem)}
8251ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     */
8351ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov    public abstract View onCreateActionView();
8451ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov
8551ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov    /**
86690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     * Factory method called by the Android framework to create new action views.
87690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     * This method returns a new action view for the given MenuItem.
88690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     *
89690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     * <p>If your ActionProvider implementation overrides the deprecated no-argument overload
90690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     * {@link #onCreateActionView()}, overriding this method for devices running API 16 or later
91690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     * is recommended but optional. The default implementation calls {@link #onCreateActionView()}
92690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     * for compatibility with applications written for older platform versions.</p>
93690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     *
94690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     * @param forItem MenuItem to create the action view for
95690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     * @return the new action view
96690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     */
97690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell    public View onCreateActionView(MenuItem forItem) {
98690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell        return onCreateActionView();
99690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell    }
100690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell
101690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell    /**
102130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     * The result of this method determines whether or not {@link #isVisible()} will be used
103130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     * by the {@link MenuItem} this ActionProvider is bound to help determine its visibility.
104130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     *
105130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     * @return true if this ActionProvider overrides the visibility of the MenuItem
106130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     *         it is bound to, false otherwise. The default implementation returns false.
107130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     * @see #isVisible()
108130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     */
109130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell    public boolean overridesItemVisibility() {
110130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell        return false;
111130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell    }
112130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell
113130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell    /**
114130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     * If {@link #overridesItemVisibility()} returns true, the return value of this method
115130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     * will help determine the visibility of the {@link MenuItem} this ActionProvider is bound to.
116130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     *
117130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     * <p>If the MenuItem's visibility is explicitly set to false by the application,
118130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     * the MenuItem will not be shown, even if this method returns true.</p>
119130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     *
120130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     * @return true if the MenuItem this ActionProvider is bound to is visible, false if
121130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     *         it is invisible. The default implementation returns true.
122130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     */
123130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell    public boolean isVisible() {
124130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell        return true;
125130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell    }
126130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell
127130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell    /**
12839d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     * If this ActionProvider is associated with an item in a menu,
12939d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     * refresh the visibility of the item based on {@link #overridesItemVisibility()} and
13039d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     * {@link #isVisible()}. If {@link #overridesItemVisibility()} returns false, this call
13139d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     * will have no effect.
13239d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     */
13339d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell    public void refreshVisibility() {
13439d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell        if (mVisibilityListener != null && overridesItemVisibility()) {
13539d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell            mVisibilityListener.onActionProviderVisibilityChanged(isVisible());
13639d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell        }
13739d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell    }
13839d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell
13939d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell    /**
14051ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * Performs an optional default action.
14151ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * <p>
14251ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * For the case of an action provider placed in a menu item not shown as an action this
143961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     * method is invoked if previous callbacks for processing menu selection has handled
14451ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * the event.
14551ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * </p>
14651ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * <p>
14751ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * A menu item selection is processed in the following order:
14851ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * <ul>
14951ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * <li>
15051ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * Receiving a call to {@link MenuItem.OnMenuItemClickListener#onMenuItemClick
15151ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     *  MenuItem.OnMenuItemClickListener.onMenuItemClick}.
15251ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * </li>
15351ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * <li>
15451ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * Receiving a call to {@link android.app.Activity#onOptionsItemSelected(MenuItem)
15551ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     *  Activity.onOptionsItemSelected(MenuItem)}
15651ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * </li>
15751ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * <li>
15851ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * Receiving a call to {@link android.app.Fragment#onOptionsItemSelected(MenuItem)
15951ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     *  Fragment.onOptionsItemSelected(MenuItem)}
16051ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * </li>
16151ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * <li>
16251ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * Launching the {@link android.content.Intent} set via
16351ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * {@link MenuItem#setIntent(android.content.Intent) MenuItem.setIntent(android.content.Intent)}
16451ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * </li>
16551ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * <li>
16651ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * Invoking this method.
16751ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * </li>
16851ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * </ul>
16951ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * </p>
17051ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * <p>
171961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     * The default implementation does not perform any action and returns false.
17251ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * </p>
173961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     */
174961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell    public boolean onPerformDefaultAction() {
175961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell        return false;
176961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell    }
177961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell
178961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell    /**
179961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     * Determines if this ActionProvider has a submenu associated with it.
180961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     *
181961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     * <p>Associated submenus will be shown when an action view is not. This
182961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     * provider instance will receive a call to {@link #onPrepareSubMenu(SubMenu)}
183961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     * after the call to {@link #onPerformDefaultAction()} and before a submenu is
184961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     * displayed to the user.
185961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     *
186961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     * @return true if the item backed by this provider should have an associated submenu
187961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     */
188961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell    public boolean hasSubMenu() {
189961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell        return false;
190961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell    }
191961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell
192961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell    /**
193961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     * Called to prepare an associated submenu for the menu item backed by this ActionProvider.
194961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     *
195961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     * <p>if {@link #hasSubMenu()} returns true, this method will be called when the
196961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     * menu item is selected to prepare the submenu for presentation to the user. Apps
197961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     * may use this to create or alter submenu content right before display.
19851ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     *
199961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     * @param subMenu Submenu that will be displayed
20051ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     */
201961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell    public void onPrepareSubMenu(SubMenu subMenu) {
20251ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov    }
203823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell
204823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell    /**
205823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell     * Notify the system that the visibility of an action view's sub-UI such as
206823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell     * an anchored popup has changed. This will affect how other system
207823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell     * visibility notifications occur.
208823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell     *
209823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell     * @hide Pending future API approval
210823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell     */
211823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell    public void subUiVisibilityChanged(boolean isVisible) {
212823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell        if (mSubUiVisibilityListener != null) {
213823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell            mSubUiVisibilityListener.onSubUiVisibilityChanged(isVisible);
214823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell        }
215823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell    }
216823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell
217823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell    /**
218823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell     * @hide Internal use only
219823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell     */
220823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell    public void setSubUiVisibilityListener(SubUiVisibilityListener listener) {
221823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell        mSubUiVisibilityListener = listener;
222823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell    }
223823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell
224823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell    /**
22539d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     * Set a listener to be notified when this ActionProvider's overridden visibility changes.
22639d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     * This should only be used by MenuItem implementations.
22739d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     *
22839d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     * @param listener listener to set
22939d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     */
23039d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell    public void setVisibilityListener(VisibilityListener listener) {
23139d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell        if (mVisibilityListener != null) {
23239d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell            Log.w(TAG, "setVisibilityListener: Setting a new ActionProvider.VisibilityListener " +
23339d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell                    "when one is already set. Are you reusing this " + getClass().getSimpleName() +
23439d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell                    " instance while it is still in use somewhere else?");
23539d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell        }
23639d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell        mVisibilityListener = listener;
23739d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell    }
23839d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell
23939d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell    /**
240823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell     * @hide Internal use only
241823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell     */
242823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell    public interface SubUiVisibilityListener {
243823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell        public void onSubUiVisibilityChanged(boolean isVisible);
244823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell    }
24539d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell
24639d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell    /**
24739d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     * Listens to changes in visibility as reported by {@link ActionProvider#refreshVisibility()}.
24839d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     *
24939d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     * @see ActionProvider#overridesItemVisibility()
25039d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     * @see ActionProvider#isVisible()
25139d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     */
25239d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell    public interface VisibilityListener {
25339d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell        public void onActionProviderVisibilityChanged(boolean isVisible);
25439d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell    }
25551ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov}
256