diff options
Diffstat (limited to 'src/com/android/launcher3/allapps/AllAppsRecyclerView.java')
-rw-r--r-- | src/com/android/launcher3/allapps/AllAppsRecyclerView.java | 92 |
1 files changed, 44 insertions, 48 deletions
diff --git a/src/com/android/launcher3/allapps/AllAppsRecyclerView.java b/src/com/android/launcher3/allapps/AllAppsRecyclerView.java index 701402b02..494cd5ac5 100644 --- a/src/com/android/launcher3/allapps/AllAppsRecyclerView.java +++ b/src/com/android/launcher3/allapps/AllAppsRecyclerView.java @@ -36,6 +36,8 @@ import com.android.launcher3.anim.SpringAnimationHandler; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.graphics.DrawableFactory; import com.android.launcher3.logging.UserEventDispatcher.LogContainerProvider; +import com.android.launcher3.touch.OverScroll; +import com.android.launcher3.touch.SwipeDetector; import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; import com.android.launcher3.userevent.nano.LauncherLogProto.Target; @@ -60,7 +62,7 @@ public class AllAppsRecyclerView extends BaseRecyclerView implements LogContaine private SpringAnimationHandler mSpringAnimationHandler; private OverScrollHelper mOverScrollHelper; - private VerticalPullDetector mPullDetector; + private SwipeDetector mPullDetector; private float mContentTranslationY = 0; public static final Property<AllAppsRecyclerView, Float> CONTENT_TRANS_Y = @@ -97,9 +99,8 @@ public class AllAppsRecyclerView extends BaseRecyclerView implements LogContaine R.dimen.all_apps_empty_search_bg_top_offset); mOverScrollHelper = new OverScrollHelper(); - mPullDetector = new VerticalPullDetector(getContext()); - mPullDetector.setListener(mOverScrollHelper); - mPullDetector.setDetectableScrollConditions(VerticalPullDetector.DIRECTION_BOTH, true); + mPullDetector = new SwipeDetector(getContext(), mOverScrollHelper, SwipeDetector.VERTICAL); + mPullDetector.setDetectableScrollConditions(SwipeDetector.DIRECTION_BOTH, true); } public void setSpringAnimationHandler(SpringAnimationHandler springAnimationHandler) { @@ -110,12 +111,6 @@ public class AllAppsRecyclerView extends BaseRecyclerView implements LogContaine } @Override - public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent ev) { - mPullDetector.onTouchEvent(ev); - return super.onInterceptTouchEvent(rv, ev) || mOverScrollHelper.isInOverScroll(); - } - - @Override public boolean onTouchEvent(MotionEvent e) { mPullDetector.onTouchEvent(e); if (FeatureFlags.LAUNCHER3_PHYSICS && mSpringAnimationHandler != null) { @@ -204,8 +199,6 @@ public class AllAppsRecyclerView extends BaseRecyclerView implements LogContaine @Override public void onDraw(Canvas c) { - c.translate(0, mContentTranslationY); - // Draw the background if (mEmptySearchBackground != null && mEmptySearchBackground.getAlpha() > 0) { mEmptySearchBackground.draw(c); @@ -214,6 +207,13 @@ public class AllAppsRecyclerView extends BaseRecyclerView implements LogContaine super.onDraw(c); } + @Override + protected void dispatchDraw(Canvas canvas) { + canvas.translate(0, mContentTranslationY); + super.dispatchDraw(canvas); + canvas.translate(0, -mContentTranslationY); + } + public float getContentTranslationY() { return mContentTranslationY; } @@ -281,7 +281,8 @@ public class AllAppsRecyclerView extends BaseRecyclerView implements LogContaine @Override public boolean onInterceptTouchEvent(MotionEvent e) { - boolean result = super.onInterceptTouchEvent(e); + mPullDetector.onTouchEvent(e); + boolean result = super.onInterceptTouchEvent(e) || mOverScrollHelper.isInOverScroll(); if (!result && e.getAction() == MotionEvent.ACTION_DOWN && mEmptySearchBackground != null && mEmptySearchBackground.getAlpha() > 0) { mEmptySearchBackground.setHotspot(e.getX(), e.getY()); @@ -338,6 +339,22 @@ public class AllAppsRecyclerView extends BaseRecyclerView implements LogContaine mFastScrollHelper.onSetAdapter((AllAppsGridAdapter) adapter); } + @Override + protected float getBottomFadingEdgeStrength() { + // No bottom fading edge. + return 0; + } + + @Override + protected boolean isPaddingOffsetRequired() { + return true; + } + + @Override + protected int getTopPaddingOffset() { + return -getPaddingTop(); + } + /** * Updates the bounds for the scrollbar. */ @@ -507,7 +524,7 @@ public class AllAppsRecyclerView extends BaseRecyclerView implements LogContaine } } - private class OverScrollHelper implements VerticalPullDetector.Listener { + private class OverScrollHelper implements SwipeDetector.Listener { private static final float MAX_RELEASE_VELOCITY = 5000; // px / s private static final float MAX_OVERSCROLL_PERCENTAGE = 0.07f; @@ -540,11 +557,16 @@ public class AllAppsRecyclerView extends BaseRecyclerView implements LogContaine // and if one of the following criteria are met: // - User scrolls down when they're already at the bottom. // - User starts scrolling up, hits the top, and continues scrolling up. + boolean wasInOverScroll = mIsInOverScroll; mIsInOverScroll = !mScrollbar.isDraggingThumb() && ((!canScrollVertically(1) && displacement < 0) || (!canScrollVertically(-1) && isScrollingUp && mFirstScrollYOnScrollUp != 0)); - if (mIsInOverScroll) { + if (wasInOverScroll && !mIsInOverScroll) { + // Exit overscroll. This can happen when the user is in overscroll and then + // scrolls the opposite way. + reset(false /* shouldSpring */); + } else if (mIsInOverScroll) { if (Float.compare(mFirstDisplacement, 0) == 0) { // Because users can scroll before entering overscroll, we need to // subtract the amount where the user was not in overscroll. @@ -559,11 +581,15 @@ public class AllAppsRecyclerView extends BaseRecyclerView implements LogContaine @Override public void onDragEnd(float velocity, boolean fling) { + reset(mIsInOverScroll /* shouldSpring */); + } + + private void reset(boolean shouldSpring) { float y = getContentTranslationY(); if (Float.compare(y, 0) != 0) { - if (FeatureFlags.LAUNCHER3_PHYSICS) { + if (FeatureFlags.LAUNCHER3_PHYSICS && shouldSpring) { // We calculate our own velocity to give the springs the desired effect. - velocity = y / getDampedOverScroll(getHeight()) * MAX_RELEASE_VELOCITY; + float velocity = y / getDampedOverScroll(getHeight()) * MAX_RELEASE_VELOCITY; // We want to negate the velocity because we are moving to 0 from -1 due to the // downward motion. (y-axis -1 is above 0). mSpringAnimationHandler.animateToPositionWithVelocity(0, -1, -velocity); @@ -585,37 +611,7 @@ public class AllAppsRecyclerView extends BaseRecyclerView implements LogContaine } private float getDampedOverScroll(float y) { - return dampedOverScroll(y, getHeight()) * MAX_OVERSCROLL_PERCENTAGE; - } - - /** - * This curve determines how the effect of scrolling over the limits of the page diminishes - * as the user pulls further and further from the bounds - * - * @param f The percentage of how much the user has overscrolled. - * @return A transformed percentage based on the influence curve. - */ - private float overScrollInfluenceCurve(float f) { - f -= 1.0f; - return f * f * f + 1.0f; - } - - /** - * @param amount The original amount overscrolled. - * @param max The maximum amount that the View can overscroll. - * @return The dampened overscroll amount. - */ - private float dampedOverScroll(float amount, float max) { - float f = amount / max; - if (Float.compare(f, 0) == 0) return 0; - f = f / (Math.abs(f)) * (overScrollInfluenceCurve(Math.abs(f))); - - // Clamp this factor, f, to -1 < f < 1 - if (Math.abs(f) >= 1) { - f /= Math.abs(f); - } - - return Math.round(f * max); + return OverScroll.dampedScroll(y, getHeight()); } } } |