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

Commit 40dc4415 authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Boost colors and animation of suggested actions

Boost chroma of suggestion chips, so colors really pop.
Also delay the animation a bit, so timing matches

Bug: 383567383
Test: atest SmartReplyScreenshotTest
Flag: com.android.systemui.notification_animated_actions_treatment
Change-Id: I6c87e039e4b4edd859abbd2c2d2375383eaa2de7
parent 28118aff
Loading
Loading
Loading
Loading
+90 −77
Original line number Diff line number Diff line
@@ -22,28 +22,27 @@ import android.content.res.ColorStateList
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.ColorFilter
import android.graphics.LinearGradient
import android.graphics.Matrix
import android.graphics.Paint
import android.graphics.Path
import android.graphics.PixelFormat
import android.graphics.drawable.Drawable
import android.graphics.LinearGradient
import android.graphics.Matrix
import android.graphics.Rect
import android.graphics.RectF
import android.graphics.Shader
import com.android.systemui.res.R
import com.android.wm.shell.shared.animation.Interpolators
import android.graphics.drawable.Drawable
import android.graphics.drawable.RippleDrawable
import androidx.core.content.ContextCompat
import androidx.core.graphics.ColorUtils
import com.android.systemui.res.R
import com.android.wm.shell.shared.animation.Interpolators

class AnimatedActionBackgroundDrawable(
    context: Context,
) : RippleDrawable(
    ContextCompat.getColorStateList(
        context,
        R.color.notification_ripple_untinted_color
    ) ?: ColorStateList.valueOf(Color.TRANSPARENT),
    createBaseDrawable(context), null
class AnimatedActionBackgroundDrawable(context: Context) :
    RippleDrawable(
        ContextCompat.getColorStateList(context, R.color.notification_ripple_untinted_color)
            ?: ColorStateList.valueOf(Color.TRANSPARENT),
        createBaseDrawable(context),
        null,
    ) {
    companion object {
        private fun createBaseDrawable(context: Context): Drawable {
@@ -52,56 +51,53 @@ class AnimatedActionBackgroundDrawable(
    }
}

class BaseBackgroundDrawable(
    context: Context,
) : Drawable() {
class BaseBackgroundDrawable(context: Context) : Drawable() {

    private val cornerRadius =
        context.resources.getDimensionPixelSize(R.dimen.animated_action_button_corner_radius)
        context.resources
            .getDimensionPixelSize(R.dimen.animated_action_button_corner_radius)
            .toFloat()

    // Stroke is clipped in draw() callback, so doubled in width here.
    private val outlineStrokeWidth =
        2 * context.resources.getDimensionPixelSize(R.dimen.animated_action_button_outline_stroke_width)
        2 *
            context.resources
                .getDimensionPixelSize(R.dimen.animated_action_button_outline_stroke_width)
                .toFloat()
    private val insetVertical =
        context.resources.getDimensionPixelSize(R.dimen.animated_action_button_inset_vertical)
        context.resources
            .getDimensionPixelSize(R.dimen.animated_action_button_inset_vertical)
            .toFloat()

    private val buttonShape = Path()
    // Color and style
    private val outlineStaticColor = context.getColor(R.color.animated_action_button_stroke_color)
    private val bgPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
    private val bgPaint =
        Paint(Paint.ANTI_ALIAS_FLAG).apply {
            val bgColor =
            context.getColor(
                com.android.internal.R.color.materialColorSurfaceContainerHigh
            )
                context.getColor(com.android.internal.R.color.materialColorSurfaceContainerHigh)
            color = bgColor
            style = Paint.Style.FILL
        }
    private val outlineGradientPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
    private val outlineGradientPaint =
        Paint(Paint.ANTI_ALIAS_FLAG).apply {
            color = outlineStaticColor
            style = Paint.Style.STROKE
            strokeWidth = outlineStrokeWidth
        }
    private val outlineSolidPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
    private val outlineSolidPaint =
        Paint(Paint.ANTI_ALIAS_FLAG).apply {
            color = outlineStaticColor
            style = Paint.Style.STROKE
            strokeWidth = outlineStrokeWidth
        }

    private val outlineStartColor =
        context.getColor(
            com.android.internal.R.color.materialColorTertiaryContainer
        )
        boostChroma(context.getColor(com.android.internal.R.color.materialColorTertiaryContainer))
    private val outlineMiddleColor =
        context.getColor(
            com.android.internal.R.color.materialColorPrimaryFixedDim
        )
        boostChroma(context.getColor(com.android.internal.R.color.materialColorPrimaryFixedDim))
    private val outlineEndColor =
        context.getColor(
            com.android.internal.R.color.materialColorPrimary
        )
        boostChroma(context.getColor(com.android.internal.R.color.materialColorPrimary))

    // Animation
    private var gradientAnimator: ValueAnimator
@@ -111,8 +107,10 @@ class BaseBackgroundDrawable(
    private var solidAlpha = 0 // Fading in solid color

    init {
        gradientAnimator = ValueAnimator.ofFloat(0f, 1f).apply {
            duration = 1500
        gradientAnimator =
            ValueAnimator.ofFloat(0f, 1f).apply {
                duration = 1750
                startDelay = 1000
                interpolator = Interpolators.LINEAR
                repeatCount = 0
                addUpdateListener { animator ->
@@ -122,9 +120,10 @@ class BaseBackgroundDrawable(
                }
                start()
            }
        fadeAnimator = ValueAnimator.ofFloat(0f, 1f).apply {
        fadeAnimator =
            ValueAnimator.ofFloat(0f, 1f).apply {
                duration = 500
            startDelay = 1000
                startDelay = 2250
                addUpdateListener { animator ->
                    val progress = animator.animatedValue as Float
                    gradientAlpha = ((1 - progress) * 255).toInt() // Fade out gradient
@@ -147,12 +146,15 @@ class BaseBackgroundDrawable(
        canvas.drawPath(buttonShape, bgPaint)

        // Set up outline gradient
        val gradientShader = LinearGradient(
            boundsF.left, boundsF.top,
            boundsF.right, boundsF.bottom,
        val gradientShader =
            LinearGradient(
                boundsF.left,
                boundsF.top,
                boundsF.right,
                boundsF.bottom,
                intArrayOf(outlineStartColor, outlineMiddleColor, outlineEndColor),
            null,
            Shader.TileMode.CLAMP
                floatArrayOf(0.2f, 0.5f, 0.8f),
                Shader.TileMode.CLAMP,
            )
        // Create a rotation matrix for the spiral effect
        val matrix = Matrix()
@@ -190,4 +192,15 @@ class BaseBackgroundDrawable(
    }

    override fun getOpacity(): Int = PixelFormat.TRANSLUCENT

    private fun boostChroma(color: Int): Int {
        val hctColor = FloatArray(3)
        ColorUtils.colorToM3HCT(color, hctColor)
        val chroma = hctColor[1]
        return if (chroma < 5) {
            color
        } else {
            ColorUtils.M3HCTToColor(hctColor[0], 120f, hctColor[2])
        }
    }
}