Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eea95000 authored by Louis Chang's avatar Louis Chang Committed by Android (Google) Code Review
Browse files

Merge "Keeps the task relative z-ordering when moving an existing recent task" into main

parents bd8c3d8f 1ff574d7
Loading
Loading
Loading
Loading
+35 −3
Original line number Diff line number Diff line
@@ -1135,16 +1135,17 @@ class RecentTasks {
                    if (!mFreezeTaskListReordering) {
                        // Simple case: this is not an affiliated task, so we just move it to the
                        // front unless overridden by the provided activity options
                        int indexToAdd = findIndexToAdd(task);
                        mTasks.remove(taskIndex);
                        mTasks.add(0, task);
                        mTasks.add(indexToAdd, task);
                        if (taskIndex != 0) {
                            // Only notify when position changes
                            mTaskNotificationController.notifyTaskListUpdated();
                        }

                        if (DEBUG_RECENTS) {
                            Slog.d(TAG_RECENTS, "addRecent: moving to top " + task
                                    + " from " + taskIndex);
                            Slog.d(TAG_RECENTS, "addRecent: moving " + task + " to index "
                                    + indexToAdd + " from " + taskIndex);
                        }
                    }
                    notifyTaskPersisterLocked(task, false);
@@ -1231,6 +1232,37 @@ class RecentTasks {
        notifyTaskPersisterLocked(task, false /* flush */);
    }

    // Looks for a new index to move the recent Task. Note that the recent Task should not be
    // placed higher than another recent Task that has higher hierarchical z-ordering.
    private int findIndexToAdd(Task task) {
        int indexToAdd = 0;
        for (int i = 0; i < mTasks.size(); i++) {
            final Task otherTask = mTasks.get(i);
            if (task == otherTask) {
                break;
            }

            if (!otherTask.isAttached()) {
                // Stop searching if not attached.
                break;
            }

            if (otherTask.inPinnedWindowingMode()) {
                // Skip pip task without increasing index since pip is always on screen.
                continue;
            }

            // Stop searching if the task has higher z-ordering, or increase the index and
            // continue the search.
            if (task.compareTo(otherTask) > 0) {
                break;
            }

            indexToAdd = i + 1;
        }
        return indexToAdd;
    }

    /**
     * Add the task to the bottom if possible.
     */