pull/1649/head
kunfei 3 years ago
parent 2530137b1d
commit 529443c0c3
  1. 9
      app/src/main/java/io/legado/app/ui/widget/BatteryView.kt

@ -31,7 +31,6 @@ class BatteryView @JvmOverloads constructor(
} }
} }
private var battery: Int = 0 private var battery: Int = 0
private var batteryWidth = 0
init { init {
setPadding(4.dp, 3.dp, 6.dp, 3.dp) setPadding(4.dp, 3.dp, 6.dp, 3.dp)
@ -55,9 +54,6 @@ class BatteryView @JvmOverloads constructor(
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
fun setBattery(battery: Int, text: String? = null) { fun setBattery(battery: Int, text: String? = null) {
this.battery = battery this.battery = battery
if (isBattery) {
batteryWidth = StaticLayout.getDesiredWidth(battery.toString(), paint).toInt()
}
if (text.isNullOrEmpty()) { if (text.isNullOrEmpty()) {
setText(battery.toString()) setText(battery.toString())
} else { } else {
@ -72,9 +68,8 @@ class BatteryView @JvmOverloads constructor(
val batteryStart = layout val batteryStart = layout
.getPrimaryHorizontal(text.length - battery.toString().length) .getPrimaryHorizontal(text.length - battery.toString().length)
.toInt() + 3.dp .toInt() + 3.dp
val batteryEnd = layout val batteryEnd =
.getSecondaryHorizontal(text.length) batteryStart + StaticLayout.getDesiredWidth(battery.toString(), paint).toInt() + 4.dp
.toInt() + 6.dp
outFrame.set( outFrame.set(
batteryStart, batteryStart,
2.dp, 2.dp,

Loading…
Cancel
Save