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

Commit 15a7514c authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Add damping to shade blurs

Mapping blur to expansion makes the animation feel to siff, let's use a
more physical metaphore by implementing a SpringAnimation

Bug: 149792636
Test: visual
Change-Id: Iadbcb5b472cbcfe4f37e96c20c845e9cd8926c2f
parent 19282c39
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -21,6 +21,9 @@ import android.animation.AnimatorListenerAdapter
import android.animation.ValueAnimator
import android.view.Choreographer
import android.view.View
import androidx.dynamicanimation.animation.FloatPropertyCompat
import androidx.dynamicanimation.animation.SpringAnimation
import androidx.dynamicanimation.animation.SpringForce
import com.android.internal.util.IndentingPrintWriter
import com.android.systemui.Dumpable
import com.android.systemui.Interpolators
@@ -59,6 +62,16 @@ class NotificationShadeWindowBlurController @Inject constructor(
    private var notificationAnimator: Animator? = null
    private var updateScheduled: Boolean = false
    private var shadeExpansion = 1.0f
    private val shadeSpring = SpringAnimation(this, object :
            FloatPropertyCompat<NotificationShadeWindowBlurController>("shadeBlurRadius") {
        override fun setValue(rect: NotificationShadeWindowBlurController?, value: Float) {
            shadeBlurRadius = value.toInt()
        }

        override fun getValue(rect: NotificationShadeWindowBlurController?): Float {
            return shadeBlurRadius.toFloat()
        }
    })
    private var shadeBlurRadius = 0
        set(value) {
            if (field == value) return
@@ -135,6 +148,9 @@ class NotificationShadeWindowBlurController @Inject constructor(
        if (WAKE_UP_ANIMATION_ENABLED) {
            keyguardStateController.addCallback(keyguardStateCallback)
        }
        shadeSpring.spring = SpringForce(0.0f)
        shadeSpring.spring.dampingRatio = SpringForce.DAMPING_RATIO_NO_BOUNCY
        shadeSpring.spring.stiffness = SpringForce.STIFFNESS_LOW
    }

    /**
@@ -153,8 +169,7 @@ class NotificationShadeWindowBlurController @Inject constructor(
        if (shadeBlurRadius == newBlur) {
            return
        }
        shadeBlurRadius = newBlur
        scheduleUpdate()
        shadeSpring.animateToFinalPosition(newBlur.toFloat())
    }

    private fun scheduleUpdate() {