Merge branch 'aosp-13' into 13-wip

This commit is contained in:
MrSluffy
2023-09-21 21:54:56 +08:00
1558 changed files with 103738 additions and 36700 deletions
+109 -60
View File
@@ -16,8 +16,6 @@
package com.android.launcher3;
import static androidx.annotation.VisibleForTesting.PACKAGE_PRIVATE;
import static com.android.launcher3.anim.Interpolators.SCROLL;
import static com.android.launcher3.compat.AccessibilityManagerCompat.isAccessibilityEnabled;
import static com.android.launcher3.compat.AccessibilityManagerCompat.isObservedEventType;
@@ -28,6 +26,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;
@@ -50,7 +50,6 @@ import android.widget.OverScroller;
import android.widget.ScrollView;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.android.launcher3.compat.AccessibilityManagerCompat;
import com.android.launcher3.config.FeatureFlags;
@@ -80,27 +79,19 @@ public abstract class PagedView<T extends View & PageIndicator> 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;
@@ -131,7 +122,10 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
private boolean mAllowEasyFling;
protected PagedOrientationHandler mOrientationHandler = PagedOrientationHandler.PORTRAIT;
protected int[] mPageScrolls;
private final ArrayList<Runnable> mOnPageScrollsInitializedCallbacks = new ArrayList<>();
// We should always check pageScrollsInitialized() is true when using mPageScrolls.
@Nullable protected int[] mPageScrolls = null;
private boolean mIsBeingDragged;
// The amount of movement to begin scrolling
@@ -191,11 +185,7 @@ public abstract class PagedView<T extends View & PageIndicator> 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);
@@ -268,8 +258,13 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
abortScrollerAnimation(true);
}
protected void onScrollerAnimationAborted() {
// No-Op
}
private void abortScrollerAnimation(boolean resetNextPage) {
mScroller.abortAnimation();
onScrollerAnimationAborted();
// We need to clean up the next page here to avoid computeScrollHelper from
// updating current page on the pass.
if (resetNextPage) {
@@ -323,7 +318,6 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
/**
* Returns an IntSet with the indices of the currently visible pages
*/
@VisibleForTesting(otherwise = PACKAGE_PRIVATE)
public IntSet getVisiblePageIndices() {
return getPageIndices(mCurrentPage);
}
@@ -564,11 +558,11 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
if (mAllowOverScroll) {
if (newPos < mMinScroll && oldPos >= mMinScroll) {
mEdgeGlowLeft.onAbsorb((int) mScroller.getCurrVelocity());
mScroller.abortAnimation();
abortScrollerAnimation(false);
onEdgeAbsorbingScroll();
} else if (newPos > mMaxScroll && oldPos <= mMaxScroll) {
mEdgeGlowRight.onAbsorb((int) mScroller.getCurrVelocity());
mScroller.abortAnimation();
abortScrollerAnimation(false);
onEdgeAbsorbingScroll();
}
}
@@ -578,7 +572,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
int finalPos = mOrientationHandler.getPrimaryValue(mScroller.getFinalX(),
mScroller.getFinalY());
if (newPos == finalPos && mEdgeGlowLeft.isFinished() && mEdgeGlowRight.isFinished()) {
mScroller.abortAnimation();
abortScrollerAnimation(false);
}
invalidate();
@@ -627,6 +621,22 @@ public abstract class PagedView<T extends View & PageIndicator> 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;
@@ -686,26 +696,48 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
setMeasuredDimension(widthSize, heightSize);
}
/** Returns true iff this PagedView's scroll amounts are initialized to each page index. */
protected boolean isPageScrollsInitialized() {
return mPageScrolls != null && mPageScrolls.length == getChildCount();
}
/**
* Queues the given callback to be run once {@code mPageScrolls} has been initialized.
*/
public void runOnPageScrollsInitialized(Runnable callback) {
mOnPageScrollsInitializedCallbacks.add(callback);
if (isPageScrollsInitialized()) {
onPageScrollsInitialized();
}
}
protected void onPageScrollsInitialized() {
for (Runnable callback : mOnPageScrollsInitializedCallbacks) {
callback.run();
}
mOnPageScrollsInitializedCallbacks.clear();
}
@SuppressLint("DrawAllocation")
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
mIsLayoutValid = true;
final int childCount = getChildCount();
int[] pageScrolls = mPageScrolls;
boolean pageScrollChanged = false;
if (mPageScrolls == null || childCount != mPageScrolls.length) {
mPageScrolls = new int[childCount];
if (!isPageScrollsInitialized()) {
pageScrolls = new int[childCount];
pageScrollChanged = true;
}
if (childCount == 0) {
return;
}
if (DEBUG) Log.d(TAG, "PagedView.onLayout()");
boolean isScrollChanged = getPageScrolls(mPageScrolls, true, SIMPLE_SCROLL_LOGIC);
if (isScrollChanged) {
pageScrollChanged = true;
pageScrollChanged |= getPageScrolls(pageScrolls, true, SIMPLE_SCROLL_LOGIC);
mPageScrolls = pageScrolls;
if (childCount == 0) {
onPageScrollsInitialized();
return;
}
final LayoutTransition transition = getLayoutTransition();
@@ -738,8 +770,16 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
}
if (mScroller.isFinished() && pageScrollChanged) {
// TODO(b/246283207): Remove logging once root cause of flake detected.
if (Utilities.isRunningInTestHarness() && !(this instanceof Workspace)) {
Log.d("b/246283207", this.getClass().getSimpleName() + "#onLayout() -> "
+ "if(mScroller.isFinished() && pageScrollChanged) -> getNextPage(): "
+ getNextPage() + ", getScrollForPage(getNextPage()): "
+ getScrollForPage(getNextPage()));
}
setCurrentPage(getNextPage());
}
onPageScrollsInitialized();
}
/**
@@ -777,7 +817,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
pageScrollChanged = true;
outPageScrolls[i] = pageScroll;
}
childStart += primaryDimension + getChildGap();
childStart += primaryDimension + getChildGap(i, i + delta);
// This makes sure that the space is added after the page, not after each panel
int lastPanel = mIsRtl ? 0 : panelCount - 1;
@@ -801,7 +841,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
return pageScrollChanged;
}
protected int getChildGap() {
protected int getChildGap(int fromIndex, int toIndex) {
return 0;
}
@@ -851,8 +891,10 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
@Override
public void onViewRemoved(View child) {
super.onViewRemoved(child);
mCurrentPage = validateNewPage(mCurrentPage);
mCurrentScrollOverPage = mCurrentPage;
runOnPageScrollsInitialized(() -> {
mCurrentPage = validateNewPage(mCurrentPage);
mCurrentScrollOverPage = mCurrentPage;
});
dispatchPageCountChanged();
}
@@ -1155,7 +1197,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
}
public int getScrollForPage(int index) {
if (mPageScrolls == null || index >= mPageScrolls.length || index < 0) {
if (!isPageScrollsInitialized() || index >= mPageScrolls.length || index < 0) {
return 0;
} else {
return mPageScrolls[index];
@@ -1165,7 +1207,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
// While layout transitions are occurring, a child's position may stray from its baseline
// position. This method returns the magnitude of this stray at any given time.
public int getLayoutTransitionOffsetForPage(int index) {
if (mPageScrolls == null || index >= mPageScrolls.length || index < 0) {
if (!isPageScrollsInitialized() || index >= mPageScrolls.length || index < 0) {
return 0;
} else {
View child = getChildAt(index);
@@ -1197,8 +1239,8 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
mAllowOverScroll = enable;
}
protected float getSignificantMoveThreshold() {
return SIGNIFICANT_MOVE_THRESHOLD;
protected boolean isSignificantMove(float absoluteDelta, int pageOrientedSize) {
return absoluteDelta > pageOrientedSize * SIGNIFICANT_MOVE_THRESHOLD;
}
@Override
@@ -1324,13 +1366,18 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
int velocity = (int) mOrientationHandler.getPrimaryVelocity(velocityTracker,
mActivePointerId);
mActivePointerId);
float delta = primaryDirection - mDownMotionPrimary;
delta /= mOrientationHandler.getPrimaryScale(this);
int pageOrientedSize = mOrientationHandler.getMeasuredSize(getPageAt(mCurrentPage));
boolean isSignificantMove = Math.abs(delta)
> pageOrientedSize * getSignificantMoveThreshold();
View current = getPageAt(mCurrentPage);
if (current == null) {
Log.e(TAG, "current page was null. this should not happen.");
return true;
}
int pageOrientedSize = (int) (mOrientationHandler.getMeasuredSize(current)
* mOrientationHandler.getPrimaryScale(this));
boolean isSignificantMove = isSignificantMove(Math.abs(delta), pageOrientedSize);
mTotalMotion += Math.abs(mLastMotion + mLastMotionRemainder - primaryDirection);
boolean passedSlop = mAllowEasyFling || mTotalMotion > mPageSlop;
@@ -1361,15 +1408,17 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
(isFling && !isVelocityLeft)) && mCurrentPage > 0) {
finalPage = returnToOriginalPage
? mCurrentPage : mCurrentPage - getPanelCount();
snapToPageWithVelocity(finalPage, velocity);
runOnPageScrollsInitialized(
() -> snapToPageWithVelocity(finalPage, velocity));
} else if (((isSignificantMove && isDeltaLeft && !isFling) ||
(isFling && isVelocityLeft)) &&
mCurrentPage < getChildCount() - 1) {
finalPage = returnToOriginalPage
? mCurrentPage : mCurrentPage + getPanelCount();
snapToPageWithVelocity(finalPage, velocity);
runOnPageScrollsInitialized(
() -> snapToPageWithVelocity(finalPage, velocity));
} else {
snapToDestination();
runOnPageScrollsInitialized(this::snapToDestination);
}
} else {
if (!mScroller.isFinished()) {
@@ -1392,7 +1441,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
int finalPos = mScroller.getFinalX();
mNextPage = getDestinationPage(finalPos);
onNotSnappingToPageInFreeScroll();
runOnPageScrollsInitialized(this::onNotSnappingToPageInFreeScroll);
}
invalidate();
}
@@ -1406,7 +1455,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
case MotionEvent.ACTION_CANCEL:
if (mIsBeingDragged) {
snapToDestination();
runOnPageScrollsInitialized(this::snapToDestination);
}
mEdgeGlowLeft.onRelease();
mEdgeGlowRight.onRelease();
@@ -1443,7 +1492,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
return Math.abs(velocity) > threshold;
}
private void resetTouchState() {
protected void resetTouchState() {
releaseVelocityTracker();
mIsBeingDragged = false;
mActivePointerId = INVALID_POINTER;
@@ -1571,7 +1620,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
}
private int getDisplacementFromScreenCenter(int childIndex, int screenCenter) {
int childSize = Math.round(getChildVisibleSize(childIndex));
int childSize = getChildVisibleSize(childIndex);
int halfChildSize = (childSize / 2);
int childCenter = getChildOffset(childIndex) + halfChildSize;
return childCenter - screenCenter;
@@ -1592,7 +1641,7 @@ public abstract class PagedView<T extends View & PageIndicator> 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
@@ -1616,7 +1665,7 @@ public abstract class PagedView<T extends View & PageIndicator> 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
@@ -1639,11 +1688,11 @@ public abstract class PagedView<T extends View & PageIndicator> 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) {
@@ -1668,7 +1717,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
return false;
}
if (FeatureFlags.IS_STUDIO_BUILD && !Utilities.IS_RUNNING_IN_TEST_HARNESS) {
if (FeatureFlags.IS_STUDIO_BUILD && !Utilities.isRunningInTestHarness()) {
duration *= Settings.Global.getFloat(getContext().getContentResolver(),
Settings.Global.WINDOW_ANIMATION_SCALE, 1);
}