Adam Powell | 4267534 | 2010-07-09 18:02:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
| 17 | package com.android.internal.view.menu; |
| 18 | |
Oren Blasberg | 9916282 | 2015-09-10 14:37:26 -0700 | [diff] [blame] | 19 | import com.android.internal.view.menu.MenuPresenter.Callback; |
| 20 | |
Alan Viverette | 708aa9d | 2015-11-20 15:21:30 -0500 | [diff] [blame] | 21 | import android.annotation.AttrRes; |
| 22 | import android.annotation.NonNull; |
| 23 | import android.annotation.Nullable; |
| 24 | import android.annotation.StyleRes; |
Adam Powell | 4267534 | 2010-07-09 18:02:59 -0700 | [diff] [blame] | 25 | import android.content.Context; |
Oren Blasberg | 93c1958 | 2016-04-14 14:08:17 -0700 | [diff] [blame] | 26 | import android.graphics.Point; |
Alan Viverette | 9109857 | 2016-01-19 14:07:31 -0500 | [diff] [blame] | 27 | import android.graphics.Rect; |
| 28 | import android.util.DisplayMetrics; |
Oren Blasberg | 93c1958 | 2016-04-14 14:08:17 -0700 | [diff] [blame] | 29 | import android.view.Display; |
Adam Powell | 54c94de | 2013-09-26 15:36:34 -0700 | [diff] [blame] | 30 | import android.view.Gravity; |
Adam Powell | 4267534 | 2010-07-09 18:02:59 -0700 | [diff] [blame] | 31 | import android.view.View; |
Oren Blasberg | 93c1958 | 2016-04-14 14:08:17 -0700 | [diff] [blame] | 32 | import android.view.WindowManager; |
Alan Viverette | 708aa9d | 2015-11-20 15:21:30 -0500 | [diff] [blame] | 33 | import android.widget.PopupWindow.OnDismissListener; |
Adam Powell | 4267534 | 2010-07-09 18:02:59 -0700 | [diff] [blame] | 34 | |
| 35 | /** |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 36 | * Presents a menu as a small, simple popup anchored to another view. |
Adam Powell | 4267534 | 2010-07-09 18:02:59 -0700 | [diff] [blame] | 37 | */ |
Alan Viverette | 021627e | 2015-11-25 14:22:00 -0500 | [diff] [blame] | 38 | public class MenuPopupHelper implements MenuHelper { |
Alan Viverette | 9109857 | 2016-01-19 14:07:31 -0500 | [diff] [blame] | 39 | private static final int TOUCH_EPICENTER_SIZE_DP = 48; |
| 40 | |
Alan Viverette | 0bce6ab | 2013-06-26 17:46:16 -0700 | [diff] [blame] | 41 | private final Context mContext; |
Alan Viverette | 708aa9d | 2015-11-20 15:21:30 -0500 | [diff] [blame] | 42 | |
| 43 | // Immutable cached popup menu properties. |
Alan Viverette | 0bce6ab | 2013-06-26 17:46:16 -0700 | [diff] [blame] | 44 | private final MenuBuilder mMenu; |
Alan Viverette | 0bce6ab | 2013-06-26 17:46:16 -0700 | [diff] [blame] | 45 | private final boolean mOverflowOnly; |
Alan Viverette | 560f170 | 2014-05-05 14:40:07 -0700 | [diff] [blame] | 46 | private final int mPopupStyleAttr; |
Alan Viverette | 2963252 | 2014-10-15 17:19:30 -0700 | [diff] [blame] | 47 | private final int mPopupStyleRes; |
Alan Viverette | 0bce6ab | 2013-06-26 17:46:16 -0700 | [diff] [blame] | 48 | |
Alan Viverette | 708aa9d | 2015-11-20 15:21:30 -0500 | [diff] [blame] | 49 | // Mutable cached popup menu properties. |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 50 | private View mAnchorView; |
Alan Viverette | d6443f6 | 2015-11-20 13:57:15 -0500 | [diff] [blame] | 51 | private int mDropDownGravity = Gravity.START; |
Oren Blasberg | ed39126 | 2015-09-01 12:12:51 -0700 | [diff] [blame] | 52 | private boolean mForceShowIcon; |
Oren Blasberg | 9916282 | 2015-09-10 14:37:26 -0700 | [diff] [blame] | 53 | private Callback mPresenterCallback; |
Alan Viverette | d6443f6 | 2015-11-20 13:57:15 -0500 | [diff] [blame] | 54 | |
Alan Viverette | 708aa9d | 2015-11-20 15:21:30 -0500 | [diff] [blame] | 55 | private MenuPopup mPopup; |
| 56 | private OnDismissListener mOnDismissListener; |
Adam Powell | 54c94de | 2013-09-26 15:36:34 -0700 | [diff] [blame] | 57 | |
Alan Viverette | 708aa9d | 2015-11-20 15:21:30 -0500 | [diff] [blame] | 58 | public MenuPopupHelper(@NonNull Context context, @NonNull MenuBuilder menu) { |
Alan Viverette | 2963252 | 2014-10-15 17:19:30 -0700 | [diff] [blame] | 59 | this(context, menu, null, false, com.android.internal.R.attr.popupMenuStyle, 0); |
Adam Powell | 8028dd3 | 2010-07-15 10:16:33 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Alan Viverette | 708aa9d | 2015-11-20 15:21:30 -0500 | [diff] [blame] | 62 | public MenuPopupHelper(@NonNull Context context, @NonNull MenuBuilder menu, |
| 63 | @NonNull View anchorView) { |
Alan Viverette | 2963252 | 2014-10-15 17:19:30 -0700 | [diff] [blame] | 64 | this(context, menu, anchorView, false, com.android.internal.R.attr.popupMenuStyle, 0); |
Adam Powell | 8028dd3 | 2010-07-15 10:16:33 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Alan Viverette | 708aa9d | 2015-11-20 15:21:30 -0500 | [diff] [blame] | 67 | public MenuPopupHelper(@NonNull Context context, @NonNull MenuBuilder menu, |
| 68 | @NonNull View anchorView, |
| 69 | boolean overflowOnly, @AttrRes int popupStyleAttr) { |
Alan Viverette | 2963252 | 2014-10-15 17:19:30 -0700 | [diff] [blame] | 70 | this(context, menu, anchorView, overflowOnly, popupStyleAttr, 0); |
| 71 | } |
| 72 | |
Alan Viverette | 708aa9d | 2015-11-20 15:21:30 -0500 | [diff] [blame] | 73 | public MenuPopupHelper(@NonNull Context context, @NonNull MenuBuilder menu, |
| 74 | @NonNull View anchorView, boolean overflowOnly, @AttrRes int popupStyleAttr, |
| 75 | @StyleRes int popupStyleRes) { |
Adam Powell | 4267534 | 2010-07-09 18:02:59 -0700 | [diff] [blame] | 76 | mContext = context; |
Adam Powell | 8028dd3 | 2010-07-15 10:16:33 -0700 | [diff] [blame] | 77 | mMenu = menu; |
Alan Viverette | 708aa9d | 2015-11-20 15:21:30 -0500 | [diff] [blame] | 78 | mAnchorView = anchorView; |
Adam Powell | 8028dd3 | 2010-07-15 10:16:33 -0700 | [diff] [blame] | 79 | mOverflowOnly = overflowOnly; |
Alan Viverette | 560f170 | 2014-05-05 14:40:07 -0700 | [diff] [blame] | 80 | mPopupStyleAttr = popupStyleAttr; |
Alan Viverette | 2963252 | 2014-10-15 17:19:30 -0700 | [diff] [blame] | 81 | mPopupStyleRes = popupStyleRes; |
Oren Blasberg | b23976e | 2015-09-01 14:55:42 -0700 | [diff] [blame] | 82 | } |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 83 | |
Alan Viverette | 708aa9d | 2015-11-20 15:21:30 -0500 | [diff] [blame] | 84 | public void setOnDismissListener(@Nullable OnDismissListener listener) { |
| 85 | mOnDismissListener = listener; |
Adam Powell | 4267534 | 2010-07-09 18:02:59 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Alan Viverette | 708aa9d | 2015-11-20 15:21:30 -0500 | [diff] [blame] | 88 | /** |
| 89 | * Sets the view to which the popup window is anchored. |
| 90 | * <p> |
| 91 | * Changes take effect on the next call to show(). |
| 92 | * |
| 93 | * @param anchor the view to which the popup window should be anchored |
| 94 | */ |
| 95 | public void setAnchorView(@NonNull View anchor) { |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 96 | mAnchorView = anchor; |
Adam Powell | f0ad6e6 | 2011-01-10 17:14:06 -0800 | [diff] [blame] | 97 | } |
| 98 | |
Alan Viverette | 708aa9d | 2015-11-20 15:21:30 -0500 | [diff] [blame] | 99 | /** |
| 100 | * Sets whether the popup menu's adapter is forced to show icons in the |
| 101 | * menu item views. |
| 102 | * <p> |
| 103 | * Changes take effect on the next call to show(). |
| 104 | * |
| 105 | * @param forceShowIcon {@code true} to force icons to be shown, or |
| 106 | * {@code false} for icons to be optionally shown |
| 107 | */ |
| 108 | public void setForceShowIcon(boolean forceShowIcon) { |
| 109 | mForceShowIcon = forceShowIcon; |
Oren Blasberg | 7b45745 | 2016-04-19 15:44:46 -0700 | [diff] [blame] | 110 | if (mPopup != null) { |
| 111 | mPopup.setForceShowIcon(forceShowIcon); |
| 112 | } |
Adam Powell | 9151103 | 2011-07-13 10:24:06 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Alan Viverette | 708aa9d | 2015-11-20 15:21:30 -0500 | [diff] [blame] | 115 | /** |
| 116 | * Sets the alignment of the popup window relative to the anchor view. |
| 117 | * <p> |
| 118 | * Changes take effect on the next call to show(). |
| 119 | * |
| 120 | * @param gravity alignment of the popup relative to the anchor |
| 121 | */ |
Adam Powell | 54c94de | 2013-09-26 15:36:34 -0700 | [diff] [blame] | 122 | public void setGravity(int gravity) { |
| 123 | mDropDownGravity = gravity; |
| 124 | } |
| 125 | |
Alan Viverette | 708aa9d | 2015-11-20 15:21:30 -0500 | [diff] [blame] | 126 | /** |
| 127 | * @return alignment of the popup relative to the anchor |
| 128 | */ |
Alan Viverette | 75d8379 | 2015-01-07 15:51:54 -0800 | [diff] [blame] | 129 | public int getGravity() { |
| 130 | return mDropDownGravity; |
| 131 | } |
| 132 | |
Adam Powell | 4267534 | 2010-07-09 18:02:59 -0700 | [diff] [blame] | 133 | public void show() { |
Adam Powell | 5e3f284 | 2011-01-07 17:16:56 -0800 | [diff] [blame] | 134 | if (!tryShow()) { |
| 135 | throw new IllegalStateException("MenuPopupHelper cannot be used without an anchor"); |
| 136 | } |
| 137 | } |
| 138 | |
Oren Blasberg | ed39126 | 2015-09-01 12:12:51 -0700 | [diff] [blame] | 139 | public void show(int x, int y) { |
| 140 | if (!tryShow(x, y)) { |
| 141 | throw new IllegalStateException("MenuPopupHelper cannot be used without an anchor"); |
| 142 | } |
| 143 | } |
| 144 | |
Alan Viverette | 708aa9d | 2015-11-20 15:21:30 -0500 | [diff] [blame] | 145 | @NonNull |
| 146 | public MenuPopup getPopup() { |
| 147 | if (mPopup == null) { |
| 148 | mPopup = createPopup(); |
| 149 | } |
Alan Viverette | ca6a3611 | 2013-08-16 14:41:06 -0700 | [diff] [blame] | 150 | return mPopup; |
| 151 | } |
| 152 | |
Alan Viverette | 8fd949e | 2015-03-11 12:21:30 -0700 | [diff] [blame] | 153 | /** |
Oren Blasberg | b23976e | 2015-09-01 14:55:42 -0700 | [diff] [blame] | 154 | * Attempts to show the popup anchored to the view specified by {@link #setAnchorView(View)}. |
Alan Viverette | 8fd949e | 2015-03-11 12:21:30 -0700 | [diff] [blame] | 155 | * |
Oren Blasberg | b23976e | 2015-09-01 14:55:42 -0700 | [diff] [blame] | 156 | * @return {@code true} if the popup was shown or was already showing prior to calling this |
| 157 | * method, {@code false} otherwise |
Alan Viverette | 8fd949e | 2015-03-11 12:21:30 -0700 | [diff] [blame] | 158 | */ |
Adam Powell | 5e3f284 | 2011-01-07 17:16:56 -0800 | [diff] [blame] | 159 | public boolean tryShow() { |
Alan Viverette | 8fd949e | 2015-03-11 12:21:30 -0700 | [diff] [blame] | 160 | if (isShowing()) { |
| 161 | return true; |
| 162 | } |
| 163 | |
Oren Blasberg | 9916282 | 2015-09-10 14:37:26 -0700 | [diff] [blame] | 164 | if (mAnchorView == null) { |
Adam Powell | 5e3f284 | 2011-01-07 17:16:56 -0800 | [diff] [blame] | 165 | return false; |
Adam Powell | 8028dd3 | 2010-07-15 10:16:33 -0700 | [diff] [blame] | 166 | } |
Adam Powell | 4267534 | 2010-07-09 18:02:59 -0700 | [diff] [blame] | 167 | |
Alan Viverette | 708aa9d | 2015-11-20 15:21:30 -0500 | [diff] [blame] | 168 | showPopup(0, 0, false, false); |
Oren Blasberg | ed39126 | 2015-09-01 12:12:51 -0700 | [diff] [blame] | 169 | return true; |
| 170 | } |
| 171 | |
Alan Viverette | d6443f6 | 2015-11-20 13:57:15 -0500 | [diff] [blame] | 172 | /** |
| 173 | * Shows the popup menu and makes a best-effort to anchor it to the |
| 174 | * specified (x,y) coordinate relative to the anchor view. |
| 175 | * <p> |
Alan Viverette | 9109857 | 2016-01-19 14:07:31 -0500 | [diff] [blame] | 176 | * Additionally, the popup's transition epicenter (see |
| 177 | * {@link android.widget.PopupWindow#setEpicenterBounds(Rect)} will be |
| 178 | * centered on the specified coordinate, rather than using the bounds of |
| 179 | * the anchor view. |
| 180 | * <p> |
Alan Viverette | d6443f6 | 2015-11-20 13:57:15 -0500 | [diff] [blame] | 181 | * If the popup's resolved gravity is {@link Gravity#LEFT}, this will |
| 182 | * display the popup with its top-left corner at (x,y) relative to the |
| 183 | * anchor view. If the resolved gravity is {@link Gravity#RIGHT}, the |
| 184 | * popup's top-right corner will be at (x,y). |
| 185 | * <p> |
| 186 | * If the popup cannot be displayed fully on-screen, this method will |
| 187 | * attempt to scroll the anchor view's ancestors and/or offset the popup |
| 188 | * such that it may be displayed fully on-screen. |
| 189 | * |
| 190 | * @param x x coordinate relative to the anchor view |
| 191 | * @param y y coordinate relative to the anchor view |
| 192 | * @return {@code true} if the popup was shown or was already showing prior |
| 193 | * to calling this method, {@code false} otherwise |
| 194 | */ |
Oren Blasberg | ed39126 | 2015-09-01 12:12:51 -0700 | [diff] [blame] | 195 | public boolean tryShow(int x, int y) { |
| 196 | if (isShowing()) { |
| 197 | return true; |
| 198 | } |
| 199 | |
| 200 | if (mAnchorView == null) { |
| 201 | return false; |
| 202 | } |
| 203 | |
Alan Viverette | 708aa9d | 2015-11-20 15:21:30 -0500 | [diff] [blame] | 204 | showPopup(x, y, true, true); |
Oren Blasberg | ed39126 | 2015-09-01 12:12:51 -0700 | [diff] [blame] | 205 | return true; |
| 206 | } |
| 207 | |
Alan Viverette | 708aa9d | 2015-11-20 15:21:30 -0500 | [diff] [blame] | 208 | /** |
| 209 | * Creates the popup and assigns cached properties. |
| 210 | * |
| 211 | * @return an initialized popup |
| 212 | */ |
| 213 | @NonNull |
| 214 | private MenuPopup createPopup() { |
Oren Blasberg | 93c1958 | 2016-04-14 14:08:17 -0700 | [diff] [blame] | 215 | final WindowManager windowManager = (WindowManager) mContext.getSystemService( |
| 216 | Context.WINDOW_SERVICE); |
| 217 | final Display display = windowManager.getDefaultDisplay(); |
| 218 | final Point displaySize = new Point(); |
| 219 | display.getRealSize(displaySize); |
| 220 | |
| 221 | final int smallestWidth = Math.min(displaySize.x, displaySize.y); |
| 222 | final int minSmallestWidthCascading = mContext.getResources().getDimensionPixelSize( |
| 223 | com.android.internal.R.dimen.cascading_menus_min_smallest_width); |
| 224 | final boolean enableCascadingSubmenus = smallestWidth >= minSmallestWidthCascading; |
Alan Viverette | d6443f6 | 2015-11-20 13:57:15 -0500 | [diff] [blame] | 225 | |
Alan Viverette | 708aa9d | 2015-11-20 15:21:30 -0500 | [diff] [blame] | 226 | final MenuPopup popup; |
| 227 | if (enableCascadingSubmenus) { |
| 228 | popup = new CascadingMenuPopup(mContext, mAnchorView, mPopupStyleAttr, |
| 229 | mPopupStyleRes, mOverflowOnly); |
| 230 | } else { |
| 231 | popup = new StandardMenuPopup(mContext, mMenu, mAnchorView, mPopupStyleAttr, |
| 232 | mPopupStyleRes, mOverflowOnly); |
| 233 | } |
| 234 | |
| 235 | // Assign immutable properties. |
| 236 | popup.addMenu(mMenu); |
| 237 | popup.setOnDismissListener(mInternalOnDismissListener); |
| 238 | |
| 239 | // Assign mutable properties. These may be reassigned later. |
| 240 | popup.setAnchorView(mAnchorView); |
| 241 | popup.setCallback(mPresenterCallback); |
| 242 | popup.setForceShowIcon(mForceShowIcon); |
| 243 | popup.setGravity(mDropDownGravity); |
| 244 | |
| 245 | return popup; |
| 246 | } |
| 247 | |
Alan Viverette | 9109857 | 2016-01-19 14:07:31 -0500 | [diff] [blame] | 248 | private void showPopup(int xOffset, int yOffset, boolean useOffsets, boolean showTitle) { |
| 249 | final MenuPopup popup = getPopup(); |
| 250 | popup.setShowTitle(showTitle); |
| 251 | |
| 252 | if (useOffsets) { |
Alan Viverette | d6443f6 | 2015-11-20 13:57:15 -0500 | [diff] [blame] | 253 | // If the resolved drop-down gravity is RIGHT, the popup's right |
| 254 | // edge will be aligned with the anchor view. Adjust by the anchor |
| 255 | // width such that the top-right corner is at the X offset. |
| 256 | final int hgrav = Gravity.getAbsoluteGravity(mDropDownGravity, |
| 257 | mAnchorView.getLayoutDirection()) & Gravity.HORIZONTAL_GRAVITY_MASK; |
Alan Viverette | d6443f6 | 2015-11-20 13:57:15 -0500 | [diff] [blame] | 258 | if (hgrav == Gravity.RIGHT) { |
Vladislav Kaznacheev | d959c9d | 2018-01-23 14:03:36 -0800 | [diff] [blame] | 259 | xOffset -= mAnchorView.getWidth(); |
Alan Viverette | d6443f6 | 2015-11-20 13:57:15 -0500 | [diff] [blame] | 260 | } |
Alan Viverette | 9109857 | 2016-01-19 14:07:31 -0500 | [diff] [blame] | 261 | |
| 262 | popup.setHorizontalOffset(xOffset); |
| 263 | popup.setVerticalOffset(yOffset); |
| 264 | |
| 265 | // Set the transition epicenter to be roughly finger (or mouse |
| 266 | // cursor) sized and centered around the offset position. This |
| 267 | // will give the appearance that the window is emerging from |
| 268 | // the touch point. |
| 269 | final float density = mContext.getResources().getDisplayMetrics().density; |
| 270 | final int halfSize = (int) (TOUCH_EPICENTER_SIZE_DP * density / 2); |
| 271 | final Rect epicenter = new Rect(xOffset - halfSize, yOffset - halfSize, |
| 272 | xOffset + halfSize, yOffset + halfSize); |
| 273 | popup.setEpicenterBounds(epicenter); |
Alan Viverette | d6443f6 | 2015-11-20 13:57:15 -0500 | [diff] [blame] | 274 | } |
Oren Blasberg | 9916282 | 2015-09-10 14:37:26 -0700 | [diff] [blame] | 275 | |
Alan Viverette | 708aa9d | 2015-11-20 15:21:30 -0500 | [diff] [blame] | 276 | popup.show(); |
Adam Powell | 4267534 | 2010-07-09 18:02:59 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Alan Viverette | 708aa9d | 2015-11-20 15:21:30 -0500 | [diff] [blame] | 279 | /** |
| 280 | * Dismisses the popup, if showing. |
| 281 | */ |
Alan Viverette | 021627e | 2015-11-25 14:22:00 -0500 | [diff] [blame] | 282 | @Override |
Adam Powell | 4267534 | 2010-07-09 18:02:59 -0700 | [diff] [blame] | 283 | public void dismiss() { |
Adam Powell | 3d3da27 | 2010-08-11 18:06:17 -0700 | [diff] [blame] | 284 | if (isShowing()) { |
| 285 | mPopup.dismiss(); |
| 286 | } |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 287 | } |
| 288 | |
Alan Viverette | 708aa9d | 2015-11-20 15:21:30 -0500 | [diff] [blame] | 289 | /** |
| 290 | * Called after the popup has been dismissed. |
| 291 | * <p> |
| 292 | * <strong>Note:</strong> Subclasses should call the super implementation |
| 293 | * last to ensure that any necessary tear down has occurred before the |
| 294 | * listener specified by {@link #setOnDismissListener(OnDismissListener)} |
| 295 | * is called. |
| 296 | */ |
| 297 | protected void onDismiss() { |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 298 | mPopup = null; |
Alan Viverette | 708aa9d | 2015-11-20 15:21:30 -0500 | [diff] [blame] | 299 | |
| 300 | if (mOnDismissListener != null) { |
| 301 | mOnDismissListener.onDismiss(); |
| 302 | } |
Adam Powell | 4267534 | 2010-07-09 18:02:59 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Adam Powell | 8028dd3 | 2010-07-15 10:16:33 -0700 | [diff] [blame] | 305 | public boolean isShowing() { |
| 306 | return mPopup != null && mPopup.isShowing(); |
| 307 | } |
| 308 | |
Alan Viverette | 021627e | 2015-11-25 14:22:00 -0500 | [diff] [blame] | 309 | @Override |
| 310 | public void setPresenterCallback(@Nullable MenuPresenter.Callback cb) { |
Oren Blasberg | 9916282 | 2015-09-10 14:37:26 -0700 | [diff] [blame] | 311 | mPresenterCallback = cb; |
Alan Viverette | 708aa9d | 2015-11-20 15:21:30 -0500 | [diff] [blame] | 312 | if (mPopup != null) { |
| 313 | mPopup.setCallback(cb); |
| 314 | } |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 315 | } |
Alan Viverette | 708aa9d | 2015-11-20 15:21:30 -0500 | [diff] [blame] | 316 | |
| 317 | /** |
| 318 | * Listener used to proxy dismiss callbacks to the helper's owner. |
| 319 | */ |
| 320 | private final OnDismissListener mInternalOnDismissListener = new OnDismissListener() { |
| 321 | @Override |
| 322 | public void onDismiss() { |
| 323 | MenuPopupHelper.this.onDismiss(); |
| 324 | } |
| 325 | }; |
Adam Powell | 4267534 | 2010-07-09 18:02:59 -0700 | [diff] [blame] | 326 | } |