2020-02-27 23:34:24 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2020 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2020-03-24 12:41:56 -07:00
|
|
|
package com.android.launcher3.statehandlers;
|
2020-02-27 23:34:24 -08:00
|
|
|
|
|
|
|
|
import static com.android.launcher3.anim.Interpolators.LINEAR;
|
2020-06-01 14:20:30 -05:00
|
|
|
import static com.android.launcher3.states.StateAnimationConfig.ANIM_DEPTH;
|
2020-04-15 15:19:49 -07:00
|
|
|
import static com.android.launcher3.states.StateAnimationConfig.SKIP_DEPTH_CONTROLLER;
|
2022-09-13 14:40:48 -07:00
|
|
|
import static com.android.launcher3.util.MultiPropertyFactory.MULTI_PROPERTY_VALUE;
|
2020-02-27 23:34:24 -08:00
|
|
|
|
2020-06-19 16:35:08 -07:00
|
|
|
import android.animation.Animator;
|
|
|
|
|
import android.animation.AnimatorListenerAdapter;
|
|
|
|
|
import android.animation.ObjectAnimator;
|
2021-06-22 16:57:34 -07:00
|
|
|
import android.view.CrossWindowBlurListeners;
|
2020-02-27 23:34:24 -08:00
|
|
|
import android.view.View;
|
2021-05-27 13:48:16 -07:00
|
|
|
import android.view.ViewRootImpl;
|
2020-03-24 12:41:56 -07:00
|
|
|
import android.view.ViewTreeObserver;
|
2020-03-06 15:56:46 -08:00
|
|
|
|
2020-06-19 16:35:08 -07:00
|
|
|
import com.android.launcher3.BaseActivity;
|
2020-02-27 23:34:24 -08:00
|
|
|
import com.android.launcher3.Launcher;
|
|
|
|
|
import com.android.launcher3.LauncherState;
|
2020-03-13 13:01:33 -07:00
|
|
|
import com.android.launcher3.anim.PendingAnimation;
|
2020-05-08 13:37:58 -07:00
|
|
|
import com.android.launcher3.statemanager.StateManager.StateHandler;
|
2020-03-13 13:01:33 -07:00
|
|
|
import com.android.launcher3.states.StateAnimationConfig;
|
2022-07-08 13:14:50 -07:00
|
|
|
import com.android.quickstep.util.BaseDepthController;
|
2020-02-27 23:34:24 -08:00
|
|
|
|
2021-09-10 22:57:24 +00:00
|
|
|
import java.io.PrintWriter;
|
2021-06-22 16:57:34 -07:00
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
|
2020-02-27 23:34:24 -08:00
|
|
|
/**
|
2020-03-17 17:11:32 -07:00
|
|
|
* Controls blur and wallpaper zoom, for the Launcher surface only.
|
2020-02-27 23:34:24 -08:00
|
|
|
*/
|
2022-07-08 13:14:50 -07:00
|
|
|
public class DepthController extends BaseDepthController implements StateHandler<LauncherState>,
|
2020-06-19 16:35:08 -07:00
|
|
|
BaseActivity.MultiWindowModeChangedListener {
|
2020-02-27 23:34:24 -08:00
|
|
|
|
2022-07-08 13:14:50 -07:00
|
|
|
private final ViewTreeObserver.OnDrawListener mOnDrawListener = this::onLauncherDraw;
|
2020-03-24 12:41:56 -07:00
|
|
|
|
2022-07-08 13:14:50 -07:00
|
|
|
private final Consumer<Boolean> mCrossWindowBlurListener = this::setCrossWindowBlursEnabled;
|
2021-06-22 16:57:34 -07:00
|
|
|
|
2022-07-08 13:14:50 -07:00
|
|
|
private final Runnable mOpaquenessListener = this::applyDepthAndBlur;
|
2021-08-09 16:11:14 -07:00
|
|
|
|
2020-06-19 16:35:08 -07:00
|
|
|
// Workaround for animating the depth when multiwindow mode changes.
|
|
|
|
|
private boolean mIgnoreStateChangesDuringMultiWindowAnimation = false;
|
|
|
|
|
|
2020-05-29 12:00:56 -07:00
|
|
|
private View.OnAttachStateChangeListener mOnAttachListener;
|
|
|
|
|
|
2020-03-17 17:11:32 -07:00
|
|
|
public DepthController(Launcher l) {
|
2022-07-08 13:14:50 -07:00
|
|
|
super(l);
|
2020-02-27 23:34:24 -08:00
|
|
|
}
|
|
|
|
|
|
2022-07-08 13:14:50 -07:00
|
|
|
private void onLauncherDraw() {
|
|
|
|
|
View view = mLauncher.getDragLayer();
|
|
|
|
|
ViewRootImpl viewRootImpl = view.getViewRootImpl();
|
|
|
|
|
setSurface(viewRootImpl != null ? viewRootImpl.getSurfaceControl() : null);
|
|
|
|
|
view.post(() -> view.getViewTreeObserver().removeOnDrawListener(mOnDrawListener));
|
|
|
|
|
}
|
2021-06-22 16:57:34 -07:00
|
|
|
|
2022-07-08 13:14:50 -07:00
|
|
|
private void ensureDependencies() {
|
2020-05-29 12:00:56 -07:00
|
|
|
if (mLauncher.getRootView() != null && mOnAttachListener == null) {
|
2022-07-08 13:14:50 -07:00
|
|
|
View rootView = mLauncher.getRootView();
|
2020-05-29 12:00:56 -07:00
|
|
|
mOnAttachListener = new View.OnAttachStateChangeListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onViewAttachedToWindow(View view) {
|
2022-07-08 13:14:50 -07:00
|
|
|
CrossWindowBlurListeners.getInstance().addListener(mLauncher.getMainExecutor(),
|
|
|
|
|
mCrossWindowBlurListener);
|
|
|
|
|
mLauncher.getScrimView().addOpaquenessListener(mOpaquenessListener);
|
|
|
|
|
|
2020-05-29 12:00:56 -07:00
|
|
|
// To handle the case where window token is invalid during last setDepth call.
|
2022-07-08 13:14:50 -07:00
|
|
|
applyDepthAndBlur();
|
2020-05-29 12:00:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onViewDetachedFromWindow(View view) {
|
2023-05-23 14:50:14 +00:00
|
|
|
removeSecondaryListeners();
|
2020-05-29 12:00:56 -07:00
|
|
|
}
|
|
|
|
|
};
|
2022-07-08 13:14:50 -07:00
|
|
|
rootView.addOnAttachStateChangeListener(mOnAttachListener);
|
|
|
|
|
if (rootView.isAttachedToWindow()) {
|
|
|
|
|
mOnAttachListener.onViewAttachedToWindow(rootView);
|
2021-06-22 16:57:34 -07:00
|
|
|
}
|
2020-05-29 12:00:56 -07:00
|
|
|
}
|
2020-02-27 23:34:24 -08:00
|
|
|
}
|
|
|
|
|
|
2023-05-23 14:50:14 +00:00
|
|
|
/**
|
|
|
|
|
* Cleans up after this controller so it can be garbage collected without leaving traces.
|
|
|
|
|
*/
|
|
|
|
|
public void dispose() {
|
|
|
|
|
removeSecondaryListeners();
|
|
|
|
|
|
|
|
|
|
if (mLauncher.getRootView() != null && mOnAttachListener != null) {
|
|
|
|
|
mLauncher.getRootView().removeOnAttachStateChangeListener(mOnAttachListener);
|
|
|
|
|
mOnAttachListener = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void removeSecondaryListeners() {
|
|
|
|
|
if (mCrossWindowBlurListener != null) {
|
|
|
|
|
CrossWindowBlurListeners.getInstance().removeListener(mCrossWindowBlurListener);
|
|
|
|
|
}
|
|
|
|
|
if (mOpaquenessListener != null) {
|
|
|
|
|
mLauncher.getScrimView().removeOpaquenessListener(mOpaquenessListener);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-27 23:34:24 -08:00
|
|
|
/**
|
2020-03-24 12:41:56 -07:00
|
|
|
* Sets if the underlying activity is started or not
|
2020-02-27 23:34:24 -08:00
|
|
|
*/
|
2020-03-24 12:41:56 -07:00
|
|
|
public void setActivityStarted(boolean isStarted) {
|
|
|
|
|
if (isStarted) {
|
|
|
|
|
mLauncher.getDragLayer().getViewTreeObserver().addOnDrawListener(mOnDrawListener);
|
|
|
|
|
} else {
|
|
|
|
|
mLauncher.getDragLayer().getViewTreeObserver().removeOnDrawListener(mOnDrawListener);
|
|
|
|
|
setSurface(null);
|
2020-02-27 23:34:24 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setState(LauncherState toState) {
|
2022-08-31 22:05:45 -07:00
|
|
|
if (mIgnoreStateChangesDuringMultiWindowAnimation) {
|
2020-02-27 23:34:24 -08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-13 14:40:48 -07:00
|
|
|
stateDepth.setValue(toState.getDepth(mLauncher));
|
2022-09-16 14:53:11 +08:00
|
|
|
if (toState == LauncherState.BACKGROUND_APP) {
|
2021-08-27 18:10:41 +00:00
|
|
|
mLauncher.getDragLayer().getViewTreeObserver().addOnDrawListener(mOnDrawListener);
|
2020-02-27 23:34:24 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2020-03-13 13:01:33 -07:00
|
|
|
public void setStateWithAnimation(LauncherState toState, StateAnimationConfig config,
|
|
|
|
|
PendingAnimation animation) {
|
2021-04-26 14:42:44 -04:00
|
|
|
if (config.hasAnimationFlag(SKIP_DEPTH_CONTROLLER)
|
2020-06-19 16:35:08 -07:00
|
|
|
|| mIgnoreStateChangesDuringMultiWindowAnimation) {
|
2020-02-27 23:34:24 -08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-17 17:11:32 -07:00
|
|
|
float toDepth = toState.getDepth(mLauncher);
|
2022-09-13 14:40:48 -07:00
|
|
|
animation.setFloat(stateDepth, MULTI_PROPERTY_VALUE, toDepth,
|
|
|
|
|
config.getInterpolator(ANIM_DEPTH, LINEAR));
|
2020-02-27 23:34:24 -08:00
|
|
|
}
|
|
|
|
|
|
2022-07-08 13:14:50 -07:00
|
|
|
@Override
|
|
|
|
|
protected void applyDepthAndBlur() {
|
2020-03-17 17:11:32 -07:00
|
|
|
ensureDependencies();
|
2022-07-08 13:14:50 -07:00
|
|
|
super.applyDepthAndBlur();
|
2020-02-27 23:34:24 -08:00
|
|
|
}
|
2020-06-19 16:35:08 -07:00
|
|
|
|
2023-06-08 13:17:20 -07:00
|
|
|
@Override
|
|
|
|
|
protected void onInvalidSurface() {
|
|
|
|
|
// Lets wait for surface to become valid again
|
|
|
|
|
mLauncher.getDragLayer().getViewTreeObserver().addOnDrawListener(mOnDrawListener);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-19 16:35:08 -07:00
|
|
|
@Override
|
|
|
|
|
public void onMultiWindowModeChanged(boolean isInMultiWindowMode) {
|
|
|
|
|
mIgnoreStateChangesDuringMultiWindowAnimation = true;
|
|
|
|
|
|
2022-09-13 14:40:48 -07:00
|
|
|
ObjectAnimator mwAnimation = ObjectAnimator.ofFloat(stateDepth, MULTI_PROPERTY_VALUE,
|
2020-06-19 16:35:08 -07:00
|
|
|
mLauncher.getStateManager().getState().getDepth(mLauncher, isInMultiWindowMode))
|
|
|
|
|
.setDuration(300);
|
|
|
|
|
mwAnimation.addListener(new AnimatorListenerAdapter() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
|
mIgnoreStateChangesDuringMultiWindowAnimation = false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
mwAnimation.setAutoCancel(true);
|
|
|
|
|
mwAnimation.start();
|
|
|
|
|
}
|
2021-09-10 22:57:24 +00:00
|
|
|
|
|
|
|
|
public void dump(String prefix, PrintWriter writer) {
|
|
|
|
|
writer.println(prefix + this.getClass().getSimpleName());
|
|
|
|
|
writer.println(prefix + "\tmMaxBlurRadius=" + mMaxBlurRadius);
|
|
|
|
|
writer.println(prefix + "\tmCrossWindowBlursEnabled=" + mCrossWindowBlursEnabled);
|
|
|
|
|
writer.println(prefix + "\tmSurface=" + mSurface);
|
2022-09-13 14:40:48 -07:00
|
|
|
writer.println(prefix + "\tmStateDepth=" + stateDepth.getValue());
|
|
|
|
|
writer.println(prefix + "\tmWidgetDepth=" + widgetDepth.getValue());
|
2021-09-10 22:57:24 +00:00
|
|
|
writer.println(prefix + "\tmCurrentBlur=" + mCurrentBlur);
|
|
|
|
|
writer.println(prefix + "\tmInEarlyWakeUp=" + mInEarlyWakeUp);
|
|
|
|
|
writer.println(prefix + "\tmIgnoreStateChangesDuringMultiWindowAnimation="
|
|
|
|
|
+ mIgnoreStateChangesDuringMultiWindowAnimation);
|
2023-04-13 13:37:34 +08:00
|
|
|
writer.println(prefix + "\tmPauseBlurs=" + mPauseBlurs);
|
2021-09-10 22:57:24 +00:00
|
|
|
}
|
2020-02-27 23:34:24 -08:00
|
|
|
}
|