From c1997fd6debbc69b53be71b7d871657fd5843c7a Mon Sep 17 00:00:00 2001 From: Adam Cohen Date: Mon, 15 Aug 2011 18:26:39 -0700 Subject: Fixing drag and drop crashes: -> Issue 5058353 -> Issue 3470970 Change-Id: Id790595898e86052c33e6b2f0a122e1df009c9ca --- src/com/android/launcher2/CellLayout.java | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'src/com/android/launcher2') diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java index 6f59d1f3c..1841713f5 100644 --- a/src/com/android/launcher2/CellLayout.java +++ b/src/com/android/launcher2/CellLayout.java @@ -792,27 +792,35 @@ public class CellLayout extends ViewGroup { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { + // First we clear the tag to ensure that on every touch down we start with a fresh slate, + // even in the case where we return early. Not clearing here was causing bugs whereby on + // long-press we'd end up picking up an item from a previous drag operation. + final int action = ev.getAction(); + + if (action == MotionEvent.ACTION_DOWN) { + clearTagCellInfo(); + } + if (mInterceptTouchListener != null && mInterceptTouchListener.onTouch(this, ev)) { return true; } - final int action = ev.getAction(); - final CellInfo cellInfo = mCellInfo; if (action == MotionEvent.ACTION_DOWN) { setTagToCellInfoForPoint((int) ev.getX(), (int) ev.getY()); - } else if (action == MotionEvent.ACTION_UP) { - cellInfo.cell = null; - cellInfo.cellX = -1; - cellInfo.cellY = -1; - cellInfo.spanX = 0; - cellInfo.spanY = 0; - setTag(cellInfo); } - return false; } - @Override + private void clearTagCellInfo() { + final CellInfo cellInfo = mCellInfo; + cellInfo.cell = null; + cellInfo.cellX = -1; + cellInfo.cellY = -1; + cellInfo.spanX = 0; + cellInfo.spanY = 0; + setTag(cellInfo); + } + public CellInfo getTag() { return (CellInfo) super.getTag(); } -- cgit v1.2.3