androidx.wear.protolayout.layout
Top-level functions summary
ResourceBuilders.AndroidImageResourceByResId |
androidImageResource(resourceId: @DrawableRes Int)Builds image resource that maps to an Android drawable by the given resource ID. |
LayoutElementBuilders.Text |
basicText(Builds a text string. |
LayoutElementBuilders.FontStyle |
fontStyle(Builds the styling of a font (e.g. font size, and metrics). |
ResourceBuilders.ImageResource |
imageResource(Builds a resource object for the image, based on the given resources types. |
ResourceBuilders.InlineImageResource |
inlineImageResource(Builds image resource that contains the compressed image data extracted from the raw image data. |
ResourceBuilders.InlineImageResource |
inlineImageResource(Builds image resource that contains the pixel buffer in the specified format of the given byte array data. |
ResourceBuilders.AndroidLottieResourceByResId |
lottieResource(Builds Lottie resource that is read from a raw Android resource ID and can be played via progress. |
ResourceBuilders.AndroidLottieResourceByResId |
lottieResource(Builds Lottie resource that is read from a raw Android resource ID and can be played via starting trigger. |
Extension functions summary
LayoutElementBuilders.Image |
ProtoLayoutScope.basicImage(Builds an image from the given resources. |
Top-level functions
androidImageResource
fun androidImageResource(resourceId: @DrawableRes Int): ResourceBuilders.AndroidImageResourceByResId
Builds image resource that maps to an Android drawable by the given resource ID.
| Parameters | |
|---|---|
resourceId: @DrawableRes Int |
The drawable resource ID to map this image |
basicText
fun basicText(
text: LayoutString,
fontStyle: LayoutElementBuilders.FontStyle? = null,
modifier: LayoutModifier? = null,
maxLines: Int = 0,
alignment: Int = TEXT_ALIGN_UNDEFINED,
overflow: Int = TEXT_OVERFLOW_UNDEFINED,
lineHeight: @Dimension(unit = 2) Float = Float.NaN
): LayoutElementBuilders.Text
Builds a text string.
| Parameters | |
|---|---|
text: LayoutString |
The text to render. |
fontStyle: LayoutElementBuilders.FontStyle? = null |
The style of font to use (size, bold etc). If not specified, defaults to the platform's default body font. |
modifier: LayoutModifier? = null |
Modifiers to set to this element. |
maxLines: Int = 0 |
The maximum number of lines that can be represented by the |
alignment: Int = TEXT_ALIGN_UNDEFINED |
Alignment of the text within its bounds. Note that a |
overflow: Int = TEXT_OVERFLOW_UNDEFINED |
How to handle text which overflows the bound of the |
lineHeight: @Dimension(unit = 2) Float = Float.NaN |
The explicit height between lines of text. This is equivalent to the vertical distance between subsequent baselines. If not specified, defaults the font's recommended interline spacing. |
fontStyle
fun fontStyle(
size: @Dimension(unit = 2) Float = 0.0f,
italic: Boolean = false,
underline: Boolean = false,
color: LayoutColor? = null,
weight: Int = FONT_WEIGHT_UNDEFINED,
letterSpacingEm: Float = Float.NaN,
@RequiresSchemaVersion(major = 1, minor = 300) additionalSizesSp: List<Float> = emptyList(),
@RequiresSchemaVersion(major = 1, minor = 400) settings: List<LayoutElementBuilders.FontSetting> = emptyList(),
@RequiresSchemaVersion(major = 1, minor = 400) preferredFontFamilies: List<String> = emptyList()
): LayoutElementBuilders.FontStyle
Builds the styling of a font (e.g. font size, and metrics).
| Parameters | |
|---|---|
size: @Dimension(unit = 2) Float = 0.0f |
The size of the font, in scaled pixels (sp). If not specified, defaults to the size of the system's "body" font. |
italic: Boolean = false |
Whether the text should be rendered in a italic typeface. |
underline: Boolean = false |
Whether the text should be rendered with an underline. |
color: LayoutColor? = null |
The text color. If not defined, defaults to white. |
weight: Int = FONT_WEIGHT_UNDEFINED |
The weight of the font. If the provided value is not supported on a platform, the nearest supported value will be used. If not defined, or when set to an invalid value, defaults to "normal". |
letterSpacingEm: Float = Float.NaN |
The text letter-spacing. Positive numbers increase the space between letters while negative numbers tighten the space. If not specified, defaults to 0. |
@RequiresSchemaVersion(major = 1, minor = 300) additionalSizesSp: List<Float> = emptyList() |
when this |
@RequiresSchemaVersion(major = 1, minor = 400) settings: List<LayoutElementBuilders.FontSetting> = emptyList() |
The collection of font settings to be applied. If more than one Setting with the same axis tag is specified, the first one will be used. Supported settings depend on the font used by the system and the renderer version. However, if using |
@RequiresSchemaVersion(major = 1, minor = 400) preferredFontFamilies: List<String> = emptyList() |
is the ordered list of font families to pick from for this |
imageResource
fun imageResource(
androidImage: ResourceBuilders.AndroidImageResourceByResId? = null,
inlineImage: ResourceBuilders.InlineImageResource? = null,
lottie: ResourceBuilders.AndroidLottieResourceByResId? = null
): ResourceBuilders.ImageResource
Builds a resource object for the image, based on the given resources types. This can hold multiple underlying resource types, which the underlying renderer will pick according to what it is supported in its version and what it thinks is appropriate.
It is recommended to use this inside the APIs for the automatic resource registration, such as basicImage.
| Parameters | |
|---|---|
androidImage: ResourceBuilders.AndroidImageResourceByResId? = null |
The image resource that maps to an Android drawable by resource ID |
inlineImage: ResourceBuilders.InlineImageResource? = null |
The image resource that contains the image data inline |
lottie: ResourceBuilders.AndroidLottieResourceByResId? = null |
The Lottie resource that is read from a raw Android resource ID |
inlineImageResource
fun inlineImageResource(
compressedBytes: ByteArray,
widthPx: @Dimension(unit = 1) Int,
heightPx: @Dimension(unit = 1) Int
): ResourceBuilders.InlineImageResource
Builds image resource that contains the compressed image data extracted from the raw image data.
This data shouldn't be in any format. If the image data bytes are formatted use inlineImageResource with (ByteArray, Int, Int, Int).
inlineImageResource
fun inlineImageResource(
pixelBuffer: ByteArray,
format: Int,
widthPx: @Dimension(unit = 1) Int,
heightPx: @Dimension(unit = 1) Int
): ResourceBuilders.InlineImageResource
Builds image resource that contains the pixel buffer in the specified format of the given byte array data.
| Parameters | |
|---|---|
pixelBuffer: ByteArray |
The byte array representing the image |
format: Int |
The format of the byte array data representing the image. This should be specific format of |
widthPx: @Dimension(unit = 1) Int |
The native width of the image, in pixels. |
heightPx: @Dimension(unit = 1) Int |
The native height of the image, in pixels. |
lottieResource
fun lottieResource(
@RawRes rawResourceId: Int,
progress: DynamicBuilders.DynamicFloat,
properties: List<ResourceBuilders.LottieProperty> = emptyList()
): ResourceBuilders.AndroidLottieResourceByResId
Builds Lottie resource that is read from a raw Android resource ID and can be played via progress.
| Parameters | |
|---|---|
@RawRes rawResourceId: Int |
The raw resource ID to map this Lottie |
progress: DynamicBuilders.DynamicFloat |
The |
properties: List<ResourceBuilders.LottieProperty> = emptyList() |
The list of properties to customize Lottie further |
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
if the number of properties is larger than |
lottieResource
fun lottieResource(
@RawRes rawResourceId: Int,
startTrigger: TriggerBuilders.Trigger? = null,
properties: List<ResourceBuilders.LottieProperty> = emptyList()
): ResourceBuilders.AndroidLottieResourceByResId
Builds Lottie resource that is read from a raw Android resource ID and can be played via starting trigger.
| Parameters | |
|---|---|
@RawRes rawResourceId: Int |
The raw resource ID to map this Lottie |
startTrigger: TriggerBuilders.Trigger? = null |
The trigger to start the animation. If not set, animation will be played on layout load |
properties: List<ResourceBuilders.LottieProperty> = emptyList() |
The list of properties to customize Lottie further |
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
if the number of properties is larger than |
Extension functions
basicImage
fun ProtoLayoutScope.basicImage(
resource: ResourceBuilders.ImageResource,
width: DimensionBuilders.ImageDimension,
height: DimensionBuilders.ImageDimension,
protoLayoutResourceId: String? = null,
modifier: LayoutModifier? = null,
contentScaleMode: Int = CONTENT_SCALE_MODE_UNDEFINED,
tintColor: LayoutColor? = null
): LayoutElementBuilders.Image
Builds an image from the given resources.
| Parameters | |
|---|---|
resource: ResourceBuilders.ImageResource |
An Image resource, used in the layout in the place of this element |
width: DimensionBuilders.ImageDimension |
The width of the image |
height: DimensionBuilders.ImageDimension |
The height of the image |
protoLayoutResourceId: String? = null |
The optional String ID for the resource. This is optional as it has a default value assigned by the automatic resource registration, but can be used to override it if desired to mark the resource with readable ID. |
modifier: LayoutModifier? = null |
Modifiers to set to this element |
contentScaleMode: Int = CONTENT_SCALE_MODE_UNDEFINED |
Defines how the content which does not match the dimensions of its bounds (e.g. an image resource being drawn inside an Image) will be resized to fit its bounds |
tintColor: LayoutColor? = null |
The tint color to apply to the image |