ComplicationSlot

public final class ComplicationSlot


Represents the slot an individual complication on the screen may go in. The number of ComplicationSlots is fixed (see ComplicationSlotsManager) but ComplicationSlots can be enabled or disabled via UserStyleSetting.ComplicationSlotsUserStyleSetting.

Summary

Nested types

ComplicationSlot.Builder

Builder for constructing ComplicationSlots.

ComplicationSlot.Companion

Public fields

final int

This is used to determine the order in which accessibility labels for the watch face are read to the user.

final int

The ComplicationSlotBoundsType of the complication slot.

final @NonNull CanvasComplicationFactory

The CanvasComplicationFactory used to generate a CanvasComplication for rendering the complication.

final @NonNull ObservableWatchData<@NonNull ComplicationData>

The androidx.wear.complications.data.ComplicationData associated with the ComplicationSlot.

final @NonNull ComplicationSlotBounds

The complication's ComplicationSlotBounds which are converted to pixels during rendering.

final @NonNull Bundle

Extras to be merged into the Intent sent when invoking the complication data source chooser activity.

final @NonNull DefaultComplicationDataSourcePolicy

The DefaultComplicationDataSourcePolicy which defines the default complicationSlots providers selected when the user hasn't yet made a choice.

final @NonNull ComplicationType

The default ComplicationType to use alongside defaultDataSourcePolicy.

final boolean

Whether or not the complication should be drawn and accept taps.

final boolean

Whether or not the complication data source is fixed (i.e.

final int

The Watch Face's ID for the complication slot.

final boolean

At creation a complication slot is either enabled or disabled.

final @NonNull CanvasComplication

The CanvasComplication used to render the complication.

final @NonNull List<@NonNull ComplicationType>

The types of complicationSlots the complication supports.

final @NonNull ComplicationTapFilter

The ComplicationTapFilter used to determine whether or not a tap hit the complication slot.

Public methods

final @NonNull Rect

Computes the bounds of the complication by converting the unitSquareBounds of the current complication type to pixels based on the screen's dimensions.

final boolean

Whether or not the complication should be considered active and should be rendered at the specified time.

final @UiThread void
render(
    @NonNull Canvas canvas,
    @NonNull ZonedDateTime zonedDateTime,
    @NonNull RenderParameters renderParameters
)

Watch faces should use this method to render a complication.

final @UiThread void
renderHighlightLayer(
    @NonNull Canvas canvas,
    @NonNull ZonedDateTime zonedDateTime,
    @NonNull RenderParameters renderParameters
)

Watch faces should use this method to render non-fixed complicationSlots for any highlight layer pass.

Public fields

accessibilityTraversalIndex

@NonNull
public final int accessibilityTraversalIndex

This is used to determine the order in which accessibility labels for the watch face are read to the user. Accessibility labels are automatically generated for the time and complicationSlots. See also Renderer.additionalContentDescriptionLabels.

boundsType

@NonNull
public final int boundsType

The ComplicationSlotBoundsType of the complication slot.

canvasComplicationFactory

@NonNull
public final @NonNull CanvasComplicationFactory canvasComplicationFactory

The CanvasComplicationFactory used to generate a CanvasComplication for rendering the complication. The factory allows us to decouple ComplicationSlot from potentially expensive asset loading.

complicationSlotBounds

@NonNull
public final @NonNull ComplicationSlotBounds complicationSlotBounds

The complication's ComplicationSlotBounds which are converted to pixels during rendering.

Note it's not allowed to change the bounds of a background complication because they are assumed to always cover the entire screen.

configExtras

@NonNull
public final @NonNull Bundle configExtras

Extras to be merged into the Intent sent when invoking the complication data source chooser activity.

defaultDataSourcePolicy

@NonNull
public final @NonNull DefaultComplicationDataSourcePolicy defaultDataSourcePolicy

The DefaultComplicationDataSourcePolicy which defines the default complicationSlots providers selected when the user hasn't yet made a choice. See also defaultDataSourceType.

defaultDataSourceType

@NonNull
public final @NonNull ComplicationType defaultDataSourceType

The default ComplicationType to use alongside defaultDataSourcePolicy.

enabled

@NonNull
public final boolean enabled

Whether or not the complication should be drawn and accept taps.

fixedComplicationDataSource

@NonNull
public final boolean fixedComplicationDataSource

Whether or not the complication data source is fixed (i.e. can't be changed by the user). This is useful for watch faces built around specific complications.

id

@NonNull
public final int id

The Watch Face's ID for the complication slot.

initiallyEnabled

@NonNull
public final boolean initiallyEnabled

At creation a complication slot is either enabled or disabled. This can be overridden by a ComplicationSlotsUserStyleSetting (see ComplicationSlotOverlay.enabled). Editors need to know the initial state of a complication slot to predict the effects of making a style change.

renderer

@NonNull
public final @NonNull CanvasComplication renderer

The CanvasComplication used to render the complication. This can't be used until after WatchFaceService.createWatchFace has completed.

supportedTypes

@NonNull
public final @NonNull List<@NonNull ComplicationTypesupportedTypes

The types of complicationSlots the complication supports. Must be non-empty.

tapFilter

@NonNull
public final @NonNull ComplicationTapFilter tapFilter

The ComplicationTapFilter used to determine whether or not a tap hit the complication slot.

Public methods

computeBounds

@NonNull
public final Rect computeBounds(@NonNull Rect screen)

Computes the bounds of the complication by converting the unitSquareBounds of the current complication type to pixels based on the screen's dimensions.

Parameters
@NonNull Rect screen

A Rect describing the dimensions of the screen.

isActiveAt

@NonNull
public final boolean isActiveAt(@NonNull Instant instant)

Whether or not the complication should be considered active and should be rendered at the specified time.

render

@UiThread
@NonNull
public final @UiThread void render(
    @NonNull Canvas canvas,
    @NonNull ZonedDateTime zonedDateTime,
    @NonNull RenderParameters renderParameters
)

Watch faces should use this method to render a complication. Note the system may call this.

Parameters
@NonNull Canvas canvas

The Canvas to render into

@NonNull ZonedDateTime zonedDateTime

The ZonedDateTime to render with

@NonNull RenderParameters renderParameters

The current RenderParameters

renderHighlightLayer

@UiThread
@NonNull
public final @UiThread void renderHighlightLayer(
    @NonNull Canvas canvas,
    @NonNull ZonedDateTime zonedDateTime,
    @NonNull RenderParameters renderParameters
)

Watch faces should use this method to render non-fixed complicationSlots for any highlight layer pass. Note the system may call this.

Parameters
@NonNull Canvas canvas

The Canvas to render into

@NonNull ZonedDateTime zonedDateTime

The ZonedDateTime to render with

@NonNull RenderParameters renderParameters

The current RenderParameters