diff options
author | Hyunyoung Song <hyunyoungs@google.com> | 2016-06-13 12:38:32 -0700 |
---|---|---|
committer | Hyunyoung Song <hyunyoungs@google.com> | 2016-06-13 12:38:32 -0700 |
commit | 35ea6591a7e8b6b951ff74305f570545865be25a (patch) | |
tree | de4146a127175ea5913561e237134533cce0fa4c | |
parent | f4cbb1428a97142e42214951f6914353e2bd70cf (diff) | |
download | android_packages_apps_Trebuchet-35ea6591a7e8b6b951ff74305f570545865be25a.tar.gz android_packages_apps_Trebuchet-35ea6591a7e8b6b951ff74305f570545865be25a.tar.bz2 android_packages_apps_Trebuchet-35ea6591a7e8b6b951ff74305f570545865be25a.zip |
All apps container should not intercept touch during animation.
b/28917826
> When all apps container is settling near either the bottom or top
end, touch event should not be intercepted.
Change-Id: I8aee6cea52e844c4615b92b15f8ef7247236a25b
-rw-r--r-- | src/com/android/launcher3/allapps/AllAppsTransitionController.java | 24 | ||||
-rw-r--r-- | src/com/android/launcher3/allapps/VerticalPullDetector.java | 65 |
2 files changed, 66 insertions, 23 deletions
diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java index d70ee477a..7f047d5cc 100644 --- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java +++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java @@ -54,6 +54,8 @@ public class AllAppsTransitionController implements TouchController, VerticalPul private float mProgressTransY; // numerator private float mTranslation = -1; // denominator + private static final float RECATCH_REJECTION_FRACTION = .0875f; + private long mAnimationDuration; private float mCurY; @@ -73,19 +75,19 @@ public class AllAppsTransitionController implements TouchController, VerticalPul mNoIntercept = false; if (mLauncher.getWorkspace().isInOverviewMode() || mLauncher.isWidgetsViewVisible()) { mNoIntercept = true; - } - if (mLauncher.isAllAppsVisible() && + } else if (mLauncher.isAllAppsVisible() && !mAppsView.shouldContainerScroll(ev.getX(), ev.getY())) { mNoIntercept = true; + } else { + mDetector.setDetectableScrollConditions(mLauncher.isAllAppsVisible() /* down */, + isInDisallowRecatchTopZone(), isInDisallowRecatchBottomZone()); } } if (mNoIntercept) { return false; - } else { - mDetector.setScrollDirectionDown(mLauncher.isAllAppsVisible()); } mDetector.onTouchEvent(ev); - return mDetector.mScrolling; + return mDetector.shouldIntercept(); } @Override @@ -93,6 +95,14 @@ public class AllAppsTransitionController implements TouchController, VerticalPul return mDetector.onTouchEvent(ev); } + private boolean isInDisallowRecatchTopZone() { + return mProgressTransY / mTranslation < RECATCH_REJECTION_FRACTION; + } + + private boolean isInDisallowRecatchBottomZone() { + return mProgressTransY / mTranslation > 1 - RECATCH_REJECTION_FRACTION; + } + private void init() { if (mAppsView != null) { return; @@ -267,7 +277,7 @@ public class AllAppsTransitionController implements TouchController, VerticalPul if ((mAppsView = mLauncher.getAppsView()) == null || animationOut == null){ return; } - if (!mDetector.mScrolling) { + if (mDetector.isRestingState()) { preparePull(true); mAnimationDuration = duration; } @@ -311,7 +321,7 @@ public class AllAppsTransitionController implements TouchController, VerticalPul if ((mAppsView = mLauncher.getAppsView()) == null || animationOut == null){ return; } - if(!mDetector.mScrolling) { + if(mDetector.isRestingState()) { preparePull(true); mAnimationDuration = duration; } diff --git a/src/com/android/launcher3/allapps/VerticalPullDetector.java b/src/com/android/launcher3/allapps/VerticalPullDetector.java index 0c3698de2..7df63e040 100644 --- a/src/com/android/launcher3/allapps/VerticalPullDetector.java +++ b/src/com/android/launcher3/allapps/VerticalPullDetector.java @@ -15,6 +15,8 @@ public class VerticalPullDetector { private float mTouchSlop; private boolean mScrollDown; // if false, only scroll up will be reported. + private boolean mDisallowRecatchFromTop; + private boolean mDisallowRecatchFromBottom; /** * The minimum release velocity in pixels per millisecond that triggers fling.. @@ -28,7 +30,23 @@ public class VerticalPullDetector { public static final float SCROLL_VELOCITY_DAMPENING_RC = 1000f / (2f * (float) Math.PI * 10); /* Scroll state, this is set to true during dragging and animation. */ - boolean mScrolling; + private State mState = State.NONE; + enum State {NONE, DRAG, SCROLLING}; + + private void setState(State newState) { + if (DBG) { + Log.d(TAG, mState + "->" + newState); + } + mState = newState; + } + + public boolean shouldIntercept() { + return mState == State.DRAG; + } + + public boolean isRestingState() { + return mState == State.NONE; + } private float mDownX; private float mDownY; @@ -53,9 +71,6 @@ public class VerticalPullDetector { } interface Listener{ - /** - * @param start when should - */ void onScrollStart(boolean start); boolean onScroll(float displacement, float velocity); void onScrollEnd(float velocity, boolean fling); @@ -65,8 +80,11 @@ public class VerticalPullDetector { mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); } - public void setScrollDirectionDown(boolean scrollDown) { + public void setDetectableScrollConditions(boolean scrollDown, boolean disallowRecatchFromTop, + boolean disallowRecatchFromBottom) { mScrollDown = scrollDown; + mDisallowRecatchFromTop = disallowRecatchFromTop; + mDisallowRecatchFromBottom = disallowRecatchFromBottom; } private boolean shouldScrollStart() { @@ -85,6 +103,21 @@ public class VerticalPullDetector { return false; } + private boolean shouldRecatchScrollStart() { + if (!mDisallowRecatchFromBottom && !mDisallowRecatchFromTop) { + return true; + } + if (mDisallowRecatchFromTop && mDisplacementY > mTouchSlop) { + mDisallowRecatchFromTop = false; + return true; + } + if (mDisallowRecatchFromBottom && mDisplacementY < -mTouchSlop) { + mDisallowRecatchFromBottom = false; + return true; + } + return false; + } + public boolean onTouchEvent(MotionEvent ev) { switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: @@ -93,8 +126,7 @@ public class VerticalPullDetector { mDownY = ev.getY(); mLastDisplacement = 0; mVelocity = 0; - - if (mScrolling) { + if (mState == State.SCROLLING && shouldRecatchScrollStart()){ reportScrollStart(true /* recatch */); } break; @@ -103,18 +135,22 @@ public class VerticalPullDetector { mDisplacementY = ev.getY() - mDownY; mVelocity = computeVelocity(ev, mVelocity); - if (!mScrolling && shouldScrollStart()) { - mScrolling = true; + if (mState == State.SCROLLING && shouldRecatchScrollStart()){ + setState(State.DRAG); + reportScrollStart(true /* recatch */); + } + if (mState == State.NONE && shouldScrollStart()) { + setState(State.DRAG); reportScrollStart(false /* recatch */); } - if (mScrolling && mListener != null) { + if (mState == State.DRAG && mListener != null) { reportScroll(); } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: // These are synthetic events and there is no need to update internal values. - if (mScrolling && mListener != null) { + if (mState == State.DRAG && mListener != null) { reportScrollEnd(); } break; @@ -132,7 +168,7 @@ public class VerticalPullDetector { } public void finishedScrolling() { - mScrolling = false; + setState(State.NONE); } private boolean reportScrollStart(boolean recatch) { @@ -170,6 +206,7 @@ public class VerticalPullDetector { mDisplacementY, mVelocity)); } mListener.onScrollEnd(mVelocity, Math.abs(mVelocity) > RELEASE_VELOCITY_PX_MS); + setState(State.SCROLLING); } /** * Computes the damped velocity using the two motion events and the previous velocity. @@ -187,10 +224,6 @@ public class VerticalPullDetector { return interpolate(previousVelocity, velocity, alpha); } - private float computeDisplacement(MotionEvent to) { - return to.getY() - mDownY; - } - private float computeDelta(MotionEvent to) { return to.getY() - mLastY; } |