在配置您的项目并添加实现手表表盘服务的类之后,您可以开始编写代码来初始化和绘制您的自定义手表表盘。
每个手表表盘都会创建一个渲染器的自定义子类,该子类实现绘制手表表盘所需的一切。
渲染器将 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
}
}