2021-09-24 10:48:01 -07:00
|
|
|
/*
|
|
|
|
|
* 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;
|
|
|
|
|
|
2021-12-15 13:09:39 -08:00
|
|
|
import java.io.PrintWriter;
|
|
|
|
|
|
2021-09-24 10:48:01 -07:00
|
|
|
/**
|
|
|
|
|
* Handles properties/data collection, and passes the results to {@link TaskbarScrimView} to render.
|
|
|
|
|
*/
|
2021-12-15 13:09:39 -08:00
|
|
|
public class TaskbarScrimViewController implements TaskbarControllers.LoggableTaskbarController {
|
2021-09-24 10:48:01 -07:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initializes the controller
|
|
|
|
|
*/
|
|
|
|
|
public void init(TaskbarControllers controllers) {
|
|
|
|
|
mControllers = controllers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Updates the scrim state based on the flags.
|
|
|
|
|
*/
|
2021-10-28 16:39:32 -07:00
|
|
|
public void updateStateForSysuiFlags(int stateFlags, boolean skipAnim) {
|
2021-09-24 10:48:01 -07:00
|
|
|
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;
|
2021-10-28 16:39:32 -07:00
|
|
|
showScrim(showScrim, scrimAlpha, skipAnim);
|
2021-09-24 10:48:01 -07:00
|
|
|
}
|
|
|
|
|
|
2021-10-28 16:39:32 -07:00
|
|
|
private void showScrim(boolean showScrim, float alpha, boolean skipAnim) {
|
2021-09-24 10:48:01 -07:00
|
|
|
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();
|
2021-10-28 16:39:32 -07:00
|
|
|
if (skipAnim) {
|
|
|
|
|
anim.end();
|
|
|
|
|
}
|
2021-09-24 10:48:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateScrimAlpha() {
|
|
|
|
|
mScrimView.setScrimAlpha(mScrimAlpha.value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onClick() {
|
|
|
|
|
SystemUiProxy.INSTANCE.get(mActivity).onBackPressed();
|
|
|
|
|
}
|
2021-12-15 13:09:39 -08:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void dumpLogs(String prefix, PrintWriter pw) {
|
|
|
|
|
pw.println(prefix + "TaskbarScrimViewController:");
|
|
|
|
|
|
2022-06-23 11:25:10 -07:00
|
|
|
pw.println(prefix + "\tmScrimAlpha.value=" + mScrimAlpha.value);
|
2021-12-15 13:09:39 -08:00
|
|
|
}
|
2021-09-24 10:48:01 -07:00
|
|
|
}
|