Renderer.CanvasRenderer2
abstract class Renderer.CanvasRenderer2<SharedAssetsT : Renderer.SharedAssets> : Renderer.CanvasRenderer
| kotlin.Any | |||
| ↳ | androidx.wear.watchface.Renderer | ||
| ↳ | androidx.wear.watchface.Renderer.CanvasRenderer | ||
| ↳ | androidx.wear.watchface.Renderer.CanvasRenderer2 |
ListenableCanvasRenderer2 |
This class is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Watch faces that require Canvas rendering and are able to take advantage of SharedAssets to save memory (there can be more than once instance when editing), should extend their Renderer from this class.
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.ListenableCanvasRenderer2 instead.
use Watch Face Format instead
| Parameters | |
|---|---|
<SharedAssetsT : Renderer.SharedAssets> |
The type extending |
Summary
Public constructors |
|---|
@WorkerThreadThis function is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Public functions |
|
|---|---|
final 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. |
final 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. |
Protected functions |
|
|---|---|
abstract suspend SharedAssetsT |
This function is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Inherited functions |
||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||
Inherited properties |
||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||
|
Public constructors
CanvasRenderer2
@WorkerThread
<SharedAssetsT : Renderer.SharedAssets>CanvasRenderer2(
surfaceHolder: SurfaceHolder,
currentUserStyleRepository: CurrentUserStyleRepository,
watchState: WatchState,
canvasType: Int,
interactiveDrawModeUpdateDelayMillis: @IntRange(from = 0, to = 60000) Long,
clearWithBackgroundTintBeforeRenderingHighlightLayer: Boolean
)
| Parameters | |
|---|---|
<SharedAssetsT : Renderer.SharedAssets> |
The type extending |
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 |
Whether the |
Public functions
render
final 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 |
render
@UiThread
abstract funrender(
canvas: Canvas,
bounds: Rect,
zonedDateTime: ZonedDateTime,
sharedAssets: SharedAssetsT
): 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 |
sharedAssets: SharedAssetsT |
The |
renderHighlightLayer
final 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 |
renderHighlightLayer
@UiThread
abstract funrenderHighlightLayer(
canvas: Canvas,
bounds: Rect,
zonedDateTime: ZonedDateTime,
sharedAssets: SharedAssetsT
): 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 |
sharedAssets: SharedAssetsT |
The |
Protected functions
createSharedAssets
@WorkerThread
protected abstract suspend funcreateSharedAssets(): 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 |