feat: 电池显示电量数值 + 充电闪电标识
1. 电池图标右侧显示"75%"电量百分比(白色60%透明度) 2. 充电中在电池壳内显示⚡闪电标识 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -47,8 +47,9 @@ class StatusBarView @JvmOverloads constructor(
|
|||||||
drawBluetoothDot(canvas, 8f, centerY)
|
drawBluetoothDot(canvas, 8f, centerY)
|
||||||
drawSignalBars(canvas, 22f, centerY)
|
drawSignalBars(canvas, 22f, centerY)
|
||||||
|
|
||||||
// ===== 右侧:电池 =====
|
// ===== 右侧:电量数值 + 电池图标 =====
|
||||||
drawBattery(canvas, width - 48f, centerY)
|
val batteryTextWidth = drawBatteryText(canvas, width.toFloat(), centerY)
|
||||||
|
drawBattery(canvas, width - batteryTextWidth - 52f, centerY)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 绘制蓝牙状态圆点 */
|
/** 绘制蓝牙状态圆点 */
|
||||||
@@ -77,7 +78,22 @@ class StatusBarView @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 绘制电池图标(壳 + 填充条 + 凸起) */
|
/** 绘制电量百分比文字(右对齐,返回文字宽度) */
|
||||||
|
private fun drawBatteryText(canvas: Canvas, rightEdge: Float, centerY: Float): Float {
|
||||||
|
val text = "${batteryLevel}%"
|
||||||
|
paint.style = Paint.Style.FILL
|
||||||
|
paint.color = 0x99FFFFFF.toInt() // 白色 60% 透明度
|
||||||
|
paint.textSize = 16f
|
||||||
|
paint.textAlign = Paint.Align.RIGHT
|
||||||
|
// 垂直居中:baseLine = centerY + textHeight/2 - descent
|
||||||
|
val metrics = paint.fontMetrics
|
||||||
|
val baselineY = centerY - (metrics.ascent + metrics.descent) / 2
|
||||||
|
canvas.drawText(text, rightEdge - 2f, baselineY, paint)
|
||||||
|
paint.textAlign = Paint.Align.LEFT // 恢复默认
|
||||||
|
return paint.measureText(text) + 4f
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 绘制电池图标(壳 + 填充条 + 凸起 + 充电闪电) */
|
||||||
private fun drawBattery(canvas: Canvas, startX: Float, centerY: Float) {
|
private fun drawBattery(canvas: Canvas, startX: Float, centerY: Float) {
|
||||||
val shellW = 28f
|
val shellW = 28f
|
||||||
val shellH = 13f
|
val shellH = 13f
|
||||||
@@ -110,6 +126,18 @@ class StatusBarView @JvmOverloads constructor(
|
|||||||
)
|
)
|
||||||
canvas.drawRoundRect(fillRect, 2f, 2f, paint)
|
canvas.drawRoundRect(fillRect, 2f, 2f, paint)
|
||||||
|
|
||||||
|
// 充电闪电标识(电池壳内居中)
|
||||||
|
if (isCharging) {
|
||||||
|
paint.color = colorWhite
|
||||||
|
paint.style = Paint.Style.FILL
|
||||||
|
paint.textSize = 11f
|
||||||
|
paint.textAlign = Paint.Align.CENTER
|
||||||
|
val metrics = paint.fontMetrics
|
||||||
|
val baselineY = centerY - (metrics.ascent + metrics.descent) / 2
|
||||||
|
canvas.drawText("⚡", startX + shellW / 2, baselineY, paint)
|
||||||
|
paint.textAlign = Paint.Align.LEFT
|
||||||
|
}
|
||||||
|
|
||||||
// 电池凸起(右侧小矩形)
|
// 电池凸起(右侧小矩形)
|
||||||
paint.color = colorBorder
|
paint.color = colorBorder
|
||||||
val nubW = 2.5f
|
val nubW = 2.5f
|
||||||
|
|||||||
Reference in New Issue
Block a user