pull/1903/head
kunfei 3 years ago
parent b9adb1854f
commit c3df746216
  1. 14
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  2. 15
      app/src/main/java/io/legado/app/utils/ViewExtensions.kt

@ -41,6 +41,7 @@ class PageView(context: Context) : FrameLayout(context) {
private var tvBookName: BatteryView? = null
private var tvTimeBattery: BatteryView? = null
private var tvTimeBatteryP: BatteryView? = null
private var bitmap: Bitmap? = null
val headerHeight: Int
get() {
@ -61,7 +62,12 @@ class PageView(context: Context) : FrameLayout(context) {
}
fun getBitmap(): Bitmap? {
return drawingCache?.copy(Bitmap.Config.ARGB_8888, false)
return bitmap?.copy(Bitmap.Config.ARGB_8888, false)
}
private fun upBitmap() {
bitmap?.recycle()
bitmap = screenshot()
}
fun upStyle() = binding.run {
@ -230,8 +236,7 @@ class PageView(context: Context) : FrameLayout(context) {
val time = timeFormat.format(Date(System.currentTimeMillis()))
tvTimeBattery?.setBattery(battery, time)
tvTimeBatteryP?.text = "$time $battery%"
destroyDrawingCache()
buildDrawingCache()
upBitmap()
}
fun setContent(textPage: TextPage, resetPageOffset: Boolean = true) {
@ -240,8 +245,7 @@ class PageView(context: Context) : FrameLayout(context) {
resetPageOffset()
}
binding.contentTextView.setContent(textPage)
destroyDrawingCache()
buildDrawingCache()
upBitmap()
}
fun setContentDescription(content: String) {

@ -126,14 +126,13 @@ fun View.visible(visible: Boolean) {
}
}
fun View.screenshot(): Bitmap? {
return runCatching {
val screenshot = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
val c = Canvas(screenshot)
c.translate(-scrollX.toFloat(), -scrollY.toFloat())
draw(c)
screenshot
}.getOrNull()
fun View.screenshot(): Bitmap {
val screenshot = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
val c = Canvas(screenshot)
c.translate(-scrollX.toFloat(), -scrollY.toFloat())
this.draw(c)
c.setBitmap(null)
return screenshot
}
fun SeekBar.progressAdd(int: Int) {

Loading…
Cancel
Save