diff --git a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java index 21c4d8cffb..7a158a525e 100644 --- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java +++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java @@ -783,7 +783,7 @@ public abstract class AbsSwipeUpHandler< && recentsAttachedToAppWindow) { // Only move running task if RecentsView has never been attached before, to avoid // TaskView jumping to new position as we move the tasks. - mRecentsView.moveRunningTaskToFront(); + mRecentsView.moveRunningTaskToExpectedPosition(); } mAnimationFactory.setRecentsAttachedToAppWindow( recentsAttachedToAppWindow, animate, updateRunningTaskAlpha); diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index aac97bb52d..f63a30d90b 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -1773,26 +1773,17 @@ public abstract class RecentsView< } /** - * Moves the running task to the front of the carousel in tablets, to minimize animation - * required to move the running task in grid. + * Moves the running task to the expected position in the carousel. In tablets, this minimize + * animation required to move the running task into focused task position. */ - public void moveRunningTaskToFront() { - if (!mContainer.getDeviceProfile().isTablet) { - return; - } - + public void moveRunningTaskToExpectedPosition() { TaskView runningTaskView = getRunningTaskView(); - if (runningTaskView == null) { + if (runningTaskView == null || mCurrentPage != indexOfChild(runningTaskView)) { return; } - if (indexOfChild(runningTaskView) != mCurrentPage) { - return; - } - - int frontIndex = enableLargeDesktopWindowingTile() ? getDesktopTaskViewCount() : 0; - - if (mCurrentPage <= frontIndex) { + int runningTaskExpectedIndex = getRunningTaskExpectedIndex(runningTaskView); + if (mCurrentPage == runningTaskExpectedIndex) { return; } @@ -1805,12 +1796,31 @@ public abstract class RecentsView< mMovingTaskView = null; runningTaskView.resetPersistentViewTransforms(); - addView(runningTaskView, frontIndex); - setCurrentPage(frontIndex); + addView(runningTaskView, runningTaskExpectedIndex); + setCurrentPage(runningTaskExpectedIndex); updateTaskSize(); } + private int getRunningTaskExpectedIndex(TaskView runningTaskView) { + if (mContainer.getDeviceProfile().isTablet) { + if (runningTaskView instanceof DesktopTaskView) { + return 0; // Desktop running task is always in front. + } else if (enableLargeDesktopWindowingTile()) { + return getDesktopTaskViewCount(); // Other running task is behind desktop tasks. + } else { + return 0; + } + } else { + int currentIndex = indexOfChild(runningTaskView); + if (currentIndex != -1) { + return currentIndex; // Keep the position if running task already in layout. + } else { + return 0; // New running task are added to the front to begin with. + } + } + } + @Override protected void onScrollerAnimationAborted() { ActiveGestureProtoLogProxy.logOnScrollerAnimationAborted(); @@ -2980,7 +2990,7 @@ public abstract class RecentsView< mTmpRunningTasks = new Task[]{runningTasks[0]}; taskView.bind(mTmpRunningTasks[0], mOrientationState, mTaskOverlayFactory); } - addView(taskView, 0); + addView(taskView, getRunningTaskExpectedIndex(taskView)); runningTaskViewId = taskView.getTaskViewId(); if (wasEmpty) { addView(mClearAllButton);