CanvasComplication


public interface CanvasComplication

Known direct subclasses
CanvasComplicationDrawable

This class is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.


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.

use Watch Face Format instead

Summary

Nested types

This interface is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

Public methods

abstract void
drawHighlight(
    @NonNull Canvas canvas,
    @NonNull Rect bounds,
    int boundsType,
    @NonNull ZonedDateTime zonedDateTime,
    @ColorInt int color
)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

default void
@ComplicationExperimental
drawHighlight(
    @NonNull Canvas canvas,
    @NonNull Rect bounds,
    int boundsType,
    @NonNull ZonedDateTime zonedDateTime,
    @ColorInt int color,
    BoundingArc boundingArc
)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

abstract @NonNull ComplicationData

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

abstract void
loadData(
    @NonNull ComplicationData complicationData,
    boolean loadDrawablesAsynchronous
)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

default void

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

abstract void
@UiThread
render(
    @NonNull Canvas canvas,
    @NonNull Rect bounds,
    @NonNull ZonedDateTime zonedDateTime,
    @NonNull RenderParameters renderParameters,
    int slotId
)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

Public methods

drawHighlight

Added in 1.0.0
Deprecated in 1.3.0-alpha06
abstract void drawHighlight(
    @NonNull Canvas canvas,
    @NonNull Rect bounds,
    int boundsType,
    @NonNull ZonedDateTime zonedDateTime,
    @ColorInt int color
)

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
@NonNull Canvas canvas

The Canvas to render into

@NonNull Rect bounds

A Rect describing the bounds of the complication

int boundsType

The ComplicationSlotBoundsTypeIntDef of the complication

@NonNull ZonedDateTime zonedDateTime

The ZonedDateTime to render the highlight with

@ColorInt int color

The color to render the highlight with

drawHighlight

Added in 1.2.0
Deprecated in 1.3.0-alpha06
@ComplicationExperimental
default void drawHighlight(
    @NonNull Canvas canvas,
    @NonNull Rect bounds,
    int boundsType,
    @NonNull ZonedDateTime zonedDateTime,
    @ColorInt int color,
    BoundingArc boundingArc
)

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
@NonNull Canvas canvas

The Canvas to render into

@NonNull Rect bounds

A Rect describing the bounds of the complication

int boundsType

The ComplicationSlotBoundsTypeIntDef of the complication

@NonNull ZonedDateTime zonedDateTime

The ZonedDateTime to render the highlight with

@ColorInt int color

The color to render the highlight with

BoundingArc boundingArc

Optional BoundingArc defining the geometry of an edge complication

getData

Added in 1.0.0
Deprecated in 1.3.0-alpha06
abstract @NonNull ComplicationData getData()

Returns the ComplicationData to render with.

loadData

Added in 1.0.0
Deprecated in 1.3.0-alpha06
abstract void loadData(
    @NonNull ComplicationData complicationData,
    boolean loadDrawablesAsynchronous
)

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
@NonNull ComplicationData complicationData

The ComplicationData to render with

boolean loadDrawablesAsynchronous

Whether or not any drawables should be loaded asynchronously

onRendererCreated

Added in 1.0.0
Deprecated in 1.3.0-alpha06
@WorkerThread
default void onRendererCreated(@NonNull Renderer renderer)

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
Deprecated in 1.3.0-alpha06
@UiThread
abstract void render(
    @NonNull Canvas canvas,
    @NonNull Rect bounds,
    @NonNull ZonedDateTime zonedDateTime,
    @NonNull RenderParameters renderParameters,
    int slotId
)

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
@NonNull Canvas canvas

The Canvas to render into

@NonNull Rect bounds

A Rect describing the bounds of the complication

@NonNull ZonedDateTime zonedDateTime

The ZonedDateTime to render with

@NonNull RenderParameters renderParameters

The current RenderParameters

int slotId

The Id of the ComplicationSlot being rendered