From 7fc34db11b6f9f199c9602407700d145afd20518 Mon Sep 17 00:00:00 2001 From: minch Date: Fri, 13 Dec 2024 18:20:50 +0000 Subject: [PATCH] Let `getOffsetToDismissedTask` not rely on `taskCount` This is a preparation to migrate TaskViews iteration that rely `getTaskViewCount` to the `TaskViewsIterable` and `TaskViewsIterator`. Flag: EXEMPT as no functionality changes Bug: 379942019 Test: Tested on tangor with `adb shell wm density 480` to simulate phone layout, and verified overview layout is correct in scenarios below: 1. Dismiss the first TaskView 2. Dismiss the last TaskView 3. Dismiss a TaskView in the middle 4. Click `ClearAll` button to dismiss all the TaskViews Change-Id: Icbaf1ea706906097fc6ac60ad3e2ab17d2781284 --- .../com/android/quickstep/views/RecentsView.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index 30052c7699..a4131284ef 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -3931,6 +3931,7 @@ public abstract class RecentsView< : -newClearAllShortTotalWidthTranslation; } mDismissPrimaryTranslations = new int[taskCount]; + int lastTaskViewIndex = indexOfChild(mUtils.getLastTaskView()); for (int i = 0; i < count; i++) { View child = getChildAt(i); if (child == dismissedTaskView) { @@ -3940,7 +3941,8 @@ public abstract class RecentsView< } else if (!showAsGrid || (enableLargeDesktopWindowingTile() && dismissedTaskView != null && dismissedTaskView.isLargeTile() && nextFocusedTaskView == null && !dismissingForSplitSelection)) { - int offset = getOffsetToDismissedTask(scrollDiffPerPage, dismissedIndex, taskCount); + int offset = getOffsetToDismissedTask(scrollDiffPerPage, dismissedIndex, + lastTaskViewIndex); int scrollDiff = newScroll[i] - oldScroll[i] + offset; if (scrollDiff != 0) { translateTaskWhenDismissed( @@ -4290,14 +4292,14 @@ public abstract class RecentsView< * - Current page is rightmost page (leftmost for RTL) * - Dragging an adjacent page on the left side (right side for RTL) */ - private int getOffsetToDismissedTask(int scrollDiffPerPage, int dismissedIndex, int taskCount) { - // When mCurrentPage is ClearAllButton, use the last TaskView instead to calculate - // offset. - int currentPage = mCurrentPage == taskCount ? taskCount - 1 : mCurrentPage; + private int getOffsetToDismissedTask(int scrollDiffPerPage, int dismissedIndex, + int lastTaskViewIndex) { + // If `mCurrentPage` is beyond `lastTaskViewIndex`, use the last TaskView instead to + // calculate offset. + int currentPage = Math.min(mCurrentPage, lastTaskViewIndex); int offset = mIsRtl ? scrollDiffPerPage : 0; if (currentPage == dismissedIndex) { - int lastPage = taskCount - 1; - if (currentPage == lastPage) { + if (currentPage == lastTaskViewIndex) { offset += mIsRtl ? -scrollDiffPerPage : scrollDiffPerPage; } } else {