1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.launcher3.taskbar; 17 18 import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_BUBBLES_EXPANDED; 19 import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_BUBBLES_MANAGE_MENU_EXPANDED; 20 21 import android.animation.ObjectAnimator; 22 import android.view.animation.Interpolator; 23 import android.view.animation.PathInterpolator; 24 25 import com.android.quickstep.AnimatedFloat; 26 import com.android.quickstep.SystemUiProxy; 27 28 /** 29 * Handles properties/data collection, and passes the results to {@link TaskbarScrimView} to render. 30 */ 31 public class TaskbarScrimViewController { 32 33 private static final float SCRIM_ALPHA = 0.6f; 34 35 private static final Interpolator SCRIM_ALPHA_IN = new PathInterpolator(0.4f, 0f, 1f, 1f); 36 private static final Interpolator SCRIM_ALPHA_OUT = new PathInterpolator(0f, 0f, 0.8f, 1f); 37 38 private final TaskbarActivityContext mActivity; 39 private final TaskbarScrimView mScrimView; 40 41 // Alpha property for the scrim. 42 private final AnimatedFloat mScrimAlpha = new AnimatedFloat(this::updateScrimAlpha); 43 44 // Initialized in init. 45 private TaskbarControllers mControllers; 46 TaskbarScrimViewController(TaskbarActivityContext activity, TaskbarScrimView scrimView)47 public TaskbarScrimViewController(TaskbarActivityContext activity, TaskbarScrimView scrimView) { 48 mActivity = activity; 49 mScrimView = scrimView; 50 mScrimView.setCornerSizes(mActivity.getLeftCornerRadius(), 51 mActivity.getRightCornerRadius()); 52 mScrimView.setBackgroundHeight(mActivity.getDeviceProfile().taskbarSize); 53 } 54 55 /** 56 * Initializes the controller 57 */ init(TaskbarControllers controllers)58 public void init(TaskbarControllers controllers) { 59 mControllers = controllers; 60 } 61 62 /** 63 * Updates the scrim state based on the flags. 64 */ updateStateForSysuiFlags(int stateFlags, boolean skipAnim)65 public void updateStateForSysuiFlags(int stateFlags, boolean skipAnim) { 66 final boolean bubblesExpanded = (stateFlags & SYSUI_STATE_BUBBLES_EXPANDED) != 0; 67 final boolean manageMenuExpanded = 68 (stateFlags & SYSUI_STATE_BUBBLES_MANAGE_MENU_EXPANDED) != 0; 69 final boolean showScrim = !mControllers.navbarButtonsViewController.isImeVisible() 70 && bubblesExpanded && mControllers.taskbarStashController.isInAppAndNotStashed(); 71 final float scrimAlpha = manageMenuExpanded 72 // When manage menu shows there's the first scrim and second scrim so figure out 73 // what the total transparency would be. 74 ? (SCRIM_ALPHA + (SCRIM_ALPHA * (1 - SCRIM_ALPHA))) 75 : showScrim ? SCRIM_ALPHA : 0; 76 showScrim(showScrim, scrimAlpha, skipAnim); 77 } 78 showScrim(boolean showScrim, float alpha, boolean skipAnim)79 private void showScrim(boolean showScrim, float alpha, boolean skipAnim) { 80 mScrimView.setOnClickListener(showScrim ? (view) -> onClick() : null); 81 mScrimView.setClickable(showScrim); 82 ObjectAnimator anim = mScrimAlpha.animateToValue(showScrim ? alpha : 0); 83 anim.setInterpolator(showScrim ? SCRIM_ALPHA_IN : SCRIM_ALPHA_OUT); 84 anim.start(); 85 if (skipAnim) { 86 anim.end(); 87 } 88 } 89 updateScrimAlpha()90 private void updateScrimAlpha() { 91 mScrimView.setScrimAlpha(mScrimAlpha.value); 92 } 93 onClick()94 private void onClick() { 95 SystemUiProxy.INSTANCE.get(mActivity).onBackPressed(); 96 } 97 } 98