diff --git a/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java b/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java index 175a1d92b2..f65b907668 100644 --- a/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java @@ -210,7 +210,7 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT 0, 1)); // Center nav buttons in new height for IME. float transForIme = (mContext.getDeviceProfile().taskbarSize - - mContext.getTaskbarHeightForIme()) / 2f; + - mControllers.taskbarInsetsController.getTaskbarHeightForIme()) / 2f; // For gesture nav, nav buttons only show for IME anyway so keep them translated down. float defaultButtonTransY = alwaysShowButtons ? 0 : transForIme; mPropertyHolders.add(new StatePropertyHolder(mTaskbarNavButtonTranslationYForIme, diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java index ef9c62dfd6..9561b749f2 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java @@ -27,9 +27,6 @@ import static com.android.launcher3.ResourceUtils.getBoolByName; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_FOLDER_OPEN; import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED; import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_QUICK_SETTINGS_EXPANDED; -import static com.android.systemui.shared.system.WindowManagerWrapper.ITYPE_BOTTOM_TAPPABLE_ELEMENT; -import static com.android.systemui.shared.system.WindowManagerWrapper.ITYPE_EXTRA_NAVIGATION_BAR; -import static com.android.systemui.shared.system.WindowManagerWrapper.ITYPE_SIZE; import android.animation.AnimatorSet; import android.app.ActivityOptions; @@ -39,7 +36,6 @@ import android.content.Intent; import android.content.pm.ActivityInfo.Config; import android.content.pm.LauncherApps; import android.content.res.Resources; -import android.graphics.Insets; import android.graphics.PixelFormat; import android.graphics.Rect; import android.os.Process; @@ -88,7 +84,6 @@ import com.android.launcher3.views.ActivityContext; import com.android.systemui.shared.recents.model.Task; import com.android.systemui.shared.rotation.RotationButtonController; import com.android.systemui.shared.system.ActivityManagerWrapper; -import com.android.systemui.shared.system.WindowManagerWrapper; import com.android.systemui.unfold.util.ScopedUnfoldTransitionProgressProvider; import java.io.PrintWriter; @@ -113,7 +108,6 @@ public class TaskbarActivityContext extends BaseTaskbarContext { private final WindowManager mWindowManager; private final @Nullable RoundedCorner mLeftCorner, mRightCorner; - private final int mTaskbarHeightForIme; private WindowManager.LayoutParams mWindowLayoutParams; private boolean mIsFullscreen; // The size we should return to when we call setTaskbarWindowFullscreen(false) @@ -154,7 +148,6 @@ public class TaskbarActivityContext extends BaseTaskbarContext { Settings.Secure.getUriFor(Settings.Secure.NAV_BAR_KIDS_MODE), 0); updateIconSize(resources); - mTaskbarHeightForIme = resources.getDimensionPixelSize(R.dimen.taskbar_ime_size); // Get display and corners first, as views might use them in constructor. Display display = windowContext.getDisplay(); @@ -202,29 +195,14 @@ public class TaskbarActivityContext extends BaseTaskbarContext { new TaskbarAutohideSuspendController(this), new TaskbarPopupController(this), new TaskbarForceVisibleImmersiveController(this), - new TaskbarAllAppsController(this)); + new TaskbarAllAppsController(this), + new TaskbarInsetsController(this)); } public void init(TaskbarSharedState sharedState) { mLastRequestedNonFullscreenHeight = getDefaultTaskbarWindowHeight(); mWindowLayoutParams = createDefaultWindowLayoutParams(); - WindowManagerWrapper wmWrapper = WindowManagerWrapper.getInstance(); - wmWrapper.setProvidesInsetsTypes( - mWindowLayoutParams, - new int[] { ITYPE_EXTRA_NAVIGATION_BAR, ITYPE_BOTTOM_TAPPABLE_ELEMENT } - ); - // Adjust the frame by the rounded corners (ie. leaving just the bar as the inset) when - // the IME is showing - mWindowLayoutParams.providedInternalImeInsets = new Insets[ITYPE_SIZE]; - final Insets reducingSize = Insets.of(0, - getDefaultTaskbarWindowHeight() - mTaskbarHeightForIme, 0, 0); - mWindowLayoutParams.providedInternalImeInsets[ITYPE_EXTRA_NAVIGATION_BAR] = reducingSize; - mWindowLayoutParams.providedInternalImeInsets[ITYPE_BOTTOM_TAPPABLE_ELEMENT] = - reducingSize; - - mWindowLayoutParams.insetsRoundedCornerFrame = true; - // Initialize controllers after all are constructed. mControllers.init(sharedState); updateSysuiStateFlags(sharedState.sysuiStateFlags, true /* fromInit */); @@ -304,6 +282,10 @@ public class TaskbarActivityContext extends BaseTaskbarContext { return mRightCorner == null ? 0 : mRightCorner.getRadius(); } + public WindowManager.LayoutParams getWindowLayoutParams() { + return mWindowLayoutParams; + } + @Override public TaskbarDragLayer getDragLayer() { return mDragLayer; @@ -577,14 +559,7 @@ public class TaskbarActivityContext extends BaseTaskbarContext { } } mWindowLayoutParams.height = height; - final Insets reducingSize = - Insets.of(0, height - mTaskbarHeightForIme, 0, 0); - if (mWindowLayoutParams.providedInternalImeInsets == null) { - mWindowLayoutParams.providedInternalImeInsets = new Insets[ITYPE_SIZE]; - } - mWindowLayoutParams.providedInternalImeInsets[ITYPE_EXTRA_NAVIGATION_BAR] = reducingSize; - mWindowLayoutParams.providedInternalImeInsets[ITYPE_BOTTOM_TAPPABLE_ELEMENT] = - reducingSize; + mControllers.taskbarInsetsController.onTaskbarWindowHeightChanged(); mWindowManager.updateViewLayout(mDragLayer, mWindowLayoutParams); } @@ -595,13 +570,6 @@ public class TaskbarActivityContext extends BaseTaskbarContext { return mDeviceProfile.taskbarSize + Math.max(getLeftCornerRadius(), getRightCornerRadius()); } - /** - * Returns the bottom insets taskbar provides to the IME when IME is visible. - */ - public int getTaskbarHeightForIme() { - return mTaskbarHeightForIme; - } - /** * Either adds or removes {@link WindowManager.LayoutParams#FLAG_NOT_FOCUSABLE} on the taskbar * window. diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java index a3586396ea..5d3a1520fc 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java @@ -51,6 +51,7 @@ public class TaskbarControllers { public final TaskbarPopupController taskbarPopupController; public final TaskbarForceVisibleImmersiveController taskbarForceVisibleImmersiveController; public final TaskbarAllAppsController taskbarAllAppsController; + public final TaskbarInsetsController taskbarInsetsController; @Nullable private LoggableTaskbarController[] mControllersToLog = null; @@ -76,7 +77,8 @@ public class TaskbarControllers { TaskbarAutohideSuspendController taskbarAutoHideSuspendController, TaskbarPopupController taskbarPopupController, TaskbarForceVisibleImmersiveController taskbarForceVisibleImmersiveController, - TaskbarAllAppsController taskbarAllAppsController) { + TaskbarAllAppsController taskbarAllAppsController, + TaskbarInsetsController taskbarInsetsController) { this.taskbarActivityContext = taskbarActivityContext; this.taskbarDragController = taskbarDragController; this.navButtonController = navButtonController; @@ -94,6 +96,7 @@ public class TaskbarControllers { this.taskbarPopupController = taskbarPopupController; this.taskbarForceVisibleImmersiveController = taskbarForceVisibleImmersiveController; this.taskbarAllAppsController = taskbarAllAppsController; + this.taskbarInsetsController = taskbarInsetsController; } /** @@ -119,13 +122,14 @@ public class TaskbarControllers { taskbarForceVisibleImmersiveController.init(this); taskbarAllAppsController.init(this, sharedState); navButtonController.init(this); + taskbarInsetsController.init(this); mControllersToLog = new LoggableTaskbarController[] { taskbarDragController, navButtonController, navbarButtonsViewController, taskbarDragLayerController, taskbarScrimViewController, taskbarViewController, taskbarUnfoldAnimationController, taskbarKeyguardController, stashedHandleViewController, taskbarStashController, taskbarEduController, - taskbarAutohideSuspendController, taskbarPopupController + taskbarAutohideSuspendController, taskbarPopupController, taskbarInsetsController }; mAreAllControllersInitialized = true; diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragLayerController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragLayerController.java index c7330d365c..307f674ee6 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragLayerController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragLayerController.java @@ -15,18 +15,10 @@ */ package com.android.launcher3.taskbar; -import static com.android.launcher3.AbstractFloatingView.TYPE_ALL; -import static com.android.launcher3.AbstractFloatingView.TYPE_TASKBAR_ALL_APPS; -import static com.android.systemui.shared.system.ViewTreeObserverWrapper.InsetsInfo.TOUCHABLE_INSETS_CONTENT; -import static com.android.systemui.shared.system.ViewTreeObserverWrapper.InsetsInfo.TOUCHABLE_INSETS_FRAME; -import static com.android.systemui.shared.system.ViewTreeObserverWrapper.InsetsInfo.TOUCHABLE_INSETS_REGION; - import android.content.res.Resources; import android.graphics.Rect; -import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.R; -import com.android.launcher3.anim.AlphaUpdateListener; import com.android.launcher3.util.TouchController; import com.android.quickstep.AnimatedFloat; import com.android.systemui.shared.system.ViewTreeObserverWrapper.InsetsInfo; @@ -168,37 +160,7 @@ public class TaskbarDragLayerController implements TaskbarControllers.LoggableTa * @see InsetsInfo#setTouchableInsets(int) */ public void updateInsetsTouchability(InsetsInfo insetsInfo) { - insetsInfo.touchableRegion.setEmpty(); - // Always have nav buttons be touchable - mControllers.navbarButtonsViewController.addVisibleButtonsRegion( - mTaskbarDragLayer, insetsInfo.touchableRegion); - boolean insetsIsTouchableRegion = true; - - if (mTaskbarDragLayer.getAlpha() < AlphaUpdateListener.ALPHA_CUTOFF_THRESHOLD) { - // Let touches pass through us. - insetsInfo.setTouchableInsets(TOUCHABLE_INSETS_REGION); - } else if (mControllers.navbarButtonsViewController.isImeVisible()) { - insetsInfo.setTouchableInsets(TOUCHABLE_INSETS_REGION); - } else if (!mControllers.uiController.isTaskbarTouchable()) { - // Let touches pass through us. - insetsInfo.setTouchableInsets(TOUCHABLE_INSETS_REGION); - } else if (mControllers.taskbarDragController.isSystemDragInProgress()) { - // Let touches pass through us. - insetsInfo.setTouchableInsets(TOUCHABLE_INSETS_REGION); - } else if (AbstractFloatingView.getOpenView(mActivity, TYPE_TASKBAR_ALL_APPS) != null) { - // Let touches pass through us. - insetsInfo.setTouchableInsets(TOUCHABLE_INSETS_REGION); - } else if (mControllers.taskbarViewController.areIconsVisible() - || AbstractFloatingView.getOpenView(mActivity, TYPE_ALL) != null - || mActivity.isNavBarKidsModeActive()) { - // Taskbar has some touchable elements, take over the full taskbar area - insetsInfo.setTouchableInsets(mActivity.isTaskbarWindowFullscreen() - ? TOUCHABLE_INSETS_FRAME : TOUCHABLE_INSETS_CONTENT); - insetsIsTouchableRegion = false; - } else { - insetsInfo.setTouchableInsets(TOUCHABLE_INSETS_REGION); - } - mActivity.excludeFromMagnificationRegion(insetsIsTouchableRegion); + mControllers.taskbarInsetsController.updateInsetsTouchability(insetsInfo); } /** diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarInsetsController.kt b/quickstep/src/com/android/launcher3/taskbar/TaskbarInsetsController.kt new file mode 100644 index 0000000000..a2ff7806f7 --- /dev/null +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarInsetsController.kt @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.launcher3.taskbar + +import android.graphics.Insets +import android.view.WindowManager +import com.android.launcher3.AbstractFloatingView +import com.android.launcher3.R +import com.android.launcher3.anim.AlphaUpdateListener +import com.android.launcher3.taskbar.TaskbarControllers.LoggableTaskbarController +import com.android.quickstep.KtR +import com.android.systemui.shared.system.ViewTreeObserverWrapper.InsetsInfo +import com.android.systemui.shared.system.WindowManagerWrapper +import com.android.systemui.shared.system.WindowManagerWrapper.* +import java.io.PrintWriter + +/** + * Handles the insets that Taskbar provides to underlying apps and the IME. + */ +class TaskbarInsetsController(val context: TaskbarActivityContext): LoggableTaskbarController { + + /** The bottom insets taskbar provides to the IME when IME is visible. */ + val taskbarHeightForIme: Int = context.resources.getDimensionPixelSize( + KtR.dimen.taskbar_ime_size) + + // Initialized in init. + private lateinit var controllers: TaskbarControllers + private lateinit var windowLayoutParams: WindowManager.LayoutParams + + fun init(controllers: TaskbarControllers) { + this.controllers = controllers + windowLayoutParams = context.windowLayoutParams + + val wmWrapper: WindowManagerWrapper = getInstance() + wmWrapper.setProvidesInsetsTypes( + windowLayoutParams, + intArrayOf( + ITYPE_EXTRA_NAVIGATION_BAR, + ITYPE_BOTTOM_TAPPABLE_ELEMENT + ) + ) + + windowLayoutParams.providedInternalImeInsets = arrayOfNulls(ITYPE_SIZE) + + onTaskbarWindowHeightChanged() + + windowLayoutParams.insetsRoundedCornerFrame = true + } + + fun onTaskbarWindowHeightChanged() { + val reducingSize = Insets.of(0, windowLayoutParams.height - taskbarHeightForIme, 0, 0) + windowLayoutParams.providedInternalImeInsets[ITYPE_EXTRA_NAVIGATION_BAR] = reducingSize + windowLayoutParams.providedInternalImeInsets[ITYPE_BOTTOM_TAPPABLE_ELEMENT] = reducingSize + } + + /** + * Called to update the touchable insets. + * @see InsetsInfo.setTouchableInsets + */ + fun updateInsetsTouchability(insetsInfo: InsetsInfo) { + insetsInfo.touchableRegion.setEmpty() + // Always have nav buttons be touchable + controllers.navbarButtonsViewController.addVisibleButtonsRegion( + context.dragLayer, insetsInfo.touchableRegion + ) + var insetsIsTouchableRegion = true + if (context.dragLayer.alpha < AlphaUpdateListener.ALPHA_CUTOFF_THRESHOLD) { + // Let touches pass through us. + insetsInfo.setTouchableInsets(InsetsInfo.TOUCHABLE_INSETS_REGION) + } else if (controllers.navbarButtonsViewController.isImeVisible) { + insetsInfo.setTouchableInsets(InsetsInfo.TOUCHABLE_INSETS_REGION) + } else if (!controllers.uiController.isTaskbarTouchable) { + // Let touches pass through us. + insetsInfo.setTouchableInsets(InsetsInfo.TOUCHABLE_INSETS_REGION) + } else if (controllers.taskbarDragController.isSystemDragInProgress) { + // Let touches pass through us. + insetsInfo.setTouchableInsets(InsetsInfo.TOUCHABLE_INSETS_REGION) + } else if (AbstractFloatingView.getOpenView( + context, + AbstractFloatingView.TYPE_TASKBAR_ALL_APPS + ) != null + ) { + // Let touches pass through us. + insetsInfo.setTouchableInsets(InsetsInfo.TOUCHABLE_INSETS_REGION) + } else if (controllers.taskbarViewController.areIconsVisible() + || AbstractFloatingView.getOpenView( + context, + AbstractFloatingView.TYPE_ALL + ) != null + || context.isNavBarKidsModeActive + ) { + // Taskbar has some touchable elements, take over the full taskbar area + insetsInfo.setTouchableInsets( + if (context.isTaskbarWindowFullscreen) { + InsetsInfo.TOUCHABLE_INSETS_FRAME + } else { + InsetsInfo.TOUCHABLE_INSETS_CONTENT + } + ) + insetsIsTouchableRegion = false + } else { + insetsInfo.setTouchableInsets(InsetsInfo.TOUCHABLE_INSETS_REGION) + } + context.excludeFromMagnificationRegion(insetsIsTouchableRegion) + } + + override fun dumpLogs(prefix: String, pw: PrintWriter) { + pw.println(prefix + "TaskbarInsetsController:") + pw.println("$prefix\twindowHeight=${windowLayoutParams.height}") + pw.println("$prefix\tprovidedInternalImeInsets[ITYPE_EXTRA_NAVIGATION_BAR]=" + + "${windowLayoutParams.providedInternalImeInsets[ITYPE_EXTRA_NAVIGATION_BAR]}") + pw.println("$prefix\tprovidedInternalImeInsets[ITYPE_BOTTOM_TAPPABLE_ELEMENT]=" + + "${windowLayoutParams.providedInternalImeInsets[ITYPE_BOTTOM_TAPPABLE_ELEMENT]}") + } +} \ No newline at end of file diff --git a/quickstep/src/com/android/quickstep/KtR.java b/quickstep/src/com/android/quickstep/KtR.java index a768ef5253..758c6e08ef 100644 --- a/quickstep/src/com/android/quickstep/KtR.java +++ b/quickstep/src/com/android/quickstep/KtR.java @@ -31,6 +31,7 @@ public class KtR { public static final class dimen { public static int task_menu_spacing = R.dimen.task_menu_spacing; public static int task_menu_horizontal_padding = R.dimen.task_menu_horizontal_padding; + public static int taskbar_ime_size = R.dimen.taskbar_ime_size; } public static final class layout {