1bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell/* 2bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * Copyright (C) 2006 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 17da10fdd1400ecfd8d7f2e55651dd528d0614dfc5Jeff Brownpackage android.support.v7.internal.view.menu; 18bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 19bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.content.ActivityNotFoundException; 2030837f1095c803f332f4a1c3f0917c8afdd50156Adam Powellimport android.content.Context; 21bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.content.Intent; 22bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.graphics.drawable.Drawable; 23937df84589168e159706463f25780f35ec63b750Chris Banesimport android.os.Build; 247fa6a00a4600aac591402398c23fea97721adf26Chris Banesimport android.support.v4.content.ContextCompat; 2530837f1095c803f332f4a1c3f0917c8afdd50156Adam Powellimport android.support.v4.view.ActionProvider; 2630837f1095c803f332f4a1c3f0917c8afdd50156Adam Powellimport android.support.v4.internal.view.SupportMenuItem; 2730837f1095c803f332f4a1c3f0917c8afdd50156Adam Powellimport android.support.v4.view.MenuItemCompat; 28b37a31664b07243ca9e86c8dac58b9be6a417e8cChris Banesimport android.support.v7.internal.widget.TintManager; 29bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.util.Log; 30bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.view.ContextMenu.ContextMenuInfo; 311ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johnsimport android.view.LayoutInflater; 3230837f1095c803f332f4a1c3f0917c8afdd50156Adam Powellimport android.view.MenuItem; 3330837f1095c803f332f4a1c3f0917c8afdd50156Adam Powellimport android.view.SubMenu; 34bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.view.View; 35bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.view.ViewDebug; 361ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johnsimport android.widget.LinearLayout; 37bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 38bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell/** 39bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * @hide 40bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell */ 4130837f1095c803f332f4a1c3f0917c8afdd50156Adam Powellpublic final class MenuItemImpl implements SupportMenuItem { 4220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 43ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private static final String TAG = "MenuItemImpl"; 44ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 45ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private static final int SHOW_AS_ACTION_MASK = SHOW_AS_ACTION_NEVER | 4620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns SHOW_AS_ACTION_IF_ROOM | 4720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns SHOW_AS_ACTION_ALWAYS; 48ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 49ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private final int mId; 50ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private final int mGroup; 51ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private final int mCategoryOrder; 52ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private final int mOrdering; 53ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private CharSequence mTitle; 54ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private CharSequence mTitleCondensed; 55ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private Intent mIntent; 56ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private char mShortcutNumericChar; 57ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private char mShortcutAlphabeticChar; 58ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 5949c78900da0d43140fb602431fb93212bd7f6c70Chris Banes /** The icon's drawable which is only created as needed */ 60ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private Drawable mIconDrawable; 6120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 62ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani /** 6349c78900da0d43140fb602431fb93212bd7f6c70Chris Banes * The icon's resource ID which is used to get the Drawable when it is 6449c78900da0d43140fb602431fb93212bd7f6c70Chris Banes * needed (if the Drawable isn't already obtained--only one of the two is 6549c78900da0d43140fb602431fb93212bd7f6c70Chris Banes * needed). 66ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani */ 67ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private int mIconResId = NO_ICON; 68ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 6949c78900da0d43140fb602431fb93212bd7f6c70Chris Banes /** The menu to which this item belongs */ 70ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private MenuBuilder mMenu; 7149c78900da0d43140fb602431fb93212bd7f6c70Chris Banes /** If this item should launch a sub menu, this is the sub menu to launch */ 72ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private SubMenuBuilder mSubMenu; 73ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 74ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private Runnable mItemCallback; 7530837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell private SupportMenuItem.OnMenuItemClickListener mClickListener; 76ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 77ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private int mFlags = ENABLED; 78ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private static final int CHECKABLE = 0x00000001; 79ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private static final int CHECKED = 0x00000002; 80ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private static final int EXCLUSIVE = 0x00000004; 81ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private static final int HIDDEN = 0x00000008; 82ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private static final int ENABLED = 0x00000010; 83ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private static final int IS_ACTION = 0x00000020; 84ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 85ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private int mShowAsAction = SHOW_AS_ACTION_NEVER; 86ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 87ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private View mActionView; 88ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private ActionProvider mActionProvider; 8930837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell private MenuItemCompat.OnActionExpandListener mOnActionExpandListener; 90ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private boolean mIsActionViewExpanded = false; 91ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 9249c78900da0d43140fb602431fb93212bd7f6c70Chris Banes /** Used for the icon resource ID if this item does not have an icon */ 93ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani static final int NO_ICON = 0; 94ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 95ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani /** 9649c78900da0d43140fb602431fb93212bd7f6c70Chris Banes * Current use case is for context menu: Extra information linked to the 9749c78900da0d43140fb602431fb93212bd7f6c70Chris Banes * View that added this item to the context menu. 98ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani */ 99ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private ContextMenuInfo mMenuInfo; 100ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 101ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private static String sPrependShortcutLabel; 102ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private static String sEnterShortcutLabel; 103ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private static String sDeleteShortcutLabel; 104ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private static String sSpaceShortcutLabel; 105ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 106ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 107ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani /** 108ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani * Instantiates this menu item. 109ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani * 11049c78900da0d43140fb602431fb93212bd7f6c70Chris Banes * @param menu 11149c78900da0d43140fb602431fb93212bd7f6c70Chris Banes * @param group Item ordering grouping control. The item will be added after 11249c78900da0d43140fb602431fb93212bd7f6c70Chris Banes * all other items whose order is <= this number, and before any 11349c78900da0d43140fb602431fb93212bd7f6c70Chris Banes * that are larger than it. This can also be used to define 11449c78900da0d43140fb602431fb93212bd7f6c70Chris Banes * groups of items for batch state changes. Normally use 0. 11549c78900da0d43140fb602431fb93212bd7f6c70Chris Banes * @param id Unique item ID. Use 0 if you do not need a unique ID. 116ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani * @param categoryOrder The ordering for this item. 11749c78900da0d43140fb602431fb93212bd7f6c70Chris Banes * @param title The text to display for the item. 118ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani */ 119ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani MenuItemImpl(MenuBuilder menu, int group, int id, int categoryOrder, int ordering, 12020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns CharSequence title, int showAsAction) { 121ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 122ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani /*if (sPrependShortcutLabel == null) { 123ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani // This is instantiated from the UI thread, so no chance of sync issues 124ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani sPrependShortcutLabel = menu.getContext().getResources().getString( 125ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani com.android.internal.R.string.prepend_shortcut_label); 126ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani sEnterShortcutLabel = menu.getContext().getResources().getString( 127ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani com.android.internal.R.string.menu_enter_shortcut_label); 128ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani sDeleteShortcutLabel = menu.getContext().getResources().getString( 129ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani com.android.internal.R.string.menu_delete_shortcut_label); 130ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani sSpaceShortcutLabel = menu.getContext().getResources().getString( 131ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani com.android.internal.R.string.menu_space_shortcut_label); 132ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani }*/ 133ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 134ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mMenu = menu; 135ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mId = id; 136ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mGroup = group; 137ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mCategoryOrder = categoryOrder; 138ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mOrdering = ordering; 139ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mTitle = title; 140ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mShowAsAction = showAsAction; 141ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 142ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 143ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani /** 144ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani * Invokes the item by calling various listeners or callbacks. 145ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani * 146ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani * @return true if the invocation was handled, false otherwise 147ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani */ 148ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public boolean invoke() { 14949c78900da0d43140fb602431fb93212bd7f6c70Chris Banes if (mClickListener != null && mClickListener.onMenuItemClick(this)) { 150ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return true; 151ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 152ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 1531ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns if (mMenu.dispatchMenuItemSelected(mMenu.getRootMenu(), this)) { 1541ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns return true; 1551ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns } 156ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 157ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mItemCallback != null) { 158ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mItemCallback.run(); 159ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return true; 160ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 161ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 162ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mIntent != null) { 163ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani try { 1641ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns mMenu.getContext().startActivity(mIntent); 165ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return true; 166ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } catch (ActivityNotFoundException e) { 167ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani Log.e(TAG, "Can't find activity to handle intent; ignoring", e); 168ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 169ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 170ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 171ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mActionProvider != null && mActionProvider.onPerformDefaultAction()) { 172ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return true; 173ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 174ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 175ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return false; 176ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 177ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 1786e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 179ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public boolean isEnabled() { 180ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return (mFlags & ENABLED) != 0; 181ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 182ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 1836e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 184ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public MenuItem setEnabled(boolean enabled) { 185ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (enabled) { 186ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mFlags |= ENABLED; 187ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } else { 188ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mFlags &= ~ENABLED; 189ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 190ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 1911ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns mMenu.onItemsChanged(false); 192ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 193ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return this; 194ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 195ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 1966e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 197ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public int getGroupId() { 198ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return mGroup; 199ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 200ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 2016e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 202ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani @ViewDebug.CapturedViewProperty 203ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public int getItemId() { 204ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return mId; 205ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 206ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 2076e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 208ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public int getOrder() { 209ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return mCategoryOrder; 210ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 211ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 212ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public int getOrdering() { 213ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return mOrdering; 214ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 215ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 2166e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 217ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public Intent getIntent() { 218ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return mIntent; 219ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 220ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 2216e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 222ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public MenuItem setIntent(Intent intent) { 223ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mIntent = intent; 224ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return this; 225ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 226ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 227ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani Runnable getCallback() { 228ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return mItemCallback; 229ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 230ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 231ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public MenuItem setCallback(Runnable callback) { 232ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mItemCallback = callback; 233ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return this; 234ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 235ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 2366e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 237ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public char getAlphabeticShortcut() { 238ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return mShortcutAlphabeticChar; 239ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 240ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 2416e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 242ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public MenuItem setAlphabeticShortcut(char alphaChar) { 24320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns if (mShortcutAlphabeticChar == alphaChar) { 24420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns return this; 24520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 246ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 247ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mShortcutAlphabeticChar = Character.toLowerCase(alphaChar); 248ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 2491ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns mMenu.onItemsChanged(false); 250ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 251ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return this; 252ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 253ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 2546e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 255ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public char getNumericShortcut() { 256ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return mShortcutNumericChar; 257ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 258ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 2596e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 260ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public MenuItem setNumericShortcut(char numericChar) { 26120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns if (mShortcutNumericChar == numericChar) { 26220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns return this; 26320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 264ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 265ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mShortcutNumericChar = numericChar; 266ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 2671ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns mMenu.onItemsChanged(false); 268ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 269ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return this; 270ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 271ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 2726e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 273ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public MenuItem setShortcut(char numericChar, char alphaChar) { 274ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mShortcutNumericChar = numericChar; 275ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mShortcutAlphabeticChar = Character.toLowerCase(alphaChar); 276ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 2771ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns mMenu.onItemsChanged(false); 278ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 279ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return this; 280ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 281ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 282ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani /** 283ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani * @return The active shortcut (based on QWERTY-mode of the menu). 284ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani */ 285ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani char getShortcut() { 28649c78900da0d43140fb602431fb93212bd7f6c70Chris Banes return (mMenu.isQwertyMode() ? mShortcutAlphabeticChar : mShortcutNumericChar); 287ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 288ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 289ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani /** 29020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * @return The label to show for the shortcut. This includes the chording key (for example 29120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * 'Menu+a'). Also, any non-human readable characters should be human readable (for 29220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * example 'Menu+enter'). 293ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani */ 294ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani String getShortcutLabel() { 295ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 296ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani char shortcut = getShortcut(); 297ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (shortcut == 0) { 298ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return ""; 299ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 300ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 301ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani StringBuilder sb = new StringBuilder(sPrependShortcutLabel); 302ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani switch (shortcut) { 303ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 304ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani case '\n': 305ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani sb.append(sEnterShortcutLabel); 306ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani break; 307ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 308ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani case '\b': 309ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani sb.append(sDeleteShortcutLabel); 310ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani break; 311ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 312ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani case ' ': 313ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani sb.append(sSpaceShortcutLabel); 314ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani break; 315bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 316ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani default: 317ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani sb.append(shortcut); 318ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani break; 319ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 320bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 321ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return sb.toString(); 322ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 323bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 324ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani /** 32549c78900da0d43140fb602431fb93212bd7f6c70Chris Banes * @return Whether this menu item should be showing shortcuts (depends on 32649c78900da0d43140fb602431fb93212bd7f6c70Chris Banes * whether the menu should show shortcuts and whether this item has 32749c78900da0d43140fb602431fb93212bd7f6c70Chris Banes * a shortcut defined) 328ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani */ 329ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani boolean shouldShowShortcut() { 330ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani // Show shortcuts if the menu is supposed to show shortcuts AND this item has a shortcut 331ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return mMenu.isShortcutsVisible() && (getShortcut() != 0); 332ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 333bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 3346e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 335ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public SubMenu getSubMenu() { 336ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return mSubMenu; 337ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 338bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 3396e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 340ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public boolean hasSubMenu() { 341ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return mSubMenu != null; 342ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 343bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 344ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani void setSubMenu(SubMenuBuilder subMenu) { 345ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mSubMenu = subMenu; 346bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 347ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani subMenu.setHeaderTitle(getTitle()); 348ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 349bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 3506e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 351ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani @ViewDebug.CapturedViewProperty 352ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public CharSequence getTitle() { 353ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return mTitle; 354ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 355bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 356ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani /** 35730837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell * Gets the title for a particular {@link MenuView.ItemView} 358ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani * 359ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani * @param itemView The ItemView that is receiving the title 36020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * @return Either the title or condensed title based on what the ItemView prefers 361ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani */ 362ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani CharSequence getTitleForItemView(MenuView.ItemView itemView) { 363ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return ((itemView != null) && itemView.prefersCondensedTitle()) 36420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns ? getTitleCondensed() 36520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns : getTitle(); 366ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 367bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 3686e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 369ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public MenuItem setTitle(CharSequence title) { 370ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mTitle = title; 371bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 3721ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns mMenu.onItemsChanged(false); 373bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 374ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mSubMenu != null) { 375ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mSubMenu.setHeaderTitle(title); 376ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 377bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 378ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return this; 379ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 380ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 3816e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 382ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public MenuItem setTitle(int title) { 383ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return setTitle(mMenu.getContext().getString(title)); 384ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 385bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 3866e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 387ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public CharSequence getTitleCondensed() { 388937df84589168e159706463f25780f35ec63b750Chris Banes final CharSequence ctitle = mTitleCondensed != null ? mTitleCondensed : mTitle; 389937df84589168e159706463f25780f35ec63b750Chris Banes 390937df84589168e159706463f25780f35ec63b750Chris Banes if (Build.VERSION.SDK_INT < 18 && ctitle != null && !(ctitle instanceof String)) { 391937df84589168e159706463f25780f35ec63b750Chris Banes // For devices pre-JB-MR2, where we have a non-String CharSequence, we need to 392937df84589168e159706463f25780f35ec63b750Chris Banes // convert this to a String so that EventLog.writeEvent() does not throw an exception 393937df84589168e159706463f25780f35ec63b750Chris Banes // in Activity.onMenuItemSelected() 394937df84589168e159706463f25780f35ec63b750Chris Banes return ctitle.toString(); 395937df84589168e159706463f25780f35ec63b750Chris Banes } else { 396937df84589168e159706463f25780f35ec63b750Chris Banes // Else, we just return the condensed title 397937df84589168e159706463f25780f35ec63b750Chris Banes return ctitle; 398937df84589168e159706463f25780f35ec63b750Chris Banes } 399ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 400ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 4016e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 402ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public MenuItem setTitleCondensed(CharSequence title) { 403ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mTitleCondensed = title; 404bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 405ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani // Could use getTitle() in the loop below, but just cache what it would do here 406ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (title == null) { 407ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani title = mTitle; 408ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 409bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 4101ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns mMenu.onItemsChanged(false); 411bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 412ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return this; 413ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 414bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 4156e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 416ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public Drawable getIcon() { 417ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mIconDrawable != null) { 418ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return mIconDrawable; 419ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 420bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 421ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mIconResId != NO_ICON) { 422b37a31664b07243ca9e86c8dac58b9be6a417e8cChris Banes Drawable icon = TintManager.getDrawable(mMenu.getContext(), mIconResId); 4231ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns mIconResId = NO_ICON; 4241ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns mIconDrawable = icon; 4251ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns return icon; 426ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 427bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 428ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return null; 429bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 430bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 4316e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 432ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public MenuItem setIcon(Drawable icon) { 433ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mIconResId = NO_ICON; 434ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mIconDrawable = icon; 4351ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns mMenu.onItemsChanged(false); 436bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 437ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return this; 438ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 439bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 4406e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 441ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public MenuItem setIcon(int iconResId) { 442ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mIconDrawable = null; 443ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mIconResId = iconResId; 444bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 445ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani // If we have a view, we need to push the Drawable to them 4461ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns mMenu.onItemsChanged(false); 447bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 448ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return this; 449bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 450bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 4516e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 452ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public boolean isCheckable() { 453ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return (mFlags & CHECKABLE) == CHECKABLE; 454ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 455bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 4566e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 457ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public MenuItem setCheckable(boolean checkable) { 458ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani final int oldFlags = mFlags; 459ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mFlags = (mFlags & ~CHECKABLE) | (checkable ? CHECKABLE : 0); 460ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (oldFlags != mFlags) { 4611ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns mMenu.onItemsChanged(false); 462ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 463bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 464ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return this; 465ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 466bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 467ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public void setExclusiveCheckable(boolean exclusive) { 468ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mFlags = (mFlags & ~EXCLUSIVE) | (exclusive ? EXCLUSIVE : 0); 469ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 470bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 471ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public boolean isExclusiveCheckable() { 472ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return (mFlags & EXCLUSIVE) != 0; 473ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 474bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 4756e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 476ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public boolean isChecked() { 477ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return (mFlags & CHECKED) == CHECKED; 478ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 479bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 4806e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 481ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public MenuItem setChecked(boolean checked) { 482ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if ((mFlags & EXCLUSIVE) != 0) { 483ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani // Call the method on the Menu since it knows about the others in this 484ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani // exclusive checkable group 4851ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns mMenu.setExclusiveItemChecked(this); 486ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } else { 487ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani setCheckedInt(checked); 488ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 489bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 490ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return this; 491ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 492bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 493ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani void setCheckedInt(boolean checked) { 494ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani final int oldFlags = mFlags; 495ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mFlags = (mFlags & ~CHECKED) | (checked ? CHECKED : 0); 496ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (oldFlags != mFlags) { 4971ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns mMenu.onItemsChanged(false); 498ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 499ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 500bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 5016e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 502ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public boolean isVisible() { 503d713f4f0643a5f6409b431f643f1ad25dba6c22fChris Banes if (mActionProvider != null && mActionProvider.overridesItemVisibility()) { 504d713f4f0643a5f6409b431f643f1ad25dba6c22fChris Banes return (mFlags & HIDDEN) == 0 && mActionProvider.isVisible(); 505d713f4f0643a5f6409b431f643f1ad25dba6c22fChris Banes } 506ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return (mFlags & HIDDEN) == 0; 507ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 508bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 509ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani /** 51020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * Changes the visibility of the item. This method DOES NOT notify the parent menu of a change 51120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * in this item, so this should only be called from methods that will eventually trigger this 51220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * change. If unsure, use {@link #setVisible(boolean)} instead. 513ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani * 514ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani * @param shown Whether to show (true) or hide (false). 515ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani * @return Whether the item's shown state was changed 516ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani */ 517ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani boolean setVisibleInt(boolean shown) { 518ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani final int oldFlags = mFlags; 519ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mFlags = (mFlags & ~HIDDEN) | (shown ? 0 : HIDDEN); 520ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return oldFlags != mFlags; 521bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 522bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 5236e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 524ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public MenuItem setVisible(boolean shown) { 525ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani // Try to set the shown state to the given state. If the shown state was changed 526ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani // (i.e. the previous state isn't the same as given state), notify the parent menu that 527ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani // the shown state has changed for this item 5281ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns if (setVisibleInt(shown)) mMenu.onItemVisibleChanged(this); 529bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 530ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return this; 531ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 532bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 5336e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 534ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public MenuItem setOnMenuItemClickListener(MenuItem.OnMenuItemClickListener clickListener) { 535ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mClickListener = clickListener; 536ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return this; 537ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 538bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 539ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani @Override 540ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public String toString() { 541ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return mTitle.toString(); 542ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 543bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 544ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani void setMenuInfo(ContextMenuInfo menuInfo) { 545ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mMenuInfo = menuInfo; 546bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 547bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 5486e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 549ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public ContextMenuInfo getMenuInfo() { 550ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return mMenuInfo; 551ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 552bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 553ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public void actionFormatChanged() { 5541ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns mMenu.onItemActionRequestChanged(this); 555ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 556bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 557ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani /** 558ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani * @return Whether the menu should show icons for menu items. 559ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani */ 560ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public boolean shouldShowIcon() { 561ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return mMenu.getOptionalIconsVisible(); 562bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 563bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 564ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public boolean isActionButton() { 565ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return (mFlags & IS_ACTION) == IS_ACTION; 566bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 567bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 568ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public boolean requestsActionButton() { 569ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return (mShowAsAction & SHOW_AS_ACTION_IF_ROOM) == SHOW_AS_ACTION_IF_ROOM; 570ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 571bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 572ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public boolean requiresActionButton() { 573ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return (mShowAsAction & SHOW_AS_ACTION_ALWAYS) == SHOW_AS_ACTION_ALWAYS; 574ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 575bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 576ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public void setIsActionButton(boolean isActionButton) { 577ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (isActionButton) { 578ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mFlags |= IS_ACTION; 579ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } else { 580ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mFlags &= ~IS_ACTION; 581ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 582ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 583bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 584ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public boolean showsTextAsAction() { 585ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return (mShowAsAction & SHOW_AS_ACTION_WITH_TEXT) == SHOW_AS_ACTION_WITH_TEXT; 586ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 587bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 5886e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 589ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public void setShowAsAction(int actionEnum) { 590ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani switch (actionEnum & SHOW_AS_ACTION_MASK) { 591ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani case SHOW_AS_ACTION_ALWAYS: 592ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani case SHOW_AS_ACTION_IF_ROOM: 593ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani case SHOW_AS_ACTION_NEVER: 594ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani // Looks good! 595ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani break; 596ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 597ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani default: 598ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani // Mutually exclusive options selected! 599ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani throw new IllegalArgumentException("SHOW_AS_ACTION_ALWAYS, SHOW_AS_ACTION_IF_ROOM," 60020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns + " and SHOW_AS_ACTION_NEVER are mutually exclusive."); 601ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 602ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mShowAsAction = actionEnum; 6031ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns mMenu.onItemActionRequestChanged(this); 604ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 605bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 6066e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 60730837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell public SupportMenuItem setActionView(View view) { 608ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mActionView = view; 609ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mActionProvider = null; 610ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (view != null && view.getId() == View.NO_ID && mId > 0) { 611ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani view.setId(mId); 612ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 6131ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns mMenu.onItemActionRequestChanged(this); 614ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return this; 615bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 616bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 6176e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 61830837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell public SupportMenuItem setActionView(int resId) { 6191ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns final Context context = mMenu.getContext(); 6201ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns final LayoutInflater inflater = LayoutInflater.from(context); 6211ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns setActionView(inflater.inflate(resId, new LinearLayout(context), false)); 622ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return this; 623ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 624ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 6256e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 626ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public View getActionView() { 627ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mActionView != null) { 628ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return mActionView; 629ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } else if (mActionProvider != null) { 63034452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell mActionView = mActionProvider.onCreateActionView(this); 631ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return mActionView; 632ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } else { 633ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return null; 634ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 635ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 636ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 63730837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell @Override 63830837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell public MenuItem setActionProvider(android.view.ActionProvider actionProvider) { 63930837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell throw new UnsupportedOperationException( 64056261b25b9890dd44f04e0083c3ea9fde5455ebdChris Banes "This is not supported, use MenuItemCompat.setActionProvider()"); 64130837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell } 64230837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell 64330837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell @Override 64430837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell public android.view.ActionProvider getActionProvider() { 64530837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell throw new UnsupportedOperationException( 64656261b25b9890dd44f04e0083c3ea9fde5455ebdChris Banes "This is not supported, use MenuItemCompat.getActionProvider()"); 64730837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell } 64830837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell 6496e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 65030837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell public ActionProvider getSupportActionProvider() { 651ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return mActionProvider; 652ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 653ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 6546e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 65530837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell public SupportMenuItem setSupportActionProvider(ActionProvider actionProvider) { 65634452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell if (mActionProvider != null) { 65734452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell mActionProvider.setVisibilityListener(null); 65834452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell } 65949c78900da0d43140fb602431fb93212bd7f6c70Chris Banes mActionView = null; 660ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mActionProvider = actionProvider; 6611ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns mMenu.onItemsChanged(true); // Measurement can be changed 66249c78900da0d43140fb602431fb93212bd7f6c70Chris Banes if (mActionProvider != null) { 66349c78900da0d43140fb602431fb93212bd7f6c70Chris Banes mActionProvider.setVisibilityListener(new ActionProvider.VisibilityListener() { 66434452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell @Override 66534452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell public void onActionProviderVisibilityChanged(boolean isVisible) { 666d713f4f0643a5f6409b431f643f1ad25dba6c22fChris Banes mMenu.onItemVisibleChanged(MenuItemImpl.this); 66734452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell } 66834452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell }); 66934452b0d1034da026b8a1d6fe2fe4399844379d6Adam Powell } 670ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return this; 671ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 672bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 673ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani @Override 67430837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell public SupportMenuItem setShowAsActionFlags(int actionEnum) { 675ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani setShowAsAction(actionEnum); 676ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return this; 677bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 678bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 679ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani @Override 680ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public boolean expandActionView() { 68149c78900da0d43140fb602431fb93212bd7f6c70Chris Banes if (!hasCollapsibleActionView()) { 682ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return false; 683ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 684bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 685ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mOnActionExpandListener == null || 68620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns mOnActionExpandListener.onMenuItemActionExpand(this)) { 6871ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns return mMenu.expandItemActionView(this); 688ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 689ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 690ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return false; 691ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 692ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 693ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani @Override 694ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public boolean collapseActionView() { 695ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if ((mShowAsAction & SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW) == 0) { 696ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return false; 697ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 698ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mActionView == null) { 699ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani // We're already collapsed if we have no action view. 700ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return true; 701ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 702ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 703ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mOnActionExpandListener == null || 70420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns mOnActionExpandListener.onMenuItemActionCollapse(this)) { 705ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return mMenu.collapseItemActionView(this); 706ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 707ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 708ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return false; 709ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 710ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 7116e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 7126e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown public SupportMenuItem setSupportOnActionExpandListener( 7136e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown MenuItemCompat.OnActionExpandListener listener) { 714ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mOnActionExpandListener = listener; 715ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return this; 716ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 717ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 718ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public boolean hasCollapsibleActionView() { 71949c78900da0d43140fb602431fb93212bd7f6c70Chris Banes if ((mShowAsAction & SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW) != 0) { 72049c78900da0d43140fb602431fb93212bd7f6c70Chris Banes if (mActionView == null && mActionProvider != null) { 72149c78900da0d43140fb602431fb93212bd7f6c70Chris Banes mActionView = mActionProvider.onCreateActionView(this); 72249c78900da0d43140fb602431fb93212bd7f6c70Chris Banes } 72349c78900da0d43140fb602431fb93212bd7f6c70Chris Banes return mActionView != null; 72449c78900da0d43140fb602431fb93212bd7f6c70Chris Banes } 72549c78900da0d43140fb602431fb93212bd7f6c70Chris Banes return false; 726ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 727ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 728ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public void setActionViewExpanded(boolean isExpanded) { 729ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mIsActionViewExpanded = isExpanded; 7301ead4e393273917ffa2bc27e7624ce359ba955f6Trevor Johns mMenu.onItemsChanged(false); 731ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 732ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 7336e6abe6eb358db4c3932752249c8ac61dd3dab21Jeff Brown @Override 734ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public boolean isActionViewExpanded() { 735ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return mIsActionViewExpanded; 736ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 73730837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell 73830837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell @Override 73930837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell public MenuItem setOnActionExpandListener(MenuItem.OnActionExpandListener listener) { 74030837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell throw new UnsupportedOperationException( 74156261b25b9890dd44f04e0083c3ea9fde5455ebdChris Banes "This is not supported, use MenuItemCompat.setOnActionExpandListener()"); 74230837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell } 743bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell} 744