CanvasComplication

interface CanvasComplication

Known direct subclasses
CanvasComplicationDrawable

A complication rendered with ComplicationDrawable which renders complicationSlots in a material design style.


Interface for rendering complicationSlots onto a Canvas. These should be created by CanvasComplicationFactory.create. If state needs to be shared with the Renderer that should be set up inside onRendererCreated.

Summary

Nested types

Interface for observing when a CanvasComplication needs the screen to be redrawn.

Public functions

Unit
drawHighlight(
    canvas: Canvas,
    bounds: Rect,
    boundsType: Int,
    zonedDateTime: ZonedDateTime,
    color: @ColorInt Int
)

Draws a highlight for a ComplicationSlotBoundsType.ROUND_RECT complication.

open Unit
@ComplicationExperimental
drawHighlight(
    canvas: Canvas,
    bounds: Rect,
    boundsType: Int,
    zonedDateTime: ZonedDateTime,
    color: @ColorInt Int,
    boundingArc: BoundingArc?
)

Draws a highlight for a ComplicationSlotBoundsType.ROUND_RECT complication.

ComplicationData

Returns the ComplicationData to render with.

Unit
loadData(
    complicationData: ComplicationData,
    loadDrawablesAsynchronous: Boolean
)

Sets the ComplicationData to render with and loads any Drawables contained within the ComplicationData.

open Unit

Called once on a background thread before any subsequent UI thread rendering to inform the CanvasComplication of the Renderer which is useful if they need to share state.

Unit
@UiThread
render(
    canvas: Canvas,
    bounds: Rect,
    zonedDateTime: ZonedDateTime,
    renderParameters: RenderParameters,
    slotId: Int
)

Draws the complication defined by getData into the canvas with the specified bounds.

Public functions

drawHighlight

Added in 1.0.0
fun drawHighlight(
    canvas: Canvas,
    bounds: Rect,
    boundsType: Int,
    zonedDateTime: ZonedDateTime,
    color: @ColorInt Int
): Unit

Draws a highlight for a ComplicationSlotBoundsType.ROUND_RECT complication. The default implementation does this by drawing a dashed line around the complication, other visual effects may be used if desired.

Parameters
canvas: Canvas

The Canvas to render into

bounds: Rect

A Rect describing the bounds of the complication

boundsType: Int

The ComplicationSlotBoundsTypeIntDef of the complication

zonedDateTime: ZonedDateTime

The ZonedDateTime to render the highlight with

color: @ColorInt Int

The color to render the highlight with

drawHighlight

Added in 1.2.0
@ComplicationExperimental
open fun drawHighlight(
    canvas: Canvas,
    bounds: Rect,
    boundsType: Int,
    zonedDateTime: ZonedDateTime,
    color: @ColorInt Int,
    boundingArc: BoundingArc?
): Unit

Draws a highlight for a ComplicationSlotBoundsType.ROUND_RECT complication. The default implementation does this by drawing a dashed line around the complication, other visual effects may be used if desired.

Parameters
canvas: Canvas

The Canvas to render into

bounds: Rect

A Rect describing the bounds of the complication

boundsType: Int

The ComplicationSlotBoundsTypeIntDef of the complication

zonedDateTime: ZonedDateTime

The ZonedDateTime to render the highlight with

color: @ColorInt Int

The color to render the highlight with

getData

Added in 1.0.0
fun getData(): ComplicationData

Returns the ComplicationData to render with.

loadData

Added in 1.0.0
fun loadData(
    complicationData: ComplicationData,
    loadDrawablesAsynchronous: Boolean
): Unit

Sets the ComplicationData to render with and loads any Drawables contained within the ComplicationData. You can choose whether this is done synchronously or asynchronously via loadDrawablesAsynchronous. When any asynchronous loading has completed InvalidateCallback.onInvalidate must be called.

Parameters
complicationData: ComplicationData

The ComplicationData to render with

loadDrawablesAsynchronous: Boolean

Whether or not any drawables should be loaded asynchronously

onRendererCreated

Added in 1.0.0
@WorkerThread
open fun onRendererCreated(renderer: Renderer): Unit

Called once on a background thread before any subsequent UI thread rendering to inform the CanvasComplication of the Renderer which is useful if they need to share state. Note the Renderer is created asynchronously which is why we can't pass it in via CanvasComplicationFactory.create as it may not be available at that time.

render

Added in 1.0.0
@UiThread
fun render(
    canvas: Canvas,
    bounds: Rect,
    zonedDateTime: ZonedDateTime,
    renderParameters: RenderParameters,
    slotId: Int
): Unit

Draws the complication defined by getData into the canvas with the specified bounds. This will usually be called by user watch face drawing code, but the system may also call it for complication selection UI rendering. The width and height will be the same as that computed by computeBounds but the translation and canvas size may differ.

Parameters
canvas: Canvas

The Canvas to render into

bounds: Rect

A Rect describing the bounds of the complication

zonedDateTime: ZonedDateTime

The ZonedDateTime to render with

renderParameters: RenderParameters

The current RenderParameters

slotId: Int

The Id of the ComplicationSlot being rendered