diff --git a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchView.java b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchView.java index 693fe9cc8f..0026396b17 100644 --- a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchView.java +++ b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchView.java @@ -18,6 +18,7 @@ package com.android.launcher3.taskbar; import static androidx.constraintlayout.widget.ConstraintLayout.LayoutParams.PARENT_ID; import static com.android.launcher3.taskbar.TaskbarDesktopExperienceFlags.enableAltTabKqsFlatenning; +import static com.android.launcher3.taskbar.TaskbarDesktopExperienceFlags.enableAltTabKqsOnConnectedDisplays; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; @@ -54,6 +55,7 @@ import com.android.launcher3.Utilities; import com.android.launcher3.anim.AnimatedFloat; import com.android.launcher3.testing.TestLogging; import com.android.launcher3.testing.shared.TestProtocol; +import com.android.quickstep.SystemUiProxy; import com.android.quickstep.util.DesktopTask; import com.android.quickstep.util.GroupTask; import com.android.quickstep.util.SingleTask; @@ -450,6 +452,9 @@ public class KeyboardQuickSwitchView extends ConstraintLayout { // Unregister the back invoked callback after the view is closed and before the // mViewCallbacks is reset. unregisterOnBackInvokedCallback(); + if (enableAltTabKqsOnConnectedDisplays.isTrue()) { + SystemUiProxy.INSTANCE.get(getContext()).getFocusState().removeListener(mViewCallbacks); + } mViewCallbacks = null; } @@ -616,6 +621,10 @@ public class KeyboardQuickSwitchView extends ConstraintLayout { displayedContent.setVisibility(VISIBLE); setVisibility(VISIBLE); requestFocus(); + if (enableAltTabKqsOnConnectedDisplays.isTrue()) { + SystemUiProxy.INSTANCE.get(getContext()).getFocusState().addListener( + mViewCallbacks); + } } @Override diff --git a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchViewController.java b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchViewController.java index fdd0887a5a..7616ebd8d0 100644 --- a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchViewController.java @@ -43,6 +43,7 @@ import com.android.launcher3.desktop.DesktopAppLaunchTransition; import com.android.launcher3.taskbar.overlay.TaskbarOverlayContext; import com.android.launcher3.taskbar.overlay.TaskbarOverlayDragLayer; import com.android.launcher3.views.BaseDragLayer; +import com.android.quickstep.FocusState; import com.android.quickstep.SystemUiProxy; import com.android.quickstep.util.DesktopTask; import com.android.quickstep.util.GroupTask; @@ -382,7 +383,7 @@ public class KeyboardQuickSwitchViewController { return dl.isEventOverView(mKeyboardQuickSwitchView, ev); } - class ViewCallbacks { + class ViewCallbacks implements FocusState.FocusChangeListener { public final OnBackInvokedCallback onBackInvokedCallback = () -> closeQuickSwitchView(true); boolean onKeyUp(int keyCode, KeyEvent event, boolean isRTL, boolean allowTraversal) { @@ -453,5 +454,12 @@ public class KeyboardQuickSwitchViewController { closeQuickSwitchView(false); mDetachingFromWindow = false; } + + @Override + public void onFocusedDisplayChanged(int displayId) { + if (mControllers.taskbarActivityContext.getDisplayId() != displayId) { + closeQuickSwitchView(/* animate= */ true); + } + } } }