From 291d88460b8dd2c75c9fdf454cbc66e1c1ac7f2e Mon Sep 17 00:00:00 2001 From: Schneider Victor-tulias Date: Wed, 12 Jan 2022 14:33:43 -0800 Subject: [PATCH] Make Taskbar focusable when a popup is open. - Added ArrowPopup#OnPopupClosedCallback to automatically remove Taskbar focus when the popup closes. Fixes: 209917078 Test: opened popup in taskbar and closed it with switch access, touching anywhere on the screen and using the back gesture. went home to check if focus was removed. Change-Id: Ie7aafc9cf0f03fadaa44e77818508e9e1d8db610 --- .../taskbar/TaskbarActivityContext.java | 17 ++++++++++++++--- .../taskbar/TaskbarLauncherStateController.java | 5 +++++ .../taskbar/TaskbarPopupController.java | 9 +++++++++ src/com/android/launcher3/popup/ArrowPopup.java | 11 ++++++----- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java index e48b26be76..facdd1ef2e 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java @@ -501,19 +501,30 @@ public class TaskbarActivityContext extends ContextThemeWrapper implements Activ return mTaskbarHeightForIme; } + /** + * Either adds or removes {@link WindowManager.LayoutParams#FLAG_NOT_FOCUSABLE} on the taskbar + * window. + */ + public void setTaskbarWindowFocusable(boolean focusable) { + if (focusable) { + mWindowLayoutParams.flags &= ~FLAG_NOT_FOCUSABLE; + } else { + mWindowLayoutParams.flags |= FLAG_NOT_FOCUSABLE; + } + mWindowManager.updateViewLayout(mDragLayer, mWindowLayoutParams); + } + /** * Either adds or removes {@link WindowManager.LayoutParams#FLAG_NOT_FOCUSABLE} on the taskbar * window. If we're now focusable, also move nav buttons to a separate window above IME. */ public void setTaskbarWindowFocusableForIme(boolean focusable) { if (focusable) { - mWindowLayoutParams.flags &= ~FLAG_NOT_FOCUSABLE; mControllers.navbarButtonsViewController.moveNavButtonsToNewWindow(); } else { - mWindowLayoutParams.flags |= FLAG_NOT_FOCUSABLE; mControllers.navbarButtonsViewController.moveNavButtonsBackToTaskbarWindow(); } - mWindowManager.updateViewLayout(mDragLayer, mWindowLayoutParams); + setTaskbarWindowFocusable(focusable); } /** Adds the given view to WindowManager with the provided LayoutParams (creates new window). */ diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java index 7a50d0bf63..a654a561e4 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java @@ -27,6 +27,7 @@ import android.animation.ObjectAnimator; import androidx.annotation.NonNull; +import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.BaseQuickstepLauncher; import com.android.launcher3.LauncherState; import com.android.launcher3.statemanager.StateManager; @@ -256,6 +257,10 @@ import java.util.function.Supplier; if (hasAnyFlag(changedFlags, FLAG_RESUMED | FLAG_RECENTS_ANIMATION_RUNNING)) { boolean goingToLauncher = hasAnyFlag(FLAG_RESUMED | FLAG_RECENTS_ANIMATION_RUNNING); + if (goingToLauncher) { + // Handle closing open popups when going home/overview + AbstractFloatingView.closeAllOpenViews(mControllers.taskbarActivityContext); + } animatorSet.play(mTaskbarBackgroundAlpha.animateToValue(goingToLauncher ? 0 : 1) .setDuration(duration)); } diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarPopupController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarPopupController.java index 2dee50688d..7af9c9dd73 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarPopupController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarPopupController.java @@ -154,6 +154,15 @@ public class TaskbarPopupController { .filter(Objects::nonNull) .collect(Collectors.toList())); container.requestFocus(); + + // Make focusable to receive back events + mControllers.taskbarActivityContext.setTaskbarWindowFocusable(true); + container.setOnCloseCallback(() -> { + mControllers.taskbarActivityContext.getDragLayer().post( + () -> mControllers.taskbarActivityContext.setTaskbarWindowFocusable(false)); + container.setOnCloseCallback(null); + }); + return container; } diff --git a/src/com/android/launcher3/popup/ArrowPopup.java b/src/com/android/launcher3/popup/ArrowPopup.java index b1a41093f5..f06e5cecd5 100644 --- a/src/com/android/launcher3/popup/ArrowPopup.java +++ b/src/com/android/launcher3/popup/ArrowPopup.java @@ -48,7 +48,7 @@ import android.view.ViewTreeObserver; import android.view.animation.Interpolator; import android.widget.FrameLayout; -import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.InsettableFrameLayout; @@ -120,7 +120,7 @@ public abstract class ArrowPopup private final GradientDrawable mRoundedTop; private final GradientDrawable mRoundedBottom; - private Runnable mOnCloseCallback = () -> { }; + @Nullable private Runnable mOnCloseCallback = null; // The rect string of the view that the arrow is attached to, in screen reference frame. protected int mArrowColor; @@ -766,7 +766,6 @@ public abstract class ArrowPopup } } - protected void animateClose() { if (!mIsOpen) { return; @@ -816,7 +815,9 @@ public abstract class ArrowPopup mDeferContainerRemoval = false; getPopupContainer().removeView(this); getPopupContainer().removeView(mArrow); - mOnCloseCallback.run(); + if (mOnCloseCallback != null) { + mOnCloseCallback.run(); + } if (mColorExtractors != null) { mColorExtractors.forEach(e -> e.setListener(null)); } @@ -825,7 +826,7 @@ public abstract class ArrowPopup /** * Callback to be called when the popup is closed */ - public void setOnCloseCallback(@NonNull Runnable callback) { + public void setOnCloseCallback(@Nullable Runnable callback) { mOnCloseCallback = callback; }