绘制表盘

配置项目并添加用来实现表盘服务的类后,您便可以开始编写代码以初始化并绘制自定义表盘。

每个表盘都会创建一个渲染程序的自定义子类,用于实现绘制表盘所需的一切。

渲染程序结合使用 UserStyleComplicationSlotsManager 中的复杂功能信息、当前时间和其他状态信息来渲染表盘,如以下示例所示

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!
    }
}