@MainThread
class ProtoLayoutScope


A scope object responsible for handling internal details of ProtoLayout layouts and Tiles.

Object of this class, in Tiles cases, can be obtained via androidx.wear.tiles.RequestBuilders#TileRequest.getScope and shouldn't be created manually as it could lead to wrong tile behaviour, such as not correctly rendering resources.

Some example of usage:

  • Used for registering Android resources automatically instead of manually via androidx.wear.tiles.TileService.onTileResourcesRequest.

This class is not thread safe and should only be used from one thread, MainThread.

Summary

Public constructors

Public functions

Unit

Clears all collected mappings from the scope, including mappings for resources and pending intents.

Bundle

Returns a Bundle with all previously registered PendingIntent.

ResourceBuilders.Resources

Returns Resources object containing all previously registered resources, with {@link Image#setImageResource} and {@link Image#Builder(ProtoLayoutScope).

Boolean

Returns whether this scope has any registered Resources or not.

Extension functions

ModifiersBuilders.Clickable
@RequiresSchemaVersion(major = 1, minor = 600)
ProtoLayoutScope.clickable(
    pendingIntent: PendingIntent,
    id: String,
    minClickableWidth: @Dimension(unit = 0) Float,
    minClickableHeight: @Dimension(unit = 0) Float
)

Creates a Clickable that allows the modified element to have a PendingIntent associated with it, which will be sent when the element is tapped.

LayoutElementBuilders.Image
ProtoLayoutScope.basicImage(
    resource: ResourceBuilders.ImageResource,
    width: DimensionBuilders.ImageDimension,
    height: DimensionBuilders.ImageDimension,
    protoLayoutResourceId: String?,
    modifier: LayoutModifier?,
    contentScaleMode: Int,
    tintColor: LayoutColor?
)

Builds an image from the given resources.

Public constructors

ProtoLayoutScope

Added in 1.4.0-alpha01
ProtoLayoutScope()

Public functions

clearAll

Added in 1.4.0-alpha01
fun clearAll(): Unit

Clears all collected mappings from the scope, including mappings for resources and pending intents.

This should only be used by the system, otherwise tile can have unexpected behaviour, such as not showing any resources.

collectPendingIntents

Added in 1.4.0-alpha01
fun collectPendingIntents(): Bundle

Returns a Bundle with all previously registered PendingIntent.

Bundle contains (key, value) pairs of android.os.Parcelable, where key is String ID corresponding to the ModifiersBuilders.Clickable ID, and value is PendingIntent.

PendingIntent is registered when building a ModifiersBuilders.Clickable which sets a PendingIntent as its click response.

collectResources

Added in 1.4.0-alpha01
fun collectResources(): ResourceBuilders.Resources

Returns Resources object containing all previously registered resources, with {@link Image#setImageResource} and {@link Image#Builder(ProtoLayoutScope).

Resource is registered with the String ID that is a hash value of all resources.

hasResources

Added in 1.4.0-alpha01
fun hasResources(): Boolean

Returns whether this scope has any registered Resources or not.

Extension functions

@RequiresSchemaVersion(major = 1, minor = 600)
fun ProtoLayoutScope.clickable(
    pendingIntent: PendingIntent,
    id: String,
    minClickableWidth: @Dimension(unit = 0) Float = Float.NaN,
    minClickableHeight: @Dimension(unit = 0) Float = Float.NaN
): ModifiersBuilders.Clickable

Creates a Clickable that allows the modified element to have a PendingIntent associated with it, which will be sent when the element is tapped.

This clickable requires to be created in a ProtoLayoutScope receiver scope which handles internal details of ProtoLayout layout and tiles. In Tiles cases, this scope object can be obtained via androidx.wear.tiles.RequestBuilders#TileRequest.getScope.

Parameters
pendingIntent: PendingIntent

is sent when the element is tapped.

id: String

is the associated identifier for this clickable. This will be used to the identify the pendingIntent to send in the renderer. Within the same tile, this id must be unique among all pendingIntent clickables.

minClickableWidth: @Dimension(unit = 0) Float = Float.NaN

of the clickable area. The default value is 48dp, following the Material design accessibility guideline. Note that this value does not affect the layout, so the minimum clickable width is not guaranteed unless there is enough space around the element within its parent bounds.

minClickableHeight: @Dimension(unit = 0) Float = Float.NaN

of the clickable area. The default value is 48dp, following the Material design accessibility guideline. Note that this value does not affect the layout, so the minimum clickable height is not guaranteed unless there is enough space around the element within its parent bounds.

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