页眉页脚 #193
This commit is contained in:
9 files changed
+230
-38
No files matched your search
@@ -22,10 +22,12 @@ object ReadTipConfig {
|
|||||||
const val chapterTitleArrow = 12
|
const val chapterTitleArrow = 12
|
||||||
const val batteryInside = 13
|
const val batteryInside = 13
|
||||||
const val batteryIcon = 14
|
const val batteryIcon = 14
|
||||||
|
const val batteryClassic = 15
|
||||||
|
const val timeBatteryClassic = 16
|
||||||
|
|
||||||
val tipValues = arrayOf(
|
val tipValues = arrayOf(
|
||||||
none, bookName, chapterTitle, chapterTitleArrow, time, battery, batteryInside, batteryIcon, batteryPercentage, page,
|
none, bookName, chapterTitle, chapterTitleArrow, time, battery, batteryClassic, batteryInside, batteryIcon, batteryPercentage, page,
|
||||||
totalProgress, totalProgress1, pageAndTotal, timeBattery, timeBatteryPercentage
|
totalProgress, totalProgress1, pageAndTotal, timeBattery, timeBatteryClassic, timeBatteryPercentage
|
||||||
)
|
)
|
||||||
val tipNames get() = appCtx.resources.getStringArray(R.array.read_tip).toList()
|
val tipNames get() = appCtx.resources.getStringArray(R.array.read_tip).toList()
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,9 @@ class PageView(context: Context) : FrameLayout(context) {
|
|||||||
private var tvTitleArrow: BatteryView? = null
|
private var tvTitleArrow: BatteryView? = null
|
||||||
private var tvBatteryInside: BatteryView? = null
|
private var tvBatteryInside: BatteryView? = null
|
||||||
private var tvBatteryIcon: BatteryView? = null
|
private var tvBatteryIcon: BatteryView? = null
|
||||||
|
private var tvBatteryClassic: BatteryView? = null
|
||||||
|
private var tvTimeBatteryClassic: BatteryView? = null
|
||||||
|
|
||||||
private var isMainView = false
|
private var isMainView = false
|
||||||
var isScroll = false
|
var isScroll = false
|
||||||
|
|
||||||
@@ -181,86 +184,92 @@ class PageView(context: Context) : FrameLayout(context) {
|
|||||||
}
|
}
|
||||||
tvTitle = getTipView(ReadTipConfig.chapterTitle)?.apply {
|
tvTitle = getTipView(ReadTipConfig.chapterTitle)?.apply {
|
||||||
tag = ReadTipConfig.chapterTitle
|
tag = ReadTipConfig.chapterTitle
|
||||||
isBattery = false
|
|
||||||
typeface = ChapterProvider.typeface
|
typeface = ChapterProvider.typeface
|
||||||
textSize = 12f
|
textSize = 12f
|
||||||
|
batteryMode = BatteryView.BatteryMode.NO_BATTERY
|
||||||
}
|
}
|
||||||
tvTitleArrow = getTipView(ReadTipConfig.chapterTitleArrow)?.apply {
|
tvTitleArrow = getTipView(ReadTipConfig.chapterTitleArrow)?.apply {
|
||||||
tag = ReadTipConfig.chapterTitleArrow
|
tag = ReadTipConfig.chapterTitleArrow
|
||||||
isBattery = false
|
|
||||||
typeface = ChapterProvider.typeface
|
typeface = ChapterProvider.typeface
|
||||||
textSize = 12f
|
textSize = 12f
|
||||||
batteryMode = BatteryView.BatteryMode.ARROW
|
batteryMode = BatteryView.BatteryMode.ARROW
|
||||||
}
|
}
|
||||||
tvTime = getTipView(ReadTipConfig.time)?.apply {
|
tvTime = getTipView(ReadTipConfig.time)?.apply {
|
||||||
tag = ReadTipConfig.time
|
tag = ReadTipConfig.time
|
||||||
isBattery = false
|
|
||||||
typeface = ChapterProvider.typeface
|
typeface = ChapterProvider.typeface
|
||||||
textSize = 12f
|
textSize = 12f
|
||||||
|
batteryMode = BatteryView.BatteryMode.NO_BATTERY
|
||||||
}
|
}
|
||||||
tvBattery = getTipView(ReadTipConfig.battery)?.apply {
|
tvBattery = getTipView(ReadTipConfig.battery)?.apply {
|
||||||
tag = ReadTipConfig.battery
|
tag = ReadTipConfig.battery
|
||||||
isBattery = true
|
|
||||||
textSize = 11f
|
textSize = 11f
|
||||||
batteryMode = BatteryView.BatteryMode.OUTER
|
batteryMode = BatteryView.BatteryMode.OUTER
|
||||||
}
|
}
|
||||||
|
tvBatteryClassic = getTipView(ReadTipConfig.batteryClassic)?.apply {
|
||||||
|
tag = ReadTipConfig.batteryClassic
|
||||||
|
textSize = 11f
|
||||||
|
batteryMode = BatteryView.BatteryMode.CLASSIC
|
||||||
|
}
|
||||||
tvBatteryInside = getTipView(ReadTipConfig.batteryInside)?.apply {
|
tvBatteryInside = getTipView(ReadTipConfig.batteryInside)?.apply {
|
||||||
tag = ReadTipConfig.batteryInside
|
tag = ReadTipConfig.batteryInside
|
||||||
isBattery = true
|
|
||||||
textSize = 11f
|
textSize = 11f
|
||||||
batteryMode = BatteryView.BatteryMode.INNER
|
batteryMode = BatteryView.BatteryMode.INNER
|
||||||
}
|
}
|
||||||
tvBatteryIcon = getTipView(ReadTipConfig.batteryIcon)?.apply {
|
tvBatteryIcon = getTipView(ReadTipConfig.batteryIcon)?.apply {
|
||||||
tag = ReadTipConfig.batteryIcon
|
tag = ReadTipConfig.batteryIcon
|
||||||
isBattery = true
|
|
||||||
textSize = 11f
|
textSize = 11f
|
||||||
batteryMode = BatteryView.BatteryMode.ICON
|
batteryMode = BatteryView.BatteryMode.ICON
|
||||||
}
|
}
|
||||||
tvPage = getTipView(ReadTipConfig.page)?.apply {
|
tvPage = getTipView(ReadTipConfig.page)?.apply {
|
||||||
tag = ReadTipConfig.page
|
tag = ReadTipConfig.page
|
||||||
isBattery = false
|
|
||||||
typeface = ChapterProvider.typeface
|
typeface = ChapterProvider.typeface
|
||||||
textSize = 12f
|
textSize = 12f
|
||||||
|
batteryMode = BatteryView.BatteryMode.NO_BATTERY
|
||||||
}
|
}
|
||||||
tvTotalProgress = getTipView(ReadTipConfig.totalProgress)?.apply {
|
tvTotalProgress = getTipView(ReadTipConfig.totalProgress)?.apply {
|
||||||
tag = ReadTipConfig.totalProgress
|
tag = ReadTipConfig.totalProgress
|
||||||
isBattery = false
|
batteryMode = BatteryView.BatteryMode.NO_BATTERY
|
||||||
typeface = ChapterProvider.typeface
|
typeface = ChapterProvider.typeface
|
||||||
textSize = 12f
|
textSize = 12f
|
||||||
}
|
}
|
||||||
tvTotalProgress1 = getTipView(ReadTipConfig.totalProgress1)?.apply {
|
tvTotalProgress1 = getTipView(ReadTipConfig.totalProgress1)?.apply {
|
||||||
tag = ReadTipConfig.totalProgress1
|
tag = ReadTipConfig.totalProgress1
|
||||||
isBattery = false
|
batteryMode = BatteryView.BatteryMode.NO_BATTERY
|
||||||
typeface = ChapterProvider.typeface
|
typeface = ChapterProvider.typeface
|
||||||
textSize = 12f
|
textSize = 12f
|
||||||
}
|
}
|
||||||
tvPageAndTotal = getTipView(ReadTipConfig.pageAndTotal)?.apply {
|
tvPageAndTotal = getTipView(ReadTipConfig.pageAndTotal)?.apply {
|
||||||
tag = ReadTipConfig.pageAndTotal
|
tag = ReadTipConfig.pageAndTotal
|
||||||
isBattery = false
|
batteryMode = BatteryView.BatteryMode.NO_BATTERY
|
||||||
typeface = ChapterProvider.typeface
|
typeface = ChapterProvider.typeface
|
||||||
textSize = 12f
|
textSize = 12f
|
||||||
}
|
}
|
||||||
tvBookName = getTipView(ReadTipConfig.bookName)?.apply {
|
tvBookName = getTipView(ReadTipConfig.bookName)?.apply {
|
||||||
tag = ReadTipConfig.bookName
|
tag = ReadTipConfig.bookName
|
||||||
isBattery = false
|
batteryMode = BatteryView.BatteryMode.NO_BATTERY
|
||||||
typeface = ChapterProvider.typeface
|
typeface = ChapterProvider.typeface
|
||||||
textSize = 12f
|
textSize = 12f
|
||||||
}
|
}
|
||||||
tvTimeBattery = getTipView(ReadTipConfig.timeBattery)?.apply {
|
tvTimeBattery = getTipView(ReadTipConfig.timeBattery)?.apply {
|
||||||
tag = ReadTipConfig.timeBattery
|
tag = ReadTipConfig.timeBattery
|
||||||
isBattery = true
|
textSize = 11f
|
||||||
|
batteryMode = BatteryView.BatteryMode.TIME
|
||||||
|
}
|
||||||
|
tvTimeBatteryClassic = getTipView(ReadTipConfig.timeBatteryClassic)?.apply {
|
||||||
|
tag = ReadTipConfig.timeBatteryClassic
|
||||||
typeface = ChapterProvider.typeface
|
typeface = ChapterProvider.typeface
|
||||||
textSize = 11f
|
textSize = 11f
|
||||||
|
batteryMode = BatteryView.BatteryMode.CLASSIC
|
||||||
}
|
}
|
||||||
tvBatteryP = getTipView(ReadTipConfig.batteryPercentage)?.apply {
|
tvBatteryP = getTipView(ReadTipConfig.batteryPercentage)?.apply {
|
||||||
tag = ReadTipConfig.batteryPercentage
|
tag = ReadTipConfig.batteryPercentage
|
||||||
isBattery = false
|
batteryMode = BatteryView.BatteryMode.NO_BATTERY
|
||||||
typeface = ChapterProvider.typeface
|
typeface = ChapterProvider.typeface
|
||||||
textSize = 12f
|
textSize = 12f
|
||||||
}
|
}
|
||||||
tvTimeBatteryP = getTipView(ReadTipConfig.timeBatteryPercentage)?.apply {
|
tvTimeBatteryP = getTipView(ReadTipConfig.timeBatteryPercentage)?.apply {
|
||||||
tag = ReadTipConfig.timeBatteryPercentage
|
tag = ReadTipConfig.timeBatteryPercentage
|
||||||
isBattery = false
|
batteryMode = BatteryView.BatteryMode.NO_BATTERY
|
||||||
typeface = ChapterProvider.typeface
|
typeface = ChapterProvider.typeface
|
||||||
textSize = 12f
|
textSize = 12f
|
||||||
}
|
}
|
||||||
@@ -318,6 +327,7 @@ class PageView(context: Context) : FrameLayout(context) {
|
|||||||
fun upBattery(battery: Int) {
|
fun upBattery(battery: Int) {
|
||||||
this.battery = battery
|
this.battery = battery
|
||||||
tvBattery?.setBattery(battery)
|
tvBattery?.setBattery(battery)
|
||||||
|
tvBatteryClassic?.setBattery(battery)
|
||||||
tvBatteryInside?.setBattery(battery)
|
tvBatteryInside?.setBattery(battery)
|
||||||
tvBatteryIcon?.setBattery(battery)
|
tvBatteryIcon?.setBattery(battery)
|
||||||
tvBatteryP?.text = "$battery%"
|
tvBatteryP?.text = "$battery%"
|
||||||
@@ -332,7 +342,8 @@ 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?.setBattery(battery, time)
|
tvTimeBatteryP?.setBattery(battery, time)
|
||||||
tvTimeBattery?.text = "$time $battery%"
|
tvTimeBatteryClassic?.setBattery(battery, time)
|
||||||
|
tvTimeBatteryClassic?.text = "$time $battery%"
|
||||||
tvTimeBatteryP?.text = "$time $battery%"
|
tvTimeBatteryP?.text = "$time $battery%"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class BatteryView @JvmOverloads constructor(
|
|||||||
private val binding: ViewBatteryBinding =
|
private val binding: ViewBatteryBinding =
|
||||||
ViewBatteryBinding.inflate(LayoutInflater.from(context), this, true)
|
ViewBatteryBinding.inflate(LayoutInflater.from(context), this, true)
|
||||||
|
|
||||||
enum class BatteryMode { OUTER, INNER, ICON, ARROW }
|
enum class BatteryMode { OUTER, INNER, ICON, ARROW, TIME, CLASSIC, NO_BATTERY }
|
||||||
|
|
||||||
private val batteryTypeface by lazy {
|
private val batteryTypeface by lazy {
|
||||||
Typeface.createFromAsset(context.assets, "font/number.ttf")
|
Typeface.createFromAsset(context.assets, "font/number.ttf")
|
||||||
@@ -28,20 +28,8 @@ class BatteryView @JvmOverloads constructor(
|
|||||||
private var battery: Int = 0
|
private var battery: Int = 0
|
||||||
|
|
||||||
init {
|
init {
|
||||||
setPadding(4.dpToPx(), 3.dpToPx(), 6.dpToPx(), 3.dpToPx())
|
//binding.batteryText.typeface = batteryTypeface
|
||||||
binding.batteryText.typeface = batteryTypeface
|
//binding.batteryTextInner.typeface = batteryTypeface
|
||||||
binding.batteryTextInner.typeface = batteryTypeface
|
|
||||||
}
|
|
||||||
|
|
||||||
var isBattery = false
|
|
||||||
set(value) {
|
|
||||||
field = value
|
|
||||||
binding.arrowIcon.visibility = if (value) VISIBLE else GONE
|
|
||||||
binding.batteryTextInner.visibility = if (value) VISIBLE else GONE
|
|
||||||
binding.batteryTextInner.typeface = if (value) Typeface.DEFAULT else batteryTypeface
|
|
||||||
binding.batteryText.typeface = if (value) Typeface.DEFAULT else batteryTypeface
|
|
||||||
binding.batteryIcon.visibility = if (value) VISIBLE else GONE
|
|
||||||
binding.batteryFill.visibility = if (value) VISIBLE else GONE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var text: CharSequence?
|
var text: CharSequence?
|
||||||
@@ -77,14 +65,35 @@ class BatteryView @JvmOverloads constructor(
|
|||||||
|
|
||||||
fun setBattery(battery: Int, text: String? = null) {
|
fun setBattery(battery: Int, text: String? = null) {
|
||||||
this.battery = battery.coerceIn(0, 100)
|
this.battery = battery.coerceIn(0, 100)
|
||||||
binding.batteryText.text = text?.let { "$it $battery" } ?: battery.toString()
|
|
||||||
binding.batteryTextInner.text = text?.let { "$it $battery" } ?: battery.toString()
|
when (batteryMode) {
|
||||||
|
BatteryMode.TIME -> {
|
||||||
|
val timePart = text ?: ""
|
||||||
|
val batteryPart = "$battery"
|
||||||
|
binding.batteryText.text = timePart
|
||||||
|
binding.batteryTextInner.text = batteryPart
|
||||||
|
}
|
||||||
|
|
||||||
|
BatteryMode.CLASSIC -> {
|
||||||
|
binding.batteryClassic.isBattery = true
|
||||||
|
binding.batteryClassic.setBattery(battery, text)
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> {
|
||||||
|
val displayText = text?.let { "$it $battery" } ?: battery.toString()
|
||||||
|
binding.batteryText.text = displayText
|
||||||
|
binding.batteryTextInner.text = displayText
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
updateFill()
|
updateFill()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setColor(@ColorInt color: Int) {
|
fun setColor(@ColorInt color: Int) {
|
||||||
binding.batteryText.setTextColor(color)
|
binding.batteryText.setTextColor(color)
|
||||||
|
binding.batteryTextInner.setTextColor(color)
|
||||||
binding.batteryFill.setCardBackgroundColor(color)
|
binding.batteryFill.setCardBackgroundColor(color)
|
||||||
|
binding.batteryClassic.setColor(color)
|
||||||
binding.arrowIcon.setColorFilter(color, PorterDuff.Mode.SRC_IN)
|
binding.arrowIcon.setColorFilter(color, PorterDuff.Mode.SRC_IN)
|
||||||
binding.batteryIcon.setColorFilter(color, PorterDuff.Mode.SRC_IN)
|
binding.batteryIcon.setColorFilter(color, PorterDuff.Mode.SRC_IN)
|
||||||
binding.batteryIcon.alpha = 0.76f
|
binding.batteryIcon.alpha = 0.76f
|
||||||
@@ -101,28 +110,58 @@ class BatteryView @JvmOverloads constructor(
|
|||||||
private fun updateMode() {
|
private fun updateMode() {
|
||||||
when (batteryMode) {
|
when (batteryMode) {
|
||||||
BatteryMode.OUTER -> {
|
BatteryMode.OUTER -> {
|
||||||
binding.arrowIcon.visibility = GONE
|
|
||||||
binding.batteryText.visibility = VISIBLE
|
binding.batteryText.visibility = VISIBLE
|
||||||
binding.batteryTextInner.visibility = GONE
|
binding.batteryTextInner.visibility = GONE
|
||||||
binding.batteryFill.visibility = VISIBLE
|
binding.batteryFill.visibility = VISIBLE
|
||||||
|
binding.batteryIcon.visibility = VISIBLE
|
||||||
|
binding.arrowIcon.visibility = GONE
|
||||||
|
binding.batteryClassic.visibility = GONE
|
||||||
}
|
}
|
||||||
BatteryMode.INNER -> {
|
BatteryMode.INNER -> {
|
||||||
binding.arrowIcon.visibility = GONE
|
|
||||||
binding.batteryText.visibility = GONE
|
binding.batteryText.visibility = GONE
|
||||||
binding.batteryTextInner.visibility = VISIBLE
|
binding.batteryTextInner.visibility = VISIBLE
|
||||||
binding.batteryFill.visibility = GONE
|
binding.batteryFill.visibility = GONE
|
||||||
|
binding.batteryIcon.visibility = VISIBLE
|
||||||
|
binding.arrowIcon.visibility = GONE
|
||||||
|
binding.batteryClassic.visibility = GONE
|
||||||
}
|
}
|
||||||
BatteryMode.ICON -> {
|
BatteryMode.ICON -> {
|
||||||
binding.arrowIcon.visibility = GONE
|
|
||||||
binding.batteryText.visibility = GONE
|
binding.batteryText.visibility = GONE
|
||||||
binding.batteryTextInner.visibility = GONE
|
binding.batteryTextInner.visibility = GONE
|
||||||
binding.batteryFill.visibility = VISIBLE
|
binding.batteryFill.visibility = VISIBLE
|
||||||
|
binding.batteryIcon.visibility = VISIBLE
|
||||||
|
binding.arrowIcon.visibility = GONE
|
||||||
|
binding.batteryClassic.visibility = GONE
|
||||||
}
|
}
|
||||||
BatteryMode.ARROW -> {
|
BatteryMode.ARROW -> {
|
||||||
binding.batteryText.visibility = VISIBLE
|
binding.batteryText.visibility = VISIBLE
|
||||||
binding.batteryTextInner.visibility = GONE
|
binding.batteryTextInner.visibility = GONE
|
||||||
binding.batteryFill.visibility = GONE
|
binding.batteryFill.visibility = GONE
|
||||||
|
binding.batteryIcon.visibility = GONE
|
||||||
binding.arrowIcon.visibility = VISIBLE
|
binding.arrowIcon.visibility = VISIBLE
|
||||||
|
binding.batteryClassic.visibility = GONE
|
||||||
|
}
|
||||||
|
BatteryMode.TIME -> {
|
||||||
|
binding.batteryText.visibility = VISIBLE
|
||||||
|
binding.batteryTextInner.visibility = VISIBLE
|
||||||
|
binding.batteryFill.visibility = GONE
|
||||||
|
binding.batteryIcon.visibility = VISIBLE
|
||||||
|
binding.arrowIcon.visibility = GONE
|
||||||
|
binding.batteryClassic.visibility = GONE
|
||||||
|
}
|
||||||
|
BatteryMode.CLASSIC -> {
|
||||||
|
binding.batteryText.visibility = GONE
|
||||||
|
binding.batteryTextInner.visibility = GONE
|
||||||
|
binding.batteryFill.visibility = GONE
|
||||||
|
binding.batteryIcon.visibility = GONE
|
||||||
|
binding.arrowIcon.visibility = GONE
|
||||||
|
binding.batteryClassic.visibility = VISIBLE
|
||||||
|
}
|
||||||
|
BatteryMode.NO_BATTERY -> {
|
||||||
|
binding.batteryFill.visibility = GONE
|
||||||
|
binding.batteryIcon.visibility = GONE
|
||||||
|
binding.arrowIcon.visibility = GONE
|
||||||
|
binding.batteryClassic.visibility = GONE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateFill()
|
updateFill()
|
||||||
|
|||||||
@@ -0,0 +1,122 @@
|
|||||||
|
package io.legado.app.ui.widget
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.Canvas
|
||||||
|
import android.graphics.Paint
|
||||||
|
import android.graphics.Rect
|
||||||
|
import android.graphics.Typeface
|
||||||
|
import android.os.Build
|
||||||
|
import android.text.StaticLayout
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import androidx.annotation.ColorInt
|
||||||
|
import androidx.appcompat.widget.AppCompatTextView
|
||||||
|
import io.legado.app.help.config.AppConfig
|
||||||
|
import io.legado.app.utils.canvasrecorder.CanvasRecorderFactory
|
||||||
|
import io.legado.app.utils.canvasrecorder.recordIfNeededThenDraw
|
||||||
|
import io.legado.app.utils.dpToPx
|
||||||
|
|
||||||
|
class BatteryViewOrgin @JvmOverloads constructor(
|
||||||
|
context: Context,
|
||||||
|
attrs: AttributeSet? = null
|
||||||
|
) : AppCompatTextView(context, attrs) {
|
||||||
|
private val batteryTypeface by lazy {
|
||||||
|
Typeface.createFromAsset(context.assets, "font/number.ttf")
|
||||||
|
}
|
||||||
|
private val batteryPaint = Paint()
|
||||||
|
private val outFrame = Rect()
|
||||||
|
private val polar = Rect()
|
||||||
|
private val canvasRecorder = CanvasRecorderFactory.create()
|
||||||
|
var isBattery = false
|
||||||
|
set(value) {
|
||||||
|
field = value
|
||||||
|
if (value && !isInEditMode) {
|
||||||
|
super.setTypeface(batteryTypeface)
|
||||||
|
postInvalidate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private var battery: Int = 0
|
||||||
|
|
||||||
|
init {
|
||||||
|
setPadding(4.dpToPx(), 3.dpToPx(), 6.dpToPx(), 3.dpToPx())
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
isFallbackLineSpacing = false
|
||||||
|
}
|
||||||
|
batteryPaint.strokeWidth = 1f.dpToPx()
|
||||||
|
batteryPaint.isAntiAlias = true
|
||||||
|
batteryPaint.color = paint.color
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setTypeface(tf: Typeface?) {
|
||||||
|
if (!isBattery) {
|
||||||
|
super.setTypeface(tf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setColor(@ColorInt color: Int) {
|
||||||
|
setTextColor(color)
|
||||||
|
batteryPaint.color = color
|
||||||
|
invalidate()
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
|
fun setBattery(battery: Int, text: String? = null) {
|
||||||
|
this.battery = battery
|
||||||
|
if (text.isNullOrEmpty()) {
|
||||||
|
setText(battery.toString())
|
||||||
|
} else {
|
||||||
|
setText("$text $battery")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
|
||||||
|
super.onLayout(changed, left, top, right, bottom)
|
||||||
|
canvasRecorder.invalidate()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDraw(canvas: Canvas) {
|
||||||
|
if (AppConfig.optimizeRender) {
|
||||||
|
canvasRecorder.recordIfNeededThenDraw(canvas, width, height) {
|
||||||
|
super.onDraw(this)
|
||||||
|
drawBattery(this)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
super.onDraw(canvas)
|
||||||
|
drawBattery(canvas)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun drawBattery(canvas: Canvas) {
|
||||||
|
if (!isBattery) return
|
||||||
|
layout.getLineBounds(0, outFrame)
|
||||||
|
val batteryStart = layout
|
||||||
|
.getPrimaryHorizontal(text.length - battery.toString().length)
|
||||||
|
.toInt() + 2.dpToPx()
|
||||||
|
val batteryEnd = batteryStart +
|
||||||
|
StaticLayout.getDesiredWidth(battery.toString(), paint).toInt() + 4.dpToPx()
|
||||||
|
outFrame.set(
|
||||||
|
batteryStart,
|
||||||
|
2.dpToPx(),
|
||||||
|
batteryEnd,
|
||||||
|
height - 2.dpToPx()
|
||||||
|
)
|
||||||
|
val dj = (outFrame.bottom - outFrame.top) / 3
|
||||||
|
polar.set(
|
||||||
|
batteryEnd,
|
||||||
|
outFrame.top + dj,
|
||||||
|
batteryEnd + 2.dpToPx(),
|
||||||
|
outFrame.bottom - dj
|
||||||
|
)
|
||||||
|
batteryPaint.style = Paint.Style.STROKE
|
||||||
|
canvas.drawRect(outFrame, batteryPaint)
|
||||||
|
batteryPaint.style = Paint.Style.FILL
|
||||||
|
canvas.drawRect(polar, batteryPaint)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("UNNECESSARY_SAFE_CALL")
|
||||||
|
override fun invalidate() {
|
||||||
|
super.invalidate()
|
||||||
|
canvasRecorder?.invalidate()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginEnd="2.4dp"
|
android:layout_marginEnd="2.4dp"
|
||||||
android:layout_marginBottom="0.8dp"
|
android:layout_marginBottom="0.8dp"
|
||||||
android:textSize="7sp"
|
android:textSize="8sp"
|
||||||
android:text="@string/text"
|
android:text="@string/text"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
app:layout_constraintStart_toStartOf="@id/battery_icon"
|
app:layout_constraintStart_toStartOf="@id/battery_icon"
|
||||||
@@ -68,4 +68,14 @@
|
|||||||
app:layout_constraintTop_toTopOf="@id/battery_icon"
|
app:layout_constraintTop_toTopOf="@id/battery_icon"
|
||||||
app:layout_constraintBottom_toBottomOf="@id/battery_icon"/>
|
app:layout_constraintBottom_toBottomOf="@id/battery_icon"/>
|
||||||
|
|
||||||
|
<io.legado.app.ui.widget.BatteryViewOrgin
|
||||||
|
android:id="@+id/battery_classic"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/text"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:layout_constraintStart_toEndOf="@id/battery_icon"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -54,6 +54,7 @@
|
|||||||
<item>標題+箭頭</item>
|
<item>標題+箭頭</item>
|
||||||
<item>時間</item>
|
<item>時間</item>
|
||||||
<item>電量</item>
|
<item>電量</item>
|
||||||
|
<item>經典電量</item>
|
||||||
<item>電量內顯</item>
|
<item>電量內顯</item>
|
||||||
<item>僅電量圖標</item>
|
<item>僅電量圖標</item>
|
||||||
<item>電量%</item>
|
<item>電量%</item>
|
||||||
@@ -62,6 +63,7 @@
|
|||||||
<item>進度(xx/yyy)</item>
|
<item>進度(xx/yyy)</item>
|
||||||
<item>頁數同埋進度</item>
|
<item>頁數同埋進度</item>
|
||||||
<item>時間同埋電量</item>
|
<item>時間同埋電量</item>
|
||||||
|
<item>時間同埋電量經典</item>
|
||||||
<item>時間同埋電量%</item>
|
<item>時間同埋電量%</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
|||||||
@@ -91,6 +91,7 @@
|
|||||||
<item>標題+箭頭</item>
|
<item>標題+箭頭</item>
|
||||||
<item>時間</item>
|
<item>時間</item>
|
||||||
<item>電量</item>
|
<item>電量</item>
|
||||||
|
<item>電量经典</item>
|
||||||
<item>電量內顯</item>
|
<item>電量內顯</item>
|
||||||
<item>僅電量圖標</item>
|
<item>僅電量圖標</item>
|
||||||
<item>電量%</item>
|
<item>電量%</item>
|
||||||
@@ -99,6 +100,7 @@
|
|||||||
<item>進度(xx/yyy)</item>
|
<item>進度(xx/yyy)</item>
|
||||||
<item>頁數及進度</item>
|
<item>頁數及進度</item>
|
||||||
<item>時間及電量</item>
|
<item>時間及電量</item>
|
||||||
|
<item>時間及電量经典</item>
|
||||||
<item>時間及電量%</item>
|
<item>時間及電量%</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,7 @@
|
|||||||
<item>带箭头的标题</item>
|
<item>带箭头的标题</item>
|
||||||
<item>时间</item>
|
<item>时间</item>
|
||||||
<item>电量</item>
|
<item>电量</item>
|
||||||
|
<item>经典电量</item>
|
||||||
<item>电量内显</item>
|
<item>电量内显</item>
|
||||||
<item>仅电量图标</item>
|
<item>仅电量图标</item>
|
||||||
<item>电量%</item>
|
<item>电量%</item>
|
||||||
@@ -86,6 +87,7 @@
|
|||||||
<item>进度(xx/yyy)</item>
|
<item>进度(xx/yyy)</item>
|
||||||
<item>页数及进度</item>
|
<item>页数及进度</item>
|
||||||
<item>时间及电量</item>
|
<item>时间及电量</item>
|
||||||
|
<item>经典电量及时间</item>
|
||||||
<item>时间及电量%</item>
|
<item>时间及电量%</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
|||||||
@@ -145,6 +145,7 @@
|
|||||||
<item>Title With Arrow</item>
|
<item>Title With Arrow</item>
|
||||||
<item>Time</item>
|
<item>Time</item>
|
||||||
<item>Battery</item>
|
<item>Battery</item>
|
||||||
|
<item>Battery Classic</item>
|
||||||
<item>Battery Inside</item>
|
<item>Battery Inside</item>
|
||||||
<item>Battery Only Icon</item>
|
<item>Battery Only Icon</item>
|
||||||
<item>Battery%</item>
|
<item>Battery%</item>
|
||||||
@@ -153,6 +154,7 @@
|
|||||||
<item>Progress(xx/yyy)</item>
|
<item>Progress(xx/yyy)</item>
|
||||||
<item>Pages and progress</item>
|
<item>Pages and progress</item>
|
||||||
<item>Time and Battery</item>
|
<item>Time and Battery</item>
|
||||||
|
<item>Time and Battery Classic</item>
|
||||||
<item>Time and Battery%</item>
|
<item>Time and Battery%</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user