From 71afdf2f19379377b576406585c5d5f3b358e26e Mon Sep 17 00:00:00 2001 From: Schneider Victor-tulias Date: Thu, 23 Nov 2023 11:53:19 -0500 Subject: [PATCH] Refactor LottieAnimationColorUtils to enforce proper usage Flag: N/A Fixes: 312941637 Test: launched all set page and gesture nav tutorial Change-Id: Iaa320fea0e78a93c4e955f617cb821a47aac6f96 --- .../taskbar/TaskbarEduTooltipController.kt | 2 +- .../quickstep/interaction/AllSetActivity.java | 2 +- .../BackGestureTutorialController.java | 4 +- .../HomeGestureTutorialController.java | 4 +- .../OverviewGestureTutorialController.java | 4 +- .../util/LottieAnimationColorUtils.java | 62 +++++++------------ 6 files changed, 32 insertions(+), 46 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarEduTooltipController.kt b/quickstep/src/com/android/launcher3/taskbar/TaskbarEduTooltipController.kt index d29f8eacbc..ea3411b075 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarEduTooltipController.kt +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarEduTooltipController.kt @@ -251,5 +251,5 @@ private fun LottieAnimationView.supportLightTheme() { return } - LottieAnimationColorUtils.updateColors(this, DARK_TO_LIGHT_COLORS, context.theme) + LottieAnimationColorUtils.updateToColorResources(this, DARK_TO_LIGHT_COLORS, context.theme) } diff --git a/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java b/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java index fce188f765..1bec97075a 100644 --- a/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java +++ b/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java @@ -184,7 +184,7 @@ public class AllSetActivity extends Activity { mAnimatedBackground.setAnimation(resources.openRawResource(R.raw.all_set_page_bg), null); - LottieAnimationColorUtils.updateColors( + LottieAnimationColorUtils.updateToColorResources( mAnimatedBackground, Map.of(LOTTIE_PRIMARY_COLOR_TOKEN, R.color.all_set_bg_primary, LOTTIE_TERTIARY_COLOR_TOKEN, R.color.all_set_bg_tertiary), diff --git a/quickstep/src/com/android/quickstep/interaction/BackGestureTutorialController.java b/quickstep/src/com/android/quickstep/interaction/BackGestureTutorialController.java index 631cff7639..404bca9795 100644 --- a/quickstep/src/com/android/quickstep/interaction/BackGestureTutorialController.java +++ b/quickstep/src/com/android/quickstep/interaction/BackGestureTutorialController.java @@ -41,13 +41,13 @@ final class BackGestureTutorialController extends TutorialController { super(fragment, tutorialType); // Set the Lottie animation colors specifically for the Back gesture if (ENABLE_NEW_GESTURE_NAV_TUTORIAL.get()) { - LottieAnimationColorUtils.updateColors( + LottieAnimationColorUtils.updateToArgbColors( mAnimatedGestureDemonstration, Map.of(".onSurfaceBack", fragment.mRootView.mColorOnSurfaceBack, ".surfaceBack", fragment.mRootView.mColorSurfaceBack, ".secondaryBack", fragment.mRootView.mColorSecondaryBack)); - LottieAnimationColorUtils.updateColors( + LottieAnimationColorUtils.updateToArgbColors( mCheckmarkAnimation, Map.of(".checkmark", Utilities.isDarkTheme(mContext) diff --git a/quickstep/src/com/android/quickstep/interaction/HomeGestureTutorialController.java b/quickstep/src/com/android/quickstep/interaction/HomeGestureTutorialController.java index daac99bfee..df552cffc6 100644 --- a/quickstep/src/com/android/quickstep/interaction/HomeGestureTutorialController.java +++ b/quickstep/src/com/android/quickstep/interaction/HomeGestureTutorialController.java @@ -38,13 +38,13 @@ final class HomeGestureTutorialController extends SwipeUpGestureTutorialControll // Set the Lottie animation colors specifically for the Home gesture if (ENABLE_NEW_GESTURE_NAV_TUTORIAL.get()) { - LottieAnimationColorUtils.updateColors( + LottieAnimationColorUtils.updateToArgbColors( mAnimatedGestureDemonstration, Map.of(".onSurfaceHome", fragment.mRootView.mColorOnSurfaceHome, ".surfaceHome", fragment.mRootView.mColorSurfaceHome, ".secondaryHome", fragment.mRootView.mColorSecondaryHome)); - LottieAnimationColorUtils.updateColors( + LottieAnimationColorUtils.updateToArgbColors( mCheckmarkAnimation, Map.of(".checkmark", Utilities.isDarkTheme(mContext) diff --git a/quickstep/src/com/android/quickstep/interaction/OverviewGestureTutorialController.java b/quickstep/src/com/android/quickstep/interaction/OverviewGestureTutorialController.java index afdc1e54a7..65f3a01149 100644 --- a/quickstep/src/com/android/quickstep/interaction/OverviewGestureTutorialController.java +++ b/quickstep/src/com/android/quickstep/interaction/OverviewGestureTutorialController.java @@ -53,13 +53,13 @@ final class OverviewGestureTutorialController extends SwipeUpGestureTutorialCont // Set the Lottie animation colors specifically for the Overview gesture if (ENABLE_NEW_GESTURE_NAV_TUTORIAL.get()) { - LottieAnimationColorUtils.updateColors( + LottieAnimationColorUtils.updateToArgbColors( mAnimatedGestureDemonstration, Map.of(".onSurfaceOverview", fragment.mRootView.mColorOnSurfaceOverview, ".surfaceOverview", fragment.mRootView.mColorSurfaceOverview, ".secondaryOverview", fragment.mRootView.mColorSecondaryOverview)); - LottieAnimationColorUtils.updateColors( + LottieAnimationColorUtils.updateToArgbColors( mCheckmarkAnimation, Map.of(".checkmark", Utilities.isDarkTheme(mContext) diff --git a/quickstep/src/com/android/quickstep/util/LottieAnimationColorUtils.java b/quickstep/src/com/android/quickstep/util/LottieAnimationColorUtils.java index f98b04bf54..8833b46802 100644 --- a/quickstep/src/com/android/quickstep/util/LottieAnimationColorUtils.java +++ b/quickstep/src/com/android/quickstep/util/LottieAnimationColorUtils.java @@ -17,13 +17,11 @@ package com.android.quickstep.util; import static com.airbnb.lottie.LottieProperty.COLOR_FILTER; -import android.content.res.Resources; import android.content.res.Resources.Theme; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import com.airbnb.lottie.LottieAnimationView; import com.airbnb.lottie.model.KeyPath; @@ -40,51 +38,39 @@ public final class LottieAnimationColorUtils { /** * Updates the given Lottie animation's tokenized colors according to the given mapping. *

- * Use this method signature only when {@code tokenToColorCodeMap} maps to packed ARBG color - * integers. - *

* @param animationView {@link LottieAnimationView} whose animation's colors need to be updated - * @param tokenToColorCodeMap A mapping from the color tokens used in the Lottie file used in + * @param tokenToArgbColorMap A mapping from the color tokens used in the Lottie file used in * {@code animationView} to packed ARBG color integers. */ - public static void updateColors( + public static void updateToArgbColors( @NonNull LottieAnimationView animationView, - @NonNull Map tokenToColorCodeMap) { - updateColors(animationView, tokenToColorCodeMap, null); - } - - /** - * Updates the given Lottie animation's tokenized colors according to the given mapping. - *

- * Use this method signature with a non-null theme only when {@code tokenToColorCodeMap} maps - * to color resource references. - *

- * @param animationView {@link LottieAnimationView} whose animation's colors need to be updated - * @param tokenToColorCodeMap A mapping from the color tokens used in the Lottie file used in - * {@code animationView} to packed ARBG color integers or color - * resource references. - * @param theme {@link Theme} to be used when resolving color resource references. {@code null} - * iff {@code tokenToColorCodeMap} maps to packed ARBG color integers. - */ - public static void updateColors( - @NonNull LottieAnimationView animationView, - @NonNull Map tokenToColorCodeMap, - @Nullable Theme theme) { - Resources resources = animationView.getResources(); - final Map tokenToColorMap = theme == null - // tokenToColorCodeMap maps directly to ARBG values - ? tokenToColorCodeMap - // tokenToColorCodeMap maps to color references, build a mapping to resolved colors - : tokenToColorCodeMap.keySet().stream().collect(Collectors.toMap( - Function.identity(), - token -> resources.getColor(tokenToColorCodeMap.get(token), theme))); - + @NonNull Map tokenToArgbColorMap) { animationView.addLottieOnCompositionLoadedListener( - composition -> tokenToColorMap.forEach( + composition -> tokenToArgbColorMap.forEach( (token, color) -> animationView.addValueCallback( new KeyPath("**", token, "**"), COLOR_FILTER, frameInfo -> new PorterDuffColorFilter( color, PorterDuff.Mode.SRC_ATOP)))); } + + /** + * Updates the given Lottie animation's tokenized colors according to the given mapping. + *

+ * @param animationView {@link LottieAnimationView} whose animation's colors need to be updated + * @param tokenToColorResourceMap A mapping from the color tokens used in the Lottie file used + * in {@code animationView} to color resource references. + * @param theme {@link Theme} to be used when resolving color resource references. + */ + public static void updateToColorResources( + @NonNull LottieAnimationView animationView, + @NonNull Map tokenToColorResourceMap, + @NonNull Theme theme) { + updateToArgbColors( + animationView, + tokenToColorResourceMap.keySet().stream().collect(Collectors.toMap( + Function.identity(), + token -> animationView.getResources().getColor( + tokenToColorResourceMap.get(token), theme)))); + } }