Introduce `mTaskViewCount` inside the RecentsView
Add a member property `mTaskViewCount` inside the RecentsView to track
the number of TaskView inside it. Its value will be increased
`onViewAdded` and decreased `onViewRemoved`.
- Then `getTaskViewCount()` can just return this variable directly.
- Invalidate the `PagedView.mPageScrolls` on a view addition and
removal util they have been updated on next `onLayout`. This is done
to guarantee that `mOnPageScrollsInitializedCallbacks` is run with
up to date `mPageScrolls`.
Flag: EXEMPT as no functionality changes
Bug: 379942019
Test: Tested on Tangor, ensure `mTaskViewCount` is correct in the
following scenarios:
1. Adding more tasks and enter overview
2. Dismissing one and more tasks
3. Dismissing all tasks
Change-Id: I32407e77dd2a9b3d8200efc334c1eadea1336b31
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index 3b46367..c2eae66 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -846,6 +846,8 @@
private final Matrix mTmpMatrix = new Matrix();
+ private int mTaskViewCount = 0;
+
@Nullable
public TaskView getFirstTaskView() {
return mUtils.getFirstTaskView(getTaskViews());
@@ -1247,26 +1249,31 @@
// - It's the initial taskview for entering split screen, we only pretend to dismiss the
// task
// - It's the focused task to be moved to the front, we immediately re-add the task
- if (child instanceof TaskView && child != mSplitHiddenTaskView
- && child != mMovingTaskView) {
- TaskView taskView = (TaskView) child;
- for (int i : taskView.getTaskIds()) {
- mHasVisibleTaskData.delete(i);
+ if (child instanceof TaskView) {
+ mTaskViewCount = Math.max(0, --mTaskViewCount);
+ if (child != mSplitHiddenTaskView && child != mMovingTaskView) {
+ TaskView taskView = (TaskView) child;
+ for (int i : taskView.getTaskIds()) {
+ mHasVisibleTaskData.delete(i);
+ }
+ if (child instanceof GroupedTaskView) {
+ mGroupedTaskViewPool.recycle((GroupedTaskView) taskView);
+ } else if (child instanceof DesktopTaskView) {
+ mDesktopTaskViewPool.recycle((DesktopTaskView) taskView);
+ } else {
+ mTaskViewPool.recycle(taskView);
+ }
+ mActionsView.updateHiddenFlags(HIDDEN_NO_TASKS, getTaskViewCount() == 0);
}
- if (child instanceof GroupedTaskView) {
- mGroupedTaskViewPool.recycle((GroupedTaskView) taskView);
- } else if (child instanceof DesktopTaskView) {
- mDesktopTaskViewPool.recycle((DesktopTaskView) taskView);
- } else {
- mTaskViewPool.recycle(taskView);
- }
- mActionsView.updateHiddenFlags(HIDDEN_NO_TASKS, getTaskViewCount() == 0);
}
}
@Override
public void onViewAdded(View child) {
super.onViewAdded(child);
+ if (child instanceof TaskView) {
+ mTaskViewCount++;
+ }
child.setAlpha(mContentAlpha);
// RecentsView is set to RTL in the constructor when system is using LTR. Here we set the
// child direction back to match system settings.
@@ -2081,11 +2088,7 @@
}
public int getTaskViewCount() {
- int taskViewCount = getChildCount();
- if (indexOfChild(mClearAllButton) != -1) {
- taskViewCount--;
- }
- return taskViewCount;
+ return mTaskViewCount;
}
/**
@@ -2291,8 +2294,7 @@
* Updates TaskView scaling and translation required to support variable width.
*/
private void updateTaskSize() {
- final int taskCount = getTaskViewCount();
- if (taskCount == 0) {
+ if (getTaskViewCount() == 0) {
return;
}
@@ -5658,8 +5660,7 @@
throw new IllegalStateException("Another pending animation is still running");
}
- int count = getTaskViewCount();
- if (count == 0) {
+ if (getTaskViewCount() == 0) {
return new PendingAnimation(duration);
}
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java
index 0ec3b79..b05a46d 100644
--- a/src/com/android/launcher3/PagedView.java
+++ b/src/com/android/launcher3/PagedView.java
@@ -903,12 +903,14 @@
@Override
public void onViewAdded(View child) {
super.onViewAdded(child);
+ mPageScrolls = null;
dispatchPageCountChanged();
}
@Override
public void onViewRemoved(View child) {
super.onViewRemoved(child);
+ mPageScrolls = null;
runOnPageScrollsInitialized(() -> {
mCurrentPage = validateNewPage(mCurrentPage);
mCurrentScrollOverPage = mCurrentPage;