style: 电量数字移回电池图标外部
电池内部只保留充电时的 ⚡ 闪电符号 数字在电池左侧显示(16sp 加粗,颜色跟随状态) 电池图标恢复 28×13 正常尺寸 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -50,6 +50,7 @@ class StatusBarView @JvmOverloads constructor(
|
|||||||
// ===== 右侧:电池图标(固定位置)+ 电量百分比(电池左侧) =====
|
// ===== 右侧:电池图标(固定位置)+ 电量百分比(电池左侧) =====
|
||||||
val batteryStartX = width - 50f
|
val batteryStartX = width - 50f
|
||||||
drawBattery(canvas, batteryStartX, centerY)
|
drawBattery(canvas, batteryStartX, centerY)
|
||||||
|
drawBatteryText(canvas, batteryStartX - 4f, centerY)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 绘制蓝牙状态圆点 */
|
/** 绘制蓝牙状态圆点 */
|
||||||
@@ -89,8 +90,8 @@ class StatusBarView @JvmOverloads constructor(
|
|||||||
|
|
||||||
/** 绘制电池图标(壳 + 填充条 + 凸起 + 内部文字/闪电) */
|
/** 绘制电池图标(壳 + 填充条 + 凸起 + 内部文字/闪电) */
|
||||||
private fun drawBattery(canvas: Canvas, startX: Float, centerY: Float) {
|
private fun drawBattery(canvas: Canvas, startX: Float, centerY: Float) {
|
||||||
val shellW = 38f
|
val shellW = 28f
|
||||||
val shellH = 16f
|
val shellH = 13f
|
||||||
val shellTop = centerY - shellH / 2
|
val shellTop = centerY - shellH / 2
|
||||||
val cornerR = 4f
|
val cornerR = 4f
|
||||||
|
|
||||||
@@ -115,25 +116,16 @@ class StatusBarView @JvmOverloads constructor(
|
|||||||
)
|
)
|
||||||
canvas.drawRoundRect(fillRect, 2f, 2f, paint)
|
canvas.drawRoundRect(fillRect, 2f, 2f, paint)
|
||||||
|
|
||||||
// 电池内部文字:充电时显示 ⚡,否则显示百分比
|
// 充电时在电池内部画闪电
|
||||||
// 白色文字 + 黑色描边,在填充条和黑色背景上都清晰
|
if (isCharging) {
|
||||||
if (batteryLevel >= 0) {
|
paint.style = Paint.Style.FILL
|
||||||
val text = if (isCharging) "⚡" else "${batteryLevel}"
|
paint.color = 0xFFFFFFFF.toInt()
|
||||||
paint.textSize = 11f
|
paint.textSize = 11f
|
||||||
paint.textAlign = Paint.Align.CENTER
|
paint.textAlign = Paint.Align.CENTER
|
||||||
paint.typeface = android.graphics.Typeface.DEFAULT_BOLD
|
paint.typeface = android.graphics.Typeface.DEFAULT_BOLD
|
||||||
val metrics = paint.fontMetrics
|
val metrics = paint.fontMetrics
|
||||||
val baselineY = centerY - (metrics.ascent + metrics.descent) / 2
|
val baselineY = centerY - (metrics.ascent + metrics.descent) / 2
|
||||||
val cx = startX + shellW / 2
|
canvas.drawText("⚡", startX + shellW / 2, baselineY, paint)
|
||||||
// 先画黑色描边(让白字在绿色填充上有边界)
|
|
||||||
paint.style = Paint.Style.STROKE
|
|
||||||
paint.strokeWidth = 2.5f
|
|
||||||
paint.color = 0xFF000000.toInt()
|
|
||||||
canvas.drawText(text, cx, baselineY, paint)
|
|
||||||
// 再画白色填充
|
|
||||||
paint.style = Paint.Style.FILL
|
|
||||||
paint.color = 0xFFFFFFFF.toInt()
|
|
||||||
canvas.drawText(text, cx, baselineY, paint)
|
|
||||||
paint.textAlign = Paint.Align.LEFT
|
paint.textAlign = Paint.Align.LEFT
|
||||||
paint.typeface = android.graphics.Typeface.DEFAULT
|
paint.typeface = android.graphics.Typeface.DEFAULT
|
||||||
}
|
}
|
||||||
@@ -151,9 +143,20 @@ class StatusBarView @JvmOverloads constructor(
|
|||||||
canvas.drawRoundRect(nubRect, 1.5f, 1.5f, paint)
|
canvas.drawRoundRect(nubRect, 1.5f, 1.5f, paint)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 不再单独绘制电量文字(已合入电池图标内部) */
|
/** 绘制电量百分比(电池图标左侧) */
|
||||||
private fun drawBatteryText(canvas: Canvas, rightEdge: Float, centerY: Float) {
|
private fun drawBatteryText(canvas: Canvas, rightEdge: Float, centerY: Float) {
|
||||||
// 电量数字已显示在电池内部,无需额外文字
|
if (batteryLevel < 0) return
|
||||||
|
val text = "${batteryLevel}%"
|
||||||
|
paint.style = Paint.Style.FILL
|
||||||
|
paint.color = getBatteryColor()
|
||||||
|
paint.textSize = 16f
|
||||||
|
paint.textAlign = Paint.Align.RIGHT
|
||||||
|
paint.typeface = android.graphics.Typeface.DEFAULT_BOLD
|
||||||
|
val metrics = paint.fontMetrics
|
||||||
|
val baselineY = centerY - (metrics.ascent + metrics.descent) / 2
|
||||||
|
canvas.drawText(text, rightEdge, baselineY, paint)
|
||||||
|
paint.textAlign = Paint.Align.LEFT
|
||||||
|
paint.typeface = android.graphics.Typeface.DEFAULT
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== 更新方法 =====
|
// ===== 更新方法 =====
|
||||||
|
|||||||
Reference in New Issue
Block a user