Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Adam Powell | fa18d18 | 2014-01-07 15:56:59 -0800 | [diff] [blame] | 17 | package android.widget; |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 18 | |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 19 | import android.content.Context; |
Adam Powell | bfcdfaf | 2011-08-19 11:46:59 -0700 | [diff] [blame] | 20 | import android.content.res.Configuration; |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 21 | import android.content.res.Resources; |
Adam Powell | 11ed1d6 | 2011-07-11 21:19:59 -0700 | [diff] [blame] | 22 | import android.os.Parcel; |
| 23 | import android.os.Parcelable; |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 24 | import android.util.SparseBooleanArray; |
Adam Powell | 823f074 | 2011-09-21 17:17:01 -0700 | [diff] [blame] | 25 | import android.view.ActionProvider; |
Adam Powell | 54c94de | 2013-09-26 15:36:34 -0700 | [diff] [blame] | 26 | import android.view.Gravity; |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 27 | import android.view.MenuItem; |
| 28 | import android.view.SoundEffectConstants; |
| 29 | import android.view.View; |
| 30 | import android.view.View.MeasureSpec; |
| 31 | import android.view.ViewGroup; |
Adam Powell | ad79b90 | 2013-06-19 11:33:28 -0700 | [diff] [blame] | 32 | import android.view.accessibility.AccessibilityNodeInfo; |
Alan Viverette | ca6a3611 | 2013-08-16 14:41:06 -0700 | [diff] [blame] | 33 | import android.widget.ListPopupWindow.ForwardingListener; |
Adam Powell | ad79b90 | 2013-06-19 11:33:28 -0700 | [diff] [blame] | 34 | import com.android.internal.transition.ActionBarTransition; |
Alan Viverette | 80e7270 | 2013-07-29 11:12:59 -0700 | [diff] [blame] | 35 | import com.android.internal.view.ActionBarPolicy; |
Adam Powell | fa18d18 | 2014-01-07 15:56:59 -0800 | [diff] [blame] | 36 | import com.android.internal.view.menu.ActionMenuItemView; |
| 37 | import com.android.internal.view.menu.BaseMenuPresenter; |
| 38 | import com.android.internal.view.menu.MenuBuilder; |
| 39 | import com.android.internal.view.menu.MenuItemImpl; |
| 40 | import com.android.internal.view.menu.MenuPopupHelper; |
| 41 | import com.android.internal.view.menu.MenuView; |
| 42 | import com.android.internal.view.menu.SubMenuBuilder; |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 43 | |
| 44 | import java.util.ArrayList; |
| 45 | |
| 46 | /** |
| 47 | * MenuPresenter for building action menus as seen in the action bar and action modes. |
Adam Powell | fa18d18 | 2014-01-07 15:56:59 -0800 | [diff] [blame] | 48 | * |
| 49 | * @hide |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 50 | */ |
Adam Powell | 823f074 | 2011-09-21 17:17:01 -0700 | [diff] [blame] | 51 | public class ActionMenuPresenter extends BaseMenuPresenter |
| 52 | implements ActionProvider.SubUiVisibilityListener { |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 53 | private static final String TAG = "ActionMenuPresenter"; |
| 54 | |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 55 | private View mOverflowButton; |
| 56 | private boolean mReserveOverflow; |
Adam Powell | 1ab418a | 2011-06-09 20:49:49 -0700 | [diff] [blame] | 57 | private boolean mReserveOverflowSet; |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 58 | private int mWidthLimit; |
| 59 | private int mActionItemWidthLimit; |
| 60 | private int mMaxItems; |
Adam Powell | 1ab418a | 2011-06-09 20:49:49 -0700 | [diff] [blame] | 61 | private boolean mMaxItemsSet; |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 62 | private boolean mStrictWidthLimit; |
Adam Powell | 1ab418a | 2011-06-09 20:49:49 -0700 | [diff] [blame] | 63 | private boolean mWidthLimitSet; |
Adam Powell | b187cd9 | 2011-07-20 14:17:56 -0700 | [diff] [blame] | 64 | private boolean mExpandedActionViewsExclusive; |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 65 | |
Adam Powell | 35aecd5 | 2011-07-01 13:43:49 -0700 | [diff] [blame] | 66 | private int mMinCellSize; |
| 67 | |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 68 | // Group IDs that have been added as actions - used temporarily, allocated here for reuse. |
| 69 | private final SparseBooleanArray mActionButtonGroups = new SparseBooleanArray(); |
| 70 | |
| 71 | private View mScrapActionButtonView; |
| 72 | |
| 73 | private OverflowPopup mOverflowPopup; |
| 74 | private ActionButtonSubmenu mActionButtonPopup; |
| 75 | |
| 76 | private OpenOverflowRunnable mPostedOpenRunnable; |
Alan Viverette | 5611072 | 2014-01-10 14:03:21 -0800 | [diff] [blame] | 77 | private ActionMenuPopupCallback mPopupCallback; |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 78 | |
Adam Powell | 11ed1d6 | 2011-07-11 21:19:59 -0700 | [diff] [blame] | 79 | final PopupPresenterCallback mPopupPresenterCallback = new PopupPresenterCallback(); |
| 80 | int mOpenSubMenuId; |
| 81 | |
Adam Powell | 538e565 | 2011-10-11 13:47:08 -0700 | [diff] [blame] | 82 | public ActionMenuPresenter(Context context) { |
| 83 | super(context, com.android.internal.R.layout.action_menu_layout, |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 84 | com.android.internal.R.layout.action_menu_item_layout); |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public void initForMenu(Context context, MenuBuilder menu) { |
| 89 | super.initForMenu(context, menu); |
| 90 | |
| 91 | final Resources res = context.getResources(); |
Adam Powell | 1ab418a | 2011-06-09 20:49:49 -0700 | [diff] [blame] | 92 | |
Adam Powell | b8139af | 2012-04-19 13:52:46 -0700 | [diff] [blame] | 93 | final ActionBarPolicy abp = ActionBarPolicy.get(context); |
Adam Powell | 1ab418a | 2011-06-09 20:49:49 -0700 | [diff] [blame] | 94 | if (!mReserveOverflowSet) { |
Adam Powell | b8139af | 2012-04-19 13:52:46 -0700 | [diff] [blame] | 95 | mReserveOverflow = abp.showsOverflowMenuButton(); |
Adam Powell | 1ab418a | 2011-06-09 20:49:49 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | if (!mWidthLimitSet) { |
Adam Powell | b8139af | 2012-04-19 13:52:46 -0700 | [diff] [blame] | 99 | mWidthLimit = abp.getEmbeddedMenuWidthLimit(); |
Adam Powell | 1ab418a | 2011-06-09 20:49:49 -0700 | [diff] [blame] | 100 | } |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 101 | |
| 102 | // Measure for initial configuration |
Adam Powell | 1ab418a | 2011-06-09 20:49:49 -0700 | [diff] [blame] | 103 | if (!mMaxItemsSet) { |
Adam Powell | b8139af | 2012-04-19 13:52:46 -0700 | [diff] [blame] | 104 | mMaxItems = abp.getMaxActionButtons(); |
Adam Powell | 1ab418a | 2011-06-09 20:49:49 -0700 | [diff] [blame] | 105 | } |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 106 | |
| 107 | int width = mWidthLimit; |
| 108 | if (mReserveOverflow) { |
Adam Powell | 9b4bee0 | 2011-04-27 19:24:47 -0700 | [diff] [blame] | 109 | if (mOverflowButton == null) { |
Adam Powell | 538e565 | 2011-10-11 13:47:08 -0700 | [diff] [blame] | 110 | mOverflowButton = new OverflowMenuButton(mSystemContext); |
Adam Powell | 9b4bee0 | 2011-04-27 19:24:47 -0700 | [diff] [blame] | 111 | final int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); |
| 112 | mOverflowButton.measure(spec, spec); |
| 113 | } |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 114 | width -= mOverflowButton.getMeasuredWidth(); |
| 115 | } else { |
| 116 | mOverflowButton = null; |
| 117 | } |
| 118 | |
| 119 | mActionItemWidthLimit = width; |
| 120 | |
Adam Powell | 35aecd5 | 2011-07-01 13:43:49 -0700 | [diff] [blame] | 121 | mMinCellSize = (int) (ActionMenuView.MIN_CELL_SIZE * res.getDisplayMetrics().density); |
| 122 | |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 123 | // Drop a scrap view as it may no longer reflect the proper context/config. |
| 124 | mScrapActionButtonView = null; |
| 125 | } |
| 126 | |
Adam Powell | bfcdfaf | 2011-08-19 11:46:59 -0700 | [diff] [blame] | 127 | public void onConfigurationChanged(Configuration newConfig) { |
| 128 | if (!mMaxItemsSet) { |
| 129 | mMaxItems = mContext.getResources().getInteger( |
| 130 | com.android.internal.R.integer.max_action_buttons); |
Adam Powell | f203e0a | 2012-03-06 17:40:12 -0800 | [diff] [blame] | 131 | } |
| 132 | if (mMenu != null) { |
| 133 | mMenu.onItemsChanged(true); |
Adam Powell | bfcdfaf | 2011-08-19 11:46:59 -0700 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 137 | public void setWidthLimit(int width, boolean strict) { |
Adam Powell | 1ab418a | 2011-06-09 20:49:49 -0700 | [diff] [blame] | 138 | mWidthLimit = width; |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 139 | mStrictWidthLimit = strict; |
Adam Powell | 1ab418a | 2011-06-09 20:49:49 -0700 | [diff] [blame] | 140 | mWidthLimitSet = true; |
| 141 | } |
| 142 | |
| 143 | public void setReserveOverflow(boolean reserveOverflow) { |
| 144 | mReserveOverflow = reserveOverflow; |
| 145 | mReserveOverflowSet = true; |
Adam Powell | 9b4bee0 | 2011-04-27 19:24:47 -0700 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | public void setItemLimit(int itemCount) { |
| 149 | mMaxItems = itemCount; |
Adam Powell | 1ab418a | 2011-06-09 20:49:49 -0700 | [diff] [blame] | 150 | mMaxItemsSet = true; |
Adam Powell | 9b4bee0 | 2011-04-27 19:24:47 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Adam Powell | b187cd9 | 2011-07-20 14:17:56 -0700 | [diff] [blame] | 153 | public void setExpandedActionViewsExclusive(boolean isExclusive) { |
| 154 | mExpandedActionViewsExclusive = isExclusive; |
| 155 | } |
| 156 | |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 157 | @Override |
| 158 | public MenuView getMenuView(ViewGroup root) { |
| 159 | MenuView result = super.getMenuView(root); |
| 160 | ((ActionMenuView) result).setPresenter(this); |
| 161 | return result; |
| 162 | } |
| 163 | |
| 164 | @Override |
Alan Viverette | fbe4a58 | 2013-09-06 13:45:54 -0700 | [diff] [blame] | 165 | public View getItemView(final MenuItemImpl item, View convertView, ViewGroup parent) { |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 166 | View actionView = item.getActionView(); |
Adam Powell | 35aecd5 | 2011-07-01 13:43:49 -0700 | [diff] [blame] | 167 | if (actionView == null || item.hasCollapsibleActionView()) { |
Adam Powell | c3ca3ea | 2013-10-10 18:07:48 -0700 | [diff] [blame] | 168 | actionView = super.getItemView(item, convertView, parent); |
Adam Powell | 35aecd5 | 2011-07-01 13:43:49 -0700 | [diff] [blame] | 169 | } |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 170 | actionView.setVisibility(item.isActionViewExpanded() ? View.GONE : View.VISIBLE); |
Adam Powell | 35aecd5 | 2011-07-01 13:43:49 -0700 | [diff] [blame] | 171 | |
Adam Powell | fe9c354 | 2014-01-10 18:32:08 +0000 | [diff] [blame] | 172 | final ActionMenuView menuParent = (ActionMenuView) parent; |
| 173 | final ViewGroup.LayoutParams lp = actionView.getLayoutParams(); |
| 174 | if (!menuParent.checkLayoutParams(lp)) { |
| 175 | actionView.setLayoutParams(menuParent.generateLayoutParams(lp)); |
| 176 | } |
| 177 | return actionView; |
| 178 | } |
| 179 | |
| 180 | @Override |
Alan Viverette | 5611072 | 2014-01-10 14:03:21 -0800 | [diff] [blame] | 181 | public void bindItemView(MenuItemImpl item, MenuView.ItemView itemView) { |
Adam Powell | fe9c354 | 2014-01-10 18:32:08 +0000 | [diff] [blame] | 182 | itemView.initialize(item, 0); |
| 183 | |
| 184 | final ActionMenuView menuView = (ActionMenuView) mMenuView; |
| 185 | final ActionMenuItemView actionItemView = (ActionMenuItemView) itemView; |
| 186 | actionItemView.setItemInvoker(menuView); |
| 187 | |
Alan Viverette | 5611072 | 2014-01-10 14:03:21 -0800 | [diff] [blame] | 188 | if (mPopupCallback == null) { |
| 189 | mPopupCallback = new ActionMenuPopupCallback(); |
Alan Viverette | fbe4a58 | 2013-09-06 13:45:54 -0700 | [diff] [blame] | 190 | } |
Alan Viverette | 5611072 | 2014-01-10 14:03:21 -0800 | [diff] [blame] | 191 | actionItemView.setPopupCallback(mPopupCallback); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | @Override |
| 195 | public boolean shouldIncludeItem(int childIndex, MenuItemImpl item) { |
| 196 | return item.isActionButton(); |
| 197 | } |
| 198 | |
| 199 | @Override |
| 200 | public void updateMenuView(boolean cleared) { |
Adam Powell | ad79b90 | 2013-06-19 11:33:28 -0700 | [diff] [blame] | 201 | final ViewGroup menuViewParent = (ViewGroup) ((View) mMenuView).getParent(); |
| 202 | if (menuViewParent != null) { |
Chet Haase | d8d7c38 | 2013-09-23 11:26:36 -0700 | [diff] [blame] | 203 | ActionBarTransition.beginDelayedTransition(menuViewParent); |
Adam Powell | ad79b90 | 2013-06-19 11:33:28 -0700 | [diff] [blame] | 204 | } |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 205 | super.updateMenuView(cleared); |
| 206 | |
Adam Powell | da97108 | 2013-10-03 18:21:58 -0700 | [diff] [blame] | 207 | ((View) mMenuView).requestLayout(); |
| 208 | |
Adam Powell | 823f074 | 2011-09-21 17:17:01 -0700 | [diff] [blame] | 209 | if (mMenu != null) { |
| 210 | final ArrayList<MenuItemImpl> actionItems = mMenu.getActionItems(); |
| 211 | final int count = actionItems.size(); |
| 212 | for (int i = 0; i < count; i++) { |
| 213 | final ActionProvider provider = actionItems.get(i).getActionProvider(); |
| 214 | if (provider != null) { |
| 215 | provider.setSubUiVisibilityListener(this); |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
Adam Powell | 275702c | 2011-09-23 17:34:04 -0700 | [diff] [blame] | 220 | final ArrayList<MenuItemImpl> nonActionItems = mMenu != null ? |
| 221 | mMenu.getNonActionItems() : null; |
| 222 | |
| 223 | boolean hasOverflow = false; |
| 224 | if (mReserveOverflow && nonActionItems != null) { |
| 225 | final int count = nonActionItems.size(); |
| 226 | if (count == 1) { |
| 227 | hasOverflow = !nonActionItems.get(0).isActionViewExpanded(); |
| 228 | } else { |
| 229 | hasOverflow = count > 0; |
| 230 | } |
| 231 | } |
| 232 | |
Adam Powell | 14b7e2c | 2011-08-12 11:11:50 -0700 | [diff] [blame] | 233 | if (hasOverflow) { |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 234 | if (mOverflowButton == null) { |
Adam Powell | 538e565 | 2011-10-11 13:47:08 -0700 | [diff] [blame] | 235 | mOverflowButton = new OverflowMenuButton(mSystemContext); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 236 | } |
| 237 | ViewGroup parent = (ViewGroup) mOverflowButton.getParent(); |
| 238 | if (parent != mMenuView) { |
| 239 | if (parent != null) { |
| 240 | parent.removeView(mOverflowButton); |
| 241 | } |
Adam Powell | 35aecd5 | 2011-07-01 13:43:49 -0700 | [diff] [blame] | 242 | ActionMenuView menuView = (ActionMenuView) mMenuView; |
| 243 | menuView.addView(mOverflowButton, menuView.generateOverflowButtonLayoutParams()); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 244 | } |
| 245 | } else if (mOverflowButton != null && mOverflowButton.getParent() == mMenuView) { |
| 246 | ((ViewGroup) mMenuView).removeView(mOverflowButton); |
| 247 | } |
Adam Powell | 14b7e2c | 2011-08-12 11:11:50 -0700 | [diff] [blame] | 248 | |
| 249 | ((ActionMenuView) mMenuView).setOverflowReserved(mReserveOverflow); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | @Override |
| 253 | public boolean filterLeftoverView(ViewGroup parent, int childIndex) { |
| 254 | if (parent.getChildAt(childIndex) == mOverflowButton) return false; |
| 255 | return super.filterLeftoverView(parent, childIndex); |
| 256 | } |
| 257 | |
| 258 | public boolean onSubMenuSelected(SubMenuBuilder subMenu) { |
| 259 | if (!subMenu.hasVisibleItems()) return false; |
| 260 | |
| 261 | SubMenuBuilder topSubMenu = subMenu; |
| 262 | while (topSubMenu.getParentMenu() != mMenu) { |
| 263 | topSubMenu = (SubMenuBuilder) topSubMenu.getParentMenu(); |
| 264 | } |
| 265 | View anchor = findViewForItem(topSubMenu.getItem()); |
Adam Powell | 11ed1d6 | 2011-07-11 21:19:59 -0700 | [diff] [blame] | 266 | if (anchor == null) { |
| 267 | if (mOverflowButton == null) return false; |
| 268 | anchor = mOverflowButton; |
| 269 | } |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 270 | |
Adam Powell | 11ed1d6 | 2011-07-11 21:19:59 -0700 | [diff] [blame] | 271 | mOpenSubMenuId = subMenu.getItem().getItemId(); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 272 | mActionButtonPopup = new ActionButtonSubmenu(mContext, subMenu); |
| 273 | mActionButtonPopup.setAnchorView(anchor); |
| 274 | mActionButtonPopup.show(); |
| 275 | super.onSubMenuSelected(subMenu); |
| 276 | return true; |
| 277 | } |
| 278 | |
| 279 | private View findViewForItem(MenuItem item) { |
| 280 | final ViewGroup parent = (ViewGroup) mMenuView; |
| 281 | if (parent == null) return null; |
| 282 | |
| 283 | final int count = parent.getChildCount(); |
| 284 | for (int i = 0; i < count; i++) { |
| 285 | final View child = parent.getChildAt(i); |
| 286 | if (child instanceof MenuView.ItemView && |
| 287 | ((MenuView.ItemView) child).getItemData() == item) { |
| 288 | return child; |
| 289 | } |
| 290 | } |
| 291 | return null; |
| 292 | } |
| 293 | |
| 294 | /** |
| 295 | * Display the overflow menu if one is present. |
| 296 | * @return true if the overflow menu was shown, false otherwise. |
| 297 | */ |
| 298 | public boolean showOverflowMenu() { |
Adam Powell | 70e9f4b | 2011-08-22 16:31:24 -0700 | [diff] [blame] | 299 | if (mReserveOverflow && !isOverflowMenuShowing() && mMenu != null && mMenuView != null && |
Jake Wharton | a647640 | 2012-03-29 01:42:37 -0700 | [diff] [blame] | 300 | mPostedOpenRunnable == null && !mMenu.getNonActionItems().isEmpty()) { |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 301 | OverflowPopup popup = new OverflowPopup(mContext, mMenu, mOverflowButton, true); |
| 302 | mPostedOpenRunnable = new OpenOverflowRunnable(popup); |
| 303 | // Post this for later; we might still need a layout for the anchor to be right. |
| 304 | ((View) mMenuView).post(mPostedOpenRunnable); |
| 305 | |
| 306 | // ActionMenuPresenter uses null as a callback argument here |
| 307 | // to indicate overflow is opening. |
| 308 | super.onSubMenuSelected(null); |
| 309 | |
| 310 | return true; |
| 311 | } |
| 312 | return false; |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * Hide the overflow menu if it is currently showing. |
| 317 | * |
| 318 | * @return true if the overflow menu was hidden, false otherwise. |
| 319 | */ |
| 320 | public boolean hideOverflowMenu() { |
| 321 | if (mPostedOpenRunnable != null && mMenuView != null) { |
| 322 | ((View) mMenuView).removeCallbacks(mPostedOpenRunnable); |
Adam Powell | 678ed0c | 2011-10-27 17:46:07 -0700 | [diff] [blame] | 323 | mPostedOpenRunnable = null; |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 324 | return true; |
| 325 | } |
| 326 | |
| 327 | MenuPopupHelper popup = mOverflowPopup; |
| 328 | if (popup != null) { |
| 329 | popup.dismiss(); |
| 330 | return true; |
| 331 | } |
| 332 | return false; |
| 333 | } |
| 334 | |
| 335 | /** |
| 336 | * Dismiss all popup menus - overflow and submenus. |
| 337 | * @return true if popups were dismissed, false otherwise. (This can be because none were open.) |
| 338 | */ |
| 339 | public boolean dismissPopupMenus() { |
| 340 | boolean result = hideOverflowMenu(); |
| 341 | result |= hideSubMenus(); |
| 342 | return result; |
| 343 | } |
| 344 | |
| 345 | /** |
| 346 | * Dismiss all submenu popups. |
| 347 | * |
| 348 | * @return true if popups were dismissed, false otherwise. (This can be because none were open.) |
| 349 | */ |
| 350 | public boolean hideSubMenus() { |
| 351 | if (mActionButtonPopup != null) { |
| 352 | mActionButtonPopup.dismiss(); |
| 353 | return true; |
| 354 | } |
| 355 | return false; |
| 356 | } |
| 357 | |
| 358 | /** |
| 359 | * @return true if the overflow menu is currently showing |
| 360 | */ |
| 361 | public boolean isOverflowMenuShowing() { |
| 362 | return mOverflowPopup != null && mOverflowPopup.isShowing(); |
| 363 | } |
| 364 | |
Adam Powell | 5fcf5b9 | 2013-09-11 08:45:36 -0700 | [diff] [blame] | 365 | public boolean isOverflowMenuShowPending() { |
| 366 | return mPostedOpenRunnable != null || isOverflowMenuShowing(); |
| 367 | } |
| 368 | |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 369 | /** |
| 370 | * @return true if space has been reserved in the action menu for an overflow item. |
| 371 | */ |
| 372 | public boolean isOverflowReserved() { |
| 373 | return mReserveOverflow; |
| 374 | } |
| 375 | |
| 376 | public boolean flagActionItems() { |
| 377 | final ArrayList<MenuItemImpl> visibleItems = mMenu.getVisibleItems(); |
| 378 | final int itemsSize = visibleItems.size(); |
| 379 | int maxActions = mMaxItems; |
| 380 | int widthLimit = mActionItemWidthLimit; |
| 381 | final int querySpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); |
| 382 | final ViewGroup parent = (ViewGroup) mMenuView; |
| 383 | |
| 384 | int requiredItems = 0; |
| 385 | int requestedItems = 0; |
| 386 | int firstActionWidth = 0; |
| 387 | boolean hasOverflow = false; |
| 388 | for (int i = 0; i < itemsSize; i++) { |
| 389 | MenuItemImpl item = visibleItems.get(i); |
| 390 | if (item.requiresActionButton()) { |
| 391 | requiredItems++; |
| 392 | } else if (item.requestsActionButton()) { |
| 393 | requestedItems++; |
| 394 | } else { |
| 395 | hasOverflow = true; |
| 396 | } |
Adam Powell | b187cd9 | 2011-07-20 14:17:56 -0700 | [diff] [blame] | 397 | if (mExpandedActionViewsExclusive && item.isActionViewExpanded()) { |
| 398 | // Overflow everything if we have an expanded action view and we're |
| 399 | // space constrained. |
| 400 | maxActions = 0; |
| 401 | } |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | // Reserve a spot for the overflow item if needed. |
| 405 | if (mReserveOverflow && |
| 406 | (hasOverflow || requiredItems + requestedItems > maxActions)) { |
| 407 | maxActions--; |
| 408 | } |
| 409 | maxActions -= requiredItems; |
| 410 | |
| 411 | final SparseBooleanArray seenGroups = mActionButtonGroups; |
| 412 | seenGroups.clear(); |
| 413 | |
Adam Powell | 35aecd5 | 2011-07-01 13:43:49 -0700 | [diff] [blame] | 414 | int cellSize = 0; |
| 415 | int cellsRemaining = 0; |
| 416 | if (mStrictWidthLimit) { |
| 417 | cellsRemaining = widthLimit / mMinCellSize; |
| 418 | final int cellSizeRemaining = widthLimit % mMinCellSize; |
| 419 | cellSize = mMinCellSize + cellSizeRemaining / cellsRemaining; |
| 420 | } |
| 421 | |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 422 | // Flag as many more requested items as will fit. |
| 423 | for (int i = 0; i < itemsSize; i++) { |
| 424 | MenuItemImpl item = visibleItems.get(i); |
| 425 | |
| 426 | if (item.requiresActionButton()) { |
Adam Powell | 35aecd5 | 2011-07-01 13:43:49 -0700 | [diff] [blame] | 427 | View v = getItemView(item, mScrapActionButtonView, parent); |
| 428 | if (mScrapActionButtonView == null) { |
| 429 | mScrapActionButtonView = v; |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 430 | } |
Adam Powell | 35aecd5 | 2011-07-01 13:43:49 -0700 | [diff] [blame] | 431 | if (mStrictWidthLimit) { |
| 432 | cellsRemaining -= ActionMenuView.measureChildForCells(v, |
| 433 | cellSize, cellsRemaining, querySpec, 0); |
| 434 | } else { |
| 435 | v.measure(querySpec, querySpec); |
| 436 | } |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 437 | final int measuredWidth = v.getMeasuredWidth(); |
| 438 | widthLimit -= measuredWidth; |
| 439 | if (firstActionWidth == 0) { |
| 440 | firstActionWidth = measuredWidth; |
| 441 | } |
| 442 | final int groupId = item.getGroupId(); |
| 443 | if (groupId != 0) { |
| 444 | seenGroups.put(groupId, true); |
| 445 | } |
Adam Powell | ea1ca95 | 2011-06-21 14:07:59 -0700 | [diff] [blame] | 446 | item.setIsActionButton(true); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 447 | } else if (item.requestsActionButton()) { |
| 448 | // Items in a group with other items that already have an action slot |
| 449 | // can break the max actions rule, but not the width limit. |
| 450 | final int groupId = item.getGroupId(); |
| 451 | final boolean inGroup = seenGroups.get(groupId); |
Adam Powell | 35aecd5 | 2011-07-01 13:43:49 -0700 | [diff] [blame] | 452 | boolean isAction = (maxActions > 0 || inGroup) && widthLimit > 0 && |
| 453 | (!mStrictWidthLimit || cellsRemaining > 0); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 454 | |
| 455 | if (isAction) { |
Adam Powell | 35aecd5 | 2011-07-01 13:43:49 -0700 | [diff] [blame] | 456 | View v = getItemView(item, mScrapActionButtonView, parent); |
| 457 | if (mScrapActionButtonView == null) { |
| 458 | mScrapActionButtonView = v; |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 459 | } |
Adam Powell | 35aecd5 | 2011-07-01 13:43:49 -0700 | [diff] [blame] | 460 | if (mStrictWidthLimit) { |
| 461 | final int cells = ActionMenuView.measureChildForCells(v, |
| 462 | cellSize, cellsRemaining, querySpec, 0); |
| 463 | cellsRemaining -= cells; |
| 464 | if (cells == 0) { |
| 465 | isAction = false; |
| 466 | } |
| 467 | } else { |
| 468 | v.measure(querySpec, querySpec); |
| 469 | } |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 470 | final int measuredWidth = v.getMeasuredWidth(); |
| 471 | widthLimit -= measuredWidth; |
| 472 | if (firstActionWidth == 0) { |
| 473 | firstActionWidth = measuredWidth; |
| 474 | } |
| 475 | |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 476 | if (mStrictWidthLimit) { |
Adam Powell | 35aecd5 | 2011-07-01 13:43:49 -0700 | [diff] [blame] | 477 | isAction &= widthLimit >= 0; |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 478 | } else { |
| 479 | // Did this push the entire first item past the limit? |
Adam Powell | 35aecd5 | 2011-07-01 13:43:49 -0700 | [diff] [blame] | 480 | isAction &= widthLimit + firstActionWidth > 0; |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 481 | } |
| 482 | } |
| 483 | |
| 484 | if (isAction && groupId != 0) { |
| 485 | seenGroups.put(groupId, true); |
| 486 | } else if (inGroup) { |
| 487 | // We broke the width limit. Demote the whole group, they all overflow now. |
| 488 | seenGroups.put(groupId, false); |
| 489 | for (int j = 0; j < i; j++) { |
| 490 | MenuItemImpl areYouMyGroupie = visibleItems.get(j); |
| 491 | if (areYouMyGroupie.getGroupId() == groupId) { |
Adam Powell | 23f4cc0 | 2011-08-18 10:30:46 -0700 | [diff] [blame] | 492 | // Give back the action slot |
| 493 | if (areYouMyGroupie.isActionButton()) maxActions++; |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 494 | areYouMyGroupie.setIsActionButton(false); |
| 495 | } |
| 496 | } |
| 497 | } |
| 498 | |
Adam Powell | 23f4cc0 | 2011-08-18 10:30:46 -0700 | [diff] [blame] | 499 | if (isAction) maxActions--; |
| 500 | |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 501 | item.setIsActionButton(isAction); |
Svetoslav Ganov | 14c4669 | 2012-10-09 18:11:36 -0700 | [diff] [blame] | 502 | } else { |
| 503 | // Neither requires nor requests an action button. |
| 504 | item.setIsActionButton(false); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 505 | } |
| 506 | } |
| 507 | return true; |
| 508 | } |
| 509 | |
| 510 | @Override |
| 511 | public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) { |
| 512 | dismissPopupMenus(); |
| 513 | super.onCloseMenu(menu, allMenusAreClosing); |
| 514 | } |
| 515 | |
Adam Powell | 11ed1d6 | 2011-07-11 21:19:59 -0700 | [diff] [blame] | 516 | @Override |
| 517 | public Parcelable onSaveInstanceState() { |
| 518 | SavedState state = new SavedState(); |
| 519 | state.openSubMenuId = mOpenSubMenuId; |
| 520 | return state; |
| 521 | } |
| 522 | |
| 523 | @Override |
| 524 | public void onRestoreInstanceState(Parcelable state) { |
| 525 | SavedState saved = (SavedState) state; |
| 526 | if (saved.openSubMenuId > 0) { |
| 527 | MenuItem item = mMenu.findItem(saved.openSubMenuId); |
| 528 | if (item != null) { |
| 529 | SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu(); |
| 530 | onSubMenuSelected(subMenu); |
| 531 | } |
| 532 | } |
| 533 | } |
| 534 | |
Adam Powell | 823f074 | 2011-09-21 17:17:01 -0700 | [diff] [blame] | 535 | @Override |
| 536 | public void onSubUiVisibilityChanged(boolean isVisible) { |
| 537 | if (isVisible) { |
| 538 | // Not a submenu, but treat it like one. |
| 539 | super.onSubMenuSelected(null); |
| 540 | } else { |
| 541 | mMenu.close(false); |
| 542 | } |
| 543 | } |
| 544 | |
Adam Powell | fa18d18 | 2014-01-07 15:56:59 -0800 | [diff] [blame] | 545 | public void setMenuView(ActionMenuView menuView) { |
| 546 | mMenuView = menuView; |
| 547 | } |
| 548 | |
Adam Powell | 11ed1d6 | 2011-07-11 21:19:59 -0700 | [diff] [blame] | 549 | private static class SavedState implements Parcelable { |
| 550 | public int openSubMenuId; |
| 551 | |
| 552 | SavedState() { |
| 553 | } |
| 554 | |
| 555 | SavedState(Parcel in) { |
| 556 | openSubMenuId = in.readInt(); |
| 557 | } |
| 558 | |
| 559 | @Override |
| 560 | public int describeContents() { |
| 561 | return 0; |
| 562 | } |
| 563 | |
| 564 | @Override |
| 565 | public void writeToParcel(Parcel dest, int flags) { |
| 566 | dest.writeInt(openSubMenuId); |
| 567 | } |
| 568 | |
| 569 | public static final Parcelable.Creator<SavedState> CREATOR |
| 570 | = new Parcelable.Creator<SavedState>() { |
| 571 | public SavedState createFromParcel(Parcel in) { |
| 572 | return new SavedState(in); |
| 573 | } |
| 574 | |
| 575 | public SavedState[] newArray(int size) { |
| 576 | return new SavedState[size]; |
| 577 | } |
| 578 | }; |
| 579 | } |
| 580 | |
Adam Powell | fa18d18 | 2014-01-07 15:56:59 -0800 | [diff] [blame] | 581 | private class OverflowMenuButton extends ImageButton implements ActionMenuView.ActionMenuChildView { |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 582 | public OverflowMenuButton(Context context) { |
| 583 | super(context, null, com.android.internal.R.attr.actionOverflowButtonStyle); |
| 584 | |
| 585 | setClickable(true); |
| 586 | setFocusable(true); |
| 587 | setVisibility(VISIBLE); |
| 588 | setEnabled(true); |
Alan Viverette | ca6a3611 | 2013-08-16 14:41:06 -0700 | [diff] [blame] | 589 | |
Alan Viverette | 6996014 | 2013-08-22 17:26:57 -0700 | [diff] [blame] | 590 | setOnTouchListener(new ForwardingListener(this) { |
Alan Viverette | ca6a3611 | 2013-08-16 14:41:06 -0700 | [diff] [blame] | 591 | @Override |
| 592 | public ListPopupWindow getPopup() { |
| 593 | if (mOverflowPopup == null) { |
| 594 | return null; |
| 595 | } |
| 596 | |
| 597 | return mOverflowPopup.getPopup(); |
| 598 | } |
| 599 | |
| 600 | @Override |
| 601 | public boolean onForwardingStarted() { |
| 602 | showOverflowMenu(); |
| 603 | return true; |
| 604 | } |
| 605 | |
| 606 | @Override |
| 607 | public boolean onForwardingStopped() { |
| 608 | // Displaying the popup occurs asynchronously, so wait for |
| 609 | // the runnable to finish before deciding whether to stop |
| 610 | // forwarding. |
| 611 | if (mPostedOpenRunnable != null) { |
| 612 | return false; |
| 613 | } |
| 614 | |
| 615 | hideOverflowMenu(); |
| 616 | return true; |
| 617 | } |
| 618 | }); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | @Override |
| 622 | public boolean performClick() { |
| 623 | if (super.performClick()) { |
| 624 | return true; |
| 625 | } |
| 626 | |
| 627 | playSoundEffect(SoundEffectConstants.CLICK); |
| 628 | showOverflowMenu(); |
| 629 | return true; |
| 630 | } |
| 631 | |
Alan Viverette | 80e7270 | 2013-07-29 11:12:59 -0700 | [diff] [blame] | 632 | @Override |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 633 | public boolean needsDividerBefore() { |
Adam Powell | 35aecd5 | 2011-07-01 13:43:49 -0700 | [diff] [blame] | 634 | return false; |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Alan Viverette | 80e7270 | 2013-07-29 11:12:59 -0700 | [diff] [blame] | 637 | @Override |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 638 | public boolean needsDividerAfter() { |
| 639 | return false; |
| 640 | } |
Adam Powell | d5c81db | 2012-08-02 14:35:26 -0700 | [diff] [blame] | 641 | |
| 642 | @Override |
| 643 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 644 | if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST) { |
| 645 | // Fill available height |
| 646 | heightMeasureSpec = MeasureSpec.makeMeasureSpec( |
| 647 | MeasureSpec.getSize(heightMeasureSpec), MeasureSpec.EXACTLY); |
| 648 | } |
| 649 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 650 | } |
Alan Viverette | 058ac7c | 2013-08-19 16:44:30 -0700 | [diff] [blame] | 651 | |
| 652 | @Override |
| 653 | public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
| 654 | super.onInitializeAccessibilityNodeInfo(info); |
Svetoslav Ganov | cb8ed39 | 2013-08-23 20:37:28 -0700 | [diff] [blame] | 655 | info.setCanOpenPopup(true); |
Alan Viverette | 058ac7c | 2013-08-19 16:44:30 -0700 | [diff] [blame] | 656 | } |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | private class OverflowPopup extends MenuPopupHelper { |
| 660 | public OverflowPopup(Context context, MenuBuilder menu, View anchorView, |
| 661 | boolean overflowOnly) { |
| 662 | super(context, menu, anchorView, overflowOnly); |
Adam Powell | 54c94de | 2013-09-26 15:36:34 -0700 | [diff] [blame] | 663 | setGravity(Gravity.END); |
Adam Powell | 11ed1d6 | 2011-07-11 21:19:59 -0700 | [diff] [blame] | 664 | setCallback(mPopupPresenterCallback); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | @Override |
| 668 | public void onDismiss() { |
| 669 | super.onDismiss(); |
| 670 | mMenu.close(); |
| 671 | mOverflowPopup = null; |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | private class ActionButtonSubmenu extends MenuPopupHelper { |
| 676 | private SubMenuBuilder mSubMenu; |
| 677 | |
| 678 | public ActionButtonSubmenu(Context context, SubMenuBuilder subMenu) { |
| 679 | super(context, subMenu); |
| 680 | mSubMenu = subMenu; |
| 681 | |
| 682 | MenuItemImpl item = (MenuItemImpl) subMenu.getItem(); |
| 683 | if (!item.isActionButton()) { |
| 684 | // Give a reasonable anchor to nested submenus. |
| 685 | setAnchorView(mOverflowButton == null ? (View) mMenuView : mOverflowButton); |
| 686 | } |
Adam Powell | 11ed1d6 | 2011-07-11 21:19:59 -0700 | [diff] [blame] | 687 | |
| 688 | setCallback(mPopupPresenterCallback); |
Adam Powell | 9151103 | 2011-07-13 10:24:06 -0700 | [diff] [blame] | 689 | |
| 690 | boolean preserveIconSpacing = false; |
| 691 | final int count = subMenu.size(); |
| 692 | for (int i = 0; i < count; i++) { |
| 693 | MenuItem childItem = subMenu.getItem(i); |
| 694 | if (childItem.isVisible() && childItem.getIcon() != null) { |
| 695 | preserveIconSpacing = true; |
| 696 | break; |
| 697 | } |
| 698 | } |
| 699 | setForceShowIcon(preserveIconSpacing); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | @Override |
| 703 | public void onDismiss() { |
| 704 | super.onDismiss(); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 705 | mActionButtonPopup = null; |
Adam Powell | 11ed1d6 | 2011-07-11 21:19:59 -0700 | [diff] [blame] | 706 | mOpenSubMenuId = 0; |
| 707 | } |
| 708 | } |
| 709 | |
Adam Powell | fa18d18 | 2014-01-07 15:56:59 -0800 | [diff] [blame] | 710 | private class PopupPresenterCallback implements Callback { |
Adam Powell | 11ed1d6 | 2011-07-11 21:19:59 -0700 | [diff] [blame] | 711 | |
| 712 | @Override |
| 713 | public boolean onOpenSubMenu(MenuBuilder subMenu) { |
Adam Powell | 823f074 | 2011-09-21 17:17:01 -0700 | [diff] [blame] | 714 | if (subMenu == null) return false; |
| 715 | |
Adam Powell | 11ed1d6 | 2011-07-11 21:19:59 -0700 | [diff] [blame] | 716 | mOpenSubMenuId = ((SubMenuBuilder) subMenu).getItem().getItemId(); |
Adam Powell | fa18d18 | 2014-01-07 15:56:59 -0800 | [diff] [blame] | 717 | final Callback cb = getCallback(); |
Adam Powell | b411b32 | 2013-11-01 18:22:11 -0700 | [diff] [blame] | 718 | return cb != null ? cb.onOpenSubMenu(subMenu) : false; |
Adam Powell | 11ed1d6 | 2011-07-11 21:19:59 -0700 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | @Override |
| 722 | public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) { |
Adam Powell | 823f074 | 2011-09-21 17:17:01 -0700 | [diff] [blame] | 723 | if (menu instanceof SubMenuBuilder) { |
| 724 | ((SubMenuBuilder) menu).getRootMenu().close(false); |
| 725 | } |
Adam Powell | fa18d18 | 2014-01-07 15:56:59 -0800 | [diff] [blame] | 726 | final Callback cb = getCallback(); |
Adam Powell | b411b32 | 2013-11-01 18:22:11 -0700 | [diff] [blame] | 727 | if (cb != null) { |
| 728 | cb.onCloseMenu(menu, allMenusAreClosing); |
| 729 | } |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 730 | } |
| 731 | } |
| 732 | |
| 733 | private class OpenOverflowRunnable implements Runnable { |
| 734 | private OverflowPopup mPopup; |
| 735 | |
| 736 | public OpenOverflowRunnable(OverflowPopup popup) { |
| 737 | mPopup = popup; |
| 738 | } |
| 739 | |
| 740 | public void run() { |
| 741 | mMenu.changeMenuMode(); |
Adam Powell | 678ed0c | 2011-10-27 17:46:07 -0700 | [diff] [blame] | 742 | final View menuView = (View) mMenuView; |
| 743 | if (menuView != null && menuView.getWindowToken() != null && mPopup.tryShow()) { |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 744 | mOverflowPopup = mPopup; |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 745 | } |
Adam Powell | 678ed0c | 2011-10-27 17:46:07 -0700 | [diff] [blame] | 746 | mPostedOpenRunnable = null; |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 747 | } |
| 748 | } |
Alan Viverette | 5611072 | 2014-01-10 14:03:21 -0800 | [diff] [blame] | 749 | |
| 750 | private class ActionMenuPopupCallback extends ActionMenuItemView.PopupCallback { |
| 751 | @Override |
| 752 | public ListPopupWindow getPopup() { |
| 753 | return mActionButtonPopup != null ? mActionButtonPopup.getPopup() : null; |
| 754 | } |
| 755 | } |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 756 | } |