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

Commit 62bbd1a9 authored by Alan Viverette's avatar Alan Viverette
Browse files

Ensure all showContextMenu() overrides have matching x,y overrides

Bug: 26340507
Change-Id: I9c6da434954d40fe689c18fa9559a80c8ca61f95
parent 17b179d5
Loading
Loading
Loading
Loading
+50 −18
Original line number Diff line number Diff line
@@ -3203,43 +3203,75 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        return mContextMenuInfo;
    }

    /** @hide */
    @Override
    public boolean showContextMenu() {
        return showContextMenuInternal(0, 0, false);
    }

    @Override
    public boolean showContextMenu(float x, float y) {
        return showContextMenuInternal(x, y, true);
    }

    private boolean showContextMenuInternal(float x, float y, boolean useOffsets) {
        final int position = pointToPosition((int)x, (int)y);
        if (position != INVALID_POSITION) {
            final long id = mAdapter.getItemId(position);
            View child = getChildAt(position - mFirstPosition);
            if (child != null) {
                mContextMenuInfo = createContextMenuInfo(child, position, id);
                return super.showContextMenuForChild(AbsListView.this, x, y);
                if (useOffsets) {
                    return super.showContextMenuForChild(this, x, y);
                } else {
                    return super.showContextMenuForChild(this);
                }
            }
        }
        if (useOffsets) {
            return super.showContextMenu(x, y);
        } else {
            return super.showContextMenu();
        }
    }

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

    @Override
    public boolean showContextMenuForChild(View originalView, float x, float y) {
        return showContextMenuForChildInternal(originalView,x, y, true);
    }

    private boolean showContextMenuForChildInternal(View originalView, float x, float y,
            boolean useOffsets) {
        final int longPressPosition = getPositionForView(originalView);
        if (longPressPosition >= 0) {
        if (longPressPosition < 0) {
            return false;
        }

        final long longPressId = mAdapter.getItemId(longPressPosition);
        boolean handled = false;

        if (mOnItemLongClickListener != null) {
                handled = mOnItemLongClickListener.onItemLongClick(AbsListView.this, originalView,
            handled = mOnItemLongClickListener.onItemLongClick(this, originalView,
                    longPressPosition, longPressId);
        }

        if (!handled) {
                mContextMenuInfo = createContextMenuInfo(
                        getChildAt(longPressPosition - mFirstPosition),
                        longPressPosition, longPressId);
            final View child = getChildAt(longPressPosition - mFirstPosition);
            mContextMenuInfo = createContextMenuInfo(child, longPressPosition, longPressId);

            if (useOffsets) {
                handled = super.showContextMenuForChild(originalView, x, y);
            } else {
                handled = super.showContextMenuForChild(originalView);
            }
        }

        return handled;
    }
        return false;
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
+35 −11
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.widget;

import android.annotation.NonNull;
import android.annotation.Widget;
import android.content.Context;
import android.content.res.TypedArray;
@@ -1097,15 +1098,15 @@ public class Gallery extends AbsSpinner implements GestureDetector.OnGestureList
    }
    
    @Override
    public void onLongPress(MotionEvent e) {
        
    public void onLongPress(@NonNull MotionEvent e) {
        if (mDownTouchPosition < 0) {
            return;
        }
        
        performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
        long id = getItemIdAtPosition(mDownTouchPosition);
        dispatchLongPress(mDownTouchView, mDownTouchPosition, id);

        final long id = getItemIdAtPosition(mDownTouchPosition);
        dispatchLongPress(mDownTouchView, mDownTouchPosition, id, e.getX(), e.getY(), true);
    }

    // Unused methods from GestureDetector.OnGestureListener below
@@ -1159,29 +1160,47 @@ public class Gallery extends AbsSpinner implements GestureDetector.OnGestureList

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

    @Override
    public boolean showContextMenuForChild(View originalView, float x, float y) {
        return showContextMenuForChildInternal(originalView, x, y, true);
    }

    private boolean showContextMenuForChildInternal(View originalView, float x, float y,
            boolean useOffsets) {
        final int longPressPosition = getPositionForView(originalView);
        if (longPressPosition < 0) {
            return false;
        }
        
        final long longPressId = mAdapter.getItemId(longPressPosition);
        return dispatchLongPress(originalView, longPressPosition, longPressId);
        return dispatchLongPress(originalView, longPressPosition, longPressId, x, y, useOffsets);
    }

    @Override
    public boolean showContextMenu() {
        return showContextMenuInternal(0, 0, false);
    }

    @Override
    public boolean showContextMenu(float x, float y) {
        return showContextMenuInternal(x, y, true);
    }

    private boolean showContextMenuInternal(float x, float y, boolean useOffsets) {
        if (isPressed() && mSelectedPosition >= 0) {
            int index = mSelectedPosition - mFirstPosition;
            View v = getChildAt(index);
            return dispatchLongPress(v, mSelectedPosition, mSelectedRowId);
            final int index = mSelectedPosition - mFirstPosition;
            final View v = getChildAt(index);
            return dispatchLongPress(v, mSelectedPosition, mSelectedRowId, x, y, useOffsets);
        }        
        
        return false;
    }

    private boolean dispatchLongPress(View view, int position, long id) {
    private boolean dispatchLongPress(View view, int position, long id, float x, float y,
            boolean useOffsets) {
        boolean handled = false;
        
        if (mOnItemLongClickListener != null) {
@@ -1191,8 +1210,13 @@ public class Gallery extends AbsSpinner implements GestureDetector.OnGestureList

        if (!handled) {
            mContextMenuInfo = new AdapterContextMenuInfo(view, position, id);

            if (useOffsets) {
                handled = super.showContextMenuForChild(view, x, y);
            } else {
                handled = super.showContextMenuForChild(this);
            }
        }

        if (handled) {
            performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);