ComplicationSlot
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.
Taps on the watch are tested first against each ComplicationSlot's ComplicationSlotBounds.perComplicationTypeBounds for the relevant ComplicationType. Its assumed that ComplicationSlotBounds.perComplicationTypeBounds don't overlap. If no intersection was found then taps are checked against ComplicationSlotBounds.perComplicationTypeBounds expanded by ComplicationSlotBounds.perComplicationTypeMargins. Expanded bounds can overlap so the ComplicationSlot with the lowest id that intersects the coordinates, if any, is selected.
use Watch Face Format instead
Summary
Nested types |
|---|
class ComplicationSlot.BuilderThis class is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Public companion functions |
|
|---|---|
ComplicationSlot.Builder |
This function is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
ComplicationSlot.Builder |
This function is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
ComplicationSlot.Builder |
@ComplicationExperimentalThis function is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
ComplicationSlot.Builder |
This function is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Public functions |
|
|---|---|
Rect |
This function is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
open operator Boolean |
This function is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
open Int |
This function is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Boolean |
This function is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Unit |
@UiThreadThis function is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Unit |
@UiThreadThis function is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Public properties |
|
|---|---|
Int |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Int |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
CanvasComplicationFactory |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
StateFlow<ComplicationData> |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
ComplicationSlotBounds |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Bundle |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
DefaultComplicationDataSourcePolicy |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
ComplicationType |
This property is deprecated. Use DefaultComplicationDataSourcePolicy.systemDataSourceFallbackDefaultType instead |
Boolean |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Boolean |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Int |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Boolean |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Int? |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
CanvasComplication |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Int? |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
List<ComplicationType> |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
ComplicationTapFilter |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Public companion functions
createBackgroundComplicationSlotBuilder
funcreateBackgroundComplicationSlotBuilder(
id: Int,
canvasComplicationFactory: CanvasComplicationFactory,
supportedTypes: List<ComplicationType>,
defaultDataSourcePolicy: DefaultComplicationDataSourcePolicy
): ComplicationSlot.Builder
Constructs a Builder for a complication with bound type ComplicationSlotBoundsType.BACKGROUND whose bounds cover the entire screen. A background complication is for watch faces that wish to have a full screen user selectable backdrop. This sort of complication isn't clickable and at most one may be present in the list of complicationSlots.
| Parameters | |
|---|---|
id: Int |
The watch face's ID for this complication. Can be any integer but should be unique within the watch face. |
canvasComplicationFactory: CanvasComplicationFactory |
The |
supportedTypes: List<ComplicationType> |
The types of complication supported by this ComplicationSlot. Used during complication, this list should be non-empty. |
defaultDataSourcePolicy: DefaultComplicationDataSourcePolicy |
The |
createEdgeComplicationSlotBuilder
funcreateEdgeComplicationSlotBuilder(
id: Int,
canvasComplicationFactory: CanvasComplicationFactory,
supportedTypes: List<ComplicationType>,
defaultDataSourcePolicy: DefaultComplicationDataSourcePolicy,
bounds: ComplicationSlotBounds,
complicationTapFilter: ComplicationTapFilter
): ComplicationSlot.Builder
Constructs a Builder for a complication with bounds type ComplicationSlotBoundsType.EDGE.
An edge complication is drawn around the border of the display and has custom hit test logic (see complicationTapFilter). When tapped the associated intent is dispatched. Edge complicationSlots should have a custom renderer with CanvasComplication.drawHighlight overridden.
Note hit detection in an editor for ComplicationSlots created with this method is not supported.
| Parameters | |
|---|---|
id: Int |
The watch face's ID for this complication. Can be any integer but should be unique within the watch face. |
canvasComplicationFactory: CanvasComplicationFactory |
The |
supportedTypes: List<ComplicationType> |
The types of complication supported by this ComplicationSlot. Used during complication, this list should be non-empty. |
defaultDataSourcePolicy: DefaultComplicationDataSourcePolicy |
The |
bounds: ComplicationSlotBounds |
The complication's |
complicationTapFilter: ComplicationTapFilter |
The |
createEdgeComplicationSlotBuilder
@ComplicationExperimental
funcreateEdgeComplicationSlotBuilder(
id: Int,
canvasComplicationFactory: CanvasComplicationFactory,
supportedTypes: List<ComplicationType>,
defaultDataSourcePolicy: DefaultComplicationDataSourcePolicy,
bounds: ComplicationSlotBounds,
boundingArc: BoundingArc,
complicationTapFilter: ComplicationTapFilter = object : ComplicationTapFilter { override fun hitTest( complicationSlot: ComplicationSlot, screenBounds: Rect, x: Int, y: Int, @Suppress("UNUSED_PARAMETER") includeMargins: Boolean ) = boundingArc.hitTest( complicationSlot.computeBounds(screenBounds), x.toFloat(), y.toFloat() ) }
): ComplicationSlot.Builder
Constructs a Builder for a complication with bounds type ComplicationSlotBoundsType.EDGE, whose contents are contained within boundingArc.
| Parameters | |
|---|---|
id: Int |
The watch face's ID for this complication. Can be any integer but should be unique within the watch face. |
canvasComplicationFactory: CanvasComplicationFactory |
The |
supportedTypes: List<ComplicationType> |
The types of complication supported by this ComplicationSlot. Used during complication, this list should be non-empty. |
defaultDataSourcePolicy: DefaultComplicationDataSourcePolicy |
The |
bounds: ComplicationSlotBounds |
The complication's |
boundingArc: BoundingArc |
The |
complicationTapFilter: ComplicationTapFilter = object : ComplicationTapFilter {
override fun hitTest(
complicationSlot: ComplicationSlot,
screenBounds: Rect,
x: Int,
y: Int,
@Suppress("UNUSED_PARAMETER") includeMargins: Boolean
) =
boundingArc.hitTest(
complicationSlot.computeBounds(screenBounds),
x.toFloat(),
y.toFloat()
)
} |
The |
createRoundRectComplicationSlotBuilder
funcreateRoundRectComplicationSlotBuilder(
id: Int,
canvasComplicationFactory: CanvasComplicationFactory,
supportedTypes: List<ComplicationType>,
defaultDataSourcePolicy: DefaultComplicationDataSourcePolicy,
bounds: ComplicationSlotBounds
): ComplicationSlot.Builder
Constructs a Builder for a complication with bounds type ComplicationSlotBoundsType.ROUND_RECT. This is the most common type of complication. These can be tapped by the user to trigger the associated intent.
| Parameters | |
|---|---|
id: Int |
The watch face's ID for this complication. Can be any integer but should be unique within the watch face. |
canvasComplicationFactory: CanvasComplicationFactory |
The |
supportedTypes: List<ComplicationType> |
The types of complication supported by this ComplicationSlot. Used during complication, this list should be non-empty. |
defaultDataSourcePolicy: DefaultComplicationDataSourcePolicy |
The |
bounds: ComplicationSlotBounds |
The complication's |
Public functions
computeBounds
funcomputeBounds(screen: Rect, applyMargins: Boolean = false): Rect
Computes the bounds of the complication by converting the unitSquareBounds of the current complication type to pixels based on the screen's dimensions.
isActiveAt
funisActiveAt(instant: Instant): Boolean
Whether or not the complication should be considered active and should be rendered at the specified time.
render
@UiThread
funrender(
canvas: Canvas,
zonedDateTime: ZonedDateTime,
renderParameters: RenderParameters
): Unit
Watch faces should use this method to render a complication. Note the system may call this.
| Parameters | |
|---|---|
canvas: Canvas |
The |
zonedDateTime: ZonedDateTime |
The |
renderParameters: RenderParameters |
The current |
renderHighlightLayer
@UiThread
funrenderHighlightLayer(
canvas: Canvas,
zonedDateTime: ZonedDateTime,
renderParameters: RenderParameters
): Unit
Watch faces should use this method to render non-fixed complicationSlots for any highlight layer pass. Note the system may call this.
| Parameters | |
|---|---|
canvas: Canvas |
The |
zonedDateTime: ZonedDateTime |
The |
renderParameters: RenderParameters |
The current |
Public properties
accessibilityTraversalIndex
val accessibilityTraversalIndex: Int
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
val boundsType: Int
The ComplicationSlotBoundsTypeIntDef of the complication slot.
canvasComplicationFactory
val 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.
complicationData
val complicationData: StateFlow<ComplicationData>
The androidx.wear.watchface.complications.data.ComplicationData associated with the ComplicationSlot. This defaults to NoDataComplicationData.
complicationSlotBounds
val 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
var configExtras: Bundle
Extras to be merged into the Intent sent when invoking the complication data source chooser activity.
defaultDataSourcePolicy
val defaultDataSourcePolicy: DefaultComplicationDataSourcePolicy
The DefaultComplicationDataSourcePolicy which defines the default complicationSlots providers selected when the user hasn't yet made a choice. See also defaultDataSourceType.
val defaultDataSourceType: ComplicationType
The default ComplicationType to use alongside defaultDataSourcePolicy.
enabled
val enabled: Boolean
Whether or not the complication should be drawn and accept taps.
fixedComplicationDataSource
val fixedComplicationDataSource: Boolean
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
val id: Int
The Watch Face's ID for the complication slot.
initiallyEnabled
val initiallyEnabled: Boolean
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.
nameResourceId
val nameResourceId: Int?
The optional ID of string resource (or null if absent) to identify the complication slot on screen in an editor. These strings should be short (perhaps 10 characters max) E.g. complication slots named 'left' and 'right' might be shown by the editor in a list from which the user selects a complication slot for editing.
renderer
val renderer: CanvasComplication
The CanvasComplication used to render the complication. This can't be used until after WatchFaceService.createWatchFace has completed.
screenReaderNameResourceId
val screenReaderNameResourceId: Int?
The optional ID of a string resource (or null if absent) for use by a watch face editor to identify the complication slot in a screen reader. While similar to nameResourceId this string can be longer and should be more descriptive. E.g. saying 'left complication' rather than just 'left'.
supportedTypes
val supportedTypes: List<ComplicationType>
tapFilter
val tapFilter: ComplicationTapFilter
The ComplicationTapFilter used to determine whether or not a tap hit the complication slot.