From c2bd15fd2af8965576b2e80aa130f6ad58f8ed29 Mon Sep 17 00:00:00 2001 From: Andras Kloczl Date: Wed, 30 Mar 2022 18:06:13 +0100 Subject: [PATCH] Fix slow page animations on large devices - Change non-fling page snap animation duration - Change fling gesture related minVelocity Test: Scroll between home pages, allapps, folder pages Bug: 229073876 Change-Id: Ib39187ec9c832e65dd0b71f8f4a00e1b636423a4 Merge "Hide web settings, if web suggestions is disabled" into tm-dev Change-Id: Ib39187ec9c832e65dd0b71f8f4a00e1b636423a4 --- res/values-sw600dp-land/dimens.xml | 3 ++ res/values-sw600dp/config.xml | 21 ++++++++ res/values-sw600dp/dimens.xml | 3 ++ res/values-sw720dp-land/dimens.xml | 3 ++ res/values-sw720dp/dimens.xml | 3 ++ res/values/config.xml | 18 +++++++ res/values/dimens.xml | 7 +++ src/com/android/launcher3/PagedView.java | 50 +++++++++++--------- src/com/android/launcher3/folder/Folder.java | 7 +-- 9 files changed, 90 insertions(+), 25 deletions(-) create mode 100644 res/values-sw600dp/config.xml diff --git a/res/values-sw600dp-land/dimens.xml b/res/values-sw600dp-land/dimens.xml index dce09e3668..63970cddc6 100644 --- a/res/values-sw600dp-land/dimens.xml +++ b/res/values-sw600dp-land/dimens.xml @@ -16,6 +16,9 @@ --> + + 3600dp + 44dp diff --git a/res/values-sw600dp/config.xml b/res/values-sw600dp/config.xml new file mode 100644 index 0000000000..072b92d5f2 --- /dev/null +++ b/res/values-sw600dp/config.xml @@ -0,0 +1,21 @@ + + + + + + 550 + + diff --git a/res/values-sw600dp/dimens.xml b/res/values-sw600dp/dimens.xml index eb347f2874..d69e7777b0 100644 --- a/res/values-sw600dp/dimens.xml +++ b/res/values-sw600dp/dimens.xml @@ -15,6 +15,9 @@ --> + + 3000dp + -1000dp diff --git a/res/values-sw720dp-land/dimens.xml b/res/values-sw720dp-land/dimens.xml index 439ea9322c..235631d6fa 100644 --- a/res/values-sw720dp-land/dimens.xml +++ b/res/values-sw720dp-land/dimens.xml @@ -15,6 +15,9 @@ --> + + 5300dp + 21.93dp 29.33dp diff --git a/res/values-sw720dp/dimens.xml b/res/values-sw720dp/dimens.xml index fad8c95039..c16792a2e4 100644 --- a/res/values-sw720dp/dimens.xml +++ b/res/values-sw720dp/dimens.xml @@ -15,6 +15,9 @@ --> + + 3400dp + 28dp diff --git a/res/values/config.xml b/res/values/config.xml index 5ecd9299c7..9aa1f03734 100644 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -1,3 +1,18 @@ + + false @@ -25,6 +40,9 @@ 50 + + 750 + diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 098c69465d..f8fa03fafc 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -99,6 +99,13 @@ 58dp -26dp + + 500dp + 400dp + 250dp + + 1500dp + 300dp 48dp diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java index 95a8a2a9c8..4d33eae01c 100644 --- a/src/com/android/launcher3/PagedView.java +++ b/src/com/android/launcher3/PagedView.java @@ -28,6 +28,8 @@ import static com.android.launcher3.touch.PagedOrientationHandler.VIEW_SCROLL_TO import android.animation.LayoutTransition; import android.annotation.SuppressLint; import android.content.Context; +import android.content.res.Configuration; +import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Rect; @@ -78,27 +80,19 @@ public abstract class PagedView extends ViewGrou public static final int INVALID_PAGE = -1; protected static final ComputePageScrollsLogic SIMPLE_SCROLL_LOGIC = (v) -> v.getVisibility() != GONE; - public static final int PAGE_SNAP_ANIMATION_DURATION = 750; - private static final float RETURN_TO_ORIGINAL_PAGE_THRESHOLD = 0.33f; // The page is moved more than halfway, automatically move to the next page on touch up. private static final float SIGNIFICANT_MOVE_THRESHOLD = 0.4f; private static final float MAX_SCROLL_PROGRESS = 1.0f; - // The following constants need to be scaled based on density. The scaled versions will be - // assigned to the corresponding member variables below. - private static final int FLING_THRESHOLD_VELOCITY = 500; - private static final int EASY_FLING_THRESHOLD_VELOCITY = 400; - private static final int MIN_SNAP_VELOCITY = 1500; - private static final int MIN_FLING_VELOCITY = 250; - private boolean mFreeScroll = false; - protected final int mFlingThresholdVelocity; - protected final int mEasyFlingThresholdVelocity; - protected final int mMinFlingVelocity; - protected final int mMinSnapVelocity; + private int mFlingThresholdVelocity; + private int mEasyFlingThresholdVelocity; + private int mMinFlingVelocity; + private int mMinSnapVelocity; + private int mPageSnapAnimationDuration; protected boolean mFirstLayout = true; @@ -192,11 +186,7 @@ public abstract class PagedView extends ViewGrou mPageSlop = configuration.getScaledPagingTouchSlop(); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); - float density = getResources().getDisplayMetrics().density; - mFlingThresholdVelocity = (int) (FLING_THRESHOLD_VELOCITY * density); - mEasyFlingThresholdVelocity = (int) (EASY_FLING_THRESHOLD_VELOCITY * density); - mMinFlingVelocity = (int) (MIN_FLING_VELOCITY * density); - mMinSnapVelocity = (int) (MIN_SNAP_VELOCITY * density); + updateVelocityValues(); initEdgeEffect(); setDefaultFocusHighlightEnabled(false); @@ -628,6 +618,22 @@ public abstract class PagedView extends ViewGrou - mInsets.left - mInsets.right; } + private void updateVelocityValues() { + Resources res = getResources(); + mFlingThresholdVelocity = res.getDimensionPixelSize(R.dimen.fling_threshold_velocity); + mEasyFlingThresholdVelocity = + res.getDimensionPixelSize(R.dimen.easy_fling_threshold_velocity); + mMinFlingVelocity = res.getDimensionPixelSize(R.dimen.min_fling_velocity); + mMinSnapVelocity = res.getDimensionPixelSize(R.dimen.min_page_snap_velocity); + mPageSnapAnimationDuration = res.getInteger(R.integer.config_pageSnapAnimationDuration); + } + + @Override + protected void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + updateVelocityValues(); + } + @Override public void requestLayout() { mIsLayoutValid = false; @@ -1616,7 +1622,7 @@ public abstract class PagedView extends ViewGrou } protected void snapToDestination() { - snapToPage(getDestinationPage(), PAGE_SNAP_ANIMATION_DURATION); + snapToPage(getDestinationPage(), mPageSnapAnimationDuration); } // We want the duration of the page snap animation to be influenced by the distance that @@ -1640,7 +1646,7 @@ public abstract class PagedView extends ViewGrou if (Math.abs(velocity) < mMinFlingVelocity) { // If the velocity is low enough, then treat this more as an automatic page advance // as opposed to an apparent physical response to flinging - return snapToPage(whichPage, PAGE_SNAP_ANIMATION_DURATION); + return snapToPage(whichPage, mPageSnapAnimationDuration); } // Here we compute a "distance" that will be used in the computation of the overall @@ -1663,11 +1669,11 @@ public abstract class PagedView extends ViewGrou } public boolean snapToPage(int whichPage) { - return snapToPage(whichPage, PAGE_SNAP_ANIMATION_DURATION); + return snapToPage(whichPage, mPageSnapAnimationDuration); } public boolean snapToPageImmediately(int whichPage) { - return snapToPage(whichPage, PAGE_SNAP_ANIMATION_DURATION, true); + return snapToPage(whichPage, mPageSnapAnimationDuration, true); } public boolean snapToPage(int whichPage, int duration) { diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java index 891651996b..8d1687eecb 100644 --- a/src/com/android/launcher3/folder/Folder.java +++ b/src/com/android/launcher3/folder/Folder.java @@ -72,7 +72,6 @@ import com.android.launcher3.ExtendedEditText; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherSettings; import com.android.launcher3.OnAlarmListener; -import com.android.launcher3.PagedView; import com.android.launcher3.R; import com.android.launcher3.ShortcutAndWidgetContainer; import com.android.launcher3.Utilities; @@ -145,7 +144,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo * Time for which the scroll hint is shown before automatically changing page. */ public static final int SCROLL_HINT_DURATION = 500; - public static final int RESCROLL_DELAY = PagedView.PAGE_SNAP_ANIMATION_DURATION + 150; + private static final int RESCROLL_EXTRA_DELAY = 150; public static final int SCROLL_NONE = -1; public static final int SCROLL_LEFT = 0; @@ -1523,7 +1522,9 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo // Pause drag event until the scrolling is finished mScrollPauseAlarm.setOnAlarmListener(new OnScrollFinishedListener(mDragObject)); - mScrollPauseAlarm.setAlarm(RESCROLL_DELAY); + int rescrollDelay = getResources().getInteger( + R.integer.config_pageSnapAnimationDuration) + RESCROLL_EXTRA_DELAY; + mScrollPauseAlarm.setAlarm(rescrollDelay); } }