Ensure only one context menu is shown at a time
Refactors the menu helper classes. Both classes now implement a common
MenuHelper interface, which eliminates the need to keep separate helpers
on PhoneWindow and unifies the DecorView showContextMenuForChild()
implementations.
We now explicitly dismiss any previously shown context menu before showing
a new context menu. Previously we relied on the modal nature of the dialog
context menu to prevent multiple menus from being opened at once, but this
is no longer reliable with popup context menus.
Bug: 25656520
Change-Id: Idab3daa6d6888f803f2e33660fe1dd488e4c28d1
diff --git a/core/java/com/android/internal/view/menu/MenuPopupHelper.java b/core/java/com/android/internal/view/menu/MenuPopupHelper.java
index 59d5f94..044ee6e 100644
--- a/core/java/com/android/internal/view/menu/MenuPopupHelper.java
+++ b/core/java/com/android/internal/view/menu/MenuPopupHelper.java
@@ -30,7 +30,7 @@
/**
* Presents a menu as a small, simple popup anchored to another view.
*/
-public class MenuPopupHelper {
+public class MenuPopupHelper implements MenuHelper {
private final Context mContext;
// Immutable cached popup menu properties.
@@ -244,6 +244,7 @@
/**
* Dismisses the popup, if showing.
*/
+ @Override
public void dismiss() {
if (isShowing()) {
mPopup.dismiss();
@@ -270,7 +271,8 @@
return mPopup != null && mPopup.isShowing();
}
- public void setCallback(@Nullable MenuPresenter.Callback cb) {
+ @Override
+ public void setPresenterCallback(@Nullable MenuPresenter.Callback cb) {
mPresenterCallback = cb;
if (mPopup != null) {
mPopup.setCallback(cb);