Cancelling the current drag when customization filter type changes to prevent crashes.

Change-Id: Iaa3f2598325950769d38ad1d6e390ab06ea194d7
diff --git a/src/com/android/launcher2/CustomizePagedView.java b/src/com/android/launcher2/CustomizePagedView.java
index ec9d52e..d2edd38 100644
--- a/src/com/android/launcher2/CustomizePagedView.java
+++ b/src/com/android/launcher2/CustomizePagedView.java
@@ -312,6 +312,7 @@
 
     public void setCustomizationFilter(CustomizationType filterType) {
         mCustomizationType = filterType;
+        cancelDragging();
         if (getChildCount() > 0) {
             setCurrentPage(0);
             updateCurrentPageScroll();
diff --git a/src/com/android/launcher2/PagedViewWithDraggableItems.java b/src/com/android/launcher2/PagedViewWithDraggableItems.java
index 283cced..b1f199b 100644
--- a/src/com/android/launcher2/PagedViewWithDraggableItems.java
+++ b/src/com/android/launcher2/PagedViewWithDraggableItems.java
@@ -54,13 +54,16 @@
         return false;
     }
 
-    @Override
-    public boolean onInterceptTouchEvent(MotionEvent ev) {
+    protected void cancelDragging() {
+        mIsDragging = false;
+        mLastTouchedItem = null;
+    }
+
+    private void handleTouchEvent(MotionEvent ev) {
         final int action = ev.getAction();
         switch (action & MotionEvent.ACTION_MASK) {
             case MotionEvent.ACTION_DOWN:
-                mIsDragging = false;
-                mLastTouchedItem = null;
+                cancelDragging();
                 break;
             case MotionEvent.ACTION_MOVE:
                 if (mTouchState != TOUCH_STATE_SCROLLING && !mIsDragging) {
@@ -68,33 +71,27 @@
                 }
                 break;
         }
+    }
+
+    @Override
+    public boolean onInterceptTouchEvent(MotionEvent ev) {
+        handleTouchEvent(ev);
         return super.onInterceptTouchEvent(ev);
     }
 
     @Override
+    public boolean onTouchEvent(MotionEvent ev) {
+        handleTouchEvent(ev);
+        return super.onTouchEvent(ev);
+    }
+
+    @Override
     public boolean onTouch(View v, MotionEvent event) {
         mLastTouchedItem = v;
         return false;
     }
 
     @Override
-    public boolean onTouchEvent(MotionEvent ev) {
-        final int action = ev.getAction();
-        switch (action & MotionEvent.ACTION_MASK) {
-            case MotionEvent.ACTION_DOWN:
-                mIsDragging = false;
-                mLastTouchedItem = null;
-                break;
-            case MotionEvent.ACTION_MOVE:
-                if (mTouchState != TOUCH_STATE_SCROLLING && !mIsDragging) {
-                    determineDraggingStart(ev);
-                }
-                break;
-        }
-        return super.onTouchEvent(ev);
-    }
-
-    @Override
     public boolean onLongClick(View v) {
         // Return early if this is not initiated from a touch
         if (!v.isInTouchMode()) return false;