From 143edac127abfc4905663b38361c3015c31f4c95 Mon Sep 17 00:00:00 2001 From: Toni Barzic Date: Tue, 22 Oct 2024 23:50:29 +0000 Subject: [PATCH] Tapping overflow button toggles KQS Updates the taskbar overflow button handler to toggle the KQS instead of merely showing it. The toggle action will open KQS view if it's not visible, or close it if it's visible and has been shown from the taskbar. If the view is shown, but in response to Alt+Tab, the view will be closed, and reshown above the task bar. Requires CL:30016166 for tapping to work as expected, and CL:30074037 for tapping overflow button reopen KQS over shelf if KQS is already active for Alt+Tab Bug: 368119679 Test: Enter task bar overflow. Tap overflow button to show KQS, tap overlow button to hide KQS. Press Alt+Tab, tap overflow button to reshow KQS over taskbar, and with filtered set of tasks. Flag: com.android.launcher3.taskbar_overflow Change-Id: Id598f9cad649aa174aaf1c5802bf6b6837413d1e --- .../KeyboardQuickSwitchController.java | 38 +++++++++++++++---- .../KeyboardQuickSwitchViewController.java | 7 ++++ .../taskbar/TaskbarViewCallbacks.java | 4 +- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchController.java b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchController.java index 9912c6ca20..711a49aff3 100644 --- a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchController.java +++ b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchController.java @@ -63,6 +63,11 @@ public final class KeyboardQuickSwitchController implements private int mTaskListChangeId = -1; // Only empty before the recent tasks list has been loaded the first time @NonNull private List mTasks = new ArrayList<>(); + // Set of task IDs filtered out of tasks in recents model to generate list of tasks to show in + // the Keyboard Quick Switch view. Non empty only if the view has been shown in response to + // toggling taskbar overflow button. + @NonNull private Set mExcludedTaskIds = Collections.emptySet(); + private int mNumHiddenTasks = 0; // Initialized in init @@ -90,10 +95,12 @@ public final class KeyboardQuickSwitchController implements return; } int currentFocusedIndex = mQuickSwitchViewController.getCurrentFocusedIndex(); + boolean wasOpenedFromTaskbar = mQuickSwitchViewController.wasOpenedFromTaskbar(); onDestroy(); if (currentFocusedIndex != -1) { mControllers.taskbarActivityContext.getMainThreadHandler().post( - () -> openQuickSwitchView(currentFocusedIndex)); + () -> openQuickSwitchView(currentFocusedIndex, mExcludedTaskIds, + wasOpenedFromTaskbar)); } } @@ -102,10 +109,19 @@ public final class KeyboardQuickSwitchController implements } /** - * Opens the view with a filtered list of tasks. + * Opens or closes the view in response to taskbar action. The view shows a filtered list of + * tasks. * @param taskIdsToExclude A list of tasks to exclude in the opened view. */ - void openQuickSwitchView(@NonNull Set taskIdsToExclude) { + void toggleQuickSwitchViewForTaskbar(@NonNull Set taskIdsToExclude) { + // Close the view if its shown, and was opened from the taskbar. + if (mQuickSwitchViewController != null + && !mQuickSwitchViewController.isCloseAnimationRunning() + && mQuickSwitchViewController.wasOpenedFromTaskbar()) { + closeQuickSwitchView(true); + return; + } + openQuickSwitchView(-1, taskIdsToExclude, true); } @@ -117,10 +133,16 @@ public final class KeyboardQuickSwitchController implements @NonNull Set taskIdsToExclude, boolean wasOpenedFromTaskbar) { if (mQuickSwitchViewController != null) { - if (!mQuickSwitchViewController.isCloseAnimationRunning()) { + if (!mQuickSwitchViewController.isCloseAnimationRunning() + && mQuickSwitchViewController.wasOpenedFromTaskbar() == wasOpenedFromTaskbar) { return; } - // Allow the KQS to be reopened during the close animation to make it more responsive + + // Allow the KQS to be reopened during the close animation to make it more responsive. + // Similarly, if KQS was opened in different mode (from taskbar vs. keyboard event), + // close it so it can be reopened in the correct mode. + // TODO(b/368119679) Consider updating list of shown tasks in place, or at least reopen + // the view in the same vertical location. closeQuickSwitchView(false); } mOverlayContext = mControllers.taskbarOverlayController.requestWindow(); @@ -139,9 +161,8 @@ public final class KeyboardQuickSwitchController implements final boolean onDesktop = mControllers.taskbarDesktopModeController.getAreDesktopTasksVisible(); - // TODO(b/368119679) For now we will re-process the task list every time, but this can be - // optimized if we have the same set of task ids to exclude. - if (mModel.isTaskListValid(mTaskListChangeId) && !Flags.taskbarOverflow()) { + if (mModel.isTaskListValid(mTaskListChangeId) + && taskIdsToExclude.equals(mExcludedTaskIds)) { // When we are opening the KQS with no focus override, check if the first task is // running. If not, focus that first task. mQuickSwitchViewController.openQuickSwitchView( @@ -157,6 +178,7 @@ public final class KeyboardQuickSwitchController implements return; } + mExcludedTaskIds = taskIdsToExclude; mTaskListChangeId = mModel.getTasks((tasks) -> { mHasDesktopTask = false; mWasDesktopTaskFilteredOut = false; diff --git a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchViewController.java b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchViewController.java index a80c11cc17..fbbdc45e8c 100644 --- a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchViewController.java @@ -67,6 +67,7 @@ public class KeyboardQuickSwitchViewController { private boolean mOnDesktop; private boolean mWasDesktopTaskFilteredOut; + private boolean mWasOpenedFromTaskbar; protected KeyboardQuickSwitchViewController( @NonNull TaskbarControllers controllers, @@ -83,6 +84,10 @@ public class KeyboardQuickSwitchViewController { return mCurrentFocusIndex; } + protected boolean wasOpenedFromTaskbar() { + return mWasOpenedFromTaskbar; + } + protected void openQuickSwitchView( @NonNull List tasks, int numHiddenTasks, @@ -96,6 +101,7 @@ public class KeyboardQuickSwitchViewController { mOverlayContext.getDragLayer().addView(mKeyboardQuickSwitchView); mOnDesktop = onDesktop; mWasDesktopTaskFilteredOut = wasDesktopTaskFilteredOut; + mWasOpenedFromTaskbar = wasOpenedFromTaskbar; mKeyboardQuickSwitchView.applyLoadPlan( mOverlayContext, @@ -246,6 +252,7 @@ public class KeyboardQuickSwitchViewController { pw.println(prefix + "\tmCurrentFocusIndex=" + mCurrentFocusIndex); pw.println(prefix + "\tmOnDesktop=" + mOnDesktop); pw.println(prefix + "\tmWasDesktopTaskFilteredOut=" + mWasDesktopTaskFilteredOut); + pw.println(prefix + "\tmWasOpenedFromTaskbar=" + mWasOpenedFromTaskbar); } /** diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarViewCallbacks.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarViewCallbacks.java index 4591f9b8bf..5d769d2962 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarViewCallbacks.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarViewCallbacks.java @@ -148,7 +148,7 @@ public class TaskbarViewCallbacks { return new View.OnClickListener() { @Override public void onClick(View v) { - mControllers.keyboardQuickSwitchController.openQuickSwitchView( + mControllers.keyboardQuickSwitchController.toggleQuickSwitchViewForTaskbar( mControllers.taskbarViewController.getTaskIdsForPinnedApps()); } }; @@ -159,7 +159,7 @@ public class TaskbarViewCallbacks { return new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { - mControllers.keyboardQuickSwitchController.openQuickSwitchView( + mControllers.keyboardQuickSwitchController.toggleQuickSwitchViewForTaskbar( mControllers.taskbarViewController.getTaskIdsForPinnedApps()); return true; }