Exclude font padding by default on Compact and Title chip
This changes the default behaviour of these two chips to
exclude font padding always and to remove existing setter
for it.
Bug: 314728587
Test: Existing passing because there's no visual diff in these chips
Relnote: "Following Compose and Wear Compose, we are making a change to turn off the font padding by default in all ProtoLayout and ProtoLayout Material components. This will address some cases of text clipping with large font sizes and may also impact screen layouts, so that screenshot tests need updated. As this fixes problems with misaligned label, we are removing the setters for it."
Change-Id: I329598c92ed34d0ee80ce2db7d2d7f021d2c6883
diff --git a/wear/protolayout/protolayout-material/api/current.txt b/wear/protolayout/protolayout-material/api/current.txt
index d73127d..257d197 100644
--- a/wear/protolayout/protolayout-material/api/current.txt
+++ b/wear/protolayout/protolayout-material/api/current.txt
@@ -138,14 +138,12 @@
method public androidx.wear.protolayout.ModifiersBuilders.Clickable getClickable();
method public String? getIconContent();
method public String getText();
- method @SuppressCompatibility @androidx.wear.protolayout.expression.ProtoLayoutExperimental public boolean hasExcludeFontPadding();
}
public static final class CompactChip.Builder {
ctor public CompactChip.Builder(android.content.Context, String, androidx.wear.protolayout.ModifiersBuilders.Clickable, androidx.wear.protolayout.DeviceParametersBuilders.DeviceParameters);
method public androidx.wear.protolayout.material.CompactChip build();
method public androidx.wear.protolayout.material.CompactChip.Builder setChipColors(androidx.wear.protolayout.material.ChipColors);
- method @SuppressCompatibility @androidx.wear.protolayout.expression.ProtoLayoutExperimental public androidx.wear.protolayout.material.CompactChip.Builder setExcludeFontPadding(boolean);
method public androidx.wear.protolayout.material.CompactChip.Builder setIconContent(String);
}
@@ -204,14 +202,12 @@
method public String? getIconContent();
method public String getText();
method public androidx.wear.protolayout.DimensionBuilders.ContainerDimension getWidth();
- method @SuppressCompatibility @androidx.wear.protolayout.expression.ProtoLayoutExperimental public boolean hasExcludeFontPadding();
}
public static final class TitleChip.Builder {
ctor public TitleChip.Builder(android.content.Context, String, androidx.wear.protolayout.ModifiersBuilders.Clickable, androidx.wear.protolayout.DeviceParametersBuilders.DeviceParameters);
method public androidx.wear.protolayout.material.TitleChip build();
method public androidx.wear.protolayout.material.TitleChip.Builder setChipColors(androidx.wear.protolayout.material.ChipColors);
- method @SuppressCompatibility @androidx.wear.protolayout.expression.ProtoLayoutExperimental public androidx.wear.protolayout.material.TitleChip.Builder setExcludeFontPadding(boolean);
method public androidx.wear.protolayout.material.TitleChip.Builder setHorizontalAlignment(int);
method public androidx.wear.protolayout.material.TitleChip.Builder setIconContent(String);
method public androidx.wear.protolayout.material.TitleChip.Builder setWidth(androidx.wear.protolayout.DimensionBuilders.ContainerDimension);
diff --git a/wear/protolayout/protolayout-material/api/restricted_current.txt b/wear/protolayout/protolayout-material/api/restricted_current.txt
index d73127d..257d197 100644
--- a/wear/protolayout/protolayout-material/api/restricted_current.txt
+++ b/wear/protolayout/protolayout-material/api/restricted_current.txt
@@ -138,14 +138,12 @@
method public androidx.wear.protolayout.ModifiersBuilders.Clickable getClickable();
method public String? getIconContent();
method public String getText();
- method @SuppressCompatibility @androidx.wear.protolayout.expression.ProtoLayoutExperimental public boolean hasExcludeFontPadding();
}
public static final class CompactChip.Builder {
ctor public CompactChip.Builder(android.content.Context, String, androidx.wear.protolayout.ModifiersBuilders.Clickable, androidx.wear.protolayout.DeviceParametersBuilders.DeviceParameters);
method public androidx.wear.protolayout.material.CompactChip build();
method public androidx.wear.protolayout.material.CompactChip.Builder setChipColors(androidx.wear.protolayout.material.ChipColors);
- method @SuppressCompatibility @androidx.wear.protolayout.expression.ProtoLayoutExperimental public androidx.wear.protolayout.material.CompactChip.Builder setExcludeFontPadding(boolean);
method public androidx.wear.protolayout.material.CompactChip.Builder setIconContent(String);
}
@@ -204,14 +202,12 @@
method public String? getIconContent();
method public String getText();
method public androidx.wear.protolayout.DimensionBuilders.ContainerDimension getWidth();
- method @SuppressCompatibility @androidx.wear.protolayout.expression.ProtoLayoutExperimental public boolean hasExcludeFontPadding();
}
public static final class TitleChip.Builder {
ctor public TitleChip.Builder(android.content.Context, String, androidx.wear.protolayout.ModifiersBuilders.Clickable, androidx.wear.protolayout.DeviceParametersBuilders.DeviceParameters);
method public androidx.wear.protolayout.material.TitleChip build();
method public androidx.wear.protolayout.material.TitleChip.Builder setChipColors(androidx.wear.protolayout.material.ChipColors);
- method @SuppressCompatibility @androidx.wear.protolayout.expression.ProtoLayoutExperimental public androidx.wear.protolayout.material.TitleChip.Builder setExcludeFontPadding(boolean);
method public androidx.wear.protolayout.material.TitleChip.Builder setHorizontalAlignment(int);
method public androidx.wear.protolayout.material.TitleChip.Builder setIconContent(String);
method public androidx.wear.protolayout.material.TitleChip.Builder setWidth(androidx.wear.protolayout.DimensionBuilders.ContainerDimension);
diff --git a/wear/protolayout/protolayout-material/src/androidTest/java/androidx/wear/protolayout/material/TestCasesGenerator.java b/wear/protolayout/protolayout-material/src/androidTest/java/androidx/wear/protolayout/material/TestCasesGenerator.java
index 04eb408..4792e9c 100644
--- a/wear/protolayout/protolayout-material/src/androidTest/java/androidx/wear/protolayout/material/TestCasesGenerator.java
+++ b/wear/protolayout/protolayout-material/src/androidTest/java/androidx/wear/protolayout/material/TestCasesGenerator.java
@@ -210,78 +210,61 @@
testCases.put(
"compactchip_default_len2_golden" + goldenSuffix,
new CompactChip.Builder(context, "Ab", clickable, deviceParameters)
- .setExcludeFontPadding(true)
.build());
testCases.put(
"compactchip_default_len5_golden" + goldenSuffix,
new CompactChip.Builder(context, "Abcde", clickable, deviceParameters)
- .setExcludeFontPadding(true)
.build());
testCases.put(
"compactchip_default_len9_golden" + goldenSuffix,
new CompactChip.Builder(context, "Abcdefghi", clickable, deviceParameters)
- .setExcludeFontPadding(true)
.build());
testCases.put(
"compactchip_default_toolong_golden" + goldenSuffix,
new CompactChip.Builder(
context, "AbcdefghiEXTRAEXTRAEXTRA", clickable, deviceParameters)
- .setExcludeFontPadding(true)
.build());
testCases.put(
"compactchip_custom_default_golden" + goldenSuffix,
new CompactChip.Builder(context, "Action", clickable, deviceParameters)
.setChipColors(new ChipColors(Color.YELLOW, Color.BLACK))
- .setExcludeFontPadding(true)
- .build());
- testCases.put(
- "compactchip_includepadding_default_golden" + goldenSuffix,
- new CompactChip.Builder(context, "Action", clickable, deviceParameters)
- .setExcludeFontPadding(false)
.build());
testCases.put(
"compactchip_icon_default_golden" + goldenSuffix,
new CompactChip.Builder(context, "Action", clickable, deviceParameters)
.setIconContent(ICON_ID_SMALL)
- .setExcludeFontPadding(true)
.build());
testCases.put(
"compactchip_icon_toolong_golden" + goldenSuffix,
new CompactChip.Builder(
context, "AbcdefghiEXTRAEXTRAEXTRA", clickable, deviceParameters)
.setIconContent(ICON_ID_SMALL)
- .setExcludeFontPadding(true)
.build());
testCases.put(
"compactchip_icon_len2_golden" + goldenSuffix,
new CompactChip.Builder(context, "Ab", clickable, deviceParameters)
.setIconContent(ICON_ID_SMALL)
- .setExcludeFontPadding(true)
.build());
testCases.put(
"compactchip_icon_custom_golden" + goldenSuffix,
new CompactChip.Builder(context, "Action", clickable, deviceParameters)
.setIconContent(ICON_ID_SMALL)
- .setExcludeFontPadding(true)
.setChipColors(new ChipColors(Color.YELLOW, Color.BLACK))
.build());
testCases.put(
"titlechip_default_golden" + goldenSuffix,
new TitleChip.Builder(context, largeChipText, clickable, deviceParameters)
- .setExcludeFontPadding(true)
.build());
testCases.put(
"titlechip_default_texttoolong_golden" + goldenSuffix,
new TitleChip.Builder(context, "abcdeabcdeabcdeEXTRA", clickable, deviceParameters)
- .setExcludeFontPadding(true)
.build());
testCases.put(
"titlechip_leftalign_secondary_default_golden" + goldenSuffix,
new TitleChip.Builder(context, largeChipText, clickable, deviceParameters)
.setHorizontalAlignment(HORIZONTAL_ALIGN_START)
.setChipColors(ChipDefaults.TITLE_SECONDARY_COLORS)
- .setExcludeFontPadding(true)
.build());
testCases.put(
"titlechip_centered_custom_150_secondary_default_golden" + goldenSuffix,
@@ -289,23 +272,15 @@
.setHorizontalAlignment(HORIZONTAL_ALIGN_CENTER)
.setChipColors(new ChipColors(Color.YELLOW, Color.BLUE))
.setWidth(150)
- .setExcludeFontPadding(true)
- .build());
- testCases.put(
- "titlechip_includepadding_default_golden" + goldenSuffix,
- new TitleChip.Builder(context, largeChipText, clickable, deviceParameters)
- .setExcludeFontPadding(false)
.build());
testCases.put(
"titlechip_icon_default_golden" + goldenSuffix,
new TitleChip.Builder(context, largeChipText, clickable, deviceParameters)
- .setExcludeFontPadding(true)
.setIconContent(ICON_ID)
.build());
testCases.put(
"titlechip_icon_default_texttoolong_golden" + goldenSuffix,
new TitleChip.Builder(context, "abcdeabcdeabcdeEXTRA", clickable, deviceParameters)
- .setExcludeFontPadding(true)
.setIconContent(ICON_ID)
.build());
testCases.put(
@@ -313,7 +288,6 @@
new TitleChip.Builder(context, largeChipText, clickable, deviceParameters)
.setChipColors(new ChipColors(Color.YELLOW, Color.BLUE))
.setWidth(150)
- .setExcludeFontPadding(true)
.setIconContent(ICON_ID)
.build());
diff --git a/wear/protolayout/protolayout-material/src/androidTest/java/androidx/wear/protolayout/material/layouts/TestCasesGenerator.java b/wear/protolayout/protolayout-material/src/androidTest/java/androidx/wear/protolayout/material/layouts/TestCasesGenerator.java
index 7c7dc9d..a515831 100644
--- a/wear/protolayout/protolayout-material/src/androidTest/java/androidx/wear/protolayout/material/layouts/TestCasesGenerator.java
+++ b/wear/protolayout/protolayout-material/src/androidTest/java/androidx/wear/protolayout/material/layouts/TestCasesGenerator.java
@@ -75,12 +75,9 @@
HashMap<String, LayoutElement> testCases = new HashMap<>();
TitleChip content =
- new TitleChip.Builder(context, "Action", clickable, deviceParameters)
- .setExcludeFontPadding(true)
- .build();
+ new TitleChip.Builder(context, "Action", clickable, deviceParameters).build();
CompactChip.Builder primaryChipBuilder =
- new CompactChip.Builder(context, "Action", clickable, deviceParameters)
- .setExcludeFontPadding(true);
+ new CompactChip.Builder(context, "Action", clickable, deviceParameters);
testCases.put(
"default_empty_primarychiplayout_golden" + goldenSuffix,
@@ -96,7 +93,6 @@
"Too_long_textToo_long_textToo_long_text",
clickable,
deviceParameters)
- .setExcludeFontPadding(true)
.build())
.build());
testCases.put(
@@ -166,8 +162,7 @@
.build());
primaryChipBuilder =
- new CompactChip.Builder(context, "Action", clickable, deviceParameters)
- .setExcludeFontPadding(true);
+ new CompactChip.Builder(context, "Action", clickable, deviceParameters);
testCases.put(
"coloredbox_1_chip_columnslayout_golden" + goldenSuffix,
new PrimaryLayout.Builder(deviceParameters)
diff --git a/wear/protolayout/protolayout-material/src/main/java/androidx/wear/protolayout/material/CompactChip.java b/wear/protolayout/protolayout-material/src/main/java/androidx/wear/protolayout/material/CompactChip.java
index 436aaad..e28dcb1 100644
--- a/wear/protolayout/protolayout-material/src/main/java/androidx/wear/protolayout/material/CompactChip.java
+++ b/wear/protolayout/protolayout-material/src/main/java/androidx/wear/protolayout/material/CompactChip.java
@@ -83,7 +83,6 @@
@NonNull private final Clickable mClickable;
@NonNull private final DeviceParameters mDeviceParameters;
@NonNull private ChipColors mChipColors = COMPACT_PRIMARY_COLORS;
- private boolean mIsFontPaddingExcluded = false;
@Nullable private String mIconResourceId = null;
/**
@@ -119,25 +118,9 @@
}
/**
- * Sets whether the font padding is excluded or not. If not set, default to false, meaning
- * that text will have font padding included.
- *
- * <p>Setting this to {@code true} will perfectly align the text label.
- */
- @NonNull
- @ProtoLayoutExperimental
- @SuppressWarnings("MissingGetterMatchingBuilder")
- public Builder setExcludeFontPadding(boolean excluded) {
- this.mIsFontPaddingExcluded = excluded;
- return this;
- }
-
- /**
* Sets the icon for the {@link CompactChip}. Provided icon will be tinted to the given
* content color from {@link ChipColors}. This icon should be image with chosen alpha
* channel that can be tinted.
- *
- * <p>It is highly recommended to use it with {@link #setExcludeFontPadding} set to true.
*/
@NonNull
public Builder setIconContent(@NonNull String imageResourceId) {
@@ -161,7 +144,7 @@
.setHorizontalPadding(COMPACT_HORIZONTAL_PADDING)
.setPrimaryLabelContent(mText)
.setPrimaryLabelTypography(Typography.TYPOGRAPHY_CAPTION1)
- .setPrimaryLabelExcludeFontPadding(mIsFontPaddingExcluded)
+ .setPrimaryLabelExcludeFontPadding(true)
.setIsPrimaryLabelScalable(false);
if (mIconResourceId != null) {
@@ -221,12 +204,6 @@
return coreChip == null ? null : new CompactChip(new Chip(coreChip));
}
- /** Returns whether the font padding for the primary label is excluded. */
- @ProtoLayoutExperimental
- public boolean hasExcludeFontPadding() {
- return mElement.hasPrimaryLabelExcludeFontPadding();
- }
-
@RestrictTo(Scope.LIBRARY_GROUP)
@NonNull
@Override
diff --git a/wear/protolayout/protolayout-material/src/main/java/androidx/wear/protolayout/material/TitleChip.java b/wear/protolayout/protolayout-material/src/main/java/androidx/wear/protolayout/material/TitleChip.java
index e6e355c..8ba8001 100644
--- a/wear/protolayout/protolayout-material/src/main/java/androidx/wear/protolayout/material/TitleChip.java
+++ b/wear/protolayout/protolayout-material/src/main/java/androidx/wear/protolayout/material/TitleChip.java
@@ -93,7 +93,6 @@
// Indicates that the width isn't set, so it will be automatically set by Chip.Builder
// constructor.
@Nullable private ContainerDimension mWidth = null;
- private boolean mIsFontPaddingExcluded = false;
@Nullable private String mIconResourceId = null;
/**
@@ -157,25 +156,9 @@
}
/**
- * Sets whether the font padding is excluded or not. If not set, default to false, meaning
- * that text will have font padding included.
- *
- * <p>Setting this to {@code true} will perfectly align the text label.
- */
- @NonNull
- @ProtoLayoutExperimental
- @SuppressWarnings("MissingGetterMatchingBuilder")
- public Builder setExcludeFontPadding(boolean excluded) {
- this.mIsFontPaddingExcluded = excluded;
- return this;
- }
-
- /**
* Sets the icon for the {@link TitleChip}. Provided icon will be tinted to the given
* content color from {@link ChipColors}. This icon should be image with chosen alpha
* channel that can be tinted.
- *
- * <p>It is highly recommended to use it with {@link #setExcludeFontPadding} set to true.
*/
@NonNull
public Builder setIconContent(@NonNull String imageResourceId) {
@@ -197,7 +180,7 @@
.setHorizontalPadding(TITLE_HORIZONTAL_PADDING)
.setPrimaryLabelContent(mText)
.setPrimaryLabelTypography(Typography.TYPOGRAPHY_TITLE2)
- .setPrimaryLabelExcludeFontPadding(mIsFontPaddingExcluded)
+ .setPrimaryLabelExcludeFontPadding(true)
.setIsPrimaryLabelScalable(false);
if (mWidth != null) {
@@ -273,12 +256,6 @@
return coreChip == null ? null : new TitleChip(new Chip(coreChip));
}
- /** Returns whether the font padding for the primary label is excluded. */
- @ProtoLayoutExperimental
- public boolean hasExcludeFontPadding() {
- return mElement.hasPrimaryLabelExcludeFontPadding();
- }
-
@RestrictTo(Scope.LIBRARY_GROUP)
@NonNull
@Override