diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt
index dbd251607..65121906c 100644
--- a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt
+++ b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt
@@ -294,5 +294,5 @@ object ChapterProvider {
}
val TextPaint.textHeight: Float
- get() = this.fontMetrics.descent - fontMetrics.ascent + fontMetrics.leading
+ get() = fontMetrics.descent - fontMetrics.ascent + fontMetrics.leading
}
\ No newline at end of file
diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt
index 534ee75d2..389d924f6 100644
--- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt
+++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt
@@ -71,7 +71,12 @@ class ContentView(context: Context) : FrameLayout(context) {
}
if (hideStatusBar) {
tv_bottom_left.text = timeFormat.format(Date(System.currentTimeMillis()))
- tv_bottom_right.text = context.getString(R.string.battery_show, battery)
+ tv_bottom_right.gone()
+ battery_view.visible()
+ battery_view.setBattery(battery)
+ } else {
+ tv_bottom_right.visible()
+ battery_view.gone()
}
}
}
@@ -98,7 +103,7 @@ class ContentView(context: Context) : FrameLayout(context) {
fun upBattery(battery: Int) {
this.battery = battery
if (ReadBookConfig.hideStatusBar) {
- tv_bottom_right.text = context.getString(R.string.battery_show, battery)
+ battery_view.setBattery(battery)
}
}
diff --git a/app/src/main/java/io/legado/app/ui/widget/BatteryView.kt b/app/src/main/java/io/legado/app/ui/widget/BatteryView.kt
new file mode 100644
index 000000000..74c1bda9f
--- /dev/null
+++ b/app/src/main/java/io/legado/app/ui/widget/BatteryView.kt
@@ -0,0 +1,50 @@
+package io.legado.app.ui.widget
+
+import android.content.Context
+import android.graphics.Canvas
+import android.graphics.Paint
+import android.graphics.Rect
+import android.graphics.Typeface
+import android.text.StaticLayout
+import android.text.TextPaint
+import android.util.AttributeSet
+import android.view.View
+import io.legado.app.utils.dp
+
+class BatteryView(context: Context, attrs: AttributeSet?) : View(context, attrs) {
+ private var battery = 100
+ private val textPaint = TextPaint()
+ private var batteryHeight: Int = 0
+ private var batteryWidth: Int = 0
+ private val outFrame = Rect()
+ private val polar = Rect()
+
+ init {
+ textPaint.isAntiAlias = true
+ textPaint.textAlign = Paint.Align.CENTER
+ textPaint.typeface = Typeface.createFromAsset(context.assets, "number.ttf")
+ batteryHeight = with(textPaint.fontMetrics) { descent - ascent + leading }.toInt() + 4.dp
+ batteryWidth = StaticLayout.getDesiredWidth("100", textPaint).toInt() + 5.dp
+ outFrame.set(0, 0, batteryWidth - 2.dp, batteryHeight)
+ polar.set(outFrame.right, batteryHeight / 4, batteryWidth, batteryHeight * 3 / 4)
+ }
+
+ override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
+ super.onMeasure(batteryWidth, batteryHeight)
+ }
+
+ fun setBattery(battery: Int) {
+ this.battery = battery
+ invalidate()
+ }
+
+ override fun onDraw(canvas: Canvas) {
+ super.onDraw(canvas)
+ canvas.drawRect(polar, textPaint)
+ textPaint.style = Paint.Style.STROKE
+ canvas.drawRect(outFrame, textPaint)
+ val text = battery.toString()
+ canvas.drawText(text, outFrame.right / 2.toFloat(), batteryHeight / 2.toFloat(), textPaint)
+ }
+
+}
\ No newline at end of file
diff --git a/app/src/main/res/layout/view_book_page.xml b/app/src/main/res/layout/view_book_page.xml
index bba89c8fb..aa8168165 100644
--- a/app/src/main/res/layout/view_book_page.xml
+++ b/app/src/main/res/layout/view_book_page.xml
@@ -51,6 +51,7 @@
android:id="@+id/ll_footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:gravity="center_vertical"
android:orientation="horizontal">
+
+
\ No newline at end of file