diff options
9 files changed, 108 insertions, 133 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 4299c41..ce6609e 100644 --- a/lottie_loading_layout/src/com/google/android/setupdesign/GlifLoadingLayout.java +++ b/lottie_loading_layout/src/com/google/android/setupdesign/GlifLoadingLayout.java @@ -17,6 +17,7 @@ package com.google.android.setupdesign; import static com.google.android.setupcompat.partnerconfig.Util.isNightMode; +import static java.lang.Math.min; import android.animation.Animator; import android.animation.Animator.AnimatorListener; @@ -395,9 +396,9 @@ public class GlifLoadingLayout extends GlifLayout { paddingBottom = (int) configPaddingBottom - (int) - Math.min( + min( configPaddingBottom, - getResources().getDimension(R.dimen.sud_glif_footer_min_height)); + getButtonContainerHeight(footerBarMixin.getButtonContainer())); } } } @@ -405,6 +406,13 @@ public class GlifLoadingLayout extends GlifLayout { linearLayout.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); } + private static final int getButtonContainerHeight(View view) { + view.measure( + MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), + MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); + return view.getMeasuredHeight(); + } + private void inflateLottieView() { final View lottieLayout = peekLottieLayout(); if (lottieLayout == null) { diff --git a/main/res/values-night/colors.xml b/main/res/values-night/colors.xml index 74a583e..b9a0975 100644 --- a/main/res/values-night/colors.xml +++ b/main/res/values-night/colors.xml @@ -17,23 +17,13 @@ <resources> - <color name="sud_system_primary_text">@color/primary_text_color_device_default_dark</color> - - <color name="sud_system_secondary_text">@color/secondary_text_color_device_default_dark</color> - - <color name="sud_system_tertiary_text_inactive">@color/tertiary_text_inactive_color_device_default_dark</color> - - <color name="sud_system_error_warning">@color/error_color_device_default_dark</color> - + <color name="sud_system_primary_text">@color/sud_primary_default_text_dark</color> + <color name="sud_system_secondary_text">@color/sud_secondary_default_text_dark</color> + <color name="sud_system_tertiary_text_inactive">@color/sud_inactive_default_dark</color> + <color name="sud_system_error_warning">@color/sud_error_warning_default_dark</color> <color name="sud_system_success_done">@color/success_color_device_default_dark</color> - <color name="sud_system_fallback_accent">@color/fallback_color_device_default_dark</color> - <color name="sud_system_background_surface">@color/background_surface_color_device_default_dark</color> - - <color name="sud_system_accent_icon_text_button">@color/accent_icon_text_color_device_default_dark</color> - - <color name="sud_system_dividing_line">@color/dividing_line_color_device_default_dark</color> <color name="sud_portal_pending_progress">@color/sud_portal_pending_progress_dark</color> </resources>
\ No newline at end of file diff --git a/main/res/values-v31/styles.xml b/main/res/values-v31/styles.xml index deaea16..b754be1 100644 --- a/main/res/values-v31/styles.xml +++ b/main/res/values-v31/styles.xml @@ -71,4 +71,4 @@ <item name="sucFullDynamicColor">true</item> </style> -</resources>
\ No newline at end of file +</resources> diff --git a/main/res/values/colors.xml b/main/res/values/colors.xml index 4ce7602..d658e9b 100644 --- a/main/res/values/colors.xml +++ b/main/res/values/colors.xml @@ -18,7 +18,6 @@ <resources> <!-- General colors --> - <color name="sud_color_accent_dark">#ff448aff</color> <color name="sud_color_accent_light">#ff3367d6</color> <color name="sud_color_background_dark">#ff303030</color> @@ -35,7 +34,6 @@ <color name="sud_flat_button_highlight">#1f000000</color> <!-- Navigation bar colors --> - <color name="sud_navbar_bg_dark">#ff21272b</color> <color name="sud_navbar_bg_light">#ffe4e7e9</color> @@ -103,10 +101,6 @@ <color name="sud_system_neutral2_700">#464646</color> - <color name="error_color_device_default_dark">#ec928e</color> - - <color name="error_color_device_default_light">#E22518</color> - <color name="success_color_device_default_dark">#5BB974</color> <color name="success_color_device_default_light">#1E8E3E</color> @@ -119,55 +113,31 @@ <color name="sud_portal_pending_progress_dark">#b06000</color> - <color name="primary_text_color_device_default_dark">#EDF2EB</color> - - <color name="primary_text_color_device_default_light">#181C14</color> - - <color name="secondary_text_color_device_default_dark">#C4C9BC</color> - - <color name="secondary_text_color_device_default_light">#43483F</color> - - <color name="tertiary_text_inactive_color_device_default_dark">#8D9287</color> - - <color name="tertiary_text_inactive_color_device_default_light">#72776C</color> - - <color name="background_surface_color_device_default_dark">#1B1D19</color> + <color name="sud_primary_default_text_dark">#FFFFFF</color> - <color name="background_surface_color_device_default_light">#F1F1EB</color> + <color name="sud_primary_default_text_light">#202124</color> - <color name="accent_icon_text_color_device_default_dark">#9FD67C</color> + <color name="sud_secondary_default_text_dark">#9AA0A6</color> - <color name="accent_icon_text_color_device_default_light">#3A691E</color> + <color name="sud_secondary_default_text_light">#5F6368</color> - <color name="button_surface_color_device_default">#BAF396</color> + <color name="sud_inactive_default_dark">#5F6368</color> - <color name="button_text_color_device_default">#1B1D19</color> + <color name="sud_inactive_default_light">#DADCE0</color> - <color name="dividing_line_color_device_default_dark">#43483F</color> + <color name="sud_error_warning_default_dark">#EE675C</color> - <color name="dividing_line_color_device_default_light">#A7ACA0</color> - - - <color name="sud_system_primary_text">@color/primary_text_color_device_default_light</color> - - <color name="sud_system_secondary_text">@color/secondary_text_color_device_default_light</color> - - <color name="sud_system_tertiary_text_inactive">@color/tertiary_text_inactive_color_device_default_light</color> - - <color name="sud_system_error_warning">@color/error_color_device_default_light</color> + <color name="sud_system_primary_text">@color/sud_primary_default_text_light</color> + <color name="sud_system_secondary_text">@color/sud_secondary_default_text_light</color> + <color name="sud_system_tertiary_text_inactive">@color/sud_inactive_default_light</color> + <color name="sud_system_error_warning">@color/sud_color_error_text_light</color> <color name="sud_system_success_done">@color/success_color_device_default_light</color> - <color name="sud_system_fallback_accent">@color/fallback_color_device_default_light</color> - <color name="sud_system_background_surface">@color/background_surface_color_device_default_light</color> - - <color name="sud_system_accent_icon_text_button">@color/accent_icon_text_color_device_default_light</color> - - <color name="sud_system_button_surface">@color/button_surface_color_device_default</color> + <color name="sud_portal_pending_progress">@color/sud_portal_pending_progress_light</color> - <color name="sud_system_button_text">@color/button_text_color_device_default</color> + <color name="sud_switch_track_off">#FF757575</color> + <color name="sud_switch_thumb_off">#BFFFFFFF</color> - <color name="sud_system_dividing_line">@color/dividing_line_color_device_default_light</color> - <color name="sud_portal_pending_progress">@color/sud_portal_pending_progress_light</color> </resources> diff --git a/main/res/values/dimens.xml b/main/res/values/dimens.xml index 5bdf41f..b309981 100644 --- a/main/res/values/dimens.xml +++ b/main/res/values/dimens.xml @@ -198,4 +198,18 @@ <!-- ExpandableSwithItem --> <dimen name="sud_expand_arrow_drawable_padding">4dp</dimen> + <!-- SwitchBar --> + <!-- Minimum width of switch --> + <dimen name="sud_switch_min_width">52dp</dimen> + <!-- Margin of switch thumb --> + <dimen name="sud_switch_thumb_margin">4dp</dimen> + <!-- Size of switch thumb --> + <dimen name="sud_switch_thumb_size">20dp</dimen> + <!-- Width of switch track --> + <dimen name="sud_switch_track_width">52dp</dimen> + <!-- Height of switch track --> + <dimen name="sud_switch_track_height">28dp</dimen> + <!-- Radius of switch track --> + <dimen name="sud_switch_track_radius">35dp</dimen> + </resources> diff --git a/main/src/com/google/android/setupdesign/util/BuildCompatUtils.java b/main/src/com/google/android/setupdesign/util/BuildCompatUtils.java deleted file mode 100644 index 524b9a2..0000000 --- a/main/src/com/google/android/setupdesign/util/BuildCompatUtils.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2020 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.os.Build; - -/** - * An util class to check whether the current OS version is higher or equal to sdk version of - * device. - * - * @deprecated Uses {@link com.google.android.setupcompat.util.BuildCompatUtils} instead. - */ -@Deprecated -public final class BuildCompatUtils { - - /** - * Implementation of BuildCompat.isAtLeast*() suitable for use in Setup - * - * <p>BuildCompat.isAtLeast*() can be changed by Android Release team, and once that is changed it - * may take weeks for that to propagate to stable/prerelease/experimental SDKs in Google3. Also it - * can be different in all these channels. This can cause random issues, especially with sidecars - * (i.e., the code running on R may not know that it runs on R). - * - * <p>This still should try using BuildCompat.isAtLeastR() as source of truth, but also checking - * for VERSION_SDK_INT and VERSION.CODENAME in case when BuildCompat implementation returned - * false. Note that both checks should be >= and not = to make sure that when Android version - * increases (i.e., from R to S), this does not stop working. - * - * <p>Supported configurations: - * - * <ul> - * <li>For current Android release: while new API is not finalized yet (CODENAME = "S", SDK_INT - * = 30|31) - * <li>For current Android release: when new API is finalized (CODENAME = "REL", SDK_INT = 31) - * <li>For next Android release (CODENAME = "T", SDK_INT = 30+) - * </ul> - * - * <p>Note that Build.VERSION_CODES.S cannot be used here until final SDK is available in all - * Google3 channels, because it is equal to Build.VERSION_CODES.CUR_DEVELOPMENT before API - * finalization. - * - * @return Whether the current OS version is higher or equal to S. - */ - public static boolean isAtLeastS() { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { - return false; - } - return (Build.VERSION.CODENAME.equals("REL") && Build.VERSION.SDK_INT >= 31) - || (Build.VERSION.CODENAME.length() == 1 - && Build.VERSION.CODENAME.charAt(0) >= 'S' - && Build.VERSION.CODENAME.charAt(0) <= 'Z'); - } - - private BuildCompatUtils() {} -} diff --git a/main/src/com/google/android/setupdesign/util/PartnerStyleHelper.java b/main/src/com/google/android/setupdesign/util/PartnerStyleHelper.java index d6eade8..d99f724 100644 --- a/main/src/com/google/android/setupdesign/util/PartnerStyleHelper.java +++ b/main/src/com/google/android/setupdesign/util/PartnerStyleHelper.java @@ -156,6 +156,44 @@ public final class PartnerStyleHelper { return shouldApplyPartnerResource(context) && usePartnerHeavyTheme; } + /** + * Returns if the current layout/activity applies dynamic color configurations or not. + * + * @param view A view would be used to get the activity and context. + */ + public static boolean useDynamicColor(View view) { + if (view == null) { + return false; + } + return getDynamicColorAttributeFromTheme(view.getContext()); + } + + static boolean getDynamicColorAttributeFromTheme(Context context) { + try { + Activity activity = PartnerCustomizationLayout.lookupActivityFromContext(context); + TemplateLayout layout = findLayoutFromActivity(activity); + if (layout instanceof GlifLayout) { + return ((GlifLayout) layout).shouldApplyDynamicColor(); + } + } catch (IllegalArgumentException | ClassCastException ex) { + // fall through + } + + // try best to get dynamic color settings from attr + TypedArray a = context.obtainStyledAttributes(new int[] {R.attr.sucFullDynamicColor}); + boolean useDynamicColorTheme = + a.hasValue( + com.google + .android + .setupcompat + .R + .styleable + .SucPartnerCustomizationLayout_sucFullDynamicColor); + a.recycle(); + + return useDynamicColorTheme; + } + private static TemplateLayout findLayoutFromActivity(Activity activity) { if (activity == null) { return null; diff --git a/main/src/com/google/android/setupdesign/util/TextViewPartnerStyler.java b/main/src/com/google/android/setupdesign/util/TextViewPartnerStyler.java index 03a1684..7b4acea 100644 --- a/main/src/com/google/android/setupdesign/util/TextViewPartnerStyler.java +++ b/main/src/com/google/android/setupdesign/util/TextViewPartnerStyler.java @@ -52,7 +52,8 @@ final class TextViewPartnerStyler { if (textPartnerConfigs.getTextLinkedColorConfig() != null && PartnerConfigHelper.get(context) - .isPartnerConfigAvailable(textPartnerConfigs.getTextLinkedColorConfig())) { + .isPartnerConfigAvailable(textPartnerConfigs.getTextLinkedColorConfig()) + && !PartnerStyleHelper.useDynamicColor(textView)) { int linkTextColor = PartnerConfigHelper.get(context) .getColor(context, textPartnerConfigs.getTextLinkedColorConfig()); diff --git a/main/src/com/google/android/setupdesign/util/ThemeHelper.java b/main/src/com/google/android/setupdesign/util/ThemeHelper.java index 32c8e5e..91e6e07 100644 --- a/main/src/com/google/android/setupdesign/util/ThemeHelper.java +++ b/main/src/com/google/android/setupdesign/util/ThemeHelper.java @@ -24,6 +24,7 @@ import android.util.Log; import androidx.annotation.StyleRes; import com.google.android.setupcompat.PartnerCustomizationLayout; import com.google.android.setupcompat.partnerconfig.PartnerConfigHelper; +import com.google.android.setupcompat.util.BuildCompatUtils; import com.google.android.setupcompat.util.WizardManagerHelper; import com.google.android.setupdesign.R; import java.util.Objects; @@ -218,6 +219,23 @@ public final class ThemeHelper { : "SudFullDynamicColorThemeGlifV3_Light")); } + if(Log.isLoggable(TAG, Log.DEBUG)) { + Log.d( + TAG, + "Gets the dynamic accentColor: [Light] " + + colorIntToHex(context, R.color.sud_dynamic_color_accent_glif_v3_light) + + ", " + + (BuildCompatUtils.isAtLeastS() + ? colorIntToHex(context, android.R.color.system_accent1_600) + : "n/a") + + ", [Dark] " + + colorIntToHex(context, R.color.sud_dynamic_color_accent_glif_v3_dark) + + ", " + + (BuildCompatUtils.isAtLeastS() + ? colorIntToHex(context, android.R.color.system_accent1_200) + : "n/a")); + } + return resId; } @@ -241,8 +259,9 @@ public final class ThemeHelper { return false; } - if (getDynamicColorTheme(context) != 0) { - activity.setTheme(getDynamicColorTheme(context)); + @StyleRes int resId = getDynamicColorTheme(context); + if (resId != 0) { + activity.setTheme(resId); } else { Log.w(TAG, "Error occurred on getting dynamic color theme."); return false; @@ -251,5 +270,9 @@ public final class ThemeHelper { return true; } + private static String colorIntToHex(Context context, int colorInt) { + return String.format("#%06X", (0xFFFFFF & context.getResources().getColor(colorInt))); + } + private ThemeHelper() {} } |