From 5fdf2d08fcc8268a11333b49d5f3bb8c945633c0 Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Fri, 24 Sep 2021 10:48:01 -0700 Subject: [PATCH] Add a scrim to taskbar for bubbles expanded state When bubbles are expanded a scrim is shown on top of everything. Taskbar is layered above bubbles but we still need the scrim to show on top of it. This CL adds the ability to show a scrim on taskbar. The scrim is a view in the taskbar drag layer and is placed between the taskbar and the nav buttons so that it can block touches / scrim the taskbar but still allow the nav buttons to be visible and touchable. Add interpolators for alpha matching what bubbles is using. Test: manual 1 - expand bubbles while taskbar is visible => observe scrim - open manage menu => observe darker scrim 2 - check that taps on scrim collapse manage menu or stack 3 - check there isn't a scrim while taskbar is stashed and bubbles / manage menu are open 4 - check that three button nav works while bubbles are expanded Bug: 197139718 Change-Id: I94c4ecd07f81b2bad55c38525d60f493d3c1f9d8 --- quickstep/res/layout/taskbar.xml | 5 + .../taskbar/TaskbarActivityContext.java | 3 + .../launcher3/taskbar/TaskbarControllers.java | 4 + .../launcher3/taskbar/TaskbarScrimView.java | 129 ++++++++++++++++++ .../taskbar/TaskbarScrimViewController.java | 94 +++++++++++++ .../taskbar/TaskbarStashController.java | 8 ++ 6 files changed, 243 insertions(+) create mode 100644 quickstep/src/com/android/launcher3/taskbar/TaskbarScrimView.java create mode 100644 quickstep/src/com/android/launcher3/taskbar/TaskbarScrimViewController.java diff --git a/quickstep/res/layout/taskbar.xml b/quickstep/res/layout/taskbar.xml index 83ad9f33e5..3fdbfb2eac 100644 --- a/quickstep/res/layout/taskbar.xml +++ b/quickstep/res/layout/taskbar.xml @@ -30,6 +30,11 @@ android:layout_gravity="bottom" android:clipChildren="false" /> + + 0f; + mTaskbarScrimPaint.setAlpha((int) (alpha * 255)); + invalidate(); + } + + /** + * Sets the radius of the left and right corners above the taskbar. + * @param leftCornerRadius the radius of the left corner. + * @param rightCornerRadius the radius of the right corner. + */ + protected void setCornerSizes(float leftCornerRadius, float rightCornerRadius) { + mLeftCornerRadius = leftCornerRadius; + mRightCornerRadius = rightCornerRadius; + + Path square = new Path(); + square.addRect(0, 0, mLeftCornerRadius, mLeftCornerRadius, Path.Direction.CW); + Path circle = new Path(); + circle.addCircle(mLeftCornerRadius, 0, mLeftCornerRadius, Path.Direction.CW); + mInvertedLeftCornerPath.op(square, circle, Path.Op.DIFFERENCE); + square.reset(); + square.addRect(0, 0, mRightCornerRadius, mRightCornerRadius, Path.Direction.CW); + circle.reset(); + circle.addCircle(0, 0, mRightCornerRadius, Path.Direction.CW); + mInvertedRightCornerPath.op(square, circle, Path.Op.DIFFERENCE); + + if (mShowScrim) { + invalidate(); + } + } +} diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarScrimViewController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarScrimViewController.java new file mode 100644 index 0000000000..e7e55efe63 --- /dev/null +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarScrimViewController.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2021 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 static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_BUBBLES_EXPANDED; +import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_BUBBLES_MANAGE_MENU_EXPANDED; + +import android.animation.ObjectAnimator; +import android.view.animation.Interpolator; +import android.view.animation.PathInterpolator; + +import com.android.quickstep.AnimatedFloat; +import com.android.quickstep.SystemUiProxy; + +/** + * Handles properties/data collection, and passes the results to {@link TaskbarScrimView} to render. + */ +public class TaskbarScrimViewController { + + private static final float SCRIM_ALPHA = 0.6f; + + private static final Interpolator SCRIM_ALPHA_IN = new PathInterpolator(0.4f, 0f, 1f, 1f); + private static final Interpolator SCRIM_ALPHA_OUT = new PathInterpolator(0f, 0f, 0.8f, 1f); + + private final TaskbarActivityContext mActivity; + private final TaskbarScrimView mScrimView; + + // Alpha property for the scrim. + private final AnimatedFloat mScrimAlpha = new AnimatedFloat(this::updateScrimAlpha); + + // Initialized in init. + private TaskbarControllers mControllers; + + public TaskbarScrimViewController(TaskbarActivityContext activity, TaskbarScrimView scrimView) { + mActivity = activity; + mScrimView = scrimView; + mScrimView.setCornerSizes(mActivity.getLeftCornerRadius(), + mActivity.getRightCornerRadius()); + mScrimView.setBackgroundHeight(mActivity.getDeviceProfile().taskbarSize); + } + + /** + * Initializes the controller + */ + public void init(TaskbarControllers controllers) { + mControllers = controllers; + } + + /** + * Updates the scrim state based on the flags. + */ + public void updateStateForSysuiFlags(int stateFlags) { + final boolean bubblesExpanded = (stateFlags & SYSUI_STATE_BUBBLES_EXPANDED) != 0; + final boolean manageMenuExpanded = + (stateFlags & SYSUI_STATE_BUBBLES_MANAGE_MENU_EXPANDED) != 0; + final boolean showScrim = !mControllers.navbarButtonsViewController.isImeVisible() + && bubblesExpanded && mControllers.taskbarStashController.isInAppAndNotStashed(); + final float scrimAlpha = manageMenuExpanded + // When manage menu shows there's the first scrim and second scrim so figure out + // what the total transparency would be. + ? (SCRIM_ALPHA + (SCRIM_ALPHA * (1 - SCRIM_ALPHA))) + : showScrim ? SCRIM_ALPHA : 0; + showScrim(showScrim, scrimAlpha); + } + + private void showScrim(boolean showScrim, float alpha) { + mScrimView.setOnClickListener(showScrim ? (view) -> onClick() : null); + mScrimView.setClickable(showScrim); + ObjectAnimator anim = mScrimAlpha.animateToValue(showScrim ? alpha : 0); + anim.setInterpolator(showScrim ? SCRIM_ALPHA_IN : SCRIM_ALPHA_OUT); + anim.start(); + } + + private void updateScrimAlpha() { + mScrimView.setScrimAlpha(mScrimAlpha.value); + } + + private void onClick() { + SystemUiProxy.INSTANCE.get(mActivity).onBackPressed(); + } +} diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java index 6d6f0f2e00..d71625ed52 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java @@ -198,6 +198,14 @@ public class TaskbarStashController { return (flags & flagMask) != 0; } + + /** + * Returns whether the taskbar is currently visible and in an app. + */ + public boolean isInAppAndNotStashed() { + return !mIsStashed && (mState & FLAG_IN_APP) != 0; + } + public int getContentHeight() { return isStashed() ? mStashedHeight : mUnstashedHeight; }