diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index ef52b41d8f..095a3150ea 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -2807,14 +2807,49 @@ public abstract class RecentsView= screenEnd - mPageSpacing; + // Rebalance only if there is a maximum gap between the task and the + // screen's edge; this ensures that rebalanced tasks are outside the + // visible screen. + if (mIsRtl) { + shouldRebalance = taskStart <= screenStart + mPageSpacing; + } else { + int screenEnd = + screenStart + mOrientationHandler.getMeasuredSize( + RecentsView.this); + int taskSize = (int) (mOrientationHandler.getMeasuredSize( + taskView) * taskView + .getSizeAdjustment(/*fullscreenEnabled=*/false)); + int taskEnd = taskStart + taskSize; + + shouldRebalance = taskEnd >= screenEnd - mPageSpacing; + } + + if (shouldRebalance) { + updateGridProperties(/*isTaskDismissal=*/ true, + highestVisibleTaskIndex); + updateScrollSynchronously(); + } } - if (shouldRebalance) { - updateGridProperties(/*isTaskDismissal=*/ true, - highestVisibleTaskIndex); - updateScrollSynchronously(); + // If snapping to another page due to indices rearranging, find the new + // index after dismissal & rearrange using the task view id. + if (taskViewIdToSnapTo != -1) { + pageToSnapTo = indexOfChild( + getTaskViewFromTaskViewId(taskViewIdToSnapTo)); } } - setCurrentPage(pageToSnapTo); dispatchScrollChanged(); } @@ -2879,11 +2924,33 @@ public abstract class RecentsView