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

Commit 290fe013 authored by Lucas Dupin's avatar Lucas Dupin Committed by Android (Google) Code Review
Browse files

Merge "Updated pill and button spec" into main

parents ffb20883 9471e8a3
Loading
Loading
Loading
Loading
+20 −6
Original line number Diff line number Diff line
@@ -20,9 +20,10 @@ import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.scaleIn
import androidx.compose.animation.scaleOut
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.Composable
@@ -42,7 +43,6 @@ fun ActionList(actions: List<ActionViewModel>, visible: Boolean, modifier: Modif
        horizontalAlignment = Alignment.CenterHorizontally,
    ) {
        actions.fastForEachIndexed { index, action ->
            val delay = 64 * (actions.size - index)
            AnimatedVisibility(
                visible = visible,
                enter =
@@ -52,9 +52,23 @@ fun ActionList(actions: List<ActionViewModel>, visible: Boolean, modifier: Modif
                            stiffness = Spring.StiffnessLow,
                        )
                    ) {
                        with(density) { 15.dp.roundToPx() * (actions.size - index) }
                    } + fadeIn(tween(450, delayMillis = delay)),
                exit = fadeOut(tween(350, delayMillis = delay)),
                        with(density) { it * (actions.size - index) }
                    } +
                        scaleIn(
                            spring(
                                dampingRatio = Spring.DampingRatioNoBouncy,
                                stiffness = Spring.StiffnessLow,
                            )
                        ),
                exit =
                    slideOutVertically(
                        spring(
                            dampingRatio = Spring.DampingRatioMediumBouncy,
                            stiffness = Spring.StiffnessLow,
                        )
                    ) {
                        with(density) { it * (actions.size - index) }
                    } + scaleOut(tween(250)),
            ) {
                Chip(action)
            }
+1 −11
Original line number Diff line number Diff line
@@ -38,8 +38,8 @@ import androidx.compose.ui.graphics.ShaderBrush
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.dp
import androidx.core.graphics.ColorUtils
import com.android.systemui.ambientcue.ui.shader.BackgroundGlowShader
import com.android.systemui.ambientcue.ui.utils.AiColorUtils.boostChroma

@Composable
fun BackgroundGlow(visible: Boolean, expanded: Boolean, modifier: Modifier) {
@@ -92,16 +92,6 @@ fun BackgroundGlow(visible: Boolean, expanded: Boolean, modifier: Modifier) {
    )
}

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

