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>
This commit is contained in:
@@ -43,6 +43,8 @@
|
|||||||
<color name="settingslib_color_grey400">#bdc1c6</color>
|
<color name="settingslib_color_grey400">#bdc1c6</color>
|
||||||
<color name="settingslib_color_grey300">#dadce0</color>
|
<color name="settingslib_color_grey300">#dadce0</color>
|
||||||
<color name="settingslib_color_grey200">#e8eaed</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_orange600">#e8710a</color>
|
||||||
<color name="settingslib_color_orange400">#fa903e</color>
|
<color name="settingslib_color_orange400">#fa903e</color>
|
||||||
<color name="settingslib_color_orange300">#fcad70</color>
|
<color name="settingslib_color_orange300">#fcad70</color>
|
||||||
|
|||||||
@@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,6 +23,7 @@ import android.view.DisplayInfo
|
|||||||
import android.view.Surface
|
import android.view.Surface
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import com.airbnb.lottie.LottieAnimationView
|
import com.airbnb.lottie.LottieAnimationView
|
||||||
|
import com.android.settingslib.widget.LottieColorUtils
|
||||||
import com.android.systemui.R
|
import com.android.systemui.R
|
||||||
import com.android.systemui.biometrics.AuthBiometricView.BiometricState
|
import com.android.systemui.biometrics.AuthBiometricView.BiometricState
|
||||||
import com.android.systemui.biometrics.AuthBiometricView.STATE_AUTHENTICATED
|
import com.android.systemui.biometrics.AuthBiometricView.STATE_AUTHENTICATED
|
||||||
@@ -100,6 +101,8 @@ open class AuthBiometricFingerprintIconController(
|
|||||||
iconView.playAnimation()
|
iconView.playAnimation()
|
||||||
iconViewOverlay.playAnimation()
|
iconViewOverlay.playAnimation()
|
||||||
}
|
}
|
||||||
|
LottieColorUtils.applyDynamicColors(context, iconView)
|
||||||
|
LottieColorUtils.applyDynamicColors(context, iconViewOverlay)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateIconNormal(@BiometricState lastState: Int, @BiometricState newState: Int) {
|
private fun updateIconNormal(@BiometricState lastState: Int, @BiometricState newState: Int) {
|
||||||
@@ -118,6 +121,7 @@ open class AuthBiometricFingerprintIconController(
|
|||||||
if (shouldAnimateForTransition(lastState, newState)) {
|
if (shouldAnimateForTransition(lastState, newState)) {
|
||||||
iconView.playAnimation()
|
iconView.playAnimation()
|
||||||
}
|
}
|
||||||
|
LottieColorUtils.applyDynamicColors(context, iconView)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateIcon(@BiometricState lastState: Int, @BiometricState newState: Int) {
|
override fun updateIcon(@BiometricState lastState: Int, @BiometricState newState: Int) {
|
||||||
|
|||||||
Reference in New Issue
Block a user