diff options
| author | 2022-09-09 16:27:28 +0000 | |
|---|---|---|
| committer | 2022-09-09 16:27:28 +0000 | |
| commit | d1633d97c9924f16cc1313cd4b8701256463bb8e (patch) | |
| tree | 092e44b705867cb301245d870052598364f84f55 | |
| parent | f5a8749afdd44581116214f9d6b0bd82d9c2fb54 (diff) | |
| parent | 17b52d76006a47699eab8a4bec7547e9482c12b4 (diff) | |
Merge "Added color light/dark theme for lotties" into tm-qpr-dev am: 17b52d7600
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19833106
Change-Id: I3cd64745b7b0c57ca55dd45d4bd1b31b223a1bbb
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
3 files changed, 94 insertions, 0 deletions
| diff --git a/packages/SettingsLib/IllustrationPreference/res/values/colors.xml b/packages/SettingsLib/IllustrationPreference/res/values/colors.xml index ead5174f9ee2..0de7be0a5a08 100644 --- a/packages/SettingsLib/IllustrationPreference/res/values/colors.xml +++ b/packages/SettingsLib/IllustrationPreference/res/values/colors.xml @@ -43,6 +43,8 @@      <color name="settingslib_color_grey400">#bdc1c6</color>      <color name="settingslib_color_grey300">#dadce0</color>      <color name="settingslib_color_grey200">#e8eaed</color> +    <color name="settingslib_color_grey100">#f1f3f4</color> +    <color name="settingslib_color_grey50">#f8f9fa</color>      <color name="settingslib_color_orange600">#e8710a</color>      <color name="settingslib_color_orange400">#fa903e</color>      <color name="settingslib_color_orange300">#fcad70</color> diff --git a/packages/SettingsLib/IllustrationPreference/src/com/android/settingslib/widget/LottieColorUtils.java b/packages/SettingsLib/IllustrationPreference/src/com/android/settingslib/widget/LottieColorUtils.java new file mode 100644 index 000000000000..93b6acc9e160 --- /dev/null +++ b/packages/SettingsLib/IllustrationPreference/src/com/android/settingslib/widget/LottieColorUtils.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2022 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.settingslib.widget; + +import android.content.Context; +import android.content.res.Configuration; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffColorFilter; + +import com.airbnb.lottie.LottieAnimationView; +import com.airbnb.lottie.LottieProperty; +import com.airbnb.lottie.model.KeyPath; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** + * 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. + */ +public class LottieColorUtils { +    private static final Map<String, Integer> DARK_TO_LIGHT_THEME_COLOR_MAP; + +    static { +        HashMap<String, Integer> map = new HashMap<>(); +        map.put( +                ".grey600", +                R.color.settingslib_color_grey300); +        map.put( +                ".grey800", +                R.color.settingslib_color_grey200); +        map.put( +                ".grey900", +                R.color.settingslib_color_grey50); +        map.put( +                ".red400", +                R.color.settingslib_color_red600); +        map.put( +                ".black", +                android.R.color.white); +        map.put( +                ".blue400", +                R.color.settingslib_color_blue600); +        map.put( +                ".green400", +                R.color.settingslib_color_green600); +        DARK_TO_LIGHT_THEME_COLOR_MAP = Collections.unmodifiableMap(map); +    } + +    private LottieColorUtils() { +    } + +    private static boolean isDarkMode(Context context) { +        return (context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) +                == Configuration.UI_MODE_NIGHT_YES; +    } + +    /** Applies dynamic colors based on DT vs. LT. The LottieAnimationView should be Dark Theme. */ +    public static void applyDynamicColors(Context context, +            LottieAnimationView lottieAnimationView) { +        // Assume the default for the lottie is dark mode +        if (isDarkMode(context)) { +            return; +        } +        for (String key : DARK_TO_LIGHT_THEME_COLOR_MAP.keySet()) { +            final int color = context.getColor(DARK_TO_LIGHT_THEME_COLOR_MAP.get(key)); +            lottieAnimationView.addValueCallback( +                    new KeyPath("**", key, "**"), +                    LottieProperty.COLOR_FILTER, +                    frameInfo -> new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP)); +        } +    } +} diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricFingerprintIconController.kt b/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricFingerprintIconController.kt index 65c4e138691d..b40b3560f9db 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricFingerprintIconController.kt +++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricFingerprintIconController.kt @@ -23,6 +23,7 @@ import android.view.DisplayInfo  import android.view.Surface  import android.view.View  import com.airbnb.lottie.LottieAnimationView +import com.android.settingslib.widget.LottieColorUtils  import com.android.systemui.R  import com.android.systemui.biometrics.AuthBiometricView.BiometricState  import com.android.systemui.biometrics.AuthBiometricView.STATE_AUTHENTICATED @@ -100,6 +101,8 @@ open class AuthBiometricFingerprintIconController(              iconView.playAnimation()              iconViewOverlay.playAnimation()          } +        LottieColorUtils.applyDynamicColors(context, iconView) +        LottieColorUtils.applyDynamicColors(context, iconViewOverlay)      }      private fun updateIconNormal(@BiometricState lastState: Int, @BiometricState newState: Int) { @@ -118,6 +121,7 @@ open class AuthBiometricFingerprintIconController(          if (shouldAnimateForTransition(lastState, newState)) {              iconView.playAnimation()          } +        LottieColorUtils.applyDynamicColors(context, iconView)      }      override fun updateIcon(@BiometricState lastState: Int, @BiometricState newState: Int) { |