diff --git a/app/src/main/java/com/ray650128/iosclockwidget/IOSClockView.kt b/app/src/main/java/com/ray650128/iosclockwidget/IOSClockView.kt index 0c00bad..0002626 100644 --- a/app/src/main/java/com/ray650128/iosclockwidget/IOSClockView.kt +++ b/app/src/main/java/com/ray650128/iosclockwidget/IOSClockView.kt @@ -59,6 +59,15 @@ class IOSClockView: View { } } + private val clockHourText: Paint by lazy { + Paint().apply { + isAntiAlias = true + style = Paint.Style.FILL + color = Color.BLACK + textSize = width * 0.1f + } + } + private val clockMinuteScale: Paint by lazy { Paint().apply { isAntiAlias = true @@ -103,7 +112,7 @@ class IOSClockView: View { drawClockFace(canvas) - drawScaleHourHand(canvas, 12) + drawTime(canvas) postInvalidateDelayed(30) } @@ -146,10 +155,20 @@ class IOSClockView: View { val stopX = centerX + sin(degrees.toDouble()).toFloat() * (radius * 0.95f) val stopY = centerY - cos(degrees.toDouble()).toFloat() * (radius * 0.95f) canvas?.drawLine(startX, startY, stopX, stopY, clockHourScale) + if (i % 5 == 0) { + val text = "${if (i % 12 == 0) 12 else i % 12}" + val textX = centerX + sin(degrees.toDouble()).toFloat() * (radius * 0.75f) - if (text.length == 1) { + (width * 0.1f) / 3.25f + } else { + (width * 0.1f) / 2f + } + val textY = centerY - cos(degrees.toDouble()).toFloat() * (radius * 0.75f) + (width * 0.1f) / 2.75f + canvas?.drawText(text, textX, textY, clockHourText) + } } } - private fun drawScaleHourHand(canvas: Canvas?, value: Int) { + private fun drawTime(canvas: Canvas?) { val mPaint = Paint() val mPointRange = 100f // 取得目前時間:時、分、秒