配置项目并添加实现表盘服务的类后,您可以开始编写代码来初始化和绘制自定义表盘。
每个表盘都会创建一个渲染器的自定义子类,该子类实现了绘制表盘所需的一切。
渲染器将 UserStyle
、来自 ComplicationSlotsManager
的复杂功能信息、当前时间和其他状态信息组合起来渲染表盘,如下例所示
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
}
}