1bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell/*
2bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * Copyright (C) 2011 The Android Open Source Project
3bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell *
4bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * Licensed under the Apache License, Version 2.0 (the "License");
5bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * you may not use this file except in compliance with the License.
6bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * You may obtain a copy of the License at
7bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell *
8bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell *      http://www.apache.org/licenses/LICENSE-2.0
9bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell *
10bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * Unless required by applicable law or agreed to in writing, software
11bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * distributed under the License is distributed on an "AS IS" BASIS,
12bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * See the License for the specific language governing permissions and
14bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * limitations under the License.
15bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell */
16bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1730837f1095c803f332f4a1c3f0917c8afdd50156Adam Powellpackage android.support.v4.view;
18bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
19bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.content.Context;
2034452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powellimport android.util.Log;
2134452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powellimport android.view.MenuItem;
2230837f1095c803f332f4a1c3f0917c8afdd50156Adam Powellimport android.view.SubMenu;
23bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.view.View;
24bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
25bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell/**
2620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * This class is a mediator for accomplishing a given task, for example sharing a file. It is
2720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * responsible for creating a view that performs an action that accomplishes the task. This class
2820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * also implements other functions such a performing a default action.
2920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns *
3020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * <p>An ActionProvider can be
3130837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell * optionally specified for a {@link android.view.MenuItem} and in such a case it will be
32e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes * responsible for
3320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * creating the action view that appears in the {@link android.app.ActionBar} as a substitute for
3420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * the menu item when the item is displayed as an action item. Also the provider is responsible for
3520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * performing a default action if a menu item placed on the overflow menu of the ActionBar is
3620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * selected and none of the menu item callbacks has handled the selection. For this case the
3720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * provider can also optionally provide a sub-menu for accomplishing the task at hand.
3820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns *
3920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * <p>There are two ways for using an action provider for creating and handling of action views:
4020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns *
4130837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell * <ul><li> Setting the action provider on a {@link android.view.MenuItem} directly by
4230837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell * calling {@link
4330837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell * android.support.v4.view.MenuItemCompat#setActionProvider(android.view.MenuItem, ActionProvider)}.
4430837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell * </li>
4520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns *
4620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * <li>Declaring the action provider in the menu XML resource. For example:
4720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns *
48bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * <pre>
49bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * <code>
50bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell *   &lt;item android:id="@+id/my_menu_item"
51bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell *     android:title="Title"
52bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell *     android:icon="@drawable/my_menu_item_icon"
53bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell *     android:showAsAction="ifRoom"
54bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell *     android:actionProviderClass="foo.bar.SomeActionProvider" /&gt;
55bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * </code>
56bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * </pre>
5720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * </li></ul></p>
58bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell *
5930837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell * @see android.support.v4.view.MenuItemCompat#setActionProvider(android.view.MenuItem, ActionProvider)
6030837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell * @see android.support.v4.view.MenuItemCompat#getActionProvider(android.view.MenuItem)
61bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell */
62bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellpublic abstract class ActionProvider {
6334452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    private static final String TAG = "ActionProvider(support)";
64e6072e2d918169bd827cf7431347fb648124c227Jeff Brown    private final Context mContext;
65bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
6620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    private SubUiVisibilityListener mSubUiVisibilityListener;
6734452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    private VisibilityListener mVisibilityListener;
68bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
6920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
7020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * Creates a new instance.
7120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
7220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @param context Context for accessing resources.
7320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
7420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public ActionProvider(Context context) {
75e6072e2d918169bd827cf7431347fb648124c227Jeff Brown        mContext = context;
76e6072e2d918169bd827cf7431347fb648124c227Jeff Brown    }
77e6072e2d918169bd827cf7431347fb648124c227Jeff Brown
78e6072e2d918169bd827cf7431347fb648124c227Jeff Brown    /**
79e6072e2d918169bd827cf7431347fb648124c227Jeff Brown     * Gets the context associated with this action provider.
80e6072e2d918169bd827cf7431347fb648124c227Jeff Brown     */
81e6072e2d918169bd827cf7431347fb648124c227Jeff Brown    public Context getContext() {
82e6072e2d918169bd827cf7431347fb648124c227Jeff Brown        return mContext;
8320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    }
84bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
8520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
8620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * Factory method for creating new action views.
8720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
8820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @return A new action view.
8920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
9020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public abstract View onCreateActionView();
91bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
9220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
9334452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * Factory method called by the Android framework to create new action views.
9434452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * This method returns a new action view for the given MenuItem.
9534452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     *
9634452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * <p>If your ActionProvider implementation overrides the deprecated no-argument overload
9734452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * {@link #onCreateActionView()}, overriding this method for devices running API 16 or later
9834452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * is recommended but optional. The default implementation calls {@link #onCreateActionView()}
9934452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * for compatibility with applications written for older platform versions.</p>
10034452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     *
10134452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * @param forItem MenuItem to create the action view for
10234452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * @return the new action view
10334452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     */
10434452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    public View onCreateActionView(MenuItem forItem) {
10534452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell        return onCreateActionView();
10634452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    }
10734452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell
10834452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    /**
10934452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * The result of this method determines whether or not {@link #isVisible()} will be used
11034452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * by the {@link MenuItem} this ActionProvider is bound to help determine its visibility.
11134452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     *
11234452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * @return true if this ActionProvider overrides the visibility of the MenuItem
11334452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     *         it is bound to, false otherwise. The default implementation returns false.
11434452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * @see #isVisible()
11534452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     */
11634452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    public boolean overridesItemVisibility() {
11734452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell        return false;
11834452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    }
11934452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell
12034452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    /**
12134452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * If {@link #overridesItemVisibility()} returns true, the return value of this method
12234452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * will help determine the visibility of the {@link MenuItem} this ActionProvider is bound to.
12334452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     *
12434452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * <p>If the MenuItem's visibility is explicitly set to false by the application,
12534452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * the MenuItem will not be shown, even if this method returns true.</p>
12634452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     *
12734452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * @return true if the MenuItem this ActionProvider is bound to is visible, false if
12834452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     *         it is invisible. The default implementation returns true.
12934452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     */
13034452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    public boolean isVisible() {
13134452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell        return true;
13234452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    }
13334452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell
13434452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    /**
13534452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * If this ActionProvider is associated with an item in a menu,
13634452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * refresh the visibility of the item based on {@link #overridesItemVisibility()} and
13734452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * {@link #isVisible()}. If {@link #overridesItemVisibility()} returns false, this call
13834452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * will have no effect.
13934452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     */
14034452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    public void refreshVisibility() {
14134452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell        if (mVisibilityListener != null && overridesItemVisibility()) {
14234452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell            mVisibilityListener.onActionProviderVisibilityChanged(isVisible());
14334452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell        }
14434452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    }
14534452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell
14634452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    /**
14720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * Performs an optional default action.
14820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
14920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * <p>For the case of an action provider placed in a menu
15020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * item not shown as an action this method is invoked if previous callbacks for processing menu
15120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * selection has handled the event.
15220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
15320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * <p> A menu item selection is processed in the following order:
15420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
155e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * <ul><li>Receiving a call to
15630837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell     * {@link android.view.MenuItem.OnMenuItemClickListener#onMenuItemClick
15720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * MenuItem.OnMenuItemClickListener.onMenuItemClick}.</li>
15820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
159e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * <li>Receiving a call to
16030837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell     * {@link android.app.Activity#onOptionsItemSelected(android.view.MenuItem)}
16130837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell     * FragmentActivity.onOptionsItemSelected(MenuItem)}
16220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * </li>
16320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
164e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * <li>Receiving a call to
16530837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell     * {@link android.support.v4.app.Fragment#onOptionsItemSelected(android.view.MenuItem)}
16630837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell     * Fragment.onOptionsItemSelected(MenuItem)}</li>
16720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
16820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * <li>Launching the {@link android.content.Intent} set via
16930837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell     * {@link android.view.MenuItem#setIntent(android.content.Intent)
170e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * MenuItem.setIntent(android.content.Intent)}
17120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * </li>
17220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
17320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * <li>Invoking this method.</li></ul>
17420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
17520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * <p>The default implementation does not perform any action and returns false.
17620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
17720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public boolean onPerformDefaultAction() {
17820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        return false;
17920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    }
180bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
18120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
18220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * Determines if this ActionProvider has a submenu associated with it.
18320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
18420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * <p>Associated submenus will be shown when an action view is not. This provider instance will
18520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * receive a call to {@link #onPrepareSubMenu(SubMenu)} after the call to {@link
18620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * #onPerformDefaultAction()} and before a submenu is displayed to the user.
18720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
18820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @return true if the item backed by this provider should have an associated submenu
18920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
19020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public boolean hasSubMenu() {
19120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        return false;
19220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    }
19320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns
19420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
19520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * Called to prepare an associated submenu for the menu item backed by this ActionProvider.
19620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
19720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * <p>if {@link #hasSubMenu()} returns true, this method will be called when the menu item is
19820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * selected to prepare the submenu for presentation to the user. Apps may use this to create or
19920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * alter submenu content right before display.
20020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
20120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @param subMenu Submenu that will be displayed
20220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
20320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public void onPrepareSubMenu(SubMenu subMenu) {
20420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    }
205bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
20620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
20720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * Notify the system that the visibility of an action view's sub-UI such as an anchored popup
20820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * has changed. This will affect how other system visibility notifications occur.
20920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
21020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @hide Pending future API approval
21120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
21220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public void subUiVisibilityChanged(boolean isVisible) {
21320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        if (mSubUiVisibilityListener != null) {
21420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns            mSubUiVisibilityListener.onSubUiVisibilityChanged(isVisible);
21520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        }
216bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
217bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
21820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
21920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @hide Internal use only
22020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
22120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public void setSubUiVisibilityListener(SubUiVisibilityListener listener) {
22220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        mSubUiVisibilityListener = listener;
22320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    }
22420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns
22520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
22634452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * Set a listener to be notified when this ActionProvider's overridden visibility changes.
22734452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * This should only be used by MenuItem implementations.
22834452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     *
22934452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * @param listener listener to set
23034452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     */
23134452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    public void setVisibilityListener(VisibilityListener listener) {
23234452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell        if (mVisibilityListener != null && listener != null) {
23334452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell            Log.w(TAG, "setVisibilityListener: Setting a new ActionProvider.VisibilityListener " +
23434452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell                    "when one is already set. Are you reusing this " + getClass().getSimpleName() +
23534452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell                    " instance while it is still in use somewhere else?");
23634452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell        }
23734452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell        mVisibilityListener = listener;
23834452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    }
23934452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell
24034452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    /**
24120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @hide Internal use only
24220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
24320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public interface SubUiVisibilityListener {
244bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
24520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        public void onSubUiVisibilityChanged(boolean isVisible);
24620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    }
24734452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell
24834452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    /**
24934452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * Listens to changes in visibility as reported by {@link ActionProvider#refreshVisibility()}.
25034452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     *
25134452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * @see ActionProvider#overridesItemVisibility()
25234452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * @see ActionProvider#isVisible()
25334452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     */
25434452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    public interface VisibilityListener {
25534452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell        public void onActionProviderVisibilityChanged(boolean isVisible);
25634452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    }
257bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell}
258