Google is committed to advancing racial equity for Black communities. See how.

Renderer

abstract class Renderer
kotlin.Any
   ↳ androidx.wear.watchface.Renderer

The base class for CanvasRenderer and GlesRenderer.

Summary

Public constructors
<init>(surfaceHolder: SurfaceHolder, userStyleRepository: UserStyleRepository, watchState: WatchState)

The base class for CanvasRenderer and GlesRenderer.

Public methods
open Rect

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

open Unit

Called when the Renderer is destroyed.

open Boolean

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

Protected methods
open Unit

Called when the DrawMode 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.

RenderParameters

The current RenderParameters.

Rect

The bounds of the SurfaceHolder this Renderer renders into.

SurfaceHolder

The SurfaceHolder that renderInternal will draw into.

Public constructors

<init>

Renderer(
    surfaceHolder: SurfaceHolder,
    userStyleRepository: UserStyleRepository,
    watchState: WatchState)

The base class for CanvasRenderer and GlesRenderer.

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

onDestroy

@UiThread open fun onDestroy(): Unit

Called when the Renderer is destroyed.

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 DrawMode has been updated. Will always be called before the first call to onDraw().

Properties

centerX

var centerX: Float

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

centerY

var centerY: Float

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

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.

surfaceHolder

val surfaceHolder: SurfaceHolder

The SurfaceHolder that renderInternal will draw into.