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

Commit 54049391 authored by Grace Cheng's avatar Grace Cheng Committed by Android (Google) Code Review
Browse files

Merge "Add dynamic coloring for secure lock device asset" into main

parents 86b8eb03 ea19b1dd
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -36,8 +36,8 @@ import java.util.Map;
 * (DT) and Light Theme (LT). This class assumes the json file is for Dark Theme.
 */
public class LottieColorUtils {
    private static final Map<String, Integer> DARK_TO_LIGHT_THEME_COLOR_MAP;
    private static final Map<String, Integer> MATERIAL_COLOR_MAP;
    public static final Map<String, Integer> DARK_TO_LIGHT_THEME_COLOR_MAP;
    public static final Map<String, Integer> MATERIAL_COLOR_MAP;

    static {
        DARK_TO_LIGHT_THEME_COLOR_MAP = Map.ofEntries(
@@ -133,7 +133,12 @@ public class LottieColorUtils {
    private LottieColorUtils() {
    }

    private static boolean isDarkMode(Context context) {
    /**
     * Checks if the current theme is dark mode.
     * @param context the current context
     * @return true if the current theme is dark mode, false otherwise
     */
    public static boolean isDarkMode(Context context) {
        return (context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK)
                == Configuration.UI_MODE_NIGHT_YES;
    }
+3 −1
Original line number Diff line number Diff line
@@ -43,10 +43,12 @@ import com.airbnb.lottie.compose.LottieConstants
import com.airbnb.lottie.compose.rememberLottieComposition
import com.android.compose.modifiers.height
import com.android.compose.modifiers.width
import com.android.systemui.Flags.bpColors
import com.android.systemui.biometrics.BiometricAuthIconAssets
import com.android.systemui.lifecycle.rememberActivated
import com.android.systemui.res.R
import com.android.systemui.securelockdevice.ui.viewmodel.SecureLockDeviceBiometricAuthContentViewModel
import com.android.systemui.util.ui.compose.LottieColorUtils
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.DurationUnit

@@ -139,7 +141,6 @@ private fun BiometricIconLottie(
        } else {
            0
        }
    // TODO(b/437829879): figure out lottie dynamic coloring

    val numIterations =
        if (iconState.shouldLoop) {
@@ -150,6 +151,7 @@ private fun BiometricIconLottie(

    LottieAnimation(
        composition = lottie,
        dynamicProperties = LottieColorUtils.getDynamicProperties(bpColors()),
        modifier =
            modifier
                .graphicsLayer { rotationZ = iconState.rotation }
+76 −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.util.ui.compose

import android.graphics.ColorFilter
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import com.airbnb.lottie.LottieProperty
import com.airbnb.lottie.compose.LottieDynamicProperties
import com.airbnb.lottie.compose.LottieDynamicProperty
import com.airbnb.lottie.compose.rememberLottieDynamicProperties
import com.airbnb.lottie.compose.rememberLottieDynamicProperty
import com.android.settingslib.widget.LottieColorUtils

/**
 * Kotlin util class which dynamically changes the color of tags in a lottie json file between Dark
 * Theme (DT) and Light Theme (LT). This class assumes the json file is for Dark Theme.
 */
object LottieColorUtils {
    /**
     * Returns [com.airbnb.lottie.compose.LottieDynamicProperties] object for composables to apply
     * dynamic colors based on DT vs. LT, and optionally material colors based on the value of
     * includeMaterialColorProperties.
     *
     * @param includeMaterialColorProperties whether to include material color properties
     */
    @Composable
    fun getDynamicProperties(includeMaterialColorProperties: Boolean): LottieDynamicProperties? {
        val context = LocalContext.current
        val allProperties = mutableListOf<LottieDynamicProperty<ColorFilter>>()

        if (!LottieColorUtils.isDarkMode(context)) {
            val dynamicColorProperties =
                LottieColorUtils.DARK_TO_LIGHT_THEME_COLOR_MAP.map { (key, colorResId) ->
                    val color = context.getColor(colorResId)
                    rememberLottieDynamicProperty(
                        property = LottieProperty.COLOR_FILTER,
                        value = PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP),
                        keyPath = arrayOf("**", key, "**"),
                    )
                }
            allProperties.addAll(dynamicColorProperties)
        }

        if (includeMaterialColorProperties) {
            val materialColorProperties =
                LottieColorUtils.MATERIAL_COLOR_MAP.map { (key, colorResId) ->
                    val color = context.getColor(colorResId)
                    rememberLottieDynamicProperty(
                        property = LottieProperty.COLOR_FILTER,
                        value = PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP),
                        keyPath = arrayOf("**", key, "**"),
                    )
                }
            allProperties.addAll(materialColorProperties)
        }

        return rememberLottieDynamicProperties(*allProperties.toTypedArray())
    }
}