Merge changes I1e06c79f,Iec0ae037 into androidx-main
* changes:
Various code style updates, to align with google-java-format.
Add material Text component, and update other components to use it.
diff --git a/wear/tiles/tiles-material/api/current.txt b/wear/tiles/tiles-material/api/current.txt
index 42f4d21..38c920e 100644
--- a/wear/tiles/tiles-material/api/current.txt
+++ b/wear/tiles/tiles-material/api/current.txt
@@ -20,8 +20,8 @@
method public androidx.wear.tiles.material.Button.Builder setImageContent(String);
method public androidx.wear.tiles.material.Button.Builder setSize(androidx.wear.tiles.DimensionBuilders.DpProp);
method public androidx.wear.tiles.material.Button.Builder setSize(@Dimension(unit=androidx.annotation.Dimension.DP) float);
- method public androidx.wear.tiles.material.Button.Builder setTextContent(String, androidx.wear.tiles.DeviceParametersBuilders.DeviceParameters);
- method public androidx.wear.tiles.material.Button.Builder setTextContent(String, androidx.wear.tiles.LayoutElementBuilders.FontStyle);
+ method public androidx.wear.tiles.material.Button.Builder setTextContent(String);
+ method public androidx.wear.tiles.material.Button.Builder setTextContent(String, int);
}
public class ButtonColors {
@@ -153,6 +153,25 @@
field public static final float GAP_START_ANGLE = -156.1f;
}
+ public class Text implements androidx.wear.tiles.LayoutElementBuilders.LayoutElement {
+ method public androidx.wear.tiles.ColorBuilders.ColorProp getColor();
+ method public androidx.wear.tiles.LayoutElementBuilders.FontStyle getFontStyle();
+ method public float getLineHeight();
+ method public float getMaxLines();
+ method public androidx.wear.tiles.ModifiersBuilders.Modifiers getModifiers();
+ method public int getMultilineAlignment();
+ method public int getOverflow();
+ method public String getText();
+ }
+
+ public static final class Text.Builder implements androidx.wear.tiles.LayoutElementBuilders.LayoutElement.Builder {
+ ctor public Text.Builder();
+ method public androidx.wear.tiles.material.Text build();
+ method public androidx.wear.tiles.material.Text.Builder setColor(androidx.wear.tiles.ColorBuilders.ColorProp);
+ method public androidx.wear.tiles.material.Text.Builder setText(String);
+ method public androidx.wear.tiles.material.Text.Builder setTypography(int);
+ }
+
public class TitleChip implements androidx.wear.tiles.LayoutElementBuilders.LayoutElement {
method public androidx.wear.tiles.ActionBuilders.Action getAction();
method public androidx.wear.tiles.material.ChipColors getChipColors();
@@ -172,6 +191,21 @@
method public androidx.wear.tiles.material.TitleChip.Builder setWidth(@Dimension(unit=androidx.annotation.Dimension.DP) float);
}
+ public class Typography {
+ field public static final int TYPOGRAPHY_BODY1 = 7; // 0x7
+ field public static final int TYPOGRAPHY_BODY2 = 8; // 0x8
+ field public static final int TYPOGRAPHY_BUTTON = 9; // 0x9
+ field public static final int TYPOGRAPHY_CAPTION1 = 10; // 0xa
+ field public static final int TYPOGRAPHY_CAPTION2 = 11; // 0xb
+ field public static final int TYPOGRAPHY_CAPTION3 = 12; // 0xc
+ field public static final int TYPOGRAPHY_DISPLAY1 = 1; // 0x1
+ field public static final int TYPOGRAPHY_DISPLAY2 = 2; // 0x2
+ field public static final int TYPOGRAPHY_DISPLAY3 = 3; // 0x3
+ field public static final int TYPOGRAPHY_TITLE1 = 4; // 0x4
+ field public static final int TYPOGRAPHY_TITLE2 = 5; // 0x5
+ field public static final int TYPOGRAPHY_TITLE3 = 6; // 0x6
+ }
+
}
package androidx.wear.tiles.material.layouts {
diff --git a/wear/tiles/tiles-material/api/public_plus_experimental_current.txt b/wear/tiles/tiles-material/api/public_plus_experimental_current.txt
index 42f4d21..38c920e 100644
--- a/wear/tiles/tiles-material/api/public_plus_experimental_current.txt
+++ b/wear/tiles/tiles-material/api/public_plus_experimental_current.txt
@@ -20,8 +20,8 @@
method public androidx.wear.tiles.material.Button.Builder setImageContent(String);
method public androidx.wear.tiles.material.Button.Builder setSize(androidx.wear.tiles.DimensionBuilders.DpProp);
method public androidx.wear.tiles.material.Button.Builder setSize(@Dimension(unit=androidx.annotation.Dimension.DP) float);
- method public androidx.wear.tiles.material.Button.Builder setTextContent(String, androidx.wear.tiles.DeviceParametersBuilders.DeviceParameters);
- method public androidx.wear.tiles.material.Button.Builder setTextContent(String, androidx.wear.tiles.LayoutElementBuilders.FontStyle);
+ method public androidx.wear.tiles.material.Button.Builder setTextContent(String);
+ method public androidx.wear.tiles.material.Button.Builder setTextContent(String, int);
}
public class ButtonColors {
@@ -153,6 +153,25 @@
field public static final float GAP_START_ANGLE = -156.1f;
}
+ public class Text implements androidx.wear.tiles.LayoutElementBuilders.LayoutElement {
+ method public androidx.wear.tiles.ColorBuilders.ColorProp getColor();
+ method public androidx.wear.tiles.LayoutElementBuilders.FontStyle getFontStyle();
+ method public float getLineHeight();
+ method public float getMaxLines();
+ method public androidx.wear.tiles.ModifiersBuilders.Modifiers getModifiers();
+ method public int getMultilineAlignment();
+ method public int getOverflow();
+ method public String getText();
+ }
+
+ public static final class Text.Builder implements androidx.wear.tiles.LayoutElementBuilders.LayoutElement.Builder {
+ ctor public Text.Builder();
+ method public androidx.wear.tiles.material.Text build();
+ method public androidx.wear.tiles.material.Text.Builder setColor(androidx.wear.tiles.ColorBuilders.ColorProp);
+ method public androidx.wear.tiles.material.Text.Builder setText(String);
+ method public androidx.wear.tiles.material.Text.Builder setTypography(int);
+ }
+
public class TitleChip implements androidx.wear.tiles.LayoutElementBuilders.LayoutElement {
method public androidx.wear.tiles.ActionBuilders.Action getAction();
method public androidx.wear.tiles.material.ChipColors getChipColors();
@@ -172,6 +191,21 @@
method public androidx.wear.tiles.material.TitleChip.Builder setWidth(@Dimension(unit=androidx.annotation.Dimension.DP) float);
}
+ public class Typography {
+ field public static final int TYPOGRAPHY_BODY1 = 7; // 0x7
+ field public static final int TYPOGRAPHY_BODY2 = 8; // 0x8
+ field public static final int TYPOGRAPHY_BUTTON = 9; // 0x9
+ field public static final int TYPOGRAPHY_CAPTION1 = 10; // 0xa
+ field public static final int TYPOGRAPHY_CAPTION2 = 11; // 0xb
+ field public static final int TYPOGRAPHY_CAPTION3 = 12; // 0xc
+ field public static final int TYPOGRAPHY_DISPLAY1 = 1; // 0x1
+ field public static final int TYPOGRAPHY_DISPLAY2 = 2; // 0x2
+ field public static final int TYPOGRAPHY_DISPLAY3 = 3; // 0x3
+ field public static final int TYPOGRAPHY_TITLE1 = 4; // 0x4
+ field public static final int TYPOGRAPHY_TITLE2 = 5; // 0x5
+ field public static final int TYPOGRAPHY_TITLE3 = 6; // 0x6
+ }
+
}
package androidx.wear.tiles.material.layouts {
diff --git a/wear/tiles/tiles-material/api/restricted_current.txt b/wear/tiles/tiles-material/api/restricted_current.txt
index 42f4d21..38c920e 100644
--- a/wear/tiles/tiles-material/api/restricted_current.txt
+++ b/wear/tiles/tiles-material/api/restricted_current.txt
@@ -20,8 +20,8 @@
method public androidx.wear.tiles.material.Button.Builder setImageContent(String);
method public androidx.wear.tiles.material.Button.Builder setSize(androidx.wear.tiles.DimensionBuilders.DpProp);
method public androidx.wear.tiles.material.Button.Builder setSize(@Dimension(unit=androidx.annotation.Dimension.DP) float);
- method public androidx.wear.tiles.material.Button.Builder setTextContent(String, androidx.wear.tiles.DeviceParametersBuilders.DeviceParameters);
- method public androidx.wear.tiles.material.Button.Builder setTextContent(String, androidx.wear.tiles.LayoutElementBuilders.FontStyle);
+ method public androidx.wear.tiles.material.Button.Builder setTextContent(String);
+ method public androidx.wear.tiles.material.Button.Builder setTextContent(String, int);
}
public class ButtonColors {
@@ -153,6 +153,25 @@
field public static final float GAP_START_ANGLE = -156.1f;
}
+ public class Text implements androidx.wear.tiles.LayoutElementBuilders.LayoutElement {
+ method public androidx.wear.tiles.ColorBuilders.ColorProp getColor();
+ method public androidx.wear.tiles.LayoutElementBuilders.FontStyle getFontStyle();
+ method public float getLineHeight();
+ method public float getMaxLines();
+ method public androidx.wear.tiles.ModifiersBuilders.Modifiers getModifiers();
+ method public int getMultilineAlignment();
+ method public int getOverflow();
+ method public String getText();
+ }
+
+ public static final class Text.Builder implements androidx.wear.tiles.LayoutElementBuilders.LayoutElement.Builder {
+ ctor public Text.Builder();
+ method public androidx.wear.tiles.material.Text build();
+ method public androidx.wear.tiles.material.Text.Builder setColor(androidx.wear.tiles.ColorBuilders.ColorProp);
+ method public androidx.wear.tiles.material.Text.Builder setText(String);
+ method public androidx.wear.tiles.material.Text.Builder setTypography(int);
+ }
+
public class TitleChip implements androidx.wear.tiles.LayoutElementBuilders.LayoutElement {
method public androidx.wear.tiles.ActionBuilders.Action getAction();
method public androidx.wear.tiles.material.ChipColors getChipColors();
@@ -172,6 +191,21 @@
method public androidx.wear.tiles.material.TitleChip.Builder setWidth(@Dimension(unit=androidx.annotation.Dimension.DP) float);
}
+ public class Typography {
+ field public static final int TYPOGRAPHY_BODY1 = 7; // 0x7
+ field public static final int TYPOGRAPHY_BODY2 = 8; // 0x8
+ field public static final int TYPOGRAPHY_BUTTON = 9; // 0x9
+ field public static final int TYPOGRAPHY_CAPTION1 = 10; // 0xa
+ field public static final int TYPOGRAPHY_CAPTION2 = 11; // 0xb
+ field public static final int TYPOGRAPHY_CAPTION3 = 12; // 0xc
+ field public static final int TYPOGRAPHY_DISPLAY1 = 1; // 0x1
+ field public static final int TYPOGRAPHY_DISPLAY2 = 2; // 0x2
+ field public static final int TYPOGRAPHY_DISPLAY3 = 3; // 0x3
+ field public static final int TYPOGRAPHY_TITLE1 = 4; // 0x4
+ field public static final int TYPOGRAPHY_TITLE2 = 5; // 0x5
+ field public static final int TYPOGRAPHY_TITLE3 = 6; // 0x6
+ }
+
}
package androidx.wear.tiles.material.layouts {
diff --git a/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/Button.java b/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/Button.java
index 440e987..60b0090 100644
--- a/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/Button.java
+++ b/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/Button.java
@@ -34,21 +34,20 @@
import androidx.annotation.RestrictTo.Scope;
import androidx.wear.tiles.ActionBuilders.Action;
import androidx.wear.tiles.ColorBuilders.ColorProp;
-import androidx.wear.tiles.DeviceParametersBuilders.DeviceParameters;
import androidx.wear.tiles.DimensionBuilders.ContainerDimension;
import androidx.wear.tiles.DimensionBuilders.DpProp;
+import androidx.wear.tiles.LayoutElementBuilders;
import androidx.wear.tiles.LayoutElementBuilders.Box;
import androidx.wear.tiles.LayoutElementBuilders.ColorFilter;
import androidx.wear.tiles.LayoutElementBuilders.FontStyle;
-import androidx.wear.tiles.LayoutElementBuilders.FontStyles;
import androidx.wear.tiles.LayoutElementBuilders.Image;
import androidx.wear.tiles.LayoutElementBuilders.LayoutElement;
-import androidx.wear.tiles.LayoutElementBuilders.Text;
import androidx.wear.tiles.ModifiersBuilders;
import androidx.wear.tiles.ModifiersBuilders.Background;
import androidx.wear.tiles.ModifiersBuilders.Clickable;
import androidx.wear.tiles.ModifiersBuilders.Corner;
import androidx.wear.tiles.ModifiersBuilders.Modifiers;
+import androidx.wear.tiles.material.Typography.TypographyName;
import androidx.wear.tiles.proto.LayoutElementProto;
import java.lang.annotation.Retention;
@@ -92,14 +91,15 @@
@NonNull private String mContentDescription = "";
@NonNull private DpProp mSize = DEFAULT_BUTTON_SIZE;
@Nullable private String mText = null;
- @Nullable private FontStyle mFontStyle = null;
+ private @TypographyName int mTypographyName =
+ getDefaultTypographyForSize(DEFAULT_BUTTON_SIZE);
+ private boolean mIsTypographyNameSet = false;
@Nullable private String mIcon = null;
@Nullable private DpProp mIconSize = null;
@Nullable private String mImage = null;
@NonNull private ButtonColors mButtonColors = PRIMARY_BUTTON_COLORS;
private @ButtonType int mType = NOT_SET;
private boolean mDefaultSize = false;
- @Nullable private DeviceParameters mDeviceParameters = null;
/**
* Creates a builder for the {@link Button} from the given content. Custom content should be
@@ -216,39 +216,38 @@
* Sets the content of this Button to be the given text with the default font for the set
* size (for the {@link ButtonDefaults#DEFAULT_BUTTON_SIZE}, {@link
* ButtonDefaults#LARGE_BUTTON_SIZE} and {@link ButtonDefaults#EXTRA_LARGE_BUTTON_SIZE} is
- * {@link FontStyles#title2}, {@link FontStyles#title1} and {@link FontStyles#display3}
- * respectively). Any previously added content will be overridden. Text should contain no
- * more than 3 characters, otherwise it will overflow from the edges.
+ * {@link Typography#TYPOGRAPHY_TITLE2}, {@link Typography#TYPOGRAPHY_TITLE1} and {@link
+ * Typography#TYPOGRAPHY_DISPLAY3} respectively). Any previously added content will be
+ * overridden. Text should contain no more than 3 characters, otherwise it will overflow
+ * from the edges.
*/
// There are multiple methods to set different type of content, but there is general getter
// getContent that will return LayoutElement set by any of them. b/217197259
@NonNull
@SuppressWarnings("MissingGetterMatchingBuilder")
- public Builder setTextContent(
- @NonNull String text, @NonNull DeviceParameters deviceParameters) {
+ public Builder setTextContent(@NonNull String text) {
resetContent();
this.mText = text;
- this.mDeviceParameters = deviceParameters;
this.mType = TEXT;
this.mDefaultSize = true;
return this;
}
/**
- * Sets the content of this Button to be the given text with the given font. You shouldn't
- * add color to your font as it will be overridden by the {@link
- * ButtonColors#getContentColor}. Only {@link #setButtonColors} should be used for
- * customizing the colors of the button. Any previously added content will be overridden.
- * Text should contain no more than 3 characters, otherwise it will overflow from the edges.
+ * Sets the content of this Button to be the given text with the given font. If you need
+ * more font related customization, consider using {@link #setContent} with {@link Text}
+ * component. Any previously added content will be overridden. Text should contain no more
+ * than 3 characters, otherwise it will overflow from the edges.
*/
// There are multiple methods to set different type of content, but there is general getter
// getContent that will return LayoutElement set by any of them. b/217197259
@NonNull
@SuppressWarnings("MissingGetterMatchingBuilder")
- public Builder setTextContent(@NonNull String text, @NonNull FontStyle font) {
+ public Builder setTextContent(@NonNull String text, @TypographyName int typographyName) {
resetContent();
this.mText = text;
- this.mFontStyle = font;
+ this.mTypographyName = typographyName;
+ this.mIsTypographyNameSet = true;
this.mType = TEXT;
this.mDefaultSize = false;
return this;
@@ -274,7 +273,7 @@
private void resetContent() {
this.mText = null;
- this.mFontStyle = null;
+ this.mIsTypographyNameSet = false;
this.mIcon = null;
this.mImage = null;
this.mCustomContent = null;
@@ -345,28 +344,16 @@
}
case TEXT:
{
- FontStyle fontStyle;
- if (mFontStyle != null) {
- fontStyle =
- FontStyle.fromProto(
- mFontStyle.toProto().toBuilder()
- .setColor(
- mButtonColors
- .getContentColor()
- .toProto())
- .build());
- } else {
- fontStyle =
- getDefaultFontForSize(mSize, checkNotNull(mDeviceParameters))
- .setColor(mButtonColors.getContentColor())
- .build();
- }
-
+ @TypographyName
+ int typographyName =
+ mIsTypographyNameSet
+ ? mTypographyName : getDefaultTypographyForSize(mSize);
mContent =
new Text.Builder()
- .setText(checkNotNull(mText))
- .setMaxLines(1)
- .setFontStyle(fontStyle);
+ .setText(checkNotNull(mText))
+ .setMaxLines(1)
+ .setTypography(typographyName)
+ .setColor(mButtonColors.getContentColor());
return mContent.build();
}
@@ -413,37 +400,33 @@
}
}
- @NonNull
- private FontStyle.Builder getDefaultFontForSize(
- @NonNull DpProp size, @NonNull DeviceParameters deviceParameters) {
+ private @TypographyName int getDefaultTypographyForSize(@NonNull DpProp size) {
if (size.getValue() == LARGE_BUTTON_SIZE.getValue()) {
- return FontStyles.title1(deviceParameters);
+ return Typography.TYPOGRAPHY_TITLE1;
} else {
if (size.getValue() == EXTRA_LARGE_BUTTON_SIZE.getValue()) {
- return FontStyles.display3(deviceParameters);
+ return Typography.TYPOGRAPHY_DISPLAY3;
} else {
- return FontStyles.title2(deviceParameters);
+ return Typography.TYPOGRAPHY_TITLE2;
}
}
}
}
- /** Returns the content of this Button. Intended for testing purposes only. */
+ /** Returns the content of this Button. */
@NonNull
public LayoutElement getContent() {
return checkNotNull(mElement.getContents().get(0));
}
- /**
- * Returns click event action associated with this Button. Intended for testing purposes only.
- */
+ /** Returns click event action associated with this Button. */
@NonNull
public Action getAction() {
return checkNotNull(
checkNotNull(checkNotNull(mElement.getModifiers()).getClickable()).getOnClick());
}
- /** Returns content description for this Button. Intended for testing purposes only. */
+ /** Returns content description for this Button. */
@NonNull
public String getContentDescription() {
return checkNotNull(
@@ -451,7 +434,7 @@
.getContentDescription());
}
- /** Returns size for this Button. Intended for testing purposes only. */
+ /** Returns size for this Button. */
@NonNull
public ContainerDimension getSize() {
return checkNotNull(mElement.getWidth());
@@ -462,7 +445,7 @@
checkNotNull(checkNotNull(mElement.getModifiers()).getBackground()).getColor());
}
- /** Returns button color of this Button. Intended for testing purposes only. */
+ /** Returns button color of this Button. */
@NonNull
public ButtonColors getButtonColors() {
ColorProp backgroundColor = getBackgroundColor();
@@ -477,7 +460,11 @@
break;
case Builder.TEXT:
contentColor =
- checkNotNull(checkNotNull(((Text) mainElement).getFontStyle()).getColor());
+ checkNotNull(
+ checkNotNull(
+ ((LayoutElementBuilders.Text) mainElement)
+ .getFontStyle())
+ .getColor());
break;
case Builder.IMAGE:
case Builder.CUSTOM_CONTENT:
@@ -502,8 +489,9 @@
* have color.
*/
private @Builder.ButtonType int getType(LayoutElement element) {
- if (element instanceof Text) {
- FontStyle fontStyle = ((Text) element).getFontStyle();
+ // To elementary Text class as Material Text when it goes to proto disappears.
+ if (element instanceof LayoutElementBuilders.Text) {
+ FontStyle fontStyle = ((LayoutElementBuilders.Text) element).getFontStyle();
if (fontStyle != null && fontStyle.getColor() != null) {
return Builder.TEXT;
}
diff --git a/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/Chip.java b/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/Chip.java
index 0391a36..9c74f0d 100644
--- a/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/Chip.java
+++ b/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/Chip.java
@@ -43,20 +43,18 @@
import androidx.wear.tiles.LayoutElementBuilders.Box;
import androidx.wear.tiles.LayoutElementBuilders.ColorFilter;
import androidx.wear.tiles.LayoutElementBuilders.Column;
-import androidx.wear.tiles.LayoutElementBuilders.FontStyle;
-import androidx.wear.tiles.LayoutElementBuilders.FontStyles;
import androidx.wear.tiles.LayoutElementBuilders.HorizontalAlignment;
import androidx.wear.tiles.LayoutElementBuilders.Image;
import androidx.wear.tiles.LayoutElementBuilders.LayoutElement;
import androidx.wear.tiles.LayoutElementBuilders.Row;
import androidx.wear.tiles.LayoutElementBuilders.Spacer;
-import androidx.wear.tiles.LayoutElementBuilders.Text;
import androidx.wear.tiles.ModifiersBuilders;
import androidx.wear.tiles.ModifiersBuilders.Background;
import androidx.wear.tiles.ModifiersBuilders.Clickable;
import androidx.wear.tiles.ModifiersBuilders.Corner;
import androidx.wear.tiles.ModifiersBuilders.Modifiers;
import androidx.wear.tiles.ModifiersBuilders.Padding;
+import androidx.wear.tiles.material.Typography.TypographyName;
import androidx.wear.tiles.proto.LayoutElementProto;
import java.lang.annotation.Retention;
@@ -68,10 +66,10 @@
* optional icon or with custom content.
*
* <p>The Chip is Stadium shape and has a max height designed to take no more than two lines of text
- * of {@link FontStyles#button} style. The {@link Chip} can have an icon horizontally parallel to
- * the two lines of text. Width of chip can very, and the recommended size is screen dependent with
- * the recommended margin being defined in {@link ChipDefaults#DEFAULT_MARGIN_PERCENT} which is set
- * by default.
+ * of {@link Typography#TYPOGRAPHY_BUTTON} style. The {@link Chip} can have an icon horizontally
+ * parallel to the two lines of text. Width of chip can very, and the recommended size is screen
+ * dependent with the recommended margin being defined in
+ * {@link ChipDefaults#DEFAULT_MARGIN_PERCENT} which is set by default.
*
* <p>The recommended set of {@link ChipColors} styles can be obtained from {@link ChipDefaults}.,
* e.g. {@link ChipDefaults#PRIMARY} to get a color scheme for a primary {@link Chip} which by
@@ -105,14 +103,13 @@
@Nullable private String mLabelText = null;
@NonNull private final Action mAction;
@NonNull private final String mClickableId;
- @NonNull private final DeviceParameters mDeviceParameters;
@NonNull private String mContentDescription = "";
@NonNull private ContainerDimension mWidth;
@NonNull private DpProp mHeight = DEFAULT_HEIGHT;
@NonNull private ChipColors mChipColors = PRIMARY;
private @ChipType int mType = NOT_SET;
private @HorizontalAlignment int mHorizontalAlign = HORIZONTAL_ALIGN_START;
- @NonNull private FontStyle mPrimaryTextFont;
+ @TypographyName private int mPrimaryTextTypography;
@NonNull private DpProp mHorizontalPadding = HORIZONTAL_PADDING;
@NonNull private DpProp mVerticalPadding = VERTICAL_PADDING;
@@ -123,7 +120,7 @@
* @param action Associated Actions for click events. When the Chip is clicked it will fire
* the associated action.
* @param clickableId The ID associated with the given action's clickable.
- * @param deviceParameters The device parameters used for styling text.
+ * @param deviceParameters The device parameters used to derive defaults for this Chip.
*/
@SuppressWarnings("LambdaLast")
public Builder(
@@ -132,13 +129,12 @@
@NonNull DeviceParameters deviceParameters) {
mAction = action;
mClickableId = clickableId;
- mDeviceParameters = deviceParameters;
mWidth =
dp(
(100 - 2 * DEFAULT_MARGIN_PERCENT)
* deviceParameters.getScreenWidthDp()
/ 100);
- mPrimaryTextFont = FontStyles.button(deviceParameters).build();
+ mPrimaryTextTypography = Typography.TYPOGRAPHY_BUTTON;
}
/**
@@ -203,8 +199,8 @@
* <p>Sets the font for the primary text and should only be used internally.
*/
@NonNull
- Builder setPrimaryTextFontStyle(@NonNull FontStyle fontStyle) {
- this.mPrimaryTextFont = fontStyle;
+ Builder setPrimaryTextTypography(@TypographyName int typography) {
+ this.mPrimaryTextTypography = typography;
return this;
}
@@ -276,7 +272,6 @@
return this;
}
- // TODO(b/207350548): In RTL mode, should icon still be on the left.
/**
* Sets the horizontal alignment in the chip. It is strongly recommended that the content of
* the chip is start-aligned if there is more than primary text in it. If not set, {@link
@@ -372,7 +367,7 @@
if (mType == NOT_SET) {
throw new IllegalStateException(
"No content set. Use setPrimaryTextContent or similar method to add"
- + " content");
+ + " content");
}
if (mType == CUSTOM_CONTENT) {
return checkNotNull(mCustomContent);
@@ -380,7 +375,8 @@
Text mainTextElement =
new Text.Builder()
.setText(mPrimaryText)
- .setFontStyle(customizeFontStyle())
+ .setTypography(mPrimaryTextTypography)
+ .setColor(mChipColors.getContentColor())
.setMaxLines(getCorrectMaxLines())
.setOverflow(LayoutElementBuilders.TEXT_OVERFLOW_TRUNCATE)
.setMultilineAlignment(LayoutElementBuilders.TEXT_ALIGN_START)
@@ -395,10 +391,8 @@
Text labelTextElement =
new Text.Builder()
.setText(mLabelText)
- .setFontStyle(
- FontStyles.caption2(mDeviceParameters)
- .setColor(mChipColors.getSecondaryContentColor())
- .build())
+ .setTypography(Typography.TYPOGRAPHY_CAPTION2)
+ .setColor(mChipColors.getSecondaryContentColor())
.setMaxLines(1)
.setOverflow(LayoutElementBuilders.TEXT_OVERFLOW_TRUNCATE)
.setMultilineAlignment(LayoutElementBuilders.TEXT_ALIGN_START)
@@ -431,13 +425,6 @@
}
}
- private FontStyle customizeFontStyle() {
- return FontStyle.fromProto(
- mPrimaryTextFont.toProto().toBuilder()
- .setColor(mChipColors.getContentColor().toProto())
- .build());
- }
-
private int getCorrectMaxLines() {
if (mMaxLines > 0) {
return mMaxLines;
@@ -503,13 +490,17 @@
if (contents.size() == 1 || contents.size() == 2) {
// This is potentially our chip and this part contains 1 or 2 lines of text.
LayoutElement element = contents.get(0);
- if (element instanceof Text) {
- contentColor = getTextColorFromContent((Text) element);
+ // To elementary Text class as Material Text when it goes to proto disappears.
+ if (element instanceof LayoutElementBuilders.Text) {
+ contentColor = getTextColorFromContent((LayoutElementBuilders.Text) element);
if (contents.size() == 2) {
element = contents.get(1);
- if (element instanceof Text) {
- secondaryContentColor = getTextColorFromContent((Text) element);
+ // To elementary Text class as Material Text when it goes to proto
+ // disappears.
+ if (element instanceof LayoutElementBuilders.Text) {
+ secondaryContentColor =
+ getTextColorFromContent((LayoutElementBuilders.Text) element);
}
}
}
@@ -530,7 +521,7 @@
return new ChipColors(backgroundColor, iconTintColor, contentColor, secondaryContentColor);
}
- private ColorProp getTextColorFromContent(Text text) {
+ private ColorProp getTextColorFromContent(LayoutElementBuilders.Text text) {
ColorProp color = new ColorProp.Builder().build();
if (text.getFontStyle() != null && text.getFontStyle().getColor() != null) {
color = checkNotNull(checkNotNull(text.getFontStyle()).getColor());
diff --git a/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/CircularProgressIndicator.java b/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/CircularProgressIndicator.java
index 1f4eea9..8455984 100644
--- a/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/CircularProgressIndicator.java
+++ b/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/CircularProgressIndicator.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 The Android Open Source Project
+ * Copyright 2022 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.
@@ -45,15 +45,14 @@
/**
* Tiles component {@link CircularProgressIndicator} that represents circular progress indicator
- * which supports a gap in the circular track between startAngle and endAngle.
- * [Progress Indicator doc]
- * (https://developer.android.com/training/wearables/components/progress-indicator)
+ * which supports a gap in the circular track between startAngle and endAngle. [Progress Indicator
+ * doc] (https://developer.android.com/training/wearables/components/progress-indicator)
*
* <p>The CircularProgressIndicator is a colored arc around the edge of the screen with the given
* start and end angles, which can describe a full or partial circle. Behind it is an arc with
- * optional gap representing full progress. The recommended sizes are defined in
- * {@link ProgressIndicatorDefaults}. Unless specified, the CircularProgressIndicator will have
- * the full length.
+ * optional gap representing full progress. The recommended sizes are defined in {@link
+ * ProgressIndicatorDefaults}. Unless specified, the CircularProgressIndicator will have the full
+ * length.
*
* <p>The recommended set of {@link ProgressIndicatorColors} can be obtained from {@link
* ProgressIndicatorDefaults}., e.g. {@link ProgressIndicatorDefaults#DEFAULT_COLOR} to get a color
@@ -192,8 +191,8 @@
.addContent(
new ArcLine.Builder()
.setColor(
- mCircularProgressIndicatorColors.getTrackColor()
- )
+ mCircularProgressIndicatorColors
+ .getTrackColor())
.setThickness(mStrokeWidth)
.setLength(length)
.build())
@@ -207,8 +206,7 @@
new ArcLine.Builder()
.setColor(
mCircularProgressIndicatorColors
- .getIndicatorColor()
- )
+ .getIndicatorColor())
.setThickness(mStrokeWidth)
.setLength(degrees(mProgress * length.getValue()))
.build());
diff --git a/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/CompactChip.java b/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/CompactChip.java
index b7021fb..55b9eaa 100644
--- a/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/CompactChip.java
+++ b/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/CompactChip.java
@@ -28,7 +28,6 @@
import androidx.wear.tiles.DeviceParametersBuilders.DeviceParameters;
import androidx.wear.tiles.DimensionBuilders.ContainerDimension;
import androidx.wear.tiles.DimensionBuilders.WrappedDimensionProp;
-import androidx.wear.tiles.LayoutElementBuilders.FontStyles;
import androidx.wear.tiles.LayoutElementBuilders.LayoutElement;
import androidx.wear.tiles.proto.LayoutElementProto;
@@ -36,7 +35,8 @@
* Tiles component {@link CompactChip} that represents clickable object with the text.
*
* <p>The Chip is Stadium shape and has a max height designed to take no more than one line of text
- * of {@link FontStyles#caption1} style. Width of the chip is adjustable to the text size.
+ * of {@link Typography#TYPOGRAPHY_CAPTION1} style. Width of the chip is adjustable to the text
+ * size.
*
* <p>The recommended set of {@link ChipColors} styles can be obtained from {@link ChipDefaults}.,
* e.g. {@link ChipDefaults#COMPACT_PRIMARY} to get a color scheme for a primary {@link CompactChip}
@@ -105,8 +105,7 @@
.setHeight(COMPACT_HEIGHT)
.setHorizontalPadding(COMPACT_HORIZONTAL_PADDING)
.setPrimaryTextContent(mText)
- .setPrimaryTextFontStyle(
- FontStyles.caption1(mDeviceParameters).build());
+ .setPrimaryTextTypography(Typography.TYPOGRAPHY_CAPTION1);
return new CompactChip(chipBuilder.build());
}
diff --git a/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/Helper.java b/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/Helper.java
index 85adda7..08c5d74 100644
--- a/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/Helper.java
+++ b/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/Helper.java
@@ -37,7 +37,10 @@
/**
* Returns given value if not null or throws {@code NullPointerException} otherwise.
+ *
+ * @hide
*/
+ @RestrictTo(Scope.LIBRARY_GROUP)
@NonNull
public static <T> T checkNotNull(@Nullable T value) {
if (value == null) {
@@ -53,7 +56,10 @@
/**
* Returns true if the given DeviceParameters belong to the round screen device.
+ *
+ * @hide
*/
+ @RestrictTo(Scope.LIBRARY_GROUP)
public static boolean isRoundDevice(@NonNull DeviceParameters deviceParameters) {
return deviceParameters.getScreenShape() == DeviceParametersBuilders.SCREEN_SHAPE_ROUND;
}
diff --git a/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/Text.java b/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/Text.java
new file mode 100644
index 0000000..1d94bb5
--- /dev/null
+++ b/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/Text.java
@@ -0,0 +1,218 @@
+/*
+ * Copyright 2022 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 androidx.wear.tiles.material;
+
+import static androidx.wear.tiles.ColorBuilders.argb;
+import static androidx.wear.tiles.LayoutElementBuilders.TEXT_ALIGN_CENTER;
+import static androidx.wear.tiles.LayoutElementBuilders.TEXT_OVERFLOW_TRUNCATE;
+import static androidx.wear.tiles.material.Helper.checkNotNull;
+import static androidx.wear.tiles.material.Typography.TYPOGRAPHY_DISPLAY1;
+import static androidx.wear.tiles.material.Typography.getFontStyleBuilder;
+import static androidx.wear.tiles.material.Typography.getLineHeightForTypography;
+
+import androidx.annotation.IntRange;
+import androidx.annotation.NonNull;
+import androidx.annotation.RestrictTo;
+import androidx.annotation.RestrictTo.Scope;
+import androidx.wear.tiles.ColorBuilders.ColorProp;
+import androidx.wear.tiles.LayoutElementBuilders;
+import androidx.wear.tiles.LayoutElementBuilders.FontStyle;
+import androidx.wear.tiles.LayoutElementBuilders.LayoutElement;
+import androidx.wear.tiles.LayoutElementBuilders.TextAlignment;
+import androidx.wear.tiles.LayoutElementBuilders.TextOverflow;
+import androidx.wear.tiles.ModifiersBuilders.Modifiers;
+import androidx.wear.tiles.material.Typography.TypographyName;
+import androidx.wear.tiles.proto.LayoutElementProto;
+
+/**
+ * Tiles component {@link Text} that represents text object holding any information.
+ *
+ * <p>There are pre-built typography styles that can be obtained from constants in
+ * {@link Typography}.
+ */
+public class Text implements LayoutElement {
+ @NonNull private final LayoutElementBuilders.Text mText;
+
+ Text(@NonNull LayoutElementBuilders.Text mText) {
+ this.mText = mText;
+ }
+
+ /** Builder class for {@link Text}. */
+ public static final class Builder implements LayoutElement.Builder {
+ @NonNull private String mTextContent = "";
+ @NonNull private ColorProp mColor = argb(Colors.ON_PRIMARY);
+ private @TypographyName int mTypographyName = TYPOGRAPHY_DISPLAY1;
+ private boolean mItalic = false;
+ private int mMaxLines = 1;
+ private boolean mUnderline = false;
+ private @TextAlignment int mMultilineAlignment = TEXT_ALIGN_CENTER;
+ @NonNull private Modifiers mModifiers = new Modifiers.Builder().build();
+ private @TextOverflow int mOverflow = TEXT_OVERFLOW_TRUNCATE;
+
+ /** Sets the text content for the {@link Text}. */
+ @NonNull
+ public Builder setText(@NonNull String text) {
+ this.mTextContent = text;
+ return this;
+ }
+
+ /**
+ * Sets the typography for the {@link Text}. If not set,
+ * {@link Typography#TYPOGRAPHY_TITLE1} will be used.
+ */
+ @NonNull
+ @SuppressWarnings("MissingGetterMatchingBuilder")
+ // There is getFontStyle matching getter for this setter as the serialized format of the
+ // ProtoLayouts do not allow for a direct reconstruction of the all arguments, but it has
+ // FontStyle object of that text.
+ public Builder setTypography(@TypographyName int typography) {
+ this.mTypographyName = typography;
+ return this;
+ }
+
+ /**
+ * Sets the color for the {@link Text}. If not set, {@link Colors#ON_PRIMARY} will be
+ * used.
+ */
+ @NonNull
+ public Builder setColor(@NonNull ColorProp color) {
+ this.mColor = color;
+ return this;
+ }
+
+ /** Sets the text to be italic. */
+ @NonNull
+ Builder setItalic(boolean italic) {
+ this.mItalic = italic;
+ return this;
+ }
+
+ /** Sets the text to be underlined. */
+ @NonNull
+ Builder setUnderline(boolean underline) {
+ this.mUnderline = underline;
+ return this;
+ }
+
+ /** Sets the maximum lines of text. If not set, 1 will be used. */
+ @NonNull
+ Builder setMaxLines(@IntRange(from = 1) int maxLines) {
+ this.mMaxLines = maxLines;
+ return this;
+ }
+
+ /**
+ * Sets the mutliline alignenment for text. If not set, {@link
+ * TextAlignment#TEXT_ALIGN_CENTER} will be used.
+ */
+ @NonNull
+ Builder setMultilineAlignment(@TextAlignment int multilineAlignment) {
+ this.mMultilineAlignment = multilineAlignment;
+ return this;
+ }
+
+ /** Sets the modifiers of text. */
+ @NonNull
+ Builder setModifiers(@NonNull Modifiers modifiers) {
+ this.mModifiers = modifiers;
+ return this;
+ }
+
+ /**
+ * Sets the overflow for text. If not set, {@link TextAlignment#TEXT_OVERFLOW_TRUNCATE} will
+ * be used.
+ */
+ @NonNull
+ Builder setOverflow(@TextOverflow int overflow) {
+ this.mOverflow = overflow;
+ return this;
+ }
+
+ /** Constructs and returns {@link Text} with the provided content and look. */
+ @NonNull
+ @Override
+ public Text build() {
+ LayoutElementBuilders.Text.Builder text =
+ new LayoutElementBuilders.Text.Builder()
+ .setText(mTextContent)
+ .setFontStyle(
+ getFontStyleBuilder(mTypographyName)
+ .setColor(mColor)
+ .setItalic(mItalic)
+ .setUnderline(mUnderline)
+ .build())
+ .setLineHeight(getLineHeightForTypography(mTypographyName))
+ .setMaxLines(mMaxLines)
+ .setMultilineAlignment(mMultilineAlignment)
+ .setModifiers(mModifiers)
+ .setOverflow(mOverflow);
+ return new Text(text.build());
+ }
+ }
+
+ /** Returns the text of this Text element. */
+ @NonNull
+ public String getText() {
+ return checkNotNull(checkNotNull(mText.getText()).getValue());
+ }
+
+ /** Returns the color of this Text element. */
+ @NonNull
+ public ColorProp getColor() {
+ return checkNotNull(checkNotNull(mText.getFontStyle()).getColor());
+ }
+
+ /** Returns the font style of this Text element. */
+ @NonNull
+ public FontStyle getFontStyle() {
+ return checkNotNull(mText.getFontStyle());
+ }
+
+ /** Returns the line height of this Text element. */
+ public float getLineHeight() {
+ return checkNotNull(mText.getLineHeight()).getValue();
+ }
+
+ /** Returns the max lines of text of this Text element. */
+ public float getMaxLines() {
+ return checkNotNull(mText.getMaxLines()).getValue();
+ }
+
+ /** Returns the multiline alignment of this Text element. */
+ public @TextAlignment int getMultilineAlignment() {
+ return checkNotNull(mText.getMultilineAlignment()).getValue();
+ }
+
+ /** Returns the modifiers of this Text element. */
+ @NonNull
+ public Modifiers getModifiers() {
+ return checkNotNull(mText.getModifiers());
+ }
+
+ /** Returns the overflow of this Text element. */
+ public @TextOverflow int getOverflow() {
+ return checkNotNull(mText.getOverflow()).getValue();
+ }
+
+ /** @hide */
+ @NonNull
+ @Override
+ @RestrictTo(Scope.LIBRARY_GROUP)
+ public LayoutElementProto.LayoutElement toLayoutElementProto() {
+ return mText.toLayoutElementProto();
+ }
+}
diff --git a/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/TitleChip.java b/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/TitleChip.java
index 37a565a..7efa8b4 100644
--- a/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/TitleChip.java
+++ b/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/TitleChip.java
@@ -32,7 +32,6 @@
import androidx.wear.tiles.DeviceParametersBuilders.DeviceParameters;
import androidx.wear.tiles.DimensionBuilders.ContainerDimension;
import androidx.wear.tiles.DimensionBuilders.DpProp;
-import androidx.wear.tiles.LayoutElementBuilders.FontStyles;
import androidx.wear.tiles.LayoutElementBuilders.HorizontalAlignment;
import androidx.wear.tiles.LayoutElementBuilders.LayoutElement;
import androidx.wear.tiles.proto.LayoutElementProto;
@@ -41,7 +40,7 @@
* Tiles component {@link TitleChip} that represents clickable object with the text.
*
* <p>The Title Chip is Stadium shaped object with a larger height then standard Chip and it will
- * take one line of text of {@link FontStyles#title2} style.
+ * take one line of text of {@link Typography#TYPOGRAPHY_TITLE2} style.
*
* <p>The recommended set of {@link ChipColors} styles can be obtained from {@link ChipDefaults},
* e.g. {@link ChipDefaults#TITLE_PRIMARY} to get a color scheme for a primary {@link TitleChip}
@@ -143,7 +142,7 @@
.setMaxLines(1)
.setHorizontalPadding(TITLE_HORIZONTAL_PADDING)
.setPrimaryTextContent(mText)
- .setPrimaryTextFontStyle(FontStyles.title2(mDeviceParameters).build());
+ .setPrimaryTextTypography(Typography.TYPOGRAPHY_TITLE2);
if (mWidth != null) {
chipBuilder.setWidth(mWidth);
diff --git a/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/Typography.java b/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/Typography.java
new file mode 100644
index 0000000..6137980d
--- /dev/null
+++ b/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/Typography.java
@@ -0,0 +1,252 @@
+/*
+ * Copyright 2022 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 androidx.wear.tiles.material;
+
+import static androidx.annotation.Dimension.SP;
+import static androidx.wear.tiles.DimensionBuilders.sp;
+import static androidx.wear.tiles.LayoutElementBuilders.FONT_WEIGHT_BOLD;
+import static androidx.wear.tiles.LayoutElementBuilders.FONT_WEIGHT_MEDIUM;
+import static androidx.wear.tiles.LayoutElementBuilders.FONT_WEIGHT_NORMAL;
+import static androidx.wear.tiles.material.Helper.checkNotNull;
+
+import android.annotation.SuppressLint;
+
+import androidx.annotation.Dimension;
+import androidx.annotation.IntDef;
+import androidx.annotation.NonNull;
+import androidx.annotation.RestrictTo;
+import androidx.wear.tiles.DimensionBuilders;
+import androidx.wear.tiles.DimensionBuilders.SpProp;
+import androidx.wear.tiles.LayoutElementBuilders.FontStyle;
+import androidx.wear.tiles.LayoutElementBuilders.FontWeight;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.util.HashMap;
+import java.util.Map;
+
+/** Typography styles, currently set up to match Wear's styling. */
+public class Typography {
+ /** Typography for large display text. */
+ public static final int TYPOGRAPHY_DISPLAY1 = 1;
+
+ /** Typography for medium display text. */
+ public static final int TYPOGRAPHY_DISPLAY2 = 2;
+
+ /** Typography for small display text. */
+ public static final int TYPOGRAPHY_DISPLAY3 = 3;
+
+ /** Typography for large title text. */
+ public static final int TYPOGRAPHY_TITLE1 = 4;
+
+ /** Typography for medium title text. */
+ public static final int TYPOGRAPHY_TITLE2 = 5;
+
+ /** Typography for small title text. */
+ public static final int TYPOGRAPHY_TITLE3 = 6;
+
+ /** Typography for large body text. */
+ public static final int TYPOGRAPHY_BODY1 = 7;
+
+ /** Typography for medium body text. */
+ public static final int TYPOGRAPHY_BODY2 = 8;
+
+ /** Typography for bold button text. */
+ public static final int TYPOGRAPHY_BUTTON = 9;
+
+ /** Typography for large caption text. */
+ public static final int TYPOGRAPHY_CAPTION1 = 10;
+
+ /** Typography for medium caption text. */
+ public static final int TYPOGRAPHY_CAPTION2 = 11;
+
+ /** Typography for small caption text. */
+ public static final int TYPOGRAPHY_CAPTION3 = 12;
+
+ /** @hide */
+ @RestrictTo(RestrictTo.Scope.LIBRARY)
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef({
+ TYPOGRAPHY_DISPLAY1,
+ TYPOGRAPHY_DISPLAY2,
+ TYPOGRAPHY_DISPLAY3,
+ TYPOGRAPHY_TITLE1,
+ TYPOGRAPHY_TITLE2,
+ TYPOGRAPHY_TITLE3,
+ TYPOGRAPHY_BODY1,
+ TYPOGRAPHY_BODY2,
+ TYPOGRAPHY_BUTTON,
+ TYPOGRAPHY_CAPTION1,
+ TYPOGRAPHY_CAPTION2,
+ TYPOGRAPHY_CAPTION3
+ })
+ public @interface TypographyName {}
+
+ /** Mapping for line height for different typography. */
+ @NonNull
+ private static final Map<Integer, Float> FONT_STYLE_TO_LINE_HEIGHT_SP = new HashMap<>();
+
+ static {
+ FONT_STYLE_TO_LINE_HEIGHT_SP.put(TYPOGRAPHY_DISPLAY1, 46f);
+ FONT_STYLE_TO_LINE_HEIGHT_SP.put(TYPOGRAPHY_DISPLAY2, 40f);
+ FONT_STYLE_TO_LINE_HEIGHT_SP.put(TYPOGRAPHY_DISPLAY3, 36f);
+ FONT_STYLE_TO_LINE_HEIGHT_SP.put(TYPOGRAPHY_TITLE1, 28f);
+ FONT_STYLE_TO_LINE_HEIGHT_SP.put(TYPOGRAPHY_TITLE2, 24f);
+ FONT_STYLE_TO_LINE_HEIGHT_SP.put(TYPOGRAPHY_TITLE3, 20f);
+ FONT_STYLE_TO_LINE_HEIGHT_SP.put(TYPOGRAPHY_BODY1, 20f);
+ FONT_STYLE_TO_LINE_HEIGHT_SP.put(TYPOGRAPHY_BODY2, 18f);
+ FONT_STYLE_TO_LINE_HEIGHT_SP.put(TYPOGRAPHY_BUTTON, 19f);
+ FONT_STYLE_TO_LINE_HEIGHT_SP.put(TYPOGRAPHY_CAPTION1, 18f);
+ FONT_STYLE_TO_LINE_HEIGHT_SP.put(TYPOGRAPHY_CAPTION2, 16f);
+ FONT_STYLE_TO_LINE_HEIGHT_SP.put(TYPOGRAPHY_CAPTION3, 14f);
+ }
+
+ private Typography() {}
+
+ /**
+ * Returns the {@link FontStyle.Builder} for the given Typography name with the recommended
+ * size, weight and letter spacing.
+ */
+ @NonNull
+ static FontStyle.Builder getFontStyleBuilder(@TypographyName int typographyCode) {
+ switch (typographyCode) {
+ case TYPOGRAPHY_BODY1:
+ return body1();
+ case TYPOGRAPHY_BODY2:
+ return body2();
+ case TYPOGRAPHY_BUTTON:
+ return button();
+ case TYPOGRAPHY_CAPTION1:
+ return caption1();
+ case TYPOGRAPHY_CAPTION2:
+ return caption2();
+ case TYPOGRAPHY_CAPTION3:
+ return caption3();
+ case TYPOGRAPHY_DISPLAY1:
+ return display1();
+ case TYPOGRAPHY_DISPLAY2:
+ return display2();
+ case TYPOGRAPHY_DISPLAY3:
+ return display3();
+ case TYPOGRAPHY_TITLE1:
+ return title1();
+ case TYPOGRAPHY_TITLE2:
+ return title2();
+ case TYPOGRAPHY_TITLE3:
+ return title3();
+ default:
+ // Shouldn't happen.
+ throw new IllegalArgumentException(
+ "Typography name " + typographyCode + " doesn't exist.");
+ }
+ }
+
+ /**
+ * Returns the recommended line height for the given Typography to be added to the Text
+ * component.
+ */
+ @NonNull
+ static SpProp getLineHeightForTypography(@TypographyName int typography) {
+ if (!FONT_STYLE_TO_LINE_HEIGHT_SP.containsKey(typography)) {
+ throw new IllegalArgumentException("Typography " + typography + " doesn't exist.");
+ }
+ return sp(checkNotNull(FONT_STYLE_TO_LINE_HEIGHT_SP.get(typography)).intValue());
+ }
+
+ // The @Dimension(unit = SP) on sp() is seemingly being ignored, so lint complains that we're
+ // passing SP to something expecting PX. Just suppress the warning for now.
+ @SuppressLint("ResourceType")
+ private static FontStyle.Builder createFontStyleBuilder(
+ @Dimension(unit = SP) int size, @FontWeight int weight, float letterSpacing) {
+ return new FontStyle.Builder()
+ .setSize(DimensionBuilders.sp(size))
+ .setLetterSpacing(DimensionBuilders.em(letterSpacing))
+ .setWeight(weight);
+ }
+
+ /** Font style for large display text. */
+ @NonNull
+ private static FontStyle.Builder display1() {
+ return createFontStyleBuilder(40, FONT_WEIGHT_MEDIUM, 0.01f);
+ }
+
+ /** Font style for medium display text. */
+ @NonNull
+ private static FontStyle.Builder display2() {
+ return createFontStyleBuilder(34, FONT_WEIGHT_MEDIUM, 0.03f);
+ }
+
+ /** Font style for small display text. */
+ @NonNull
+ private static FontStyle.Builder display3() {
+ return createFontStyleBuilder(30, FONT_WEIGHT_MEDIUM, 0.03f);
+ }
+
+ /** Font style for large title text. */
+ @NonNull
+ private static FontStyle.Builder title1() {
+ return createFontStyleBuilder(24, FONT_WEIGHT_MEDIUM, 0.008f);
+ }
+
+ /** Font style for medium title text. */
+ @NonNull
+ private static FontStyle.Builder title2() {
+ return createFontStyleBuilder(20, FONT_WEIGHT_MEDIUM, 0.01f);
+ }
+
+ /** Font style for small title text. */
+ @NonNull
+ private static FontStyle.Builder title3() {
+ return createFontStyleBuilder(16, FONT_WEIGHT_MEDIUM, 0.01f);
+ }
+
+ /** Font style for normal body text. */
+ @NonNull
+ private static FontStyle.Builder body1() {
+ return createFontStyleBuilder(16, FONT_WEIGHT_NORMAL, 0.01f);
+ }
+
+ /** Font style for small body text. */
+ @NonNull
+ private static FontStyle.Builder body2() {
+ return createFontStyleBuilder(14, FONT_WEIGHT_NORMAL, 0.014f);
+ }
+
+ /** Font style for bold button text. */
+ @NonNull
+ private static FontStyle.Builder button() {
+ return createFontStyleBuilder(15, FONT_WEIGHT_BOLD, 0.03f);
+ }
+
+ /** Font style for large caption text. */
+ @NonNull
+ private static FontStyle.Builder caption1() {
+ return createFontStyleBuilder(14, FONT_WEIGHT_MEDIUM, 0.01f);
+ }
+
+ /** Font style for medium caption text. */
+ @NonNull
+ private static FontStyle.Builder caption2() {
+ return createFontStyleBuilder(12, FONT_WEIGHT_MEDIUM, 0.01f);
+ }
+
+ /** Font style for small caption text. */
+ @NonNull
+ private static FontStyle.Builder caption3() {
+ return createFontStyleBuilder(10, FONT_WEIGHT_MEDIUM, 0.01f);
+ }
+}
diff --git a/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/layouts/LayoutDefaults.java b/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/layouts/LayoutDefaults.java
index b482f48..c7c132a 100644
--- a/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/layouts/LayoutDefaults.java
+++ b/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/layouts/LayoutDefaults.java
@@ -25,26 +25,24 @@
private LayoutDefaults() {}
/**
- * The default percentage for the bottom margin for primary chip in the {@link
- * PrimaryLayout}.
+ * The default percentage for the bottom margin for primary chip in the {@link PrimaryLayout}.
*/
static final float PRIMARY_LAYOUT_MARGIN_BOTTOM_ROUND_PERCENT = 6.3f / 100;
/**
- * The default percentage for the bottom margin for primary chip in the {@link
- * PrimaryLayout}.
+ * The default percentage for the bottom margin for primary chip in the {@link PrimaryLayout}.
*/
static final float PRIMARY_LAYOUT_MARGIN_BOTTOM_SQUARE_PERCENT = 2.2f / 100;
/**
- * The default percentage for the top margin for primary chip in the {@link PrimaryLayout}
- * on round devices.
+ * The default percentage for the top margin for primary chip in the {@link PrimaryLayout} on
+ * round devices.
*/
static final float PRIMARY_LAYOUT_MARGIN_TOP_ROUND_PERCENT = 16.7f / 100;
/**
- * The default percentage for the top margin for primary chip in the {@link PrimaryLayout}
- * on square devices.
+ * The default percentage for the top margin for primary chip in the {@link PrimaryLayout} on
+ * square devices.
*/
static final float PRIMARY_LAYOUT_MARGIN_TOP_SQUARE_PERCENT = 15.6f / 100;
@@ -81,9 +79,9 @@
*/
public static final float PROGRESS_INDICATOR_LAYOUT_PADDING_BELOW_MAIN_CONTENT_DP = 8;
- /** The default spacer width for slots in the {@link MultiSlotLayout}. */
+ /** The default spacer width for slots in a {@link MultiSlotLayout}. */
public static final DpProp MULTI_SLOT_LAYOUT_HORIZONTAL_SPACER_WIDTH = dp(8);
- /** The recommended space between slots in the {@link MultiSlotLayout} and additional labels. */
+ /** The recommended space between slots in a {@link MultiSlotLayout} and additional labels. */
public static final DpProp MULTI_SLOT_LAYOUT_VERTICAL_SPACER_HEIGHT = dp(8);
}
diff --git a/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/layouts/MultiSlotLayout.java b/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/layouts/MultiSlotLayout.java
index f7ddb6d..a71012c 100644
--- a/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/layouts/MultiSlotLayout.java
+++ b/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/layouts/MultiSlotLayout.java
@@ -75,10 +75,9 @@
@NonNull private DpProp mVerticalSpacerHeight = MULTI_SLOT_LAYOUT_VERTICAL_SPACER_HEIGHT;
/**
- * Creates a builder for the {@link MultiSlotLayout} from the given content. Custom content
- * inside of it can later be set with {@link #addSlotContent}, {@link
- * #setPrimaryChipContent}, {@link #setPrimaryLabelTextContent}, {@link
- * #setSecondaryLabelTextContent}.
+ * Creates a builder for the {@link MultiSlotLayout}. Content inside of it can later be set
+ * with {@link #addSlotContent}, {@link #setPrimaryChipContent}, {@link
+ * #setPrimaryLabelTextContent} and {@link #setSecondaryLabelTextContent}.
*/
public Builder(@NonNull DeviceParameters deviceParameters) {
this.mDeviceParameters = deviceParameters;
@@ -123,14 +122,14 @@
// There is no direct matching getter for this setter as the serialized format of the
// ProtoLayouts do not allow for a direct reconstruction of the arguments. Instead there are
// methods to get the contents a whole for rendering.
- public Builder addSlotContent(@NonNull LayoutElement slotsContent) {
- mSlotsContent.add(slotsContent);
+ public Builder addSlotContent(@NonNull LayoutElement slotContent) {
+ mSlotsContent.add(slotContent);
return this;
}
/**
- * Sets the horizontal spacer width which is used as a space between slots if there is
- * more than one slot. If not set, {@link
+ * Sets the horizontal spacer width which is used as a space between slots if there is more
+ * than one slot. If not set, {@link
* LayoutDefaults#MULTI_SLOT_LAYOUT_HORIZONTAL_SPACER_WIDTH} will be used.
*/
@NonNull
@@ -144,8 +143,8 @@
}
/**
- * Sets the vertical spacer height which is used as a space between all slots and primary
- * or secondary label if there is any. If not set, {@link
+ * Sets the vertical spacer height which is used as a space between all slots and primary or
+ * secondary label if there is any. If not set, {@link
* LayoutDefaults#MULTI_SLOT_LAYOUT_VERTICAL_SPACER_HEIGHT} will be used.
*/
@NonNull
@@ -161,8 +160,7 @@
@NonNull
@Override
public MultiSlotLayout build() {
- PrimaryLayout.Builder layoutBuilder =
- new PrimaryLayout.Builder(mDeviceParameters);
+ PrimaryLayout.Builder layoutBuilder = new PrimaryLayout.Builder(mDeviceParameters);
if (mPrimaryChip != null) {
layoutBuilder.setCompactChipContent(mPrimaryChip);
diff --git a/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/layouts/PrimaryLayout.java b/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/layouts/PrimaryLayout.java
index 58c2652..f0766ed 100644
--- a/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/layouts/PrimaryLayout.java
+++ b/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/layouts/PrimaryLayout.java
@@ -50,7 +50,7 @@
/**
* Tiles layout that represents a suggested layout style for Material Tiles with the primary
- * (compact) chip at the bottom with the given content in a center and the recommended margin and
+ * (compact) chip at the bottom with the given content in the center and the recommended margin and
* padding applied.
*/
// TODO(b/215323986): Link visuals.
@@ -69,8 +69,8 @@
@NonNull private LayoutElement mContent = new Box.Builder().build();
/**
- * Creates a builder for the {@link PrimaryLayout} from the given content. Custom
- * content inside of it can later be set with ({@link #setContent}.
+ * Creates a builder for the {@link PrimaryLayout} from the given content. Custom content
+ * inside of it can later be set with ({@link #setContent}.
*/
public Builder(@NonNull DeviceParameters deviceParameters) {
this.mDeviceParameters = deviceParameters;
@@ -118,8 +118,7 @@
float primaryChipHeight =
mPrimaryChip != null
- ? (COMPACT_HEIGHT.getValue()
- + PRIMARY_LAYOUT_SPACER_HEIGHT.getValue())
+ ? (COMPACT_HEIGHT.getValue() + PRIMARY_LAYOUT_SPACER_HEIGHT.getValue())
: 0;
DpProp mainContentHeight =
diff --git a/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/layouts/ProgressIndicatorLayout.java b/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/layouts/ProgressIndicatorLayout.java
index 0497de9..06e41d0 100644
--- a/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/layouts/ProgressIndicatorLayout.java
+++ b/wear/tiles/tiles-material/src/main/java/androidx/wear/tiles/material/layouts/ProgressIndicatorLayout.java
@@ -191,7 +191,7 @@
/** Get the inner content from this layout. */
@NonNull
public LayoutElement getContent() {
- return checkNotNull(((Box) ((Box) mElement).getContents().get(0))).getContents().get(0);
+ return checkNotNull(((Box) ((Box) mElement).getContents().get(0)).getContents().get(0));
}
/** @hide */
diff --git a/wear/tiles/tiles/api/current.txt b/wear/tiles/tiles/api/current.txt
index d0a67d7..37c11ec 100644
--- a/wear/tiles/tiles/api/current.txt
+++ b/wear/tiles/tiles/api/current.txt
@@ -151,6 +151,7 @@
method public static androidx.wear.tiles.DimensionBuilders.DegreesProp degrees(float);
method public static androidx.wear.tiles.DimensionBuilders.DpProp dp(@Dimension(unit=androidx.annotation.Dimension.DP) float);
method public static androidx.wear.tiles.DimensionBuilders.EmProp em(int);
+ method public static androidx.wear.tiles.DimensionBuilders.EmProp em(float);
method public static androidx.wear.tiles.DimensionBuilders.ExpandedDimensionProp expand();
method public static androidx.wear.tiles.DimensionBuilders.SpProp sp(@Dimension(unit=androidx.annotation.Dimension.SP) float);
method public static androidx.wear.tiles.DimensionBuilders.WrappedDimensionProp wrap();
diff --git a/wear/tiles/tiles/api/public_plus_experimental_current.txt b/wear/tiles/tiles/api/public_plus_experimental_current.txt
index ce5af10..161cb59 100644
--- a/wear/tiles/tiles/api/public_plus_experimental_current.txt
+++ b/wear/tiles/tiles/api/public_plus_experimental_current.txt
@@ -151,6 +151,7 @@
method public static androidx.wear.tiles.DimensionBuilders.DegreesProp degrees(float);
method public static androidx.wear.tiles.DimensionBuilders.DpProp dp(@Dimension(unit=androidx.annotation.Dimension.DP) float);
method public static androidx.wear.tiles.DimensionBuilders.EmProp em(int);
+ method public static androidx.wear.tiles.DimensionBuilders.EmProp em(float);
method public static androidx.wear.tiles.DimensionBuilders.ExpandedDimensionProp expand();
method public static androidx.wear.tiles.DimensionBuilders.SpProp sp(@Dimension(unit=androidx.annotation.Dimension.SP) float);
method public static androidx.wear.tiles.DimensionBuilders.WrappedDimensionProp wrap();
diff --git a/wear/tiles/tiles/api/restricted_current.txt b/wear/tiles/tiles/api/restricted_current.txt
index d0a67d7..37c11ec 100644
--- a/wear/tiles/tiles/api/restricted_current.txt
+++ b/wear/tiles/tiles/api/restricted_current.txt
@@ -151,6 +151,7 @@
method public static androidx.wear.tiles.DimensionBuilders.DegreesProp degrees(float);
method public static androidx.wear.tiles.DimensionBuilders.DpProp dp(@Dimension(unit=androidx.annotation.Dimension.DP) float);
method public static androidx.wear.tiles.DimensionBuilders.EmProp em(int);
+ method public static androidx.wear.tiles.DimensionBuilders.EmProp em(float);
method public static androidx.wear.tiles.DimensionBuilders.ExpandedDimensionProp expand();
method public static androidx.wear.tiles.DimensionBuilders.SpProp sp(@Dimension(unit=androidx.annotation.Dimension.SP) float);
method public static androidx.wear.tiles.DimensionBuilders.WrappedDimensionProp wrap();
diff --git a/wear/tiles/tiles/src/main/java/androidx/wear/tiles/DimensionBuilders.java b/wear/tiles/tiles/src/main/java/androidx/wear/tiles/DimensionBuilders.java
index fadeb59..3a754fc 100644
--- a/wear/tiles/tiles/src/main/java/androidx/wear/tiles/DimensionBuilders.java
+++ b/wear/tiles/tiles/src/main/java/androidx/wear/tiles/DimensionBuilders.java
@@ -53,6 +53,12 @@
return new EmProp.Builder().setValue(valueEm).build();
}
+ /** Shortcut for building a {@link EmProp} using a measurement in EM. */
+ @NonNull
+ public static EmProp em(float valueEm) {
+ return new EmProp.Builder().setValue(valueEm).build();
+ }
+
/** Shortcut for building an {@link DegreesProp} using a measurement in degrees. */
@NonNull
public static DegreesProp degrees(float valueDegrees) {