diff options
| author | 2016-01-22 15:20:43 +0000 | |
|---|---|---|
| committer | 2016-01-22 15:20:43 +0000 | |
| commit | 09a02f1c34cc8c8952805e0088723f999ea2aa6f (patch) | |
| tree | 7960ede9b8f72c7c544679233ce58b027731bfaf | |
| parent | 35635150b44936b980e3b430a59e590491a0adf3 (diff) | |
| parent | 62bbd1a95208971db1688b237aa15c50b1cc6756 (diff) | |
Merge "Ensure all showContextMenu() overrides have matching x,y overrides"
| -rw-r--r-- | core/java/android/widget/AbsListView.java | 68 | ||||
| -rw-r--r-- | core/java/android/widget/Gallery.java | 46 |
2 files changed, 85 insertions, 29 deletions
diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java index 6241a4cd3462..6c2c956efa7d 100644 --- a/core/java/android/widget/AbsListView.java +++ b/core/java/android/widget/AbsListView.java @@ -3203,42 +3203,74 @@ 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); + } } } - return super.showContextMenu(x, y); + 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) { - final long longPressId = mAdapter.getItemId(longPressPosition); - boolean handled = false; - - if (mOnItemLongClickListener != null) { - handled = mOnItemLongClickListener.onItemLongClick(AbsListView.this, originalView, - longPressPosition, longPressId); - } - if (!handled) { - mContextMenuInfo = createContextMenuInfo( - getChildAt(longPressPosition - mFirstPosition), - longPressPosition, longPressId); + if (longPressPosition < 0) { + return false; + } + + final long longPressId = mAdapter.getItemId(longPressPosition); + boolean handled = false; + + if (mOnItemLongClickListener != null) { + handled = mOnItemLongClickListener.onItemLongClick(this, originalView, + longPressPosition, longPressId); + } + + if (!handled) { + 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; + + return handled; } @Override diff --git a/core/java/android/widget/Gallery.java b/core/java/android/widget/Gallery.java index 9ebbe36da1c5..a6ef572a2e3a 100644 --- a/core/java/android/widget/Gallery.java +++ b/core/java/android/widget/Gallery.java @@ -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,7 +1210,12 @@ public class Gallery extends AbsSpinner implements GestureDetector.OnGestureList if (!handled) { mContextMenuInfo = new AdapterContextMenuInfo(view, position, id); - handled = super.showContextMenuForChild(this); + + if (useOffsets) { + handled = super.showContextMenuForChild(view, x, y); + } else { + handled = super.showContextMenuForChild(this); + } } if (handled) { |