diff options
author | Xin Li <delphij@google.com> | 2023-12-08 13:14:08 -0800 |
---|---|---|
committer | Xin Li <delphij@google.com> | 2023-12-08 13:14:08 -0800 |
commit | b454fe7937082619a4c673dd883f489b83c5a7d3 (patch) | |
tree | a686dbe049dd9304a041a66c0b8ee5fb88484551 | |
parent | a6a7cc0368bbd3950804d66f33996d110705fbd2 (diff) | |
parent | fe93969af2d6c96f953af718a1a1c7f29dc979e5 (diff) | |
download | setupdesign-b454fe7937082619a4c673dd883f489b83c5a7d3.tar.gz |
Merge Android 14 QPR1
Merged-In: If9d9e69ac0255ffb503b9e2a067f7be81ed6c139
Bug: 315507370
Change-Id: Ie657cdd67c85b40cfbd7ca02e4ab7065331bb9c9
5 files changed, 71 insertions, 30 deletions
diff --git a/main/src/com/google/android/setupdesign/util/ContentStyler.java b/main/src/com/google/android/setupdesign/util/ContentStyler.java index 5fc1d1c..45d89ec 100644 --- a/main/src/com/google/android/setupdesign/util/ContentStyler.java +++ b/main/src/com/google/android/setupdesign/util/ContentStyler.java @@ -53,9 +53,10 @@ public final class ContentStyler { PartnerConfig.CONFIG_CONTENT_LINK_TEXT_COLOR, PartnerConfig.CONFIG_CONTENT_TEXT_SIZE, PartnerConfig.CONFIG_CONTENT_FONT_FAMILY, + /* textFontWeightConfig= */ null, PartnerConfig.CONFIG_DESCRIPTION_LINK_FONT_FAMILY, - null, - null, + /* textMarginTopConfig= */ null, + /* textMarginBottomConfig= */ null, ContentStyler.getPartnerContentTextGravity(contentText.getContext()))); } @@ -90,16 +91,17 @@ public final class ContentStyler { TextViewPartnerStyler.applyPartnerCustomizationStyle( infoText, new TextPartnerConfigs( - null, - null, + /* textColorConfig= */ null, + /* textLinkedColorConfig= */ null, textSizeConfigAvailable ? PartnerConfig.CONFIG_CONTENT_INFO_TEXT_SIZE : null, fontFamilyConfigAvailable ? PartnerConfig.CONFIG_CONTENT_INFO_FONT_FAMILY : null, + /* textFontWeightConfig= */ null, linkFontFamilyConfigAvailable ? PartnerConfig.CONFIG_DESCRIPTION_LINK_FONT_FAMILY : null, - null, - null, - 0)); + /* textMarginTopConfig= */ null, + /* textMarginBottomConfig= */ null, + /* textGravity= */ 0)); // TODO: Move CONFIG_CONTENT_INFO_LINE_SPACING_EXTRA to TextPartnerConfigs for // customize diff --git a/main/src/com/google/android/setupdesign/util/DescriptionStyler.java b/main/src/com/google/android/setupdesign/util/DescriptionStyler.java index b779bc6..52a2e10 100644 --- a/main/src/com/google/android/setupdesign/util/DescriptionStyler.java +++ b/main/src/com/google/android/setupdesign/util/DescriptionStyler.java @@ -41,9 +41,10 @@ public final class DescriptionStyler { PartnerConfig.CONFIG_DESCRIPTION_LINK_TEXT_COLOR, PartnerConfig.CONFIG_DESCRIPTION_TEXT_SIZE, PartnerConfig.CONFIG_DESCRIPTION_FONT_FAMILY, + PartnerConfig.CONFIG_DESCRIPTION_FONT_WEIGHT, PartnerConfig.CONFIG_DESCRIPTION_LINK_FONT_FAMILY, - null, - null, + /* textMarginTopConfig= */ null, + /* textMarginBottomConfig= */ null, PartnerStyleHelper.getLayoutGravity(description.getContext()))); } @@ -57,13 +58,14 @@ public final class DescriptionStyler { TextViewPartnerStyler.applyPartnerCustomizationLightStyle( description, new TextPartnerConfigs( - null, - null, - null, - null, - null, - null, - null, + /* textColorConfig= */ null, + /* textLinkedColorConfig= */ null, + /* textSizeConfig= */ null, + /* textFontFamilyConfig= */ null, + /* textFontWeightConfig= */ null, + /* textLinkFontFamilyConfig= */ null, + /* textMarginTopConfig= */ null, + /* textMarginBottomConfig= */ null, PartnerStyleHelper.getLayoutGravity(description.getContext()))); } diff --git a/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java b/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java index bb1c667..a52101d 100644 --- a/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java +++ b/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java @@ -70,10 +70,11 @@ public final class HeaderAreaStyler { header, new TextPartnerConfigs( PartnerConfig.CONFIG_HEADER_TEXT_COLOR, - null, + /* textLinkedColorConfig= */ null, PartnerConfig.CONFIG_HEADER_TEXT_SIZE, PartnerConfig.CONFIG_HEADER_FONT_FAMILY, - null, + PartnerConfig.CONFIG_HEADER_FONT_WEIGHT, + /* textLinkFontFamilyConfig= */ null, PartnerConfig.CONFIG_HEADER_TEXT_MARGIN_TOP, PartnerConfig.CONFIG_HEADER_TEXT_MARGIN_BOTTOM, PartnerStyleHelper.getLayoutGravity(header.getContext()))); @@ -97,6 +98,7 @@ public final class HeaderAreaStyler { PartnerConfig.CONFIG_DESCRIPTION_LINK_TEXT_COLOR, PartnerConfig.CONFIG_DESCRIPTION_TEXT_SIZE, PartnerConfig.CONFIG_DESCRIPTION_FONT_FAMILY, + PartnerConfig.CONFIG_DESCRIPTION_FONT_WEIGHT, PartnerConfig.CONFIG_DESCRIPTION_LINK_FONT_FAMILY, PartnerConfig.CONFIG_DESCRIPTION_TEXT_MARGIN_TOP, PartnerConfig.CONFIG_DESCRIPTION_TEXT_MARGIN_BOTTOM, diff --git a/main/src/com/google/android/setupdesign/util/ItemStyler.java b/main/src/com/google/android/setupdesign/util/ItemStyler.java index 5dbf0a4..e6d0131 100644 --- a/main/src/com/google/android/setupdesign/util/ItemStyler.java +++ b/main/src/com/google/android/setupdesign/util/ItemStyler.java @@ -89,13 +89,14 @@ public final class ItemStyler { TextViewPartnerStyler.applyPartnerCustomizationStyle( titleTextView, new TextPartnerConfigs( - null, - null, + /* textColorConfig= */ null, + /* textLinkedColorConfig= */ null, PartnerConfig.CONFIG_ITEMS_TITLE_TEXT_SIZE, PartnerConfig.CONFIG_ITEMS_TITLE_FONT_FAMILY, - null, - null, - null, + /* textFontWeightConfig= */ null, + /* textLinkFontFamilyConfig= */ null, + /* textMarginTopConfig= */ null, + /* textMarginBottomConfig= */ null, PartnerStyleHelper.getLayoutGravity(titleTextView.getContext()))); } @@ -113,13 +114,14 @@ public final class ItemStyler { TextViewPartnerStyler.applyPartnerCustomizationStyle( summaryTextView, new TextPartnerConfigs( - null, - null, + /* textColorConfig= */ null, + /* textLinkedColorConfig= */ null, PartnerConfig.CONFIG_ITEMS_SUMMARY_TEXT_SIZE, PartnerConfig.CONFIG_ITEMS_SUMMARY_FONT_FAMILY, - null, + /* textFontWeightConfig= */ null, + /* textLinkFontFamilyConfig= */ null, PartnerConfig.CONFIG_ITEMS_SUMMARY_MARGIN_TOP, - null, + /* textMarginBottomConfig= */ null, PartnerStyleHelper.getLayoutGravity(summaryTextView.getContext()))); } diff --git a/main/src/com/google/android/setupdesign/util/TextViewPartnerStyler.java b/main/src/com/google/android/setupdesign/util/TextViewPartnerStyler.java index b56d09a..ced6fd4 100644 --- a/main/src/com/google/android/setupdesign/util/TextViewPartnerStyler.java +++ b/main/src/com/google/android/setupdesign/util/TextViewPartnerStyler.java @@ -16,6 +16,9 @@ package com.google.android.setupdesign.util; +import static com.google.android.setupcompat.partnerconfig.PartnerConfigHelper.isFontWeightEnabled; + +import android.annotation.SuppressLint; import android.content.Context; import android.graphics.Typeface; import android.util.TypedValue; @@ -31,7 +34,11 @@ import com.google.android.setupdesign.view.RichTextView; /** Helper class to apply partner configurations to a textView. */ final class TextViewPartnerStyler { + /** Normal font weight. */ + private static final int FONT_WEIGHT_NORMAL = 400; + /** Applies given partner configurations {@code textPartnerConfigs} to the {@code textView}. */ + @SuppressLint("NewApi") // Applying partner config should be guarded before Android S public static void applyPartnerCustomizationStyle( @NonNull TextView textView, @NonNull TextPartnerConfigs textPartnerConfigs) { @@ -74,16 +81,35 @@ final class TextViewPartnerStyler { } } + Typeface fontFamily = null; if (textPartnerConfigs.getTextFontFamilyConfig() != null && PartnerConfigHelper.get(context) .isPartnerConfigAvailable(textPartnerConfigs.getTextFontFamilyConfig())) { String fontFamilyName = PartnerConfigHelper.get(context) .getString(context, textPartnerConfigs.getTextFontFamilyConfig()); - Typeface font = Typeface.create(fontFamilyName, Typeface.NORMAL); - if (font != null) { - textView.setTypeface(font); + fontFamily = Typeface.create(fontFamilyName, Typeface.NORMAL); + } + + Typeface font; + if (isFontWeightEnabled(context) + && textPartnerConfigs.getTextFontWeightConfig() != null + && PartnerConfigHelper.get(context) + .isPartnerConfigAvailable(textPartnerConfigs.getTextFontWeightConfig())) { + int weight = + PartnerConfigHelper.get(context) + .getInteger( + context, textPartnerConfigs.getTextFontWeightConfig(), FONT_WEIGHT_NORMAL); + if (fontFamily == null) { + fontFamily = textView.getTypeface(); } + font = Typeface.create(fontFamily, weight, /* italic= */ false); + } else { + font = fontFamily; + } + + if (font != null) { + textView.setTypeface(font); } if (textView instanceof RichTextView && textPartnerConfigs.getLinkTextFontFamilyConfig() != null @@ -162,6 +188,7 @@ final class TextViewPartnerStyler { private final PartnerConfig textLinkedColorConfig; private final PartnerConfig textSizeConfig; private final PartnerConfig textFontFamilyConfig; + private final PartnerConfig textFontWeightConfig; private final PartnerConfig textLinkFontFamilyConfig; private final PartnerConfig textMarginTopConfig; private final PartnerConfig textMarginBottomConfig; @@ -172,6 +199,7 @@ final class TextViewPartnerStyler { @Nullable PartnerConfig textLinkedColorConfig, @Nullable PartnerConfig textSizeConfig, @Nullable PartnerConfig textFontFamilyConfig, + @Nullable PartnerConfig textFontWeightConfig, @Nullable PartnerConfig textLinkFontFamilyConfig, @Nullable PartnerConfig textMarginTopConfig, @Nullable PartnerConfig textMarginBottomConfig, @@ -180,6 +208,7 @@ final class TextViewPartnerStyler { this.textLinkedColorConfig = textLinkedColorConfig; this.textSizeConfig = textSizeConfig; this.textFontFamilyConfig = textFontFamilyConfig; + this.textFontWeightConfig = textFontWeightConfig; this.textLinkFontFamilyConfig = textLinkFontFamilyConfig; this.textMarginTopConfig = textMarginTopConfig; this.textMarginBottomConfig = textMarginBottomConfig; @@ -202,6 +231,10 @@ final class TextViewPartnerStyler { return textFontFamilyConfig; } + public PartnerConfig getTextFontWeightConfig() { + return textFontWeightConfig; + } + public PartnerConfig getLinkTextFontFamilyConfig() { return textLinkFontFamilyConfig; } |