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
diff --git a/res/values-sw600dp-land/dimens.xml b/res/values-sw600dp-land/dimens.xml
index dce09e3..63970cd 100644
--- a/res/values-sw600dp-land/dimens.xml
+++ b/res/values-sw600dp-land/dimens.xml
@@ -16,6 +16,9 @@
-->
<resources>
+<!-- PagedView -->
+ <dimen name="min_page_snap_velocity">3600dp</dimen>
+
<!-- Hotseat -->
<dimen name="spring_loaded_hotseat_top_margin">44dp</dimen>
diff --git a/res/values-sw600dp/config.xml b/res/values-sw600dp/config.xml
new file mode 100644
index 0000000..072b92d
--- /dev/null
+++ b/res/values-sw600dp/config.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2022 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources>
+
+ <!-- The duration of the PagedView page snap animation -->
+ <integer name="config_pageSnapAnimationDuration">550</integer>
+
+</resources>
diff --git a/res/values-sw600dp/dimens.xml b/res/values-sw600dp/dimens.xml
index eb347f2..d69e777 100644
--- a/res/values-sw600dp/dimens.xml
+++ b/res/values-sw600dp/dimens.xml
@@ -15,6 +15,9 @@
-->
<resources>
+<!-- PagedView-->
+ <dimen name="min_page_snap_velocity">3000dp</dimen>
+
<!-- DragController -->
<dimen name="drag_flingToDeleteMinVelocity">-1000dp</dimen>
diff --git a/res/values-sw720dp-land/dimens.xml b/res/values-sw720dp-land/dimens.xml
index 439ea93..235631d 100644
--- a/res/values-sw720dp-land/dimens.xml
+++ b/res/values-sw720dp-land/dimens.xml
@@ -15,6 +15,9 @@
-->
<resources>
+<!-- PagedView -->
+ <dimen name="min_page_snap_velocity">5300dp</dimen>
+
<!-- Dynamic grid -->
<dimen name="dynamic_grid_edge_margin">21.93dp</dimen>
<dimen name="cell_layout_padding">29.33dp</dimen>
diff --git a/res/values-sw720dp/dimens.xml b/res/values-sw720dp/dimens.xml
index fad8c95..c16792a 100644
--- a/res/values-sw720dp/dimens.xml
+++ b/res/values-sw720dp/dimens.xml
@@ -15,6 +15,9 @@
-->
<resources>
+<!-- PagedView -->
+ <dimen name="min_page_snap_velocity">3400dp</dimen>
+
<!-- AllApps -->
<dimen name="all_apps_bottom_sheet_horizontal_padding">28dp</dimen>
diff --git a/res/values/config.xml b/res/values/config.xml
index 5ecd929..9aa1f03 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -1,3 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2022 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
<resources>
<!-- Miscellaneous -->
<bool name="config_largeHeap">false</bool>
@@ -25,6 +40,9 @@
<!-- The duration of the animation from search hint to text entry -->
<integer name="config_searchHintAnimationDuration">50</integer>
+ <!-- The duration of the PagedView page snap animation -->
+ <integer name="config_pageSnapAnimationDuration">750</integer>
+
<!-- View tag key used to store SpringAnimation data. -->
<item type="id" name="spring_animation_tag" />
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 098c694..f8fa03f 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -99,6 +99,13 @@
<dimen name="fastscroll_width">58dp</dimen>
<dimen name="fastscroll_end_margin">-26dp</dimen>
+ <!-- PagedView -->
+ <dimen name="fling_threshold_velocity">500dp</dimen>
+ <dimen name="easy_fling_threshold_velocity">400dp</dimen>
+ <dimen name="min_fling_velocity">250dp</dimen>
+ <!-- The minimum velocity of a page snap after a fling gesture -->
+ <dimen name="min_page_snap_velocity">1500dp</dimen>
+
<!-- All Apps -->
<dimen name="all_apps_starting_vertical_translate">300dp</dimen>
<dimen name="all_apps_search_bar_field_height">48dp</dimen>
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java
index 95a8a2a..4d33eae 100644
--- a/src/com/android/launcher3/PagedView.java
+++ b/src/com/android/launcher3/PagedView.java
@@ -28,6 +28,8 @@
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 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 @@
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 @@
- 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 @@
}
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 @@
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 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 8916519..8d1687e 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.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 @@
* 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 @@
// 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);
}
}