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

Commit fd32ceca authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I27f56426,I7b0d6cbb into main

* changes:
  Override the scrims alpha across the board to match the new UI specs
  Extract reusable logic into smaller methods
parents 41420865 5ce77909
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ import android.view.animation.DecelerateInterpolator;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.graphics.ColorUtils;
import com.android.systemui.statusbar.notification.stack.StackStateAnimator;
import static com.android.systemui.Flags.notificationShadeBlur;
import com.android.systemui.window.flag.WindowBlurFlag;

/**
 * Drawable used on SysUI scrims.
@@ -214,8 +214,9 @@ public class ScrimDrawable extends Drawable {
    public void draw(@NonNull Canvas canvas) {
        mPaint.setColor(mMainColor);
        mPaint.setAlpha(mAlpha);
        if (notificationShadeBlur()) {
        if (WindowBlurFlag.isEnabled()) {
            // TODO(b/370555223): Match the alpha to the visual spec when it is finalized.
            // TODO (b/381263600), wire this at ScrimController, move it to PrimaryBouncerTransition
            mPaint.setAlpha((int) (0.5f * mAlpha));
        }
        if (mConcaveInfo != null) {
+30 −17
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import androidx.dynamicanimation.animation.SpringAnimation
import androidx.dynamicanimation.animation.SpringForce
import com.android.app.animation.Interpolators
import com.android.systemui.Dumpable
import com.android.systemui.Flags.notificationShadeBlur
import com.android.systemui.animation.ShadeInterpolation
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dump.DumpManager
@@ -53,7 +54,6 @@ import java.io.PrintWriter
import javax.inject.Inject
import kotlin.math.max
import kotlin.math.sign
import com.android.systemui.Flags.notificationShadeBlur

/**
 * Responsible for blurring the notification shade window, and applying a zoom effect to the
@@ -212,19 +212,13 @@ constructor(
            shadeRadius = 0f
        }

        var zoomOut = MathUtils.saturate(blurUtils.ratioOfBlurRadius(shadeRadius))
        var blur = shadeRadius.toInt()

        if (inSplitShade) {
            zoomOut = 0f
        }

        val zoomOut = blurRadiusToZoomOut(blurRadius = shadeRadius)
        // Make blur be 0 if it is necessary to stop blur effect.
        if (scrimsVisible) {
            if (!notificationShadeBlur()) {
                blur = 0
            }
            zoomOut = 0f
        }

        if (!blurUtils.supportsBlursOnWindows()) {
@@ -237,22 +231,41 @@ constructor(
        return Pair(blur, zoomOut)
    }

    private fun blurRadiusToZoomOut(blurRadius: Float): Float {
        var zoomOut = MathUtils.saturate(blurUtils.ratioOfBlurRadius(blurRadius))
        if (inSplitShade) {
            zoomOut = 0f
        }

        if (scrimsVisible) {
            zoomOut = 0f
        }
        return zoomOut
    }

    private val shouldBlurBeOpaque: Boolean
        get() = if (notificationShadeBlur()) false else scrimsVisible && !blursDisabledForAppLaunch

    /** Callback that updates the window blur value and is called only once per frame. */
    @VisibleForTesting
    val updateBlurCallback =
        Choreographer.FrameCallback {
            updateScheduled = false
            val (blur, zoomOut) = computeBlurAndZoomOut()
            val opaque = if (notificationShadeBlur()) false else scrimsVisible && !blursDisabledForAppLaunch
            val (blur, zoomOutFromShadeRadius) = computeBlurAndZoomOut()
            val opaque = shouldBlurBeOpaque
            Trace.traceCounter(Trace.TRACE_TAG_APP, "shade_blur_radius", blur)
            blurUtils.applyBlur(root.viewRootImpl, blur, opaque)
            lastAppliedBlur = blur
            wallpaperController.setNotificationShadeZoom(zoomOut)
            onBlurApplied(blur, zoomOutFromShadeRadius)
        }

    private fun onBlurApplied(appliedBlurRadius: Int, zoomOutFromShadeRadius: Float) {
        lastAppliedBlur = appliedBlurRadius
        wallpaperController.setNotificationShadeZoom(zoomOutFromShadeRadius)
        listeners.forEach {
                it.onWallpaperZoomOutChanged(zoomOut)
                it.onBlurRadiusChanged(blur)
            it.onWallpaperZoomOutChanged(zoomOutFromShadeRadius)
            it.onBlurRadiusChanged(appliedBlurRadius)
        }
            notificationShadeWindowController.setBackgroundBlurRadius(blur)
        notificationShadeWindowController.setBackgroundBlurRadius(appliedBlurRadius)
    }

    /** Animate blurs when unlocking. */
+32 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.systemui.window.flag

import com.android.systemui.Flags

/**
 * Flag that controls whether the background surface is blurred or not while on the
 * lockscreen/shade/bouncer. This makes the background of scrim, bouncer and few other opaque
 * surfaces transparent so that we can see the blur effect on the background surface (wallpaper).
 */
object WindowBlurFlag {
    /** Whether the blur is enabled or not */
    @JvmStatic
    val isEnabled
        // Add flags here that require scrims/background surfaces to be transparent.
        get() = Flags.notificationShadeBlur() || Flags.bouncerUiRevamp()
}