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     */
83514c5ef8d5774d8820ed1bf90fe53af1606cf106Aurimas Liutikas    @Deprecated
8451ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov    public abstract View onCreateActionView();
8551ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov
8651ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov    /**
87690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     * Factory method called by the Android framework to create new action views.
88690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     * This method returns a new action view for the given MenuItem.
89690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     *
90690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     * <p>If your ActionProvider implementation overrides the deprecated no-argument overload
91690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     * {@link #onCreateActionView()}, overriding this method for devices running API 16 or later
92690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     * is recommended but optional. The default implementation calls {@link #onCreateActionView()}
93690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     * for compatibility with applications written for older platform versions.</p>
94690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     *
95690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     * @param forItem MenuItem to create the action view for
96690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     * @return the new action view
97690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell     */
98690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell    public View onCreateActionView(MenuItem forItem) {
99690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell        return onCreateActionView();
100690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell    }
101690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell
102690ffb4e1f735148a15f2036d9a3c1962fba188cAdam Powell    /**
103130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     * The result of this method determines whether or not {@link #isVisible()} will be used
104130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     * by the {@link MenuItem} this ActionProvider is bound to help determine its visibility.
105130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     *
106130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     * @return true if this ActionProvider overrides the visibility of the MenuItem
107130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     *         it is bound to, false otherwise. The default implementation returns false.
108130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     * @see #isVisible()
109130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     */
110130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell    public boolean overridesItemVisibility() {
111130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell        return false;
112130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell    }
113130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell
114130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell    /**
115130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     * If {@link #overridesItemVisibility()} returns true, the return value of this method
116130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     * will help determine the visibility of the {@link MenuItem} this ActionProvider is bound to.
117130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     *
118130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     * <p>If the MenuItem's visibility is explicitly set to false by the application,
119130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     * the MenuItem will not be shown, even if this method returns true.</p>
120130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     *
121130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     * @return true if the MenuItem this ActionProvider is bound to is visible, false if
122130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     *         it is invisible. The default implementation returns true.
123130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell     */
124130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell    public boolean isVisible() {
125130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell        return true;
126130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell    }
127130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell
128130b4572d1f3df702e5b296a655d15a41f6d4c66Adam Powell    /**
12939d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     * If this ActionProvider is associated with an item in a menu,
13039d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     * refresh the visibility of the item based on {@link #overridesItemVisibility()} and
13139d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     * {@link #isVisible()}. If {@link #overridesItemVisibility()} returns false, this call
13239d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     * will have no effect.
13339d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     */
13439d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell    public void refreshVisibility() {
13539d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell        if (mVisibilityListener != null && overridesItemVisibility()) {
13639d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell            mVisibilityListener.onActionProviderVisibilityChanged(isVisible());
13739d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell        }
13839d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell    }
13939d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell
14039d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell    /**
14151ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * Performs an optional default action.
14251ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * <p>
14351ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * For the case of an action provider placed in a menu item not shown as an action this
144961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     * method is invoked if previous callbacks for processing menu selection has handled
14551ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * the event.
14651ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * </p>
14751ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * <p>
14851ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * A menu item selection is processed in the following order:
14951ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * <ul>
15051ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * <li>
15151ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * Receiving a call to {@link MenuItem.OnMenuItemClickListener#onMenuItemClick
15251ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     *  MenuItem.OnMenuItemClickListener.onMenuItemClick}.
15351ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * </li>
15451ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * <li>
15551ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * Receiving a call to {@link android.app.Activity#onOptionsItemSelected(MenuItem)
15651ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     *  Activity.onOptionsItemSelected(MenuItem)}
15751ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * </li>
15851ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * <li>
15951ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * Receiving a call to {@link android.app.Fragment#onOptionsItemSelected(MenuItem)
16051ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     *  Fragment.onOptionsItemSelected(MenuItem)}
16151ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * </li>
16251ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * <li>
16351ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * Launching the {@link android.content.Intent} set via
16451ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * {@link MenuItem#setIntent(android.content.Intent) MenuItem.setIntent(android.content.Intent)}
16551ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * </li>
16651ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * <li>
16751ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * Invoking this method.
16851ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * </li>
16951ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * </ul>
17051ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * </p>
17151ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * <p>
172961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     * The default implementation does not perform any action and returns false.
17351ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     * </p>
174961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     */
175961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell    public boolean onPerformDefaultAction() {
176961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell        return false;
177961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell    }
178961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell
179961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell    /**
180961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     * Determines if this ActionProvider has a submenu associated with it.
181961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     *
182961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     * <p>Associated submenus will be shown when an action view is not. This
183961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     * provider instance will receive a call to {@link #onPrepareSubMenu(SubMenu)}
184961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     * after the call to {@link #onPerformDefaultAction()} and before a submenu is
185961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     * displayed to the user.
186961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     *
187961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     * @return true if the item backed by this provider should have an associated submenu
188961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     */
189961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell    public boolean hasSubMenu() {
190961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell        return false;
191961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell    }
192961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell
193961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell    /**
194961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     * Called to prepare an associated submenu for the menu item backed by this ActionProvider.
195961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     *
196961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     * <p>if {@link #hasSubMenu()} returns true, this method will be called when the
197961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     * menu item is selected to prepare the submenu for presentation to the user. Apps
198961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     * may use this to create or alter submenu content right before display.
19951ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     *
200961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell     * @param subMenu Submenu that will be displayed
20151ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov     */
202961dd11895ce72e59bca124ef5bea4e4c1183099Adam Powell    public void onPrepareSubMenu(SubMenu subMenu) {
20351ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov    }
204823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell
205823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell    /**
206823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell     * Notify the system that the visibility of an action view's sub-UI such as
207823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell     * an anchored popup has changed. This will affect how other system
208823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell     * visibility notifications occur.
209823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell     *
210823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell     * @hide Pending future API approval
211823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell     */
212823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell    public void subUiVisibilityChanged(boolean isVisible) {
213823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell        if (mSubUiVisibilityListener != null) {
214823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell            mSubUiVisibilityListener.onSubUiVisibilityChanged(isVisible);
215823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell        }
216823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell    }
217823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell
218823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell    /**
219823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell     * @hide Internal use only
220823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell     */
221823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell    public void setSubUiVisibilityListener(SubUiVisibilityListener listener) {
222823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell        mSubUiVisibilityListener = listener;
223823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell    }
224823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell
225823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell    /**
22639d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     * Set a listener to be notified when this ActionProvider's overridden visibility changes.
22739d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     * This should only be used by MenuItem implementations.
22839d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     *
22939d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     * @param listener listener to set
23039d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     */
23139d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell    public void setVisibilityListener(VisibilityListener listener) {
23239d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell        if (mVisibilityListener != null) {
23339d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell            Log.w(TAG, "setVisibilityListener: Setting a new ActionProvider.VisibilityListener " +
23439d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell                    "when one is already set. Are you reusing this " + getClass().getSimpleName() +
23539d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell                    " instance while it is still in use somewhere else?");
23639d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell        }
23739d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell        mVisibilityListener = listener;
23839d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell    }
23939d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell
24039d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell    /**
241c8f6ecc265656cdf68d2010a4e04666017c3b907Chris Banes     * @hide
242c8f6ecc265656cdf68d2010a4e04666017c3b907Chris Banes     */
243c8f6ecc265656cdf68d2010a4e04666017c3b907Chris Banes    public void reset() {
244c8f6ecc265656cdf68d2010a4e04666017c3b907Chris Banes        mVisibilityListener = null;
245c8f6ecc265656cdf68d2010a4e04666017c3b907Chris Banes        mSubUiVisibilityListener = null;
246c8f6ecc265656cdf68d2010a4e04666017c3b907Chris Banes    }
247c8f6ecc265656cdf68d2010a4e04666017c3b907Chris Banes
248c8f6ecc265656cdf68d2010a4e04666017c3b907Chris Banes    /**
249823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell     * @hide Internal use only
250823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell     */
251823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell    public interface SubUiVisibilityListener {
252823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell        public void onSubUiVisibilityChanged(boolean isVisible);
253823f074a73cfc23c40a7b576c71daa096ee9ed6aAdam Powell    }
25439d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell
25539d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell    /**
25639d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     * Listens to changes in visibility as reported by {@link ActionProvider#refreshVisibility()}.
25739d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     *
25839d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     * @see ActionProvider#overridesItemVisibility()
25939d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     * @see ActionProvider#isVisible()
26039d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell     */
26139d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell    public interface VisibilityListener {
26239d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell        public void onActionProviderVisibilityChanged(boolean isVisible);
26339d5c6172503620ac3761148adac5fd7fa20d02dAdam Powell    }
26451ac0e94a83cfccb5105aa14df1077729a5b4cccSvetoslav Ganov}
265