diff options
Diffstat (limited to 'main/src/com')
5 files changed, 71 insertions, 62 deletions
diff --git a/main/src/com/google/android/setupdesign/template/IconMixin.java b/main/src/com/google/android/setupdesign/template/IconMixin.java index 1b2fbbf..75e624a 100644 --- a/main/src/com/google/android/setupdesign/template/IconMixin.java +++ b/main/src/com/google/android/setupdesign/template/IconMixin.java @@ -33,6 +33,7 @@ import com.google.android.setupcompat.internal.TemplateLayout; import com.google.android.setupcompat.template.Mixin; import com.google.android.setupdesign.R; import com.google.android.setupdesign.util.HeaderAreaStyler; +import com.google.android.setupdesign.util.PartnerStyleHelper; /** * A {@link com.google.android.setupcompat.template.Mixin} for setting an icon on the template @@ -91,7 +92,13 @@ public class IconMixin implements Mixin { /** Tries to apply the partner customization to the header icon. */ public void tryApplyPartnerCustomizationStyle() { - HeaderAreaStyler.applyPartnerCustomizationIconStyle(getView(), getContainerView()); + if (PartnerStyleHelper.isPartnerHeavyThemeLayout(templateLayout)) { + // apply partner heavy configs + HeaderAreaStyler.applyPartnerCustomizationIconStyle(getView(), getContainerView()); + } else if (PartnerStyleHelper.isPartnerLightThemeLayout(templateLayout)) { + // apply partner light configs + HeaderAreaStyler.applyPartnerCustomizationIconStyle(getView()); + } } /** diff --git a/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java b/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java index 44a7d49..1b3daac 100644 --- a/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java +++ b/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java @@ -180,8 +180,8 @@ public final class HeaderAreaStyler { } /** - * Applies the partner style of header icon to the given {@code iconImage}. The theme should set - * partner heavy theme first, and then the partner icon size would be applied. + * Applies the partner heavy style of header icon to the given {@code iconImage}. The theme should + * check partner heavy theme first, and then the partner icon size would be applied. * * @param iconImage A ImageView would apply the partner style of header icon * @param iconContainer The container of the header icon @@ -192,41 +192,47 @@ public final class HeaderAreaStyler { return; } - if (PartnerStyleHelper.shouldApplyPartnerResource(iconImage)) { - Context context = iconImage.getContext(); - int gravity = PartnerStyleHelper.getLayoutGravity(context); - if (gravity != 0) { - setGravity(iconImage, gravity); - } + Context context = iconImage.getContext(); + int gravity = PartnerStyleHelper.getLayoutGravity(context); + if (gravity != 0) { + setGravity(iconImage, gravity); + } - if (PartnerStyleHelper.shouldApplyPartnerHeavyThemeResource(iconContainer)) { - final ViewGroup.LayoutParams lp = iconContainer.getLayoutParams(); - boolean partnerConfigAvailable = - PartnerConfigHelper.get(context) - .isPartnerConfigAvailable(PartnerConfig.CONFIG_ICON_MARGIN_TOP); - if (partnerConfigAvailable && lp instanceof ViewGroup.MarginLayoutParams) { - final ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) lp; - int topMargin = - (int) - PartnerConfigHelper.get(context) - .getDimension(context, PartnerConfig.CONFIG_ICON_MARGIN_TOP); - mlp.setMargins(mlp.leftMargin, topMargin, mlp.rightMargin, mlp.bottomMargin); - } + final ViewGroup.LayoutParams lp = iconContainer.getLayoutParams(); + boolean partnerConfigAvailable = + PartnerConfigHelper.get(context) + .isPartnerConfigAvailable(PartnerConfig.CONFIG_ICON_MARGIN_TOP); + if (partnerConfigAvailable && lp instanceof ViewGroup.MarginLayoutParams) { + final ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) lp; + int topMargin = + (int) + PartnerConfigHelper.get(context) + .getDimension(context, PartnerConfig.CONFIG_ICON_MARGIN_TOP); + mlp.setMargins(mlp.leftMargin, topMargin, mlp.rightMargin, mlp.bottomMargin); + } - if (PartnerConfigHelper.get(context) - .isPartnerConfigAvailable(PartnerConfig.CONFIG_ICON_SIZE)) { + if (PartnerConfigHelper.get(context).isPartnerConfigAvailable(PartnerConfig.CONFIG_ICON_SIZE)) { - checkImageType(iconImage); + checkImageType(iconImage); - final ViewGroup.LayoutParams lpIcon = iconImage.getLayoutParams(); - lpIcon.height = - (int) - PartnerConfigHelper.get(context) - .getDimension(context, PartnerConfig.CONFIG_ICON_SIZE); - lpIcon.width = LayoutParams.WRAP_CONTENT; - iconImage.setScaleType(ScaleType.FIT_CENTER); - } - } + final ViewGroup.LayoutParams lpIcon = iconImage.getLayoutParams(); + lpIcon.height = + (int) + PartnerConfigHelper.get(context) + .getDimension(context, PartnerConfig.CONFIG_ICON_SIZE); + lpIcon.width = LayoutParams.WRAP_CONTENT; + iconImage.setScaleType(ScaleType.FIT_CENTER); + } + } + + /** Applies the partner light style of header icon to the given {@code iconImage}. */ + public static void applyPartnerCustomizationIconStyle(@Nullable ImageView iconImage) { + if (iconImage == null) { + return; + } + int gravity = PartnerStyleHelper.getLayoutGravity(iconImage.getContext()); + if (gravity != 0) { + setGravity(iconImage, gravity); } } diff --git a/main/src/com/google/android/setupdesign/util/PartnerStyleHelper.java b/main/src/com/google/android/setupdesign/util/PartnerStyleHelper.java index d99f724..78900b1 100644 --- a/main/src/com/google/android/setupdesign/util/PartnerStyleHelper.java +++ b/main/src/com/google/android/setupdesign/util/PartnerStyleHelper.java @@ -74,7 +74,7 @@ public final class PartnerStyleHelper { * Returns if the current layout/activity of the given {@code view} applies partner customized * configurations or not. * - * @param view A view would be used to get the activity and context. + * @param view A PartnerCustomizationLayout view, would be used to get the activity and context. */ public static boolean shouldApplyPartnerResource(View view) { if (view == null) { @@ -159,7 +159,7 @@ public final class PartnerStyleHelper { /** * 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. + * @param view A GlifLayout view would be used to get the activity and context. */ public static boolean useDynamicColor(View view) { if (view == null) { @@ -198,6 +198,7 @@ public final class PartnerStyleHelper { if (activity == null) { return null; } + // This only worked after activity setContentView, otherwise it will return null View rootView = activity.findViewById(R.id.suc_layout_status); return rootView != null ? (TemplateLayout) rootView.getParent() : null; } diff --git a/main/src/com/google/android/setupdesign/util/ThemeHelper.java b/main/src/com/google/android/setupdesign/util/ThemeHelper.java index 91e6e07..ba2ca1d 100644 --- a/main/src/com/google/android/setupdesign/util/ThemeHelper.java +++ b/main/src/com/google/android/setupdesign/util/ThemeHelper.java @@ -20,11 +20,11 @@ import android.app.Activity; import android.content.Context; import android.content.Intent; import androidx.annotation.NonNull; -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.Logger; import com.google.android.setupcompat.util.WizardManagerHelper; import com.google.android.setupdesign.R; import java.util.Objects; @@ -32,7 +32,7 @@ import java.util.Objects; /** The helper class holds the constant names of themes and util functions */ public final class ThemeHelper { - private static final String TAG = "ThemeHelper"; + private static final Logger LOG = new Logger("ThemeHelper"); /** * Passed in a setup wizard intent as {@link WizardManagerHelper#EXTRA_THEME}. This is the dark @@ -192,7 +192,7 @@ public final class ThemeHelper { try { activity = PartnerCustomizationLayout.lookupActivityFromContext(context); } catch (IllegalArgumentException ex) { - Log.e(TAG, Objects.requireNonNull(ex.getMessage())); + LOG.e(Objects.requireNonNull(ex.getMessage())); return resId; } @@ -211,30 +211,26 @@ public final class ThemeHelper { isDayNightEnabled ? R.style.SudFullDynamicColorThemeGlifV3_DayNight : R.style.SudFullDynamicColorThemeGlifV3_Light; - Log.i( - TAG, + LOG.atInfo( "Return " + (isDayNightEnabled ? "SudFullDynamicColorThemeGlifV3_DayNight" : "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")); - } + LOG.atDebug( + "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; } @@ -242,12 +238,12 @@ public final class ThemeHelper { /** Returns {@code true} if the dynamic color is set. */ public static boolean trySetDynamicColor(@NonNull Context context) { if (!shouldApplyExtendedPartnerConfig(context)) { - Log.w(TAG, "SetupWizard does not supports the extended partner configs."); + LOG.w("SetupWizard does not supports the extended partner configs."); return false; } if (!isSetupWizardDynamicColorEnabled(context)) { - Log.w(TAG, "SetupWizard does not support the dynamic color or supporting status unknown."); + LOG.w("SetupWizard does not support the dynamic color or supporting status unknown."); return false; } @@ -255,7 +251,7 @@ public final class ThemeHelper { try { activity = PartnerCustomizationLayout.lookupActivityFromContext(context); } catch (IllegalArgumentException ex) { - Log.e(TAG, Objects.requireNonNull(ex.getMessage())); + LOG.e(Objects.requireNonNull(ex.getMessage())); return false; } @@ -263,7 +259,7 @@ public final class ThemeHelper { if (resId != 0) { activity.setTheme(resId); } else { - Log.w(TAG, "Error occurred on getting dynamic color theme."); + LOG.w("Error occurred on getting dynamic color theme."); return false; } diff --git a/main/src/com/google/android/setupdesign/view/BottomScrollView.java b/main/src/com/google/android/setupdesign/view/BottomScrollView.java index c376c36..a3b250d 100644 --- a/main/src/com/google/android/setupdesign/view/BottomScrollView.java +++ b/main/src/com/google/android/setupdesign/view/BottomScrollView.java @@ -68,7 +68,6 @@ public class BottomScrollView extends ScrollView { return listener; } - @VisibleForTesting public int getScrollThreshold() { return scrollThreshold; } |