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
This commit is contained in:
Alex Chau
2021-03-08 15:16:07 +00:00
parent d10382995f
commit ae53cb246f
4 changed files with 46 additions and 20 deletions
@@ -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);
}
/**
@@ -160,6 +160,8 @@ public class LauncherRecentsView extends RecentsView<BaseQuickstepLauncher>
reset();
}
setOverlayEnabled(finalState == OVERVIEW || finalState == OVERVIEW_MODAL_TASK);
setOverviewGridEnabled(finalState.displayOverviewTasksAsGrid(mActivity));
setOverviewFullscreenEnabled(finalState.getOverviewFullscreenProgress() == 1);
setFreezeViewVisibility(false);
}
@@ -299,6 +299,8 @@ public abstract class RecentsView<T extends StatefulActivity> 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<T extends StatefulActivity> 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<T extends StatefulActivity> 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<T extends StatefulActivity> 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<T extends StatefulActivity> 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<T extends StatefulActivity> 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.
@@ -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;