ProtoLayoutScope
@MainThread
public final 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
Nested types |
|---|
public enum ProtoLayoutScope.RendererCapability extends EnumDefines the capabilities or features that a renderer can support. |
Public constructors |
|---|
ProtoLayoutScope( |
Public methods |
|
|---|---|
final void |
clearAll()Clears all collected mappings from the scope, including mappings for resources and pending intents. |
final @NonNull Bundle |
Returns a |
final @NonNull ResourceBuilders.Resources |
Returns |
final boolean |
hasCapability(@NonNull ProtoLayoutScope.RendererCapability capability)Checks if the current tile renderer supports a specific capability. |
final boolean |
Returns whether this scope has any registered |
Extension functions |
|
|---|---|
final @NonNull ModifiersBuilders.Clickable |
ClickableKt.clickable(Creates a |
final @NonNull LayoutElementBuilders.Image |
ImageKt.basicImage(Builds an image from the given resources. |
Public constructors
ProtoLayoutScope
public ProtoLayoutScope(
@NonNull VersionBuilders.VersionInfo rendererVersionInfo
)
Public methods
clearAll
public final void clearAll()
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
public final @NonNull Bundle collectPendingIntents()
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
public final @NonNull ResourceBuilders.Resources collectResources()
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.
hasCapability
public final boolean hasCapability(@NonNull ProtoLayoutScope.RendererCapability capability)
Checks if the current tile renderer supports a specific capability.
hasResources
public final boolean hasResources()
Returns whether this scope has any registered Resources or not.
Extension functions
ClickableKt.clickable
public final @NonNull ModifiersBuilders.Clickable ClickableKt.clickable(
@NonNull ProtoLayoutScope receiver,
@NonNull PendingIntent pendingIntent,
@NonNull String id,
ActionBuilders.Action fallbackAction,
@Dimension(unit = 0) float minClickableWidth,
@Dimension(unit = 0) float minClickableHeight
)
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 | |
|---|---|
@NonNull PendingIntent pendingIntent |
is sent when the element is tapped. |
@NonNull String id |
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. |
ActionBuilders.Action fallbackAction |
The Action to use as a fallback when PendingIntent isn't supported by the ProtoLayout Renderer. |
@Dimension(unit = 0) float minClickableWidth |
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. |
@Dimension(unit = 0) float minClickableHeight |
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. |
ImageKt.basicImage
public final @NonNull LayoutElementBuilders.Image ImageKt.basicImage(
@NonNull ProtoLayoutScope receiver,
@NonNull ResourceBuilders.ImageResource resource,
@NonNull DimensionBuilders.ImageDimension width,
@NonNull DimensionBuilders.ImageDimension height,
String protoLayoutResourceId,
LayoutModifier modifier,
int contentScaleMode,
LayoutColor tintColor
)
Builds an image from the given resources.
| Parameters | |
|---|---|
@NonNull ResourceBuilders.ImageResource resource |
An Image resource, used in the layout in the place of this element |
@NonNull DimensionBuilders.ImageDimension width |
The width of the image |
@NonNull DimensionBuilders.ImageDimension height |
The height of the image |
String protoLayoutResourceId |
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. |
LayoutModifier modifier |
Modifiers to set to this element |
int contentScaleMode |
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 |
LayoutColor tintColor |
The tint color to apply to the image |