Merge "Updating call to match framework." into honeycomb
diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java
index af2f984..3249724 100644
--- a/src/com/android/launcher2/CellLayout.java
+++ b/src/com/android/launcher2/CellLayout.java
@@ -53,7 +53,7 @@
 
 import java.util.Arrays;
 
-public class CellLayout extends ViewGroup implements Dimmable, VisibilityChangedListener {
+public class CellLayout extends ViewGroup implements VisibilityChangedListener {
     static final String TAG = "CellLayout";
 
     private int mCellWidth;
@@ -568,20 +568,6 @@
         }
     }
 
-    public void setDimmableProgress(float progress) {
-        for (int i = 0; i < getChildCount(); i++) {
-            Dimmable d = (Dimmable) getChildAt(i);
-            d.setDimmableProgress(progress);
-        }
-    }
-
-    public float getDimmableProgress() {
-        if (getChildCount() > 0) {
-            return ((Dimmable) getChildAt(0)).getDimmableProgress();
-        }
-        return 0.0f;
-    }
-
     @Override
     public void cancelLongPress() {
         super.cancelLongPress();
diff --git a/src/com/android/launcher2/Dimmable.java b/src/com/android/launcher2/Dimmable.java
deleted file mode 100644
index df43b3c..0000000
--- a/src/com/android/launcher2/Dimmable.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.android.launcher2;
-
-public interface Dimmable {
-    public void setDimmableProgress(float progress);
-    public float getDimmableProgress();
-}
diff --git a/src/com/android/launcher2/PagedView.java b/src/com/android/launcher2/PagedView.java
index 1965712..4a0f44e 100644
--- a/src/com/android/launcher2/PagedView.java
+++ b/src/com/android/launcher2/PagedView.java
@@ -696,6 +696,20 @@
         super.requestDisallowInterceptTouchEvent(disallowIntercept);
     }
 
+    /**
+     * Return true if a tap at (x, y) should trigger a flip to the previous page.
+     */
+    protected boolean hitsPreviousPage(float x, float y) {
+        return (x < getRelativeChildOffset(mCurrentPage) - mPageSpacing);
+    }
+
+    /**
+     * Return true if a tap at (x, y) should trigger a flip to the next page.
+     */
+    protected boolean hitsNextPage(float x, float y) {
+        return  (x > (getMeasuredWidth() - getRelativeChildOffset(mCurrentPage) + mPageSpacing));
+    }
+
     @Override
     public boolean onInterceptTouchEvent(MotionEvent ev) {
         /*
@@ -761,14 +775,11 @@
 
                 // check if this can be the beginning of a tap on the side of the pages
                 // to scroll the current page
-                if ((mTouchState != TOUCH_STATE_PREV_PAGE) && !handlePagingClicks() &&
-                        (mTouchState != TOUCH_STATE_NEXT_PAGE)) {
+                if (mTouchState != TOUCH_STATE_PREV_PAGE && mTouchState != TOUCH_STATE_NEXT_PAGE) {
                     if (getChildCount() > 0) {
-                        int width = getMeasuredWidth();
-                        int offset = getRelativeChildOffset(mCurrentPage);
-                        if (x < offset - mPageSpacing) {
+                        if (hitsPreviousPage(x, y)) {
                             mTouchState = TOUCH_STATE_PREV_PAGE;
-                        } else if (x > (width - offset + mPageSpacing)) {
+                        } else if (hitsNextPage(x, y)) {
                             mTouchState = TOUCH_STATE_NEXT_PAGE;
                         }
                     }
@@ -856,10 +867,6 @@
         }
     }
 
-    protected boolean handlePagingClicks() {
-        return false;
-    }
-
     // This curve determines how the effect of scrolling over the limits of the page dimishes
     // as the user pulls further and further from the bounds
     private float overScrollInfluenceCurve(float f) {
@@ -966,7 +973,7 @@
                 } else {
                     snapToDestination();
                 }
-            } else if (mTouchState == TOUCH_STATE_PREV_PAGE && !handlePagingClicks()) {
+            } else if (mTouchState == TOUCH_STATE_PREV_PAGE) {
                 // at this point we have not moved beyond the touch slop
                 // (otherwise mTouchState would be TOUCH_STATE_SCROLLING), so
                 // we can just page
@@ -976,7 +983,7 @@
                 } else {
                     snapToDestination();
                 }
-            } else if (mTouchState == TOUCH_STATE_NEXT_PAGE && !handlePagingClicks()) {
+            } else if (mTouchState == TOUCH_STATE_NEXT_PAGE) {
                 // at this point we have not moved beyond the touch slop
                 // (otherwise mTouchState would be TOUCH_STATE_SCROLLING), so
                 // we can just page
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index d3d8175..b248dd6 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -465,6 +465,36 @@
         }
     }
 
+    /**
+     * Check if the point (x, y) hits a given page.
+     */
+    private boolean hitsPage(int index, float x, float y) {
+        final View page = getChildAt(index);
+        if (page != null) {
+            float[] localXY = { x, y };
+            mapPointFromSelfToChild(page, localXY);
+            return (localXY[0] >= 0 && localXY[0] < page.getWidth()
+                    && localXY[1] >= 0 && localXY[1] < page.getHeight());
+        }
+        return false;
+    }
+
+    @Override
+    protected boolean hitsPreviousPage(float x, float y) {
+        // mNextPage is set to INVALID_PAGE whenever we are stationary.
+        // Calculating "next page" this way ensures that you scroll to whatever page you tap on
+        final int current = (mNextPage == INVALID_PAGE) ? mCurrentPage : mNextPage;
+        return hitsPage(current - 1, x, y);
+    }
+
+    @Override
+    protected boolean hitsNextPage(float x, float y) {
+        // mNextPage is set to INVALID_PAGE whenever we are stationary.
+        // Calculating "next page" this way ensures that you scroll to whatever page you tap on
+        final int current = (mNextPage == INVALID_PAGE) ? mCurrentPage : mNextPage;
+        return hitsPage(current + 1, x, y);
+    }
+
     public boolean onTouch(View v, MotionEvent event) {
         // this is an intercepted event being forwarded from a cell layout
         if (mIsSmall || mIsInUnshrinkAnimation) {
@@ -473,14 +503,6 @@
                 mLauncher.onWorkspaceClick((CellLayout) v);
             }
             return true;
-        } else if (!mPageMoving) {
-            if (v == getChildAt(mCurrentPage - 1)) {
-                snapToPage(mCurrentPage - 1);
-                return true;
-            } else if (v == getChildAt(mCurrentPage + 1)) {
-                snapToPage(mCurrentPage + 1);
-                return true;
-            }
         }
         return false;
     }
@@ -1482,11 +1504,6 @@
         updateWhichPagesAcceptDrops(mShrinkState);
     }
 
-    @Override
-    protected boolean handlePagingClicks() {
-        return true;
-    }
-
     // We call this when we trigger an unshrink by clicking on the CellLayout cl
     public void unshrink(CellLayout clThatWasClicked) {
         unshrink(clThatWasClicked, false);