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 *
309dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <p class="note"><strong>Note:</strong> This class is included in the <a
319dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * href="{@docRoot}tools/extras/support-library.html">support library</a> for compatibility
329dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * with API level 4 and higher. If you're developing your app for API level 14 and higher
339dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <em>only</em>, you should instead use the framework {@link android.view.ActionProvider}
349dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * class.</p>
359dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main *
3620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * <p>An ActionProvider can be
3730837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell * optionally specified for a {@link android.view.MenuItem} and in such a case it will be
38e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes * responsible for
3920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * creating the action view that appears in the {@link android.app.ActionBar} as a substitute for
4020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * the menu item when the item is displayed as an action item. Also the provider is responsible for
4120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * performing a default action if a menu item placed on the overflow menu of the ActionBar is
4220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * selected and none of the menu item callbacks has handled the selection. For this case the
4320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * provider can also optionally provide a sub-menu for accomplishing the task at hand.
4420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns *
4520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * <p>There are two ways for using an action provider for creating and handling of action views:
4620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns *
4730837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell * <ul><li> Setting the action provider on a {@link android.view.MenuItem} directly by
4830837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell * calling {@link
4930837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell * android.support.v4.view.MenuItemCompat#setActionProvider(android.view.MenuItem, ActionProvider)}.
5030837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell * </li>
5120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns *
5220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * <li>Declaring the action provider in the menu XML resource. For example:
5320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns *
549dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <pre><code>
55bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell *   &lt;item android:id="@+id/my_menu_item"
569dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main *     android:title="@string/my_menu_item_title"
57bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell *     android:icon="@drawable/my_menu_item_icon"
58bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell *     android:showAsAction="ifRoom"
59bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell *     android:actionProviderClass="foo.bar.SomeActionProvider" /&gt;
609dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * </code></pre>
6120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * </li></ul></p>
62bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell *
6330837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell * @see android.support.v4.view.MenuItemCompat#setActionProvider(android.view.MenuItem, ActionProvider)
6430837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell * @see android.support.v4.view.MenuItemCompat#getActionProvider(android.view.MenuItem)
65bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell */
66bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellpublic abstract class ActionProvider {
6734452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    private static final String TAG = "ActionProvider(support)";
68e6072e2d918169bd827cf7431347fb648124c227Jeff Brown    private final Context mContext;
69bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
7020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    private SubUiVisibilityListener mSubUiVisibilityListener;
7134452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    private VisibilityListener mVisibilityListener;
72bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
7320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
7420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * Creates a new instance.
7520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
7620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @param context Context for accessing resources.
7720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
7820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public ActionProvider(Context context) {
79e6072e2d918169bd827cf7431347fb648124c227Jeff Brown        mContext = context;
80e6072e2d918169bd827cf7431347fb648124c227Jeff Brown    }
81e6072e2d918169bd827cf7431347fb648124c227Jeff Brown
82e6072e2d918169bd827cf7431347fb648124c227Jeff Brown    /**
83e6072e2d918169bd827cf7431347fb648124c227Jeff Brown     * Gets the context associated with this action provider.
84e6072e2d918169bd827cf7431347fb648124c227Jeff Brown     */
85e6072e2d918169bd827cf7431347fb648124c227Jeff Brown    public Context getContext() {
86e6072e2d918169bd827cf7431347fb648124c227Jeff Brown        return mContext;
8720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    }
88bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
8920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
9020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * Factory method for creating new action views.
9120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
9220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @return A new action view.
9320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
9420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public abstract View onCreateActionView();
95bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
9620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
9734452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * Factory method called by the Android framework to create new action views.
9834452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * This method returns a new action view for the given MenuItem.
9934452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     *
10034452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * <p>If your ActionProvider implementation overrides the deprecated no-argument overload
10134452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * {@link #onCreateActionView()}, overriding this method for devices running API 16 or later
10234452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * is recommended but optional. The default implementation calls {@link #onCreateActionView()}
10334452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * for compatibility with applications written for older platform versions.</p>
10434452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     *
10534452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * @param forItem MenuItem to create the action view for
10634452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * @return the new action view
10734452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     */
10834452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    public View onCreateActionView(MenuItem forItem) {
10934452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell        return onCreateActionView();
11034452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    }
11134452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell
11234452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    /**
11334452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * The result of this method determines whether or not {@link #isVisible()} will be used
11434452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * by the {@link MenuItem} this ActionProvider is bound to help determine its visibility.
11534452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     *
11634452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * @return true if this ActionProvider overrides the visibility of the MenuItem
11734452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     *         it is bound to, false otherwise. The default implementation returns false.
11834452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * @see #isVisible()
11934452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     */
12034452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    public boolean overridesItemVisibility() {
12134452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell        return false;
12234452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    }
12334452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell
12434452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    /**
12534452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * If {@link #overridesItemVisibility()} returns true, the return value of this method
12634452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * will help determine the visibility of the {@link MenuItem} this ActionProvider is bound to.
12734452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     *
12834452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * <p>If the MenuItem's visibility is explicitly set to false by the application,
12934452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * the MenuItem will not be shown, even if this method returns true.</p>
13034452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     *
13134452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * @return true if the MenuItem this ActionProvider is bound to is visible, false if
13234452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     *         it is invisible. The default implementation returns true.
13334452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     */
13434452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    public boolean isVisible() {
13534452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell        return true;
13634452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    }
13734452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell
13834452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    /**
13934452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * If this ActionProvider is associated with an item in a menu,
14034452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * refresh the visibility of the item based on {@link #overridesItemVisibility()} and
14134452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * {@link #isVisible()}. If {@link #overridesItemVisibility()} returns false, this call
14234452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * will have no effect.
14334452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     */
14434452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    public void refreshVisibility() {
14534452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell        if (mVisibilityListener != null && overridesItemVisibility()) {
14634452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell            mVisibilityListener.onActionProviderVisibilityChanged(isVisible());
14734452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell        }
14834452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    }
14934452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell
15034452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    /**
15120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * Performs an optional default action.
15220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
15320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * <p>For the case of an action provider placed in a menu
15420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * item not shown as an action this method is invoked if previous callbacks for processing menu
15520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * selection has handled the event.
15620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
15720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * <p> A menu item selection is processed in the following order:
15820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
159e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * <ul><li>Receiving a call to
16030837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell     * {@link android.view.MenuItem.OnMenuItemClickListener#onMenuItemClick
16120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * MenuItem.OnMenuItemClickListener.onMenuItemClick}.</li>
16220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
163e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * <li>Receiving a call to
16430837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell     * {@link android.app.Activity#onOptionsItemSelected(android.view.MenuItem)}
16530837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell     * FragmentActivity.onOptionsItemSelected(MenuItem)}
16620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * </li>
16720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
168e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * <li>Receiving a call to
16930837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell     * {@link android.support.v4.app.Fragment#onOptionsItemSelected(android.view.MenuItem)}
17030837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell     * Fragment.onOptionsItemSelected(MenuItem)}</li>
17120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
17220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * <li>Launching the {@link android.content.Intent} set via
17330837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell     * {@link android.view.MenuItem#setIntent(android.content.Intent)
174e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * MenuItem.setIntent(android.content.Intent)}
17520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * </li>
17620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
17720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * <li>Invoking this method.</li></ul>
17820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
17920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * <p>The default implementation does not perform any action and returns false.
18020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
18120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public boolean onPerformDefaultAction() {
18220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        return false;
18320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    }
184bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
18520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
18620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * Determines if this ActionProvider has a submenu associated with it.
18720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
18820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * <p>Associated submenus will be shown when an action view is not. This provider instance will
18920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * receive a call to {@link #onPrepareSubMenu(SubMenu)} after the call to {@link
19020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * #onPerformDefaultAction()} and before a submenu is displayed to the user.
19120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
19220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @return true if the item backed by this provider should have an associated submenu
19320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
19420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public boolean hasSubMenu() {
19520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        return false;
19620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    }
19720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns
19820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
19920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * Called to prepare an associated submenu for the menu item backed by this ActionProvider.
20020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
20120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * <p>if {@link #hasSubMenu()} returns true, this method will be called when the menu item is
20220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * selected to prepare the submenu for presentation to the user. Apps may use this to create or
20320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * alter submenu content right before display.
20420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
20520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @param subMenu Submenu that will be displayed
20620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
20720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public void onPrepareSubMenu(SubMenu subMenu) {
20820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    }
209bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
21020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
21120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * Notify the system that the visibility of an action view's sub-UI such as an anchored popup
21220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * has changed. This will affect how other system visibility notifications occur.
21320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
21420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @hide Pending future API approval
21520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
21620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public void subUiVisibilityChanged(boolean isVisible) {
21720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        if (mSubUiVisibilityListener != null) {
21820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns            mSubUiVisibilityListener.onSubUiVisibilityChanged(isVisible);
21920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        }
220bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
221bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
22220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
22320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @hide Internal use only
22420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
22520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public void setSubUiVisibilityListener(SubUiVisibilityListener listener) {
22620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        mSubUiVisibilityListener = listener;
22720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    }
22820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns
22920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
23034452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * Set a listener to be notified when this ActionProvider's overridden visibility changes.
23134452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * This should only be used by MenuItem implementations.
23234452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     *
23334452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * @param listener listener to set
23434452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     */
23534452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    public void setVisibilityListener(VisibilityListener listener) {
23634452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell        if (mVisibilityListener != null && listener != null) {
23734452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell            Log.w(TAG, "setVisibilityListener: Setting a new ActionProvider.VisibilityListener " +
23834452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell                    "when one is already set. Are you reusing this " + getClass().getSimpleName() +
23934452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell                    " instance while it is still in use somewhere else?");
24034452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell        }
24134452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell        mVisibilityListener = listener;
24234452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    }
24334452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell
24434452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    /**
24520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @hide Internal use only
24620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
24720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public interface SubUiVisibilityListener {
248bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
24920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        public void onSubUiVisibilityChanged(boolean isVisible);
25020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    }
25134452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell
25234452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    /**
25334452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * Listens to changes in visibility as reported by {@link ActionProvider#refreshVisibility()}.
25434452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     *
25534452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * @see ActionProvider#overridesItemVisibility()
25634452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     * @see ActionProvider#isVisible()
25734452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell     */
25834452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    public interface VisibilityListener {
25934452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell        public void onActionProviderVisibilityChanged(boolean isVisible);
26034452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell    }
261bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell}
262