From ae53cb246f9dc369e800a99733a7be007ceed99f Mon Sep 17 00:00:00 2001 From: Alex Chau Date: Fri, 5 Mar 2021 19:00:37 +0000 Subject: [PATCH] Fix overview grid scroll problem - This can be reproduced ocassionally without any obvious pattern, when this happen the page scroll and min/max scroll is messed up - When this happen, onLayout happens before the first setGridProgress call from animations - The fix is to request a relayout at the end of state transition Bug: 174464863 Test: manual Change-Id: I12683c49d7ed72349a4b9cb3b4d3871741e3e22e --- .../quickstep/views/ClearAllButton.java | 8 ++-- .../quickstep/views/LauncherRecentsView.java | 2 + .../android/quickstep/views/RecentsView.java | 38 +++++++++++++++---- .../com/android/quickstep/views/TaskView.java | 18 ++++----- 4 files changed, 46 insertions(+), 20 deletions(-) diff --git a/quickstep/src/com/android/quickstep/views/ClearAllButton.java b/quickstep/src/com/android/quickstep/views/ClearAllButton.java index 9af4d3054c..e7101ccfe9 100644 --- a/quickstep/src/com/android/quickstep/views/ClearAllButton.java +++ b/quickstep/src/com/android/quickstep/views/ClearAllButton.java @@ -130,16 +130,16 @@ public class ClearAllButton extends Button implements PageCallbacks { applyPrimaryTranslation(); } - public float getScrollAdjustment() { + public float getScrollAdjustment(boolean gridEnabled) { float scrollAdjustment = 0; - if (mGridProgress > 0) { + if (gridEnabled) { scrollAdjustment += mGridTranslationPrimary; } return scrollAdjustment; } - public float getOffsetAdjustment() { - return getScrollAdjustment(); + public float getOffsetAdjustment(boolean gridEnabled) { + return getScrollAdjustment(gridEnabled); } /** diff --git a/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java b/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java index d99f707a68..c62f3e28ab 100644 --- a/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java +++ b/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java @@ -160,6 +160,8 @@ public class LauncherRecentsView extends RecentsView reset(); } setOverlayEnabled(finalState == OVERVIEW || finalState == OVERVIEW_MODAL_TASK); + setOverviewGridEnabled(finalState.displayOverviewTasksAsGrid(mActivity)); + setOverviewFullscreenEnabled(finalState.getOverviewFullscreenProgress() == 1); setFreezeViewVisibility(false); } diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index f20ca82217..bdd0a3678e 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -299,6 +299,8 @@ public abstract class RecentsView extends PagedView protected boolean mDisallowScrollToClearAll; private boolean mOverlayEnabled; protected boolean mFreezeViewVisibility; + private boolean mOverviewGridEnabled; + private boolean mOverviewFullscreenEnabled; private float mAdjacentPageOffset = 0; private float mTaskViewsSecondaryTranslation = 0; @@ -676,8 +678,10 @@ public abstract class RecentsView extends PagedView } private boolean isTaskViewWithinBounds(TaskView tv, int start, int end) { - int taskStart = mOrientationHandler.getChildStart(tv) + (int) tv.getOffsetAdjustment(); - int taskSize = (int) (mOrientationHandler.getMeasuredSize(tv) * tv.getSizeAdjustment()); + int taskStart = mOrientationHandler.getChildStart(tv) + (int) tv.getOffsetAdjustment( + mOverviewFullscreenEnabled, mOverviewGridEnabled); + int taskSize = (int) (mOrientationHandler.getMeasuredSize(tv) * tv.getSizeAdjustment( + mOverviewFullscreenEnabled, mOverviewGridEnabled)); int taskEnd = taskStart + taskSize; return (taskStart >= start && taskStart <= end) || (taskEnd >= start && taskEnd <= end); @@ -2664,9 +2668,10 @@ public abstract class RecentsView extends PagedView View child = getChildAt(i); float scrollDiff = 0; if (child instanceof TaskView) { - scrollDiff = ((TaskView) child).getScrollAdjustment(); + scrollDiff = ((TaskView) child).getScrollAdjustment(mOverviewFullscreenEnabled, + mOverviewGridEnabled); } else if (child instanceof ClearAllButton) { - scrollDiff = ((ClearAllButton) child).getScrollAdjustment(); + scrollDiff = ((ClearAllButton) child).getScrollAdjustment(mOverviewGridEnabled); } if (scrollDiff != 0) { @@ -2682,9 +2687,10 @@ public abstract class RecentsView extends PagedView int childOffset = super.getChildOffset(index); View child = getChildAt(index); if (child instanceof TaskView) { - childOffset += ((TaskView) child).getOffsetAdjustment(); + childOffset += ((TaskView) child).getOffsetAdjustment(mOverviewFullscreenEnabled, + mOverviewGridEnabled); } else if (child instanceof ClearAllButton) { - childOffset += ((ClearAllButton) child).getOffsetAdjustment(); + childOffset += ((ClearAllButton) child).getOffsetAdjustment(mOverviewGridEnabled); } return childOffset; } @@ -2695,7 +2701,8 @@ public abstract class RecentsView extends PagedView if (taskView == null) { return super.getChildVisibleSize(index); } - return (int) (super.getChildVisibleSize(index) * taskView.getSizeAdjustment()); + return (int) (super.getChildVisibleSize(index) * taskView.getSizeAdjustment( + mOverviewFullscreenEnabled, mOverviewGridEnabled)); } @Override @@ -2810,6 +2817,23 @@ public abstract class RecentsView extends PagedView } } + public void setOverviewGridEnabled(boolean overviewGridEnabled) { + if (mOverviewGridEnabled != overviewGridEnabled) { + mOverviewGridEnabled = overviewGridEnabled; + // Request layout to ensure scroll position is recalculated with updated mGridProgress. + requestLayout(); + } + } + + public void setOverviewFullscreenEnabled(boolean overviewFullscreenEnabled) { + if (mOverviewFullscreenEnabled != overviewFullscreenEnabled) { + mOverviewFullscreenEnabled = overviewFullscreenEnabled; + // Request layout to ensure scroll position is recalculated with updated + // mFullscreenProgress. + requestLayout(); + } + } + /** * Switch the current running task view to static snapshot mode, * capturing the snapshot at the same time. diff --git a/quickstep/src/com/android/quickstep/views/TaskView.java b/quickstep/src/com/android/quickstep/views/TaskView.java index 0cf7261fa8..88545c6436 100644 --- a/quickstep/src/com/android/quickstep/views/TaskView.java +++ b/quickstep/src/com/android/quickstep/views/TaskView.java @@ -938,31 +938,31 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable { mNonRtlVisibleOffset = nonRtlVisibleOffset; } - public float getScrollAdjustment() { + public float getScrollAdjustment(boolean fullscreenEnabled, boolean gridEnabled) { float scrollAdjustment = 0; - if (mFullscreenProgress > 0) { + if (fullscreenEnabled) { scrollAdjustment += mFullscreenTranslationX + mAccumulatedFullscreenTranslationX; } - if (mGridProgress > 0) { + if (gridEnabled) { scrollAdjustment += mGridTranslationX; } return scrollAdjustment; } - public float getOffsetAdjustment() { - float offsetAdjustment = getScrollAdjustment(); - if (mGridProgress > 0) { + public float getOffsetAdjustment(boolean fullscreenEnabled, boolean gridEnabled) { + float offsetAdjustment = getScrollAdjustment(fullscreenEnabled, gridEnabled); + if (gridEnabled) { offsetAdjustment += mGridOffsetTranslationX + mNonRtlVisibleOffset; } return offsetAdjustment; } - public float getSizeAdjustment() { + public float getSizeAdjustment(boolean fullscreenEnabled, boolean gridEnabled) { float sizeAdjustment = 1; - if (mFullscreenProgress > 0) { + if (fullscreenEnabled) { sizeAdjustment *= mFullscreenScale; } - if (mGridProgress > 0) { + if (gridEnabled) { sizeAdjustment *= mGridScale; } return sizeAdjustment;