From 8542541b2b715b79185b1a06669de172a033c3d4 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Mon, 10 May 2021 16:24:14 -0700 Subject: [PATCH] End scroller if it has already reached the final position - The system overscroller seems to take a long time to settle even after the final position has been reached, so if that has already happened and there is no edge effect, then just end the scroller. - Remove unused code related to SmoothPageView Bug: 184983443 Test: Quickswitch and ensure we finish the recents animation after it settles Change-Id: I9fa72ddd6b6e0d38b6f622c776a2ac5f5b055760 --- src/com/android/launcher3/PagedView.java | 41 ++++++++++--------- src/com/android/launcher3/Workspace.java | 4 -- .../touch/PagedOrientationHandler.java | 2 +- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java index fb216987c9..a70936abb2 100644 --- a/src/com/android/launcher3/PagedView.java +++ b/src/com/android/launcher3/PagedView.java @@ -461,11 +461,6 @@ public abstract class PagedView extends ViewGrou } } - // we moved this functionality to a helper function so SmoothPagedView can reuse it - protected boolean computeScrollHelper() { - return computeScrollHelper(true); - } - protected void announcePageForAccessibility() { if (isAccessibilityEnabled(getContext())) { // Notify the user when the page changes @@ -473,7 +468,7 @@ public abstract class PagedView extends ViewGrou } } - protected boolean computeScrollHelper(boolean shouldInvalidate) { + protected boolean computeScrollHelper() { if (mScroller.computeScrollOffset()) { // Don't bother scrolling if the page does not need to be moved int oldPos = mOrientationHandler.getPrimaryScroll(this); @@ -481,23 +476,29 @@ public abstract class PagedView extends ViewGrou if (oldPos != newPos) { mOrientationHandler.set(this, VIEW_SCROLL_TO, mScroller.getCurrX()); } - if (shouldInvalidate) { - if (mAllowOverScroll) { - if (newPos < mMinScroll && oldPos >= mMinScroll) { - mEdgeGlowLeft.onAbsorb((int) mScroller.getCurrVelocity()); - mScroller.abortAnimation(); - } else if (newPos > mMaxScroll && oldPos <= mMaxScroll) { - mEdgeGlowRight.onAbsorb((int) mScroller.getCurrVelocity()); - mScroller.abortAnimation(); - } + + if (mAllowOverScroll) { + if (newPos < mMinScroll && oldPos >= mMinScroll) { + mEdgeGlowLeft.onAbsorb((int) mScroller.getCurrVelocity()); + mScroller.abortAnimation(); + } else if (newPos > mMaxScroll && oldPos <= mMaxScroll) { + mEdgeGlowRight.onAbsorb((int) mScroller.getCurrVelocity()); + mScroller.abortAnimation(); } - - invalidate(); } - return true; - } else if (mNextPage != INVALID_PAGE && shouldInvalidate) { - sendScrollAccessibilityEvent(); + // If the scroller has scrolled to the final position and there is no edge effect, then + // finish the scroller to skip waiting for additional settling + int finalPos = mOrientationHandler.getPrimaryValue(mScroller.getFinalX(), + mScroller.getFinalY()); + if (newPos == finalPos && mEdgeGlowLeft.isFinished() && mEdgeGlowRight.isFinished()) { + mScroller.abortAnimation(); + } + + invalidate(); + return true; + } else if (mNextPage != INVALID_PAGE) { + sendScrollAccessibilityEvent(); int prevPage = mCurrentPage; mCurrentPage = validateNewPage(mNextPage); mNextPage = INVALID_PAGE; diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 7c5f99e07b..3bdf28c9d3 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -1163,10 +1163,6 @@ public class Workspace extends PagedView mWallpaperOffset.syncWithScroll(); } - public void computeScrollWithoutInvalidation() { - computeScrollHelper(false); - } - @Override public void announceForAccessibility(CharSequence text) { // Don't announce if apps is on top of us. diff --git a/src/com/android/launcher3/touch/PagedOrientationHandler.java b/src/com/android/launcher3/touch/PagedOrientationHandler.java index d8e5a485fd..6811438c6a 100644 --- a/src/com/android/launcher3/touch/PagedOrientationHandler.java +++ b/src/com/android/launcher3/touch/PagedOrientationHandler.java @@ -105,7 +105,7 @@ public interface PagedOrientationHandler { int getPrimaryValue(int x, int y); int getSecondaryValue(int x, int y); - float getPrimaryValue(float x, float y); + float getPrimaryValue(float x, float y); float getSecondaryValue(float x, float y); boolean isLayoutNaturalToLauncher();