diff options
Diffstat (limited to 'main/src/com/google/android/setupdesign')
4 files changed, 65 insertions, 72 deletions
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() {} } |