Renderer
sealed class Renderer
kotlin.Any | |
↳ | androidx.wear.watchface.Renderer |
The base class for CanvasRenderer and GlesRenderer.
Summary
Nested classes | |
---|---|
abstract |
Watch faces that require Canvas rendering should extend their Renderer from this class. |
abstract |
Watch faces that require GLES20 rendering should extend their Renderer from this class. |
Public methods | |
---|---|
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. |
Unit |
Posts a message to schedule a call to either CanvasRenderer.render or GlesRenderer.render to draw the next frame. |
open Boolean |
The system periodically (at least once per minute) calls onTimeTick() to trigger a display update. |
Protected methods | |
---|---|
open Unit |
onRenderParametersChanged(renderParameters: RenderParameters) Called when the RenderParameters has been updated. |
Properties | |
---|---|
Float |
The center x coordinate of the SurfaceHolder this Renderer renders into. |
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. |
Public methods
getMainClockElementBounds
@UiThread open fun getMainClockElementBounds(): Rect
This method is used for accessibility support to describe the portion of the screen containing the main clock element. By default we assume this is contained in the central half of the watch face. Watch faces should override this to return the correct bounds for the main clock element.
Return | |
---|---|
A | Rect describing the bounds of the watch faces' main clock element |
invalidate
@UiThread fun invalidate(): Unit
Schedules a call to either CanvasRenderer.render or GlesRenderer.render to draw the next frame.
postInvalidate
fun postInvalidate(): Unit
Posts a message to schedule a call to either CanvasRenderer.render or GlesRenderer.render to draw the next frame. Unlike invalidate, this method is thread-safe and may be called on any thread.
shouldAnimate
@UiThread open fun shouldAnimate(): Boolean
The system periodically (at least once per minute) calls onTimeTick() to trigger a display update. If the watch face needs to animate with an interactive frame rate, calls to invalidate must be scheduled. This method controls whether or not we should do that and if shouldAnimate returns true we inhibit entering DrawMode.AMBIENT.
By default we remain at an interactive frame rate when the watch face is visible and we're not in ambient mode. Watchfaces with animated transitions for entering ambient mode may need to override this to ensure they play smoothly.
Return | |
---|---|
Whether we should schedule an onDraw call to maintain an interactive frame rate |
Protected methods
onRenderParametersChanged
@UiThread protected open fun onRenderParametersChanged(renderParameters: RenderParameters): Unit
Called when the RenderParameters has been updated. Will always be called before the first call to CanvasRenderer.render or GlesRenderer.render.
Properties
interactiveDrawModeUpdateDelayMillis
var interactiveDrawModeUpdateDelayMillis: Long
The interval in milliseconds between frames in interactive DrawModes. To render at 60hz set to 16. Note when battery is low, the frame rate will be clamped to 10fps. Watch faces are recommended to use lower frame rates if possible for better battery life. Variable frame rates can also help preserve battery life, e.g. if a watch face has a short animation once per second it can adjust the frame rate inorder to sleep when not animating.
renderParameters
var renderParameters: RenderParameters
The current RenderParameters. Updated before every onDraw call.
screenBounds
var screenBounds: Rect
The bounds of the SurfaceHolder this Renderer renders into. Depending on the shape of the device's screen not all of these pixels may be visible to the user (see Configuration.isScreenRound). Note also that API level 27+ devices draw indicators in the top and bottom 24dp of the screen, avoid rendering anything important there.
surfaceHolder
val surfaceHolder: SurfaceHolder
The SurfaceHolder that renderInternal will draw into.