|
|
@ -53,28 +53,39 @@ class BatteryView @JvmOverloads constructor( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("SetTextI18n") |
|
|
|
@SuppressLint("SetTextI18n") |
|
|
|
fun setTextAndBattery(text: String = "", battery: Int = 0) { |
|
|
|
fun setBattery(battery: Int, text: String? = null) { |
|
|
|
this.battery = battery |
|
|
|
this.battery = battery |
|
|
|
if (isBattery) { |
|
|
|
if (isBattery) { |
|
|
|
batteryWidth = StaticLayout.getDesiredWidth(battery.toString(), paint).toInt() |
|
|
|
batteryWidth = StaticLayout.getDesiredWidth(battery.toString(), paint).toInt() |
|
|
|
} |
|
|
|
} |
|
|
|
setText("$text $battery") |
|
|
|
if (text.isNullOrEmpty()) { |
|
|
|
|
|
|
|
setText(battery.toString()) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
setText("$text $battery") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onDraw(canvas: Canvas) { |
|
|
|
override fun onDraw(canvas: Canvas) { |
|
|
|
super.onDraw(canvas) |
|
|
|
super.onDraw(canvas) |
|
|
|
if (!isBattery) return |
|
|
|
if (!isBattery) return |
|
|
|
|
|
|
|
layout.getLineBounds(0, outFrame) |
|
|
|
|
|
|
|
val batteryStart = layout |
|
|
|
|
|
|
|
.getPrimaryHorizontal(text.length - battery.toString().length) |
|
|
|
|
|
|
|
.toInt() + 3.dp |
|
|
|
|
|
|
|
val batteryEnd = layout |
|
|
|
|
|
|
|
.getSecondaryHorizontal(text.length) |
|
|
|
|
|
|
|
.toInt() + 6.dp |
|
|
|
outFrame.set( |
|
|
|
outFrame.set( |
|
|
|
width - 6.dp - batteryWidth, |
|
|
|
batteryStart, |
|
|
|
1.dp, |
|
|
|
1.dp, |
|
|
|
width - 3.dp, |
|
|
|
batteryEnd, |
|
|
|
height - 1.dp |
|
|
|
height - 1.dp |
|
|
|
) |
|
|
|
) |
|
|
|
val dj = (outFrame.bottom - outFrame.top) / 3 |
|
|
|
val dj = (outFrame.bottom - outFrame.top) / 3 |
|
|
|
polar.set( |
|
|
|
polar.set( |
|
|
|
outFrame.right, |
|
|
|
batteryEnd, |
|
|
|
outFrame.top + dj, |
|
|
|
outFrame.top + dj, |
|
|
|
width - 1.dp, |
|
|
|
batteryEnd + 2.dp, |
|
|
|
outFrame.bottom - dj |
|
|
|
outFrame.bottom - dj |
|
|
|
) |
|
|
|
) |
|
|
|
batteryPaint.style = Paint.Style.STROKE |
|
|
|
batteryPaint.style = Paint.Style.STROKE |
|
|
|