Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 950a1073 authored by Alex Chau's avatar Alex Chau
Browse files

Fix STATE_DEPTH stuck at 1 after setting wallpaper

- Made BaseDepthController.setDepth/mDepth private, all get/set should be done through STATE_DEPTH or WIDGET_DEPTH
- Generified ClampedDepthProperty into Utilities.ClampedProperty to apply on STATE_DEPTH

Bug: 240580498
Test: Go to walppaper&style, set new wallpaper, then go to widget picker, wallpaper depth should transition smoothly
Change-Id: I53cdedf970fd7ffba6a952c4edf4b34251b01f07
parent 7c914432
Loading
Loading
Loading
Loading
+5 −45
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import static com.android.launcher3.states.StateAnimationConfig.SKIP_DEPTH_CONTR
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.util.FloatProperty;
import android.view.CrossWindowBlurListeners;
import android.view.View;
import android.view.ViewRootImpl;
@@ -32,7 +31,6 @@ import android.view.ViewTreeObserver;
import com.android.launcher3.BaseActivity;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.statemanager.StateManager.StateHandler;
import com.android.launcher3.states.StateAnimationConfig;
@@ -47,43 +45,12 @@ import java.util.function.Consumer;
public class DepthController extends BaseDepthController implements StateHandler<LauncherState>,
        BaseActivity.MultiWindowModeChangedListener {

    /**
     * A property that updates the background blur within a given range of values (ie. even if the
     * animator goes beyond 0..1, the interpolated value will still be bounded).
     */
    public static class ClampedDepthProperty extends FloatProperty<DepthController> {
        private final float mMinValue;
        private final float mMaxValue;

        public ClampedDepthProperty(float minValue, float maxValue) {
            super("depthClamped");
            mMinValue = minValue;
            mMaxValue = maxValue;
        }

        @Override
        public void setValue(DepthController depthController, float depth) {
            depthController.setDepth(Utilities.boundToRange(depth, mMinValue, mMaxValue));
        }

        @Override
        public Float get(DepthController depthController) {
            return depthController.mDepth;
        }
    }

    private final ViewTreeObserver.OnDrawListener mOnDrawListener = this::onLauncherDraw;

    private final Consumer<Boolean> mCrossWindowBlurListener = this::setCrossWindowBlursEnabled;

    private final Runnable mOpaquenessListener = this::applyDepthAndBlur;

    /**
     * If we're launching and app and should not be blurring the screen for performance reasons.
     */
    private boolean mBlurDisabledForAppLaunch;


    // Workaround for animating the depth when multiwindow mode changes.
    private boolean mIgnoreStateChangesDuringMultiWindowAnimation = false;

@@ -145,12 +112,8 @@ public class DepthController extends BaseDepthController implements StateHandler
            return;
        }

        float toDepth = toState.getDepth(mLauncher);
        if (Float.compare(mDepth, toDepth) != 0) {
            setDepth(toDepth);
        } else if (toState == LauncherState.OVERVIEW) {
            applyDepthAndBlur();
        } else if (toState == LauncherState.BACKGROUND_APP) {
        STATE_DEPTH.set(this, toState.getDepth(mLauncher));
        if (toState == LauncherState.BACKGROUND_APP) {
            mLauncher.getDragLayer().getViewTreeObserver().addOnDrawListener(mOnDrawListener);
        }
    }
@@ -164,10 +127,7 @@ public class DepthController extends BaseDepthController implements StateHandler
        }

        float toDepth = toState.getDepth(mLauncher);
        if (Float.compare(mDepth, toDepth) != 0) {
            animation.setFloat(this, STATE_DEPTH, toDepth,
                    config.getInterpolator(ANIM_DEPTH, LINEAR));
        }
        animation.setFloat(this, STATE_DEPTH, toDepth, config.getInterpolator(ANIM_DEPTH, LINEAR));
    }

    @Override
@@ -198,9 +158,9 @@ public class DepthController extends BaseDepthController implements StateHandler
        writer.println(prefix + "\tmMaxBlurRadius=" + mMaxBlurRadius);
        writer.println(prefix + "\tmCrossWindowBlursEnabled=" + mCrossWindowBlursEnabled);
        writer.println(prefix + "\tmSurface=" + mSurface);
        writer.println(prefix + "\tmDepth=" + mDepth);
        writer.println(prefix + "\tmStateDepth=" + STATE_DEPTH.get(this));
        writer.println(prefix + "\tmWidgetDepth=" + WIDGET_DEPTH.get(this));
        writer.println(prefix + "\tmCurrentBlur=" + mCurrentBlur);
        writer.println(prefix + "\tmBlurDisabledForAppLaunch=" + mBlurDisabledForAppLaunch);
        writer.println(prefix + "\tmInEarlyWakeUp=" + mInEarlyWakeUp);
        writer.println(prefix + "\tmIgnoreStateChangesDuringMultiWindowAnimation="
                + mIgnoreStateChangesDuringMultiWindowAnimation);
