Update the All set page lottie animation to use dynamic colors

Flag: not needed
Fixes: 263088674
Test: Launched the All set page on handheld, foldable and tablet
Change-Id: I5c742985c3fcce32742553f0ab5d237c1a77f991
This commit is contained in:
Schneider Victor-tulias
2023-03-27 11:16:29 -07:00
parent 296f8776f7
commit 5285763d99
11 changed files with 153 additions and 17 deletions
@@ -15,8 +15,6 @@
*/
package com.android.launcher3.taskbar
import android.graphics.PorterDuff.Mode.SRC_ATOP
import android.graphics.PorterDuffColorFilter
import android.os.Bundle
import android.view.View
import android.view.View.GONE
@@ -27,8 +25,6 @@ import android.view.accessibility.AccessibilityNodeInfo
import androidx.annotation.IntDef
import androidx.annotation.LayoutRes
import com.airbnb.lottie.LottieAnimationView
import com.airbnb.lottie.LottieProperty.COLOR_FILTER
import com.airbnb.lottie.model.KeyPath
import com.android.launcher3.R
import com.android.launcher3.Utilities
import com.android.launcher3.config.FeatureFlags.ENABLE_TASKBAR_EDU_TOOLTIP
@@ -36,6 +32,7 @@ import com.android.launcher3.taskbar.TaskbarAutohideSuspendController.FLAG_AUTOH
import com.android.launcher3.taskbar.TaskbarControllers.LoggableTaskbarController
import com.android.launcher3.util.DisplayController
import com.android.launcher3.util.OnboardingPrefs.TASKBAR_EDU_TOOLTIP_STEP
import com.android.quickstep.util.LottieAnimationColorUtils
import java.io.PrintWriter
/** First EDU step for swiping up to show transient Taskbar. */
@@ -240,11 +237,5 @@ private fun LottieAnimationView.supportLightTheme() {
return
}
addLottieOnCompositionLoadedListener {
DARK_TO_LIGHT_COLORS.forEach { (key, color) ->
addValueCallback(KeyPath("**", key, "**"), COLOR_FILTER) {
PorterDuffColorFilter(context.getColor(color), SRC_ATOP)
}
}
}
LottieAnimationColorUtils.updateColors(this, DARK_TO_LIGHT_COLORS, context.theme)
}
@@ -26,6 +26,7 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
@@ -63,11 +64,13 @@ import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.util.Executors;
import com.android.quickstep.GestureState;
import com.android.quickstep.TouchInteractionService.TISBinder;
import com.android.quickstep.util.LottieAnimationColorUtils;
import com.android.quickstep.util.TISBindHelper;
import com.airbnb.lottie.LottieAnimationView;
import java.net.URISyntaxException;
import java.util.Map;
/**
* A page shows after SUW flow to hint users to swipe up from the bottom of the screen to go home
@@ -82,6 +85,9 @@ public class AllSetActivity extends Activity {
private static final String EXTRA_ACCENT_COLOR_LIGHT_MODE = "suwColorAccentLight";
private static final String EXTRA_DEVICE_NAME = "suwDeviceName";
private static final String LOTTIE_PRIMARY_COLOR_TOKEN = ".primary";
private static final String LOTTIE_TERTIARY_COLOR_TOKEN = ".tertiary";
private static final float HINT_BOTTOM_FACTOR = 1 - .94f;
private static final int MAX_SWIPE_DURATION = 350;
@@ -114,7 +120,8 @@ public class AllSetActivity extends Activity {
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
int mode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
Resources resources = getResources();
int mode = resources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
boolean isDarkTheme = mode == Configuration.UI_MODE_NIGHT_YES;
Intent intent = getIntent();
int accentColor = intent.getIntExtra(
@@ -126,7 +133,7 @@ public class AllSetActivity extends Activity {
mBackground = new BgDrawable(this);
findViewById(R.id.root_view).setBackground(mBackground);
mContentView = findViewById(R.id.content_view);
mSwipeUpShift = getResources().getDimension(R.dimen.allset_swipe_up_shift);
mSwipeUpShift = resources.getDimension(R.dimen.allset_swipe_up_shift);
TextView subtitle = findViewById(R.id.subtitle);
String suwDeviceName = intent.getStringExtra(EXTRA_DEVICE_NAME);
@@ -188,8 +195,15 @@ public class AllSetActivity extends Activity {
// There's a bug in the currently used external Lottie library (v5.2.0), and it doesn't load
// the correct animation from the raw resources when configuration changes, so we need to
// manually load the resource and pass it to Lottie.
mAnimatedBackground.setAnimation(getResources().openRawResource(R.raw.all_set_page_bg),
mAnimatedBackground.setAnimation(resources.openRawResource(R.raw.all_set_page_bg),
null);
LottieAnimationColorUtils.updateColors(
mAnimatedBackground,
Map.of(LOTTIE_PRIMARY_COLOR_TOKEN, R.color.all_set_bg_primary,
LOTTIE_TERTIARY_COLOR_TOKEN, R.color.all_set_bg_tertiary),
getTheme());
startBackgroundAnimation();
}
@@ -0,0 +1,90 @@
/*
* Copyright (C) 2023 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.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;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/** Utility class for programmatically updating Lottie animation tokenized colors. */
public final class LottieAnimationColorUtils {
private LottieAnimationColorUtils() {}
/**
* Updates the given Lottie animation's tokenized colors according to the given mapping.
* <p>
* Use this method signature only when {@code tokenToColorCodeMap} maps to packed ARBG color
* integers.
* <p>
* @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.
*/
public static void updateColors(
@NonNull LottieAnimationView animationView,
@NonNull Map<String, Integer> tokenToColorCodeMap) {
updateColors(animationView, tokenToColorCodeMap, null);
}
/**
* Updates the given Lottie animation's tokenized colors according to the given mapping.
* <p>
* Use this method signature with a non-null theme only when {@code tokenToColorCodeMap} maps
* to color resource references.
* <p>
* @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<String, Integer> tokenToColorCodeMap,
@Nullable Theme theme) {
Resources resources = animationView.getResources();
final Map<String, Integer> 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)));
animationView.addLottieOnCompositionLoadedListener(
composition -> tokenToColorMap.forEach(
(token, color) -> animationView.addValueCallback(
new KeyPath("**", token, "**"),
COLOR_FILTER,
frameInfo -> new PorterDuffColorFilter(
color, PorterDuff.Mode.SRC_ATOP))));
}
}