ListenableCanvasRenderer2


abstract class ListenableCanvasRenderer2<SharedAssetsT : Renderer.SharedAssets> : Renderer.CanvasRenderer2


ListenableFuture-based compatibility wrapper around Renderer.CanvasRenderer2's suspending methods.

Summary

Public constructors

<SharedAssetsT : Renderer.SharedAssets> ListenableCanvasRenderer2(
    surfaceHolder: SurfaceHolder,
    currentUserStyleRepository: CurrentUserStyleRepository,
    watchState: WatchState,
    canvasType: Int,
    interactiveDrawModeUpdateDelayMillis: @IntRange(from = 0, to = 60000) Long,
    clearWithBackgroundTintBeforeRenderingHighlightLayer: Boolean
)

Public functions

abstract ListenableFuture<SharedAssetsT>

Implement to allow your Renderers to share data with SharedAssets.

final suspend Unit

Perform UiThread specific initialization.

open ListenableFuture<Unit>

Perform UiThread specific initialization.

Protected functions

final suspend SharedAssetsT

When editing multiple WatchFaceService instances and hence Renderers can exist concurrently (e.g. a headless instance and an interactive instance) and using SharedAssets allows memory to be saved by sharing immutable data (e.g. Bitmaps, shaders, etc...) between them.

Inherited functions

From androidx.wear.watchface.Renderer
open Rect

This method is used for accessibility support to describe the portion of the screen containing the main clock element.

Unit

Schedules a call to either CanvasRenderer.render or GlesRenderer.render to draw the next frame.

open Unit

Called when the Renderer is destroyed.

open Unit

Called when the RenderParameters has been updated.

Unit

Posts a message to schedule a call to either CanvasRenderer.render or GlesRenderer.render to draw the next frame.

Unit

Sends a request to the system asking it to update the preview image.

open Boolean

The system periodically (at least once per minute) calls onTimeTick() to trigger a display update.

From androidx.wear.watchface.Renderer.CanvasRenderer
open Unit

Called when adb shell dumpsys is invoked for the WatchFaceService, allowing the renderer to optionally record state for debugging purposes.

From androidx.wear.watchface.Renderer.CanvasRenderer2
final Unit
render(canvas: Canvas, bounds: Rect, zonedDateTime: ZonedDateTime)

Sub-classes should override this to implement their watch face rendering logic which should respect the current renderParameters.

abstract Unit
@UiThread
render(
    canvas: Canvas,
    bounds: Rect,
    zonedDateTime: ZonedDateTime,
    sharedAssets: SharedAssetsT
)

Sub-classes should override this to implement their watch face rendering logic which should respect the current renderParameters.

final Unit
renderHighlightLayer(
    canvas: Canvas,
    bounds: Rect,
    zonedDateTime: ZonedDateTime
)

Sub-classes should override this to implement their watch face highlight layer rendering logic for the RenderParameters.highlightLayer aspect of renderParameters.

abstract Unit
@UiThread
renderHighlightLayer(
    canvas: Canvas,
    bounds: Rect,
    zonedDateTime: ZonedDateTime,
    sharedAssets: SharedAssetsT
)

Sub-classes should override this to implement their watch face highlight layer rendering logic for the RenderParameters.highlightLayer aspect of renderParameters.

Inherited properties

From androidx.wear.watchface.Renderer
Collection<Pair<IntContentDescriptionLabel>>

Accessibility ContentDescriptionLabel for any rendered watch face elements other than the time and ComplicationSlots which are generated automatically.

@Px Float

The center x coordinate of the SurfaceHolder this Renderer renders into.

@Px Float

The center y coordinate of the SurfaceHolder this Renderer renders into.

Long

The interval in milliseconds between frames in interactive DrawModes.

RenderParameters

The current RenderParameters.

Rect

The bounds of the SurfaceHolder this Renderer renders into.

SurfaceHolder

The SurfaceHolder that renderInternal will draw into.

WatchFaceColors?

Representative WatchFaceColors which are made available to system clients via androidx.wear.watchface.client.InteractiveWatchFaceClient.OnWatchFaceColorsListener.

From androidx.wear.watchface.Renderer.CanvasRenderer

Public constructors

ListenableCanvasRenderer2

<SharedAssetsT : Renderer.SharedAssets> ListenableCanvasRenderer2(
    surfaceHolder: SurfaceHolder,
    currentUserStyleRepository: CurrentUserStyleRepository,
    watchState: WatchState,
    canvasType: Int,
    interactiveDrawModeUpdateDelayMillis: @IntRange(from = 0, to = 60000) Long,
    clearWithBackgroundTintBeforeRenderingHighlightLayer: Boolean = false
)

Public functions

createSharedAssetsFuture

Added in 1.1.0
@WorkerThread
abstract fun createSharedAssetsFuture(): ListenableFuture<SharedAssetsT>

Implement to allow your Renderers to share data with SharedAssets. When editing multiple WatchFaceService, instances and hence Renderers can exist concurrently (e.g. a headless instance and an interactive instance). Using SharedAssets allows memory to be saved by sharing immutable data (e.g. Bitmaps, shaders, etc...) between them.

To take advantage of SharedAssets, override this method. The constructed SharedAssets are passed into the render as an argument (NB you'll have to cast this to your type).

When all instances using SharedAssets have been closed, SharedAssets.onDestroy will be called.

Note that while SharedAssets are constructed on a background thread, they'll typically be used on the main thread and subsequently destroyed there.

Returns
ListenableFuture<SharedAssetsT>

A ListenableFuture for the SharedAssetsT that will be passed into render and renderHighlightLayer

init

Added in 1.1.0
final suspend fun init(): Unit

Perform UiThread specific initialization. Will be called once during initialization before any subsequent calls to render. If you need to override this method in java, consider using androidx.wear.watchface.ListenableCanvasRenderer instead.

initFuture

Added in 1.1.0
@UiThread
open fun initFuture(): ListenableFuture<Unit>

Perform UiThread specific initialization. Will be called once during initialization before any subsequent calls to render. Note cancellation of the returned future is not supported.

Returns
ListenableFuture<Unit>

A ListenableFuture which is resolved when UiThread has completed. Rendering will be blocked until this has resolved.

Protected functions

createSharedAssets

protected final suspend fun createSharedAssets(): SharedAssetsT

When editing multiple WatchFaceService instances and hence Renderers can exist concurrently (e.g. a headless instance and an interactive instance) and using SharedAssets allows memory to be saved by sharing immutable data (e.g. Bitmaps, shaders, etc...) between them.

To take advantage of SharedAssets, override this method. The constructed SharedAssets are passed into the render as an argument (NB you'll have to cast this to your type).

When all instances using SharedAssets have been closed, SharedAssets.onDestroy will be called.

Note that while SharedAssets are constructed on a background thread, they'll typically be used on the main thread and subsequently destroyed there.

Returns
SharedAssetsT

The SharedAssetsT that will be passed into render and renderHighlightLayer.