+6 −3
Original line number Diff line number Diff line
@@ -186,6 +186,8 @@ public class QuickstepLauncher extends Launcher {

    private SafeCloseable mViewCapture;

    private boolean mEnableWidgetDepth;

    @Override
    protected void setupViews() {
        super.setupViews();
@@ -206,6 +208,9 @@ public class QuickstepLauncher extends Launcher {
        mTISBindHelper = new TISBindHelper(this, this::onTISConnected);
        mDepthController = new DepthController(this);
        mHotseatPredictionController = new HotseatPredictionController(this);

        mEnableWidgetDepth = ENABLE_WIDGET_PICKER_DEPTH.get()
                && SystemProperties.getBoolean("ro.launcher.depth.widget", true);
    }

    @Override
@@ -587,9 +592,7 @@ public class QuickstepLauncher extends Launcher {
    public void onWidgetsTransition(float progress) {
        super.onWidgetsTransition(progress);
        onTaskbarInAppDisplayProgressUpdate(progress, WIDGETS_PAGE_PROGRESS_INDEX);
        // Change of wallpaper depth in widget picker is disabled for tests as it causes flakiness
        // on very slow cuttlefish devices.
        if (ENABLE_WIDGET_PICKER_DEPTH.get() && !Utilities.IS_RUNNING_IN_TEST_HARNESS) {
        if (mEnableWidgetDepth) {
            WIDGET_DEPTH.set(getDepthController(),
                    Utilities.mapToRange(progress, 0f, 1f, 0f, getDeviceProfile().bottomSheetDepth,
                            EMPHASIZED));
+3 −2
Original line number Diff line number Diff line
@@ -34,11 +34,11 @@ import androidx.annotation.UiThread;

import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAnimUtils;
import com.android.launcher3.LauncherInitListener;
import com.android.launcher3.LauncherState;
import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.statehandlers.DepthController;
import com.android.launcher3.statehandlers.DepthController.ClampedDepthProperty;
import com.android.launcher3.statemanager.StateManager;
import com.android.launcher3.taskbar.LauncherTaskbarUIController;
import com.android.launcher3.touch.PagedOrientationHandler;
@@ -129,7 +129,8 @@ public final class LauncherActivityInterface extends
                float fromDepthRatio = BACKGROUND_APP.getDepth(activity);
                float toDepthRatio = OVERVIEW.getDepth(activity);
                pa.addFloat(getDepthController(),
                        new ClampedDepthProperty(fromDepthRatio, toDepthRatio),
                        new LauncherAnimUtils.ClampedProperty<>(
                                DepthController.STATE_DEPTH, fromDepthRatio, toDepthRatio),
                        fromDepthRatio, toDepthRatio, LINEAR);
            }
        };
+2 −2
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ public class BaseDepthController {
     * Ratio from 0 to 1, where 0 is fully zoomed out, and 1 is zoomed in.
     * @see android.service.wallpaper.WallpaperService.Engine#onZoomChanged(float)
     */
    protected float mDepth;
    private float mDepth;

    protected SurfaceControl mSurface;

@@ -143,7 +143,7 @@ public class BaseDepthController {
        }
    }

    protected void setDepth(float depth) {
    private void setDepth(float depth) {
        depth = Utilities.boundToRange(depth, 0, 1);
        // Round out the depth to dedupe frequent, non-perceptable updates
        int depthI = (int) (depth * 256);
+28 −0
Original line number Diff line number Diff line
@@ -218,4 +218,32 @@ public class LauncherAnimUtils {
            }
        };
    }

    /**
     * A property that updates the specified property within a given range of values (ie. even if
     * the animator goes beyond 0..1, the interpolated value will still be bounded).
     * @param <T> the specified property
     */
    public static class ClampedProperty<T> extends FloatProperty<T> {
        private final FloatProperty<T> mProperty;
        private final float mMinValue;
        private final float mMaxValue;

        public ClampedProperty(FloatProperty<T> property, float minValue, float maxValue) {
            super(property.getName() + "Clamped");
            mProperty = property;
            mMinValue = minValue;
            mMaxValue = maxValue;
        }

        @Override
        public void setValue(T t, float v) {
            mProperty.set(t, Utilities.boundToRange(v, mMinValue, mMaxValue));
        }

        @Override
        public Float get(T t) {
            return mProperty.get(t);
        }
    }
}
Loading