Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2af189a0 authored by Adam Powell's avatar Adam Powell
Browse files

Preserve compatibility for ViewGroup#showContextMenuForChild

Have the new showContextMenuForChild(View, float, float) call through
to the old showContextMenuForChild(View) before recursing up to its
parent. This ensures that existing apps with custom views that
override the old method still get called as expected if they implement
custom behavior.

Unlike some other similar circumstances we aren't implementing this to
be bidirectional as the new behavior doesn't need to be triggered by
invoking the old. If the older method is invoked explicitly we will
still show old-style dialog context menus instead of the newer popup
style since we won't have a good place to visually anchor a popup.

Bug 26919262

Change-Id: Ie09f922d322b5a24789c7867820c4bc43824c385
(cherry picked from commit 759a4c54)
parent 199cb4df
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -386,6 +386,12 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
     */
    private static final int FLAG_START_ACTION_MODE_FOR_CHILD_IS_NOT_TYPED = 0x10000000;

    /**
     * When set, indicates that a call to showContextMenuForChild was made with explicit
     * coordinates within the initiating child view.
     */
    private static final int FLAG_SHOW_CONTEXT_MENU_WITH_COORDS = 0x20000000;

    /**
     * Indicates which types of drawing caches are to be kept in memory.
     * This field should be made private, so it is hidden from the SDK.
@@ -756,11 +762,31 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager

    @Override
    public boolean showContextMenuForChild(View originalView) {
        if (isShowingContextMenuWithCoords()) {
            // We're being called for compatibility. Return false and let the version
            // with coordinates recurse up.
            return false;
        }
        return mParent != null && mParent.showContextMenuForChild(originalView);
    }

    /**
     * @hide used internally for compatibility with existing app code only
     */
    public final boolean isShowingContextMenuWithCoords() {
        return (mGroupFlags & FLAG_SHOW_CONTEXT_MENU_WITH_COORDS) != 0;
    }

    @Override
    public boolean showContextMenuForChild(View originalView, float x, float y) {
        try {
            mGroupFlags |= FLAG_SHOW_CONTEXT_MENU_WITH_COORDS;
            if (showContextMenuForChild(originalView)) {
                return true;
            }
        } finally {
            mGroupFlags &= ~FLAG_SHOW_CONTEXT_MENU_WITH_COORDS;
        }
        return mParent != null && mParent.showContextMenuForChild(originalView, x, y);
    }

+4 −1
Original line number Diff line number Diff line
@@ -192,6 +192,9 @@ public interface ViewParent {
     * 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.
     * <p>
     * If a subclass overrides this method it should also override
     * {@link #showContextMenuForChild(View)}.
     *
     * @param originalView the source view where the context menu was first
     *                     invoked
@@ -202,7 +205,7 @@ public interface ViewParent {
     * @return {@code true} if the context menu was shown, {@code false}
     *         otherwise
     */
    public boolean showContextMenuForChild(View originalView, float x, float y);
    boolean showContextMenuForChild(View originalView, float x, float y);

    /**
     * Have the parent populate the specified context menu if it has anything to
+3 −0
Original line number Diff line number Diff line
@@ -3247,6 +3247,9 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te

    @Override
    public boolean showContextMenuForChild(View originalView) {
        if (isShowingContextMenuWithCoords()) {
            return false;
        }
        return showContextMenuForChildInternal(originalView, 0, 0, false);
    }

+3 −0
Original line number Diff line number Diff line
@@ -1160,6 +1160,9 @@ public class Gallery extends AbsSpinner implements GestureDetector.OnGestureList

    @Override
    public boolean showContextMenuForChild(View originalView) {
        if (isShowingContextMenuWithCoords()) {
            return false;
        }
        return showContextMenuForChildInternal(originalView, 0, 0, false);
    }