From 021627eb5875372dea57ba91fa782fffbfbbc559 Mon Sep 17 00:00:00 2001 From: Alan Viverette Date: Wed, 25 Nov 2015 14:22:00 -0500 Subject: 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 --- core/java/android/view/ViewParent.java | 40 ++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 14 deletions(-) (limited to 'core/java/android/view/ViewParent.java') diff --git a/core/java/android/view/ViewParent.java b/core/java/android/view/ViewParent.java index 6ae448a7e888..f2ab35e90c17 100644 --- a/core/java/android/view/ViewParent.java +++ b/core/java/android/view/ViewParent.java @@ -174,26 +174,38 @@ public interface ViewParent { public void focusableViewAvailable(View v); /** - * Bring up a context menu for the specified view or its ancestors. - * - *

In most cases, a subclass does not need to override this. However, if + * Shows the context menu for the specified view or its ancestors. + *

+ * In most cases, a subclass does not need to override this. However, if * the subclass is added directly to the window manager (for example, * {@link ViewManager#addView(View, android.view.ViewGroup.LayoutParams)}) - * then it should override this and show the context menu.

- * - * @param originalView The source view where the context menu was first invoked - * @return true if a context menu was displayed + * then it should override this and show the context menu. + * + * @param originalView the source view where the context menu was first + * invoked + * @return {@code true} if the context menu was shown, {@code false} + * otherwise + * @see #showContextMenuForChild(View, float, float) */ public boolean showContextMenuForChild(View originalView); /** - * Bring up a context menu for the specified view at the given x/y offset from - * the top left corner. - * - * @param originalView - * @param x The x offset at which to open the menu - * @param y The y offset at which to open the menu - * @return true if a context menu was displayed + * Shows the context menu for the specified view or its ancestors anchored + * to the specified view-relative coordinate. + *

+ * In most cases, a subclass does not need to override this. However, if + * the subclass is added directly to the window manager (for example, + * {@link ViewManager#addView(View, android.view.ViewGroup.LayoutParams)}) + * then it should override this and show the context menu. + * + * @param originalView the source view where the context menu was first + * invoked + * @param x the X coordinate in pixels relative to the original view to + * which the menu should be anchored + * @param y the Y coordinate in pixels relative to the original view to + * which the menu should be anchored + * @return {@code true} if the context menu was shown, {@code false} + * otherwise */ public boolean showContextMenuForChild(View originalView, float x, float y); -- cgit v1.2.3