private object Defaults {
    const val COLLAPSED_TRANSLATION_DP = 110
    const val TURBULENCE_SIZE = 4.7f
+7 −2
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
@@ -56,6 +55,7 @@ import androidx.compose.ui.util.fastForEach
import androidx.compose.ui.util.lerp
import com.android.compose.PlatformIconButton
import com.android.compose.ui.graphics.painter.rememberDrawablePainter
import com.android.systemui.ambientcue.ui.compose.modifier.animatedActionBorder
import com.android.systemui.ambientcue.ui.viewmodel.ActionViewModel
import com.android.systemui.res.R

@@ -114,9 +114,14 @@ fun NavBarPill(
                verticalAlignment = Alignment.CenterVertically,
                modifier =
                    Modifier.clip(RoundedCornerShape(16.dp))
                        .border(2.dp, outlineColor, RoundedCornerShape(16.dp))
                        .defaultMinSize(minWidth = navBarWidth)
                        .background(backgroundColor)
                        .animatedActionBorder(
                            strokeWidth = 2.dp,
                            strokeColor = outlineColor,
                            cornerRadius = 16.dp,
                            visible = visible,
                        )
                        .clickable { onClick() }
                        .padding(horizontal = 8.dp, vertical = 6.dp)
                        .onGloballyPositioned { expandedSize = it.size },
+155 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.ambientcue.ui.compose.modifier

import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.tween
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.geometry.CornerRadius
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.geometry.center
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.TileMode
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Dp
import com.android.systemui.ambientcue.ui.utils.AiColorUtils.boostChroma
import kotlin.math.cos
import kotlin.math.sin
import kotlinx.coroutines.launch

@Composable
fun Modifier.animatedActionBorder(
    strokeWidth: Dp,
    strokeColor: Color,
    cornerRadius: Dp,
    visible: Boolean = true,
): Modifier {
    val rotationAngle = remember { Animatable(Constants.INITIAL_ROTATION_DEGREES) }
    val fadeProgress = remember { Animatable(0f) } // 0f = full gradient, 1f = full solid

    val strokeWidthPx = with(LocalDensity.current) { strokeWidth.toPx() }
    val halfStroke = strokeWidthPx / 2f
    val topLeft = Offset(halfStroke, halfStroke)
    val strokeAnimStartColor =
        Color(boostChroma(MaterialTheme.colorScheme.tertiaryContainer.toArgb()))
    val strokeAnimMiddleColor =
        Color(boostChroma(dynamicDarkColorScheme(LocalContext.current).primary.toArgb()))
    val strokeAnimEndColor = Color(boostChroma(MaterialTheme.colorScheme.primary.toArgb()))

    // Trigger animations when the composable enters the composition
    LaunchedEffect(visible) {
        if (visible) {
            launch {
                rotationAngle.snapTo(Constants.INITIAL_ROTATION_DEGREES)
                rotationAngle.animateTo(
                    targetValue = Constants.INITIAL_ROTATION_DEGREES + 360f,
                    animationSpec =
                        tween(
                            durationMillis = Constants.ROTATION_DURATION_MILLIS,
                            easing = LinearEasing,
                        ),
                )
            }

            launch {
                fadeProgress.snapTo(0f)
                fadeProgress.animateTo(
                    targetValue = 1f,
                    animationSpec =
                        tween(
                            durationMillis = Constants.FADE_DURATION_MILLIS,
                            delayMillis = Constants.FADE_DELAY_MILLIS,
                            easing = LinearEasing,
                        ),
                )
            }
        }
    }

    return drawWithContent {
        val currentRotationRad = Math.toRadians(rotationAngle.value.toDouble()).toFloat()
        val solidOutlineFadeIn = fadeProgress.value

        val gradientOutlineFadeOut = (1f - solidOutlineFadeIn)
        val cornerRadiusPx = with(density) { cornerRadius.toPx() }
        val gradientWidth = size.width / 2f

        val center = size.center
        val strokeStyle = Stroke(width = strokeWidthPx)

        // Gradient
        val cosTheta = cos(currentRotationRad)
        val sinTheta = sin(currentRotationRad)

        val startOffset =
            Offset(x = center.x - gradientWidth * cosTheta, y = center.y - gradientWidth * sinTheta)
        val endOffset =
            Offset(x = center.x + gradientWidth * cosTheta, y = center.y + gradientWidth * sinTheta)

        val gradientBrush =
            Brush.linearGradient(
                Constants.GRADIENT_START_FRACTION to strokeAnimStartColor,
                Constants.GRADIENT_MIDDLE_FRACTION to strokeAnimMiddleColor,
                Constants.GRADIENT_END_FRACTION to strokeAnimEndColor,
                start = startOffset,
                end = endOffset,
                tileMode = TileMode.Clamp,
            )

        drawRoundRect(
            brush = gradientBrush,
            topLeft = topLeft,
            size = Size(size.width - strokeWidthPx, size.height - strokeWidthPx),
            cornerRadius = CornerRadius(cornerRadiusPx),
            alpha = gradientOutlineFadeOut,
            style = strokeStyle,
        )

        drawRoundRect(
            color = strokeColor,
            topLeft = topLeft,
            size = Size(size.width - strokeWidthPx, size.height - strokeWidthPx),
            cornerRadius = CornerRadius(cornerRadiusPx),
            alpha = solidOutlineFadeIn,
            style = strokeStyle,
        )

        drawContent()
    }
}

private object Constants {
    const val INITIAL_ROTATION_DEGREES: Float = 20f // Start rotation at 20 degrees
    const val GRADIENT_START_FRACTION = 0.2f
    const val GRADIENT_MIDDLE_FRACTION = 0.5f
    const val GRADIENT_END_FRACTION = 0.8f
    const val ROTATION_DURATION_MILLIS: Int = 1500
    const val FADE_DURATION_MILLIS: Int = 500
    const val FADE_DELAY_MILLIS: Int = 1000
}
+34 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.ambientcue.ui.utils

import androidx.core.graphics.ColorUtils

object AiColorUtils {
    /**
     * Sets the chroma of a color to the maximum possible - unless it's a very desaturated color.
     */
    fun boostChroma(color: Int): Int {
        val outColor = FloatArray(3)
        ColorUtils.colorToM3HCT(color, outColor)
        val chroma = outColor[1]
        if (chroma <= 5) {
            return color
        }
        return ColorUtils.M3HCTToColor(outColor[0], 120f, outColor[2])
    }
}