优化
This commit is contained in:
@@ -41,6 +41,7 @@ class PageView(context: Context) : FrameLayout(context) {
|
|||||||
private var tvBookName: BatteryView? = null
|
private var tvBookName: BatteryView? = null
|
||||||
private var tvTimeBattery: BatteryView? = null
|
private var tvTimeBattery: BatteryView? = null
|
||||||
private var tvTimeBatteryP: BatteryView? = null
|
private var tvTimeBatteryP: BatteryView? = null
|
||||||
|
private var bitmap: Bitmap? = null
|
||||||
|
|
||||||
val headerHeight: Int
|
val headerHeight: Int
|
||||||
get() {
|
get() {
|
||||||
@@ -61,7 +62,12 @@ class PageView(context: Context) : FrameLayout(context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getBitmap(): Bitmap? {
|
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 {
|
fun upStyle() = binding.run {
|
||||||
@@ -230,8 +236,7 @@ class PageView(context: Context) : FrameLayout(context) {
|
|||||||
val time = timeFormat.format(Date(System.currentTimeMillis()))
|
val time = timeFormat.format(Date(System.currentTimeMillis()))
|
||||||
tvTimeBattery?.setBattery(battery, time)
|
tvTimeBattery?.setBattery(battery, time)
|
||||||
tvTimeBatteryP?.text = "$time $battery%"
|
tvTimeBatteryP?.text = "$time $battery%"
|
||||||
destroyDrawingCache()
|
upBitmap()
|
||||||
buildDrawingCache()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setContent(textPage: TextPage, resetPageOffset: Boolean = true) {
|
fun setContent(textPage: TextPage, resetPageOffset: Boolean = true) {
|
||||||
@@ -240,8 +245,7 @@ class PageView(context: Context) : FrameLayout(context) {
|
|||||||
resetPageOffset()
|
resetPageOffset()
|
||||||
}
|
}
|
||||||
binding.contentTextView.setContent(textPage)
|
binding.contentTextView.setContent(textPage)
|
||||||
destroyDrawingCache()
|
upBitmap()
|
||||||
buildDrawingCache()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setContentDescription(content: String) {
|
fun setContentDescription(content: String) {
|
||||||
|
|||||||
@@ -126,14 +126,13 @@ fun View.visible(visible: Boolean) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun View.screenshot(): Bitmap? {
|
fun View.screenshot(): Bitmap {
|
||||||
return runCatching {
|
|
||||||
val screenshot = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
val screenshot = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
||||||
val c = Canvas(screenshot)
|
val c = Canvas(screenshot)
|
||||||
c.translate(-scrollX.toFloat(), -scrollY.toFloat())
|
c.translate(-scrollX.toFloat(), -scrollY.toFloat())
|
||||||
draw(c)
|
this.draw(c)
|
||||||
screenshot
|
c.setBitmap(null)
|
||||||
}.getOrNull()
|
return screenshot
|
||||||
}
|
}
|
||||||
|
|
||||||
fun SeekBar.progressAdd(int: Int) {
|
fun SeekBar.progressAdd(int: Int) {
|
||||||
|
|||||||
Reference in New Issue
Block a user