Renderer.CanvasRenderer
abstract class Renderer.CanvasRenderer : Renderer
ListenableCanvasRenderer |
This class is deprecated. Use ListenableCanvasRenderer2 instead |
Renderer.CanvasRenderer2 |
This class is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
ListenableCanvasRenderer2 |
This class is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Watch faces that require Canvas rendering should extend their Renderer from this class or CanvasRenderer2 if they can take advantage of SharedAssets to save memory when editing (there can be more than once WatchFace instance when editing).
A CanvasRenderer is expected to be constructed on the background thread associated with WatchFaceService.getBackgroundThreadHandler inside a call to WatchFaceService.createWatchFace. All rendering is be done on the UiThread. There is a memory barrier between construction and rendering so no special threading primitives are required.
In Java it may be easier to extend androidx.wear.watchface.ListenableCanvasRenderer instead.
Summary
Public constructors |
|---|
@WorkerThreadThis function is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Public functions |
|
|---|---|
open suspend Unit |
This function is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
open Unit |
This function is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
abstract Unit |
@UiThreadThis function is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
abstract Unit |
@UiThreadThis function is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Public properties |
|
|---|---|
Boolean |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Inherited functions |
||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Inherited properties |
||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Public constructors
@WorkerThreadCanvasRenderer(
surfaceHolder: SurfaceHolder,
currentUserStyleRepository: CurrentUserStyleRepository,
watchState: WatchState,
canvasType: Int,
interactiveDrawModeUpdateDelayMillis: @IntRange(from = 0, to = 60000) Long,
clearWithBackgroundTintBeforeRenderingHighlightLayer: Boolean = false
)
| Parameters | |
|---|---|
surfaceHolder: SurfaceHolder |
The |
currentUserStyleRepository: CurrentUserStyleRepository |
The watch face's associated |
watchState: WatchState |
The watch face's associated |
canvasType: Int |
The |
interactiveDrawModeUpdateDelayMillis: @IntRange(from = 0, to = 60000) Long |
The interval in milliseconds between frames in interactive |
clearWithBackgroundTintBeforeRenderingHighlightLayer: Boolean = false |
Whether the |
Public functions
@UiThread
open suspend funinit(): 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.
onDump
open funonDump(writer: PrintWriter): Unit
Called when adb shell dumpsys is invoked for the WatchFaceService, allowing the renderer to optionally record state for debugging purposes.
@UiThread
abstract funrender(canvas: Canvas, bounds: Rect, zonedDateTime: ZonedDateTime): Unit
Sub-classes should override this to implement their watch face rendering logic which should respect the current renderParameters. Please note WatchState.isAmbient may not match the RenderParameters.drawMode and should not be used to decide what to render. E.g. when editing from the companion phone while the watch is ambient, renders may be requested with DrawMode.INTERACTIVE.
Any highlights due to RenderParameters.highlightLayer should be rendered by renderHighlightLayer instead where possible. For correct behavior this function must use the supplied ZonedDateTime in favor of any other ways of getting the time.
Before any calls to render, init will be called once.
| Parameters | |
|---|---|
canvas: Canvas |
The |
bounds: Rect |
A |
zonedDateTime: ZonedDateTime |
The |
@UiThread
abstract funrenderHighlightLayer(
canvas: Canvas,
bounds: Rect,
zonedDateTime: ZonedDateTime
): Unit
Sub-classes should override this to implement their watch face highlight layer rendering logic for the RenderParameters.highlightLayer aspect of renderParameters. Typically the implementation will clear canvas to RenderParameters.HighlightLayer.backgroundTint before rendering a transparent highlight or a solid outline around the RenderParameters.HighlightLayer.highlightedElement. This will be composited as needed on top of the results of render. For correct behavior this function must use the supplied ZonedDateTime in favor of any other ways of getting the time.
Note if clearWithBackgroundTintBeforeRenderingHighlightLayer is true then canvas will cleared with RenderParameters.HighlightLayer.backgroundTint before renderHighlightLayer is called. Otherwise it is up to the overridden function to clear the Canvas if necessary.
| Parameters | |
|---|---|
canvas: Canvas |
The |
bounds: Rect |
A |
zonedDateTime: ZonedDateTime |
the |
Public properties
val clearWithBackgroundTintBeforeRenderingHighlightLayer: Boolean
Whether the Canvas is cleared with RenderParameters.HighlightLayer.backgroundTint before renderHighlightLayer is called. Defaults to false.