style: 电量和闪电显示在电池图标内部
- 电池图标加大 28×13 → 38×16,内部空间足够放文字 - 正常时电池内显示百分比数字(如 73) - 充电时电池内显示 ⚡ 闪电符号 - 去掉电池外部的百分比文字,信息集中在图标上 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -48,9 +48,8 @@ class StatusBarView @JvmOverloads constructor(
|
||||
drawSignalBars(canvas, 22f, centerY)
|
||||
|
||||
// ===== 右侧:电池图标(固定位置)+ 电量百分比(电池左侧) =====
|
||||
val batteryStartX = width - 48f
|
||||
val batteryStartX = width - 50f
|
||||
drawBattery(canvas, batteryStartX, centerY)
|
||||
drawBatteryText(canvas, batteryStartX - 4f, centerY)
|
||||
}
|
||||
|
||||
/** 绘制蓝牙状态圆点 */
|
||||
@@ -88,29 +87,14 @@ class StatusBarView @JvmOverloads constructor(
|
||||
else -> colorGreen
|
||||
}
|
||||
|
||||
/** 绘制电量百分比文字(电池图标左侧) */
|
||||
private fun drawBatteryText(canvas: Canvas, rightEdge: Float, centerY: Float) {
|
||||
if (batteryLevel < 0) return // 未获取时不显示
|
||||
// 充电时显示 ⚡ 前缀
|
||||
val text = if (isCharging) "⚡${batteryLevel}%" else "${batteryLevel}%"
|
||||
paint.style = Paint.Style.FILL
|
||||
paint.color = getBatteryColor()
|
||||
paint.textSize = 18f
|
||||
paint.textAlign = Paint.Align.RIGHT
|
||||
val metrics = paint.fontMetrics
|
||||
val baselineY = centerY - (metrics.ascent + metrics.descent) / 2
|
||||
canvas.drawText(text, rightEdge, baselineY, paint)
|
||||
paint.textAlign = Paint.Align.LEFT
|
||||
}
|
||||
|
||||
/** 绘制电池图标(壳 + 填充条 + 凸起) */
|
||||
/** 绘制电池图标(壳 + 填充条 + 凸起 + 内部文字/闪电) */
|
||||
private fun drawBattery(canvas: Canvas, startX: Float, centerY: Float) {
|
||||
val shellW = 28f
|
||||
val shellH = 13f
|
||||
val shellW = 38f
|
||||
val shellH = 16f
|
||||
val shellTop = centerY - shellH / 2
|
||||
val cornerR = 3.5f
|
||||
val cornerR = 4f
|
||||
|
||||
// 电池壳边框(颜色跟随状态)
|
||||
// 电池壳边框
|
||||
paint.style = Paint.Style.STROKE
|
||||
paint.strokeWidth = 1.5f
|
||||
paint.color = if (batteryLevel <= 10 && !isCharging) colorRed else colorBorder
|
||||
@@ -131,17 +115,37 @@ class StatusBarView @JvmOverloads constructor(
|
||||
)
|
||||
canvas.drawRoundRect(fillRect, 2f, 2f, paint)
|
||||
|
||||
// 电池内部文字:充电时显示 ⚡,否则显示百分比
|
||||
if (batteryLevel >= 0) {
|
||||
val text = if (isCharging) "⚡" else "${batteryLevel}"
|
||||
paint.style = Paint.Style.FILL
|
||||
paint.color = 0xFFFFFFFF.toInt()
|
||||
paint.textSize = 11f
|
||||
paint.textAlign = Paint.Align.CENTER
|
||||
paint.typeface = android.graphics.Typeface.DEFAULT_BOLD
|
||||
val metrics = paint.fontMetrics
|
||||
val baselineY = centerY - (metrics.ascent + metrics.descent) / 2
|
||||
canvas.drawText(text, startX + shellW / 2, baselineY, paint)
|
||||
paint.textAlign = Paint.Align.LEFT
|
||||
paint.typeface = android.graphics.Typeface.DEFAULT
|
||||
}
|
||||
|
||||
// 电池凸起(右侧小矩形)
|
||||
paint.color = if (batteryLevel <= 10 && !isCharging) colorRed else colorBorder
|
||||
val nubW = 2.5f
|
||||
val nubH = 6f
|
||||
val nubW = 3f
|
||||
val nubH = 7f
|
||||
val nubRect = RectF(
|
||||
startX + shellW + 1f,
|
||||
centerY - nubH / 2,
|
||||
startX + shellW + 1f + nubW,
|
||||
centerY + nubH / 2
|
||||
)
|
||||
canvas.drawRoundRect(nubRect, 1f, 1f, paint)
|
||||
canvas.drawRoundRect(nubRect, 1.5f, 1.5f, paint)
|
||||
}
|
||||
|
||||
/** 不再单独绘制电量文字(已合入电池图标内部) */
|
||||
private fun drawBatteryText(canvas: Canvas, rightEdge: Float, centerY: Float) {
|
||||
// 电量数字已显示在电池内部,无需额外文字
|
||||
}
|
||||
|
||||
// ===== 更新方法 =====
|
||||
|
||||
Reference in New Issue
Block a user