Fixing drag and drop crashes:

-> Issue 5058353
-> Issue 3470970

Change-Id: Id790595898e86052c33e6b2f0a122e1df009c9ca
diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java
index 6f59d1f..1841713 100644
--- a/src/com/android/launcher2/CellLayout.java
+++ b/src/com/android/launcher2/CellLayout.java
@@ -792,27 +792,35 @@
 
     @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();
     }