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

Commit 3d768975 authored by Johannes Gallmann's avatar Johannes Gallmann
Browse files

Use better heuristic for when to apply statusbar customization during predictive back

Bug: 341921089
Flag: ACONFIG com.android.window.flags.predictive_back_system_anims NEXTFOOD
Test: Manual, i.e. verifying on device that the color switch happens when the closing window passes the middle of the statusbar
Change-Id: I7116a3808880ed504f8d41b0ba97f16406992e8c
parent e71598ed
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -19,8 +19,6 @@ package com.android.wm.shell.back;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS;

import static com.android.wm.shell.back.BackAnimationConstants.UPDATE_SYSUI_FLAGS_THRESHOLD;

import android.annotation.NonNull;
import android.graphics.Color;
import android.graphics.Rect;
@@ -45,6 +43,7 @@ public class BackAnimationBackground {
    private boolean mIsRequestingStatusBarAppearance;
    private boolean mBackgroundIsDark;
    private Rect mStartBounds;
    private int mStatusbarHeight;

    public BackAnimationBackground(RootTaskDisplayAreaOrganizer rootTaskDisplayAreaOrganizer) {
        mRootTaskDisplayAreaOrganizer = rootTaskDisplayAreaOrganizer;
@@ -56,9 +55,10 @@ public class BackAnimationBackground {
     * @param startRect The start bounds of the closing target.
     * @param color The background color.
     * @param transaction The animation transaction.
     * @param statusbarHeight The height of the statusbar (in px).
     */
    public void ensureBackground(
            Rect startRect, int color, @NonNull SurfaceControl.Transaction transaction) {
    public void ensureBackground(Rect startRect, int color,
            @NonNull SurfaceControl.Transaction transaction, int statusbarHeight) {
        if (mBackgroundSurface != null) {
            return;
        }
@@ -80,6 +80,7 @@ public class BackAnimationBackground {
                .show(mBackgroundSurface);
        mStartBounds = startRect;
        mIsRequestingStatusBarAppearance = false;
        mStatusbarHeight = statusbarHeight;
    }

    /**
@@ -111,14 +112,14 @@ public class BackAnimationBackground {
    /**
     * Update back animation background with for the progress.
     *
     * @param progress Progress value from {@link android.window.BackProgressAnimator}
     * @param top The top coordinate of the closing target
     */
    public void onBackProgressed(float progress) {
    public void customizeStatusBarAppearance(int top) {
        if (mCustomizer == null || mStartBounds.isEmpty()) {
            return;
        }

        final boolean shouldCustomizeSystemBar = progress > UPDATE_SYSUI_FLAGS_THRESHOLD;
        final boolean shouldCustomizeSystemBar = top > mStatusbarHeight / 2;
        if (shouldCustomizeSystemBar == mIsRequestingStatusBarAppearance) {
            return;
        }
+6 −2
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import com.android.internal.dynamicanimation.animation.SpringAnimation
import com.android.internal.dynamicanimation.animation.SpringForce
import com.android.internal.jank.Cuj
import com.android.internal.policy.ScreenDecorationsUtils
import com.android.internal.policy.SystemBarUtils
import com.android.internal.protolog.common.ProtoLog
import com.android.wm.shell.R
import com.android.wm.shell.RootTaskDisplayAreaOrganizer
@@ -76,6 +77,7 @@ abstract class CrossActivityBackAnimation(
    private val tempRectF = RectF()

    private var cornerRadius = ScreenDecorationsUtils.getWindowCornerRadius(context)
    private var statusbarHeight = SystemBarUtils.getStatusBarHeight(context)

    private val backAnimationRunner =
        BackAnimationRunner(Callback(), Runner(), context, Cuj.CUJ_PREDICTIVE_BACK_CROSS_ACTIVITY)
@@ -137,6 +139,7 @@ abstract class CrossActivityBackAnimation(

    override fun onConfigurationChanged(newConfiguration: Configuration) {
        cornerRadius = ScreenDecorationsUtils.getWindowCornerRadius(context)
        statusbarHeight = SystemBarUtils.getStatusBarHeight(context)
    }

    override fun getRunner() = backAnimationRunner
@@ -182,7 +185,8 @@ abstract class CrossActivityBackAnimation(
        background.ensureBackground(
            closingTarget!!.windowConfiguration.bounds,
            getBackgroundColor(),
            transaction
            transaction,
            statusbarHeight
        )
        ensureScrimLayer()
        if (isLetterboxed && enteringHasSameLetterbox) {
@@ -203,7 +207,6 @@ abstract class CrossActivityBackAnimation(

    private fun onGestureProgress(backEvent: BackEvent) {
        val progress = gestureInterpolator.getInterpolation(backEvent.progress)
        background.onBackProgressed(progress)
        currentClosingRect.setInterpolatedRectF(startClosingRect, targetClosingRect, progress)
        val yOffset = getYOffset(currentClosingRect, backEvent.touchY)
        currentClosingRect.offset(0f, yOffset)
@@ -218,6 +221,7 @@ abstract class CrossActivityBackAnimation(
            enteringTransformation
        )
        applyTransaction()
        background.customizeStatusBarAppearance(currentClosingRect.top.toInt())
    }

    private fun getYOffset(centeredRect: RectF, touchY: Float): Float {
+10 −3
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import android.window.BackProgressAnimator;
import android.window.IOnBackInvokedCallback;

import com.android.internal.policy.ScreenDecorationsUtils;
import com.android.internal.policy.SystemBarUtils;
import com.android.internal.protolog.common.ProtoLog;
import com.android.wm.shell.R;
import com.android.wm.shell.animation.Interpolators;
@@ -82,6 +83,7 @@ public class CrossTaskBackAnimation extends ShellBackAnimation {

    private final Rect mStartTaskRect = new Rect();
    private float mCornerRadius;
    private int mStatusbarHeight;

    // The closing window properties.
    private final Rect mClosingStartRect = new Rect();
@@ -114,16 +116,21 @@ public class CrossTaskBackAnimation extends ShellBackAnimation {

    @Inject
    public CrossTaskBackAnimation(Context context, BackAnimationBackground background) {
        mCornerRadius = ScreenDecorationsUtils.getWindowCornerRadius(context);
        mBackAnimationRunner = new BackAnimationRunner(
                new Callback(), new Runner(), context, CUJ_PREDICTIVE_BACK_CROSS_TASK);
        mBackground = background;
        mContext = context;
        loadResources();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        loadResources();
    }

    private void loadResources() {
        mCornerRadius = ScreenDecorationsUtils.getWindowCornerRadius(mContext);
        mStatusbarHeight = SystemBarUtils.getStatusBarHeight(mContext);
    }

    private static float mapRange(float value, float min, float max) {
@@ -149,7 +156,7 @@ public class CrossTaskBackAnimation extends ShellBackAnimation {

        // Draw background.
        mBackground.ensureBackground(mClosingTarget.windowConfiguration.getBounds(),
                BACKGROUNDCOLOR, mTransaction);
                BACKGROUNDCOLOR, mTransaction, mStatusbarHeight);
        mInterWindowMargin = mContext.getResources()
                .getDimension(R.dimen.cross_task_back_inter_window_margin);
        mVerticalMargin = mContext.getResources()
@@ -201,7 +208,7 @@ public class CrossTaskBackAnimation extends ShellBackAnimation {
        applyTransform(mEnteringTarget.leash, mEnteringCurrentRect, mCornerRadius);
        applyTransaction();

        mBackground.onBackProgressed(progress);
        mBackground.customizeStatusBarAppearance((int) scaledTop);
    }

    private void updatePostCommitClosingAnimation(float progress) {