-Changing page scroll click regions
-Cleaning up code for page rotations
Change-Id: I046784b108186b6627ce0df3aed57d70c303ef23
diff --git a/src/com/android/launcher2/PagedView.java b/src/com/android/launcher2/PagedView.java
index 578bbcc..2a96736 100644
--- a/src/com/android/launcher2/PagedView.java
+++ b/src/com/android/launcher2/PagedView.java
@@ -649,14 +649,14 @@
// 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) &&
+ if ((mTouchState != TOUCH_STATE_PREV_PAGE) && !handlePagingClicks() &&
(mTouchState != TOUCH_STATE_NEXT_PAGE)) {
if (getChildCount() > 0) {
int width = getMeasuredWidth();
int offset = getRelativeChildOffset(mCurrentPage);
- if (x < offset) {
+ if (x < offset - mPageSpacing) {
mTouchState = TOUCH_STATE_PREV_PAGE;
- } else if (x > (width - offset)) {
+ } else if (x > (width - offset + mPageSpacing)) {
mTouchState = TOUCH_STATE_NEXT_PAGE;
}
}
@@ -741,6 +741,10 @@
}
}
+ protected boolean handlePagingClicks() {
+ return false;
+ }
+
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (mVelocityTracker == null) {
@@ -835,7 +839,7 @@
mVelocityTracker.recycle();
mVelocityTracker = null;
}
- } else if (mTouchState == TOUCH_STATE_PREV_PAGE) {
+ } else if (mTouchState == TOUCH_STATE_PREV_PAGE && !handlePagingClicks()) {
// at this point we have not moved beyond the touch slop
// (otherwise mTouchState would be TOUCH_STATE_SCROLLING), so
// we can just page
@@ -845,7 +849,7 @@
} else {
snapToDestination();
}
- } else if (mTouchState == TOUCH_STATE_NEXT_PAGE) {
+ } else if (mTouchState == TOUCH_STATE_NEXT_PAGE && !handlePagingClicks()) {
// 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 881fb59..6802966 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -89,6 +89,8 @@
private boolean mWaitingToShrinkToBottom = false;
+ private boolean mPageMoving = false;
+
/**
* CellInfo for the cell that is currently being dragged
*/
@@ -207,6 +209,7 @@
if (!(child instanceof CellLayout)) {
throw new IllegalArgumentException("A Workspace can only have CellLayout children.");
}
+ ((CellLayout) child).setOnInterceptTouchListener(this);
super.addView(child, index, params);
}
@@ -215,6 +218,7 @@
if (!(child instanceof CellLayout)) {
throw new IllegalArgumentException("A Workspace can only have CellLayout children.");
}
+ ((CellLayout) child).setOnInterceptTouchListener(this);
super.addView(child);
}
@@ -223,6 +227,7 @@
if (!(child instanceof CellLayout)) {
throw new IllegalArgumentException("A Workspace can only have CellLayout children.");
}
+ ((CellLayout) child).setOnInterceptTouchListener(this);
super.addView(child, index);
}
@@ -231,6 +236,7 @@
if (!(child instanceof CellLayout)) {
throw new IllegalArgumentException("A Workspace can only have CellLayout children.");
}
+ ((CellLayout) child).setOnInterceptTouchListener(this);
super.addView(child, width, height);
}
@@ -239,6 +245,7 @@
if (!(child instanceof CellLayout)) {
throw new IllegalArgumentException("A Workspace can only have CellLayout children.");
}
+ ((CellLayout) child).setOnInterceptTouchListener(this);
super.addView(child, params);
}
@@ -367,6 +374,14 @@
if (mIsSmall || mIsInUnshrinkAnimation) {
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;
}
@@ -399,15 +414,16 @@
enableChildrenCache(mCurrentPage - 1, mCurrentPage + 1);
}
showOutlines();
+ mPageMoving = true;
}
protected void onPageEndMoving() {
clearChildrenCache();
-
// Hide the outlines, as long as we're not dragging
if (!mDragController.dragging()) {
hideOutlines();
}
+ mPageMoving = false;
}
@Override
@@ -444,10 +460,6 @@
}
}
- private float getScaleXForRotation(float degrees) {
- return (float) (1.0f / Math.cos(Math.PI * degrees / 180.0f));
- }
-
public void showOutlines() {
if (mBackgroundFadeOut != null) mBackgroundFadeOut.cancel();
if (mBackgroundFadeIn != null) mBackgroundFadeIn.cancel();
@@ -479,62 +491,20 @@
@Override
protected void screenScrolled(int screenCenter) {
- CellLayout cur = (CellLayout) getChildAt(mCurrentPage);
- CellLayout toRight = (CellLayout) getChildAt(mCurrentPage + 1);
- CellLayout toLeft = (CellLayout) getChildAt(mCurrentPage - 1);
-
- for (int i = 0; i < mCurrentPage - 1; i++) {
+ final int halfScreenSize = getMeasuredWidth() / 2;
+ for (int i = 0; i < getChildCount(); i++) {
View v = getChildAt(i);
if (v != null) {
- v.setRotationY(WORKSPACE_ROTATION);
- v.setScaleX(getScaleXForRotation(WORKSPACE_ROTATION));
- }
- }
- for (int i = mCurrentPage + 1; i < getChildCount(); i++) {
- View v = getChildAt(i);
- if (v != null) {
- v.setRotationY(-WORKSPACE_ROTATION);
- v.setScaleX(getScaleXForRotation(-WORKSPACE_ROTATION));
- }
- }
+ int totalDistance = v.getMeasuredWidth() + mPageSpacing;
+ int delta = screenCenter - (getChildOffset(i) -
+ getRelativeChildOffset(i) + halfScreenSize);
- int halfScreenSize = getMeasuredWidth() / 2;
- int pageWidth = cur.getMeasuredWidth();
- int delta = screenCenter - (getChildOffset(mCurrentPage) -
- getRelativeChildOffset(mCurrentPage) + halfScreenSize);
+ float scrollProgress = delta/(totalDistance*1.0f);
+ scrollProgress = Math.min(scrollProgress, 1.0f);
+ scrollProgress = Math.max(scrollProgress, -1.0f);
- float scrollProgress = Math.abs(delta/(pageWidth*1.0f + mPageSpacing));
- boolean scrollRight = (delta <= 0);
-
- float rotation;
-
- if (scrollRight) {
- rotation = -scrollProgress * WORKSPACE_ROTATION;
- cur.setRotationY(rotation);
- cur.setScaleX(getScaleXForRotation(rotation));
-
- if (toLeft != null) {
- rotation = WORKSPACE_ROTATION * (1 - scrollProgress);
- toLeft.setRotationY(rotation);
- toLeft.setScaleX(getScaleXForRotation(rotation));
- }
- if (toRight != null) {
- toRight.setRotationY(-WORKSPACE_ROTATION);
- toRight.setScaleX(getScaleXForRotation(WORKSPACE_ROTATION));
- }
- } else {
- rotation = scrollProgress * WORKSPACE_ROTATION;
- cur.setRotationY(rotation);
- cur.setScaleX(getScaleXForRotation(rotation));
-
- if (toRight != null) {
- rotation = -WORKSPACE_ROTATION * (1 - scrollProgress);
- toRight.setRotationY(rotation);
- toRight.setScaleX(getScaleXForRotation(rotation));
- }
- if (toLeft != null) {
- toLeft.setRotationY(WORKSPACE_ROTATION);
- toLeft.setScaleX(getScaleXForRotation(WORKSPACE_ROTATION));
+ float rotation = WORKSPACE_ROTATION * scrollProgress;
+ v.setRotationY(rotation);
}
}
}
@@ -764,7 +734,6 @@
}
// increment newX for the next screen
newX += scaledPageWidth + extraScaledSpacing;
- cl.setOnInterceptTouchListener(this);
}
setChildrenDrawnWithCacheEnabled(true);
}
@@ -781,6 +750,11 @@
unshrink(newCurrentPage);
}
+ @Override
+ protected boolean handlePagingClicks() {
+ return true;
+ }
+
private void unshrink(int newCurrentPage) {
if (mIsSmall) {
int newX = getChildOffset(newCurrentPage) - getRelativeChildOffset(newCurrentPage);