summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHank Sheng <hanksheng@google.com>2022-12-13 03:48:37 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2022-12-13 03:48:37 +0000
commite64d2d55d8841e1decd729f31400ceb0787ad6ab (patch)
treea8dc5290e36781dabe53cf1f5956166853d88a51
parentc53dd318e186e1a1b5881099bfd836911e290629 (diff)
parent2cd6b524cc6e9b5c299a2eec1d5291b90d25e875 (diff)
downloadsetupdesign-e64d2d55d8841e1decd729f31400ceb0787ad6ab.tar.gz
Merge "Import updated Android Setupdesign Library 493170328"
-rw-r--r--lottie_loading_layout/src/com/google/android/setupdesign/GlifLoadingLayout.java53
-rw-r--r--lottie_loading_layout/src/com/google/android/setupdesign/util/LottieAnimationHelper.java129
-rw-r--r--main/res/values-sw600dp-land-v33/dimens.xml23
-rw-r--r--main/res/values-sw600dp-v31/diments.xml24
-rw-r--r--main/res/values-v31/styles.xml31
-rw-r--r--main/res/values-v34/colors.xml21
-rw-r--r--main/res/values-v34/dimens.xml20
-rw-r--r--main/src/com/google/android/setupdesign/util/ThemeHelper.java2
8 files changed, 257 insertions, 46 deletions
diff --git a/lottie_loading_layout/src/com/google/android/setupdesign/GlifLoadingLayout.java b/lottie_loading_layout/src/com/google/android/setupdesign/GlifLoadingLayout.java
index db0b1f3..7284f7b 100644
--- a/lottie_loading_layout/src/com/google/android/setupdesign/GlifLoadingLayout.java
+++ b/lottie_loading_layout/src/com/google/android/setupdesign/GlifLoadingLayout.java
@@ -26,7 +26,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.TypedArray;
-import android.graphics.Color;
import android.graphics.ColorFilter;
import android.os.Build;
import android.os.Build.VERSION_CODES;
@@ -50,7 +49,6 @@ import androidx.annotation.VisibleForTesting;
import com.airbnb.lottie.LottieAnimationView;
import com.airbnb.lottie.LottieDrawable;
import com.airbnb.lottie.LottieProperty;
-import com.airbnb.lottie.SimpleColorFilter;
import com.airbnb.lottie.model.KeyPath;
import com.airbnb.lottie.value.LottieValueCallback;
import com.airbnb.lottie.value.SimpleLottieValueCallback;
@@ -62,14 +60,13 @@ import com.google.android.setupcompat.template.FooterBarMixin;
import com.google.android.setupcompat.util.BuildCompatUtils;
import com.google.android.setupdesign.lottieloadinglayout.R;
import com.google.android.setupdesign.util.LayoutStyler;
+import com.google.android.setupdesign.util.LottieAnimationHelper;
import com.google.android.setupdesign.view.IllustrationVideoView;
import java.io.InputStream;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
/**
* A GLIF themed layout with a {@link com.airbnb.lottie.LottieAnimationView} to showing lottie
@@ -88,8 +85,6 @@ public class GlifLoadingLayout extends GlifLayout {
@VisibleForTesting @RawRes int customLottieResource = 0;
- @VisibleForTesting Map<KeyPath, SimpleColorFilter> customizationMap = new HashMap<>();
-
private AnimatorListener animatorListener;
private Runnable nextActionRunnable;
private boolean workFinished;
@@ -230,7 +225,6 @@ public class GlifLoadingLayout extends GlifLayout {
if (!illustrationType.equals(type)) {
illustrationType = type;
- customizationMap.clear();
}
switch (type) {
@@ -521,7 +515,13 @@ public class GlifLoadingLayout extends GlifLayout {
lottieView.playAnimation();
setLottieLayoutVisibility(View.VISIBLE);
setIllustrationLayoutVisibility(View.GONE);
- applyThemeCustomization();
+ LottieAnimationHelper.get()
+ .applyColor(
+ getContext(),
+ findLottieAnimationView(),
+ isNightMode(getResources().getConfiguration())
+ ? animationConfig.getDarkThemeCustomization()
+ : animationConfig.getLightThemeCustomization());
} else {
setLottieLayoutVisibility(View.GONE);
setIllustrationLayoutVisibility(View.VISIBLE);
@@ -654,43 +654,6 @@ public class GlifLoadingLayout extends GlifLayout {
}
}
- @VisibleForTesting
- protected void loadCustomization() {
- if (customizationMap.isEmpty()) {
- PartnerConfigHelper helper = PartnerConfigHelper.get(getContext());
- List<String> lists =
- helper.getStringArray(
- getContext(),
- isNightMode(getResources().getConfiguration())
- ? animationConfig.getDarkThemeCustomization()
- : animationConfig.getLightThemeCustomization());
- for (String item : lists) {
- String[] splitItem = item.split(":");
- if (splitItem.length == 2) {
- customizationMap.put(
- new KeyPath("**", splitItem[0], "**"),
- new SimpleColorFilter(Color.parseColor(splitItem[1])));
- } else {
- Log.w(TAG, "incorrect format customization, value=" + item);
- }
- }
- }
- }
-
- @VisibleForTesting
- protected void applyThemeCustomization() {
- LottieAnimationView animationView = findLottieAnimationView();
- if (animationView != null) {
- loadCustomization();
- for (KeyPath keyPath : customizationMap.keySet()) {
- animationView.addValueCallback(
- keyPath,
- LottieProperty.COLOR_FILTER,
- new LottieValueCallback<>(customizationMap.get(keyPath)));
- }
- }
- }
-
@Nullable
private View peekLottieLayout() {
return findViewById(R.id.sud_layout_lottie_illustration);
diff --git a/lottie_loading_layout/src/com/google/android/setupdesign/util/LottieAnimationHelper.java b/lottie_loading_layout/src/com/google/android/setupdesign/util/LottieAnimationHelper.java
new file mode 100644
index 0000000..c61f0e1
--- /dev/null
+++ b/lottie_loading_layout/src/com/google/android/setupdesign/util/LottieAnimationHelper.java
@@ -0,0 +1,129 @@
+/*
+ * 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.google.android.setupdesign.util;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Color;
+import android.util.Log;
+import androidx.annotation.NonNull;
+import androidx.annotation.VisibleForTesting;
+import com.airbnb.lottie.LottieAnimationView;
+import com.airbnb.lottie.LottieProperty;
+import com.airbnb.lottie.SimpleColorFilter;
+import com.airbnb.lottie.model.KeyPath;
+import com.airbnb.lottie.value.LottieValueCallback;
+import com.google.android.setupcompat.partnerconfig.PartnerConfig;
+import com.google.android.setupcompat.partnerconfig.PartnerConfigHelper;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/** A helper to help apply color on lottie animation */
+public class LottieAnimationHelper {
+
+ private static final String TAG = "LottieAnimationHelper";
+
+ private static LottieAnimationHelper instance = null;
+
+ @VisibleForTesting public final Map<String, Integer> colorResourceMapping;
+
+ public static LottieAnimationHelper get() {
+ if (instance == null) {
+ instance = new LottieAnimationHelper();
+ }
+ return instance;
+ }
+
+ private LottieAnimationHelper() {
+ colorResourceMapping = new HashMap<>();
+ }
+
+ /**
+ * The color resource is from PartnerConfig, which is a string array and each string will be
+ * {key_path_name}:@{color_reference} or {key_path_name}:{color code}
+ */
+ public void applyColor(
+ @NonNull Context context, LottieAnimationView lottieView, PartnerConfig partnerConfig) {
+ applyColor(
+ context,
+ lottieView,
+ PartnerConfigHelper.get(context).getStringArray(context, partnerConfig));
+ }
+
+ /**
+ * The color resource is from list of string and each string will be
+ * {key_path_name}:@{color_reference} or {key_path_name}:#{color code}
+ */
+ public void applyColor(
+ @NonNull Context context, LottieAnimationView lottieView, List<String> colorMappings) {
+ applyColor(context, lottieView, parseColorMapping(context, colorMappings));
+ }
+
+ /**
+ * The color resource is from a color mapping table and the key is the keypath, and value is color
+ * Integer.
+ */
+ public void applyColor(
+ @NonNull Context context,
+ LottieAnimationView lottieView,
+ Map<KeyPath, Integer> colorMappings) {
+ for (KeyPath keyPath : colorMappings.keySet()) {
+ lottieView.addValueCallback(
+ keyPath,
+ LottieProperty.COLOR_FILTER,
+ new LottieValueCallback<>(new SimpleColorFilter(colorMappings.get(keyPath))));
+ }
+ }
+
+ private Map<KeyPath, Integer> parseColorMapping(
+ @NonNull Context context, List<String> colorMappings) {
+ Map<KeyPath, Integer> customizationMap = new HashMap<>();
+ for (String colorMapping : colorMappings) {
+ String[] splitItem = colorMapping.split(":");
+ if (splitItem.length == 2) {
+ if (splitItem[1].charAt(0) == '#') { // color code
+ customizationMap.put(
+ new KeyPath("**", splitItem[0], "**"), Color.parseColor(splitItem[1]));
+ } else if (splitItem[1].charAt(0) == '@') { // color resource
+ int colorResourceId;
+ if (colorResourceMapping.containsKey(splitItem[1])) {
+ colorResourceId = colorResourceMapping.get(splitItem[1]);
+ } else {
+ colorResourceId =
+ context
+ .getResources()
+ .getIdentifier(splitItem[1].substring(1), "color", context.getPackageName());
+ colorResourceMapping.put(splitItem[1], colorResourceId);
+ }
+ try {
+ customizationMap.put(
+ new KeyPath("**", splitItem[0], "**"),
+ context.getResources().getColor(colorResourceId));
+ } catch (Resources.NotFoundException exception) {
+ Log.e(TAG, "Resource Not found, resource value=" + colorMapping);
+ }
+ } else {
+ Log.w(TAG, "incorrect format customization, value=" + colorMapping);
+ }
+ } else {
+ Log.w(TAG, "incorrect format customization, value=" + colorMapping);
+ }
+ }
+ return customizationMap;
+ }
+}
diff --git a/main/res/values-sw600dp-land-v33/dimens.xml b/main/res/values-sw600dp-land-v33/dimens.xml
new file mode 100644
index 0000000..d672ce6
--- /dev/null
+++ b/main/res/values-sw600dp-land-v33/dimens.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+
+<resources>
+
+ <!-- General -->
+ <dimen name="sud_glif_land_middle_horizontal_spacing">76dp</dimen>
+
+</resources> \ No newline at end of file
diff --git a/main/res/values-sw600dp-v31/diments.xml b/main/res/values-sw600dp-v31/diments.xml
new file mode 100644
index 0000000..899fa39
--- /dev/null
+++ b/main/res/values-sw600dp-v31/diments.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (C) 2021 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.
+-->
+
+<resources>
+
+ <!-- GLIF card layout for tablets. Set 0dp to enable fullscreen layout -->
+ <dimen name="sud_glif_card_width">0dp</dimen>
+ <dimen name="sud_glif_card_height">0dp</dimen>
+
+</resources>
diff --git a/main/res/values-v31/styles.xml b/main/res/values-v31/styles.xml
index 5fab1c1..3862741 100644
--- a/main/res/values-v31/styles.xml
+++ b/main/res/values-v31/styles.xml
@@ -22,6 +22,7 @@
<item name="android:colorAccent">?attr/colorAccent</item>
<item name="android:textColorLink">@color/sud_system_hyperlink_text</item>
<item name="alertDialogTheme">@style/SudDynamicColorAlertDialogThemeCompat</item>
+ <item name="android:alertDialogTheme">@style/SudDynamicColorAlertDialogTheme</item>
<item name="android:datePickerDialogTheme">@style/SudDynamicColorDateTimePickerDialogTheme</item>
<item name="android:timePickerDialogTheme">@style/SudDynamicColorDateTimePickerDialogTheme</item>
<item name="sucFullDynamicColor">false</item>
@@ -37,6 +38,7 @@
<item name="android:colorAccent">?attr/colorAccent</item>
<item name="android:textColorLink">@color/sud_system_hyperlink_text</item>
<item name="alertDialogTheme">@style/SudDynamicColorAlertDialogThemeCompat.Light</item>
+ <item name="android:alertDialogTheme">@style/SudDynamicColorAlertDialogTheme.Light</item>
<item name="android:datePickerDialogTheme">@style/SudDynamicColorDateTimePickerDialogTheme.Light</item>
<item name="android:timePickerDialogTheme">@style/SudDynamicColorDateTimePickerDialogTheme.Light</item>
<item name="sucFullDynamicColor">false</item>
@@ -71,6 +73,7 @@
<item name="colorSwitchThumbNormal">@color/switch_thumb_material_dark</item>
<item name="alertDialogTheme">@style/SudFullDynamicColorAlertDialogThemeCompat</item>
+ <item name="android:alertDialogTheme">@style/SudFullDynamicColorAlertDialogTheme</item>
<item name="sucFullDynamicColor">true</item>
</style>
@@ -95,6 +98,7 @@
<item name="colorSwitchThumbNormal">@color/switch_thumb_material_light</item>
<item name="alertDialogTheme">@style/SudFullDynamicColorAlertDialogThemeCompat.Light</item>
+ <item name="android:alertDialogTheme">@style/SudFullDynamicColorAlertDialogTheme.Light</item>
<item name="sucFullDynamicColor">true</item>
</style>
@@ -188,6 +192,15 @@
<item name="android:windowTitleStyle">@style/SudMaterialYouWindowTitleStyle</item>
</style>
+ <style name="SudDynamicColorAlertDialogTheme" parent="android:Theme.DeviceDefault.Dialog.Alert">
+ <item name="android:textAllCaps">false</item>
+ <item name="android:colorBackground">@color/sud_glif_v3_dialog_background_color_dark</item>
+ <item name="colorAccent">@color/sud_dynamic_color_accent_glif_v3_dark</item>
+ <item name="dialogCornerRadius">@dimen/sud_glif_device_default_dialog_corner_radius</item>
+ <item name="buttonBarButtonStyle">@style/SudAppCompatButtonButtonBarAlertDialog</item>
+ <item name="android:windowTitleStyle">@style/SudMaterialYouWindowTitleStyle</item>
+ </style>
+
<style name="SudDynamicColorAlertDialogThemeCompat.Light" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textAllCaps">false</item>
<item name="android:colorBackground">@color/sud_glif_v3_dialog_background_color_light</item>
@@ -197,6 +210,16 @@
<item name="android:windowTitleStyle">@style/SudMaterialYouWindowTitleStyle</item>
</style>
+ <style name="SudDynamicColorAlertDialogTheme.Light" parent="android:Theme.DeviceDefault.Light.Dialog.Alert">
+ <item name="android:textAllCaps">false</item>
+ <item name="android:colorBackground">@color/sud_glif_v3_dialog_background_color_light</item>
+ <item name="colorAccent">@color/sud_dynamic_color_accent_glif_v3_light</item>
+ <item name="dialogCornerRadius">@dimen/sud_glif_device_default_dialog_corner_radius</item>
+ <item name="buttonBarButtonStyle">@style/SudAppCompatButtonButtonBarAlertDialog.Light</item>
+ <item name="android:windowTitleStyle">@style/SudMaterialYouWindowTitleStyle</item>
+ </style>
+
+
<style name="SudAppCompatButtonButtonBarAlertDialog" parent="Widget.AppCompat.ButtonBar.AlertDialog">
<item name="android:layout_marginStart">@dimen/sud_glif_alert_dialog_footer_bar_padding_start</item>
<item name="android:layout_marginLeft">@dimen/sud_glif_alert_dialog_footer_bar_padding_start</item>
@@ -233,6 +256,14 @@
<item name="android:colorBackground">@color/sud_system_neutral1_50</item>
</style>
+ <style name="SudFullDynamicColorAlertDialogTheme" parent="SudDynamicColorAlertDialogTheme">
+ <item name="android:colorBackground">@color/sud_system_neutral1_900</item>
+ </style>
+ <style name="SudFullDynamicColorAlertDialogTheme.Light" parent="SudDynamicColorAlertDialogTheme.Light">
+ <item name="android:colorBackground">@color/sud_system_neutral1_50</item>
+ </style>
+
+
<!-- Dynamic color theme for date time dialog -->
<style name="SudDynamicColorDateTimePickerDialogTheme" parent="SudDateTimePickerDialogTheme">
<item name="colorAccent">@color/sud_dynamic_color_accent_glif_v3_dark</item>
diff --git a/main/res/values-v34/colors.xml b/main/res/values-v34/colors.xml
new file mode 100644
index 0000000..9460e6e
--- /dev/null
+++ b/main/res/values-v34/colors.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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.
+-->
+
+<resources>
+ <!-- Accent color -->
+ <color name="sud_dynamic_color_accent_glif_v3_dark">@color/sud_system_accent1_300</color>
+</resources> \ No newline at end of file
diff --git a/main/res/values-v34/dimens.xml b/main/res/values-v34/dimens.xml
new file mode 100644
index 0000000..6bc38bc
--- /dev/null
+++ b/main/res/values-v34/dimens.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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.
+-->
+
+<resources>
+ <dimen name="sud_glif_margin_start_material_you">24dp</dimen>
+</resources> \ No newline at end of file
diff --git a/main/src/com/google/android/setupdesign/util/ThemeHelper.java b/main/src/com/google/android/setupdesign/util/ThemeHelper.java
index 57a8278..4c349e4 100644
--- a/main/src/com/google/android/setupdesign/util/ThemeHelper.java
+++ b/main/src/com/google/android/setupdesign/util/ThemeHelper.java
@@ -201,7 +201,7 @@ public final class ThemeHelper {
boolean isSetupFlow = WizardManagerHelper.isAnySetupWizard(activity.getIntent());
boolean isDayNightEnabled = isSetupWizardDayNightEnabled(context);
- if (isSetupFlow) {
+ if (isSetupFlow && !BuildCompatUtils.isAtLeastU()) {
// return theme for inside setup flow
resId =
isDayNightEnabled