Po skonfigurowaniu projektu i dodaniu klasy, która implementuje możesz zacząć pisać kod, aby zainicjować i narysować niestandardową tarczę zegarka.
Każda tarcza zegarka tworzy niestandardową podklasę mechanizmu renderowania, który implementuje wszystko, co jest potrzebne do narysowania tarczy zegarka.
Mechanizm renderowania łączy
UserStyle
,
widżety z
ComplicationSlotsManager
,
aktualną godzinę i inne informacje o stanie,
wyrenderuj tarczę zegarka, tak jak w tym przykładzie:
class CustomCanvasRenderer(
private val context: Context,
surfaceHolder: SurfaceHolder,
watchState: WatchState,
private val complicationSlotsManager: ComplicationSlotsManager,
currentUserStyleRepository: CurrentUserStyleRepository,
canvasType: Int
) : Renderer.CanvasRenderer(
surfaceHolder = surfaceHolder,
currentUserStyleRepository = currentUserStyleRepository,
watchState = watchState,
canvasType = canvasType,
interactiveDrawModeUpdateDelayMillis = 16L
) {
override fun render(canvas: Canvas, bounds: Rect, zonedDateTime: ZonedDateTime) {
// Draw into the canvas
}
override fun renderHighlightLayer(canvas: Canvas, bounds: Rect, zonedDateTime: ZonedDateTime) {
// Draw into the canvas
}
}