下划线颜色、高度、虚线空隙比例设置

This commit is contained in:
HapeLee
2025-11-12 22:58:03 +08:00
parent 5fbdcf54d8
commit 4dcf097825
10 changed files with 242 additions and 32 deletions
@@ -38,6 +38,7 @@ import io.legado.app.ui.book.read.config.InfoConfigDialog
import io.legado.app.ui.book.read.config.PaddingConfigDialog
import io.legado.app.ui.book.read.config.PageKeyDialog
import io.legado.app.ui.book.read.config.ShadowSetDialog
import io.legado.app.ui.book.read.config.UnderlineConfigDialog
import io.legado.app.ui.file.HandleFileContract
import io.legado.app.utils.ColorUtils
import io.legado.app.utils.FileDoc
@@ -150,6 +151,10 @@ abstract class BaseReadBookActivity :
showDialogFragment<FontSelectDialog>()
}
fun showUnderlineConfig() {
showDialogFragment<UnderlineConfigDialog>()
}
fun showBgTextConfig() {
showDialogFragment<BgTextConfigDialog>()
}
@@ -86,6 +86,7 @@ import io.legado.app.ui.book.read.config.TipConfigDialog.Companion.B_COLOR
import io.legado.app.ui.book.read.config.TipConfigDialog.Companion.TIP_COLOR
import io.legado.app.ui.book.read.config.TipConfigDialog.Companion.TIP_DIVIDER_COLOR
import io.legado.app.ui.book.read.config.ToolButtonConfigDialog
import io.legado.app.ui.book.read.config.UnderlineConfigDialog.Companion.U_COLOR
import io.legado.app.ui.book.read.page.ContentTextView
import io.legado.app.ui.book.read.page.ReadView
import io.legado.app.ui.book.read.page.entities.PageDirection
@@ -1572,6 +1573,12 @@ class ReadBookActivity : BaseReadBookActivity(),
setMenuCurAc(color)
postEvent(EventBus.UPDATE_READ_ACTION_BAR, true)
}
U_COLOR -> {
setUnderlineColor(color)
postEvent(EventBus.UP_CONFIG, arrayListOf(2))
postEvent(EventBus.UP_CONFIG, arrayListOf(6, 9, 11))
}
}
}
@@ -9,7 +9,6 @@ import io.legado.app.base.BaseBottomSheetDialogFragment
import io.legado.app.constant.EventBus
import io.legado.app.databinding.DialogFontConfigBinding
import io.legado.app.help.config.AppConfig
import io.legado.app.help.config.ReadBookConfig.dottedLine
import io.legado.app.help.config.ReadBookConfig.underline
import io.legado.app.lib.dialogs.alert
import io.legado.app.ui.book.read.ReadBookActivity
@@ -50,8 +49,6 @@ class FontConfigDialog : BaseBottomSheetDialogFragment(R.layout.dialog_font_conf
private fun initView() = binding.run {
binding.btnTextColor.color = ReadBookConfig.durConfig.curTextColor()
binding.swUnderline.isChecked = underline
binding.swDottedline.isChecked = dottedLine
binding.swDottedline.isEnabled = underline
dsbTextLetterSpacing.valueFormat = {
((it - 50) / 100f).toString()
}
@@ -136,18 +133,10 @@ class FontConfigDialog : BaseBottomSheetDialogFragment(R.layout.dialog_font_conf
}
binding.swUnderline.addOnCheckedChangeListener { _, isChecked ->
underline = isChecked
binding.swDottedline.isEnabled = isChecked
if (!isChecked) {
dottedLine = false
binding.swDottedline.isChecked = false
}
postEvent(EventBus.UP_CONFIG, arrayListOf(6, 9, 11))
}
binding.swDottedline.addOnCheckedChangeListener { _, isChecked ->
dottedLine = isChecked
postEvent(EventBus.UP_CONFIG, arrayListOf(6, 9, 11))
callBack2?.showUnderlineConfig()
dismissAllowingStateLoss()
}
binding.btnDefaultFonts.setOnClickListener {
val requireContext = requireContext()
alert(titleResource = R.string.system_typeface) {
@@ -0,0 +1,92 @@
package io.legado.app.ui.book.read.config
import android.os.Bundle
import android.view.View
import io.legado.app.help.config.ReadBookConfig
import com.jaredrummler.android.colorpicker.ColorPickerDialog
import io.legado.app.R
import io.legado.app.base.BaseBottomSheetDialogFragment
import io.legado.app.constant.EventBus
import io.legado.app.databinding.DialogUnderlineConfigBinding
import io.legado.app.help.config.ReadBookConfig.dottedLine
import io.legado.app.help.config.ReadBookConfig.underline
import io.legado.app.utils.observeEvent
import io.legado.app.utils.postEvent
import io.legado.app.utils.viewbindingdelegate.viewBinding
/**
* 字体选择对话框
*/
class UnderlineConfigDialog : BaseBottomSheetDialogFragment(R.layout.dialog_underline_config) {
companion object {
const val U_COLOR = 810
}
private val binding by viewBinding(DialogUnderlineConfigBinding::bind)
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
observeEvent<ArrayList<Int>>(EventBus.UP_CONFIG) { list ->
if (list.contains(2)) {
binding.btnUnderlineColor.color = ReadBookConfig.durConfig.curUnderlineColor()
}
}
initView()
}
private fun initView() = binding.run {
binding.btnUnderlineColor.color = ReadBookConfig.durConfig.curTextColor()
binding.swUnderline.isChecked = underline
binding.swDottedline.isChecked = dottedLine
binding.swDottedline.isEnabled = underline
binding.swUnderline.addOnCheckedChangeListener { _, isChecked ->
underline = isChecked
binding.swDottedline.isEnabled = isChecked
if (!isChecked) {
dottedLine = false
binding.swDottedline.isChecked = false
}
postEvent(EventBus.UP_CONFIG, arrayListOf(6, 9, 11))
}
binding.swDottedline.addOnCheckedChangeListener { _, isChecked ->
dottedLine = isChecked
postEvent(EventBus.UP_CONFIG, arrayListOf(6, 9, 11))
}
binding.btnDottedLineBlack.apply {
progress = ReadBookConfig.durConfig.dottedBase.toInt()
onChanged = {
ReadBookConfig.durConfig.dottedBase = it.toFloat()
postEvent(EventBus.UP_CONFIG, arrayListOf(6, 8, 10))
}
}
binding.btnDottedLineWhile.apply {
progress = ReadBookConfig.durConfig.dottedRatio.toInt()
onChanged = {
ReadBookConfig.durConfig.dottedRatio = it.toFloat()
postEvent(EventBus.UP_CONFIG, arrayListOf(6, 8, 10))
}
}
binding.btnUnderlineColor.setOnClickListener {
ColorPickerDialog.newBuilder()
.setColor(ReadBookConfig.durConfig.curUnderlineColor())
.setShowAlphaSlider(false)
.setDialogType(ColorPickerDialog.TYPE_CUSTOM)
.setDialogId(U_COLOR)
.show(requireActivity())
}
binding.btnUnderlineHeight.apply {
progress = ReadBookConfig.underlineHeight
onChanged = {
ReadBookConfig.underlineHeight = it
postEvent(EventBus.UP_CONFIG, arrayListOf(8, 9, 6))
}
}
}
}
@@ -211,16 +211,19 @@ data class TextLine(
*/
private fun drawUnderline(canvas: Canvas, dottedLine: Boolean) {
val paint = ChapterProvider.linePaint
paint.pathEffect =
if (dottedLine && !AppConfig.isEInkMode)
ChapterProvider.dashEffect
else
null
paint.color = ReadBookConfig.durConfig.curUnderlineColor()
paint.strokeWidth = ReadBookConfig.underlineHeight.toFloat()
paint.pathEffect = if (dottedLine && !AppConfig.isEInkMode)
ChapterProvider.dashEffect
else
null
val lineY = height - 1.dpToPx()
canvas.drawLine(lineStart + indentWidth, lineY, lineEnd, lineY, paint)
}
fun checkFastDraw(): Boolean {
if (!AppConfig.optimizeRender || exceed || !onlyTextColumn || textPage.isMsgPage) {
return false
@@ -66,7 +66,7 @@ object ChapterProvider {
}
}
val dashEffect = DashPathEffect(floatArrayOf(dottedBase, dottedRatio), 0f)
var dashEffect = DashPathEffect(floatArrayOf(dottedBase, dottedRatio), 0f)
@JvmStatic
var viewWidth = 0
@@ -877,6 +877,10 @@ object ChapterProvider {
// reviewPaint.textSize = contentPaint.textSize * 0.45f
// reviewPaint.textAlign = Paint.Align.CENTER
}
dashEffect = DashPathEffect(
floatArrayOf(ReadBookConfig.durConfig.dottedBase, ReadBookConfig.durConfig.dottedRatio),
0f
)
//间距
lineSpacingExtra = ReadBookConfig.lineSpacingExtra / 10f
titleLineSpacingExtra = ReadBookConfig.titleLineSpacingExtra / 10f
+2 -10
View File
@@ -24,8 +24,9 @@
android:id="@+id/bottom_sheet_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginVertical="8dp"
android:text="@string/text_font"
android:textSize="16sp"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
@@ -64,15 +65,6 @@
android:checkable="true"
android:focusable="true"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/sw_dottedline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Widget.Material3Expressive.Button.IconButton.Tonal"
app:icon="@drawable/ic_dottedline"
android:checkable="true"
android:focusable="true"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_textItalic"
android:layout_width="wrap_content"
@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:paddingBottom="8dp"
android:paddingHorizontal="16dp">
<com.google.android.material.bottomsheet.BottomSheetDragHandleView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingVertical="8dp"
android:minHeight="0dp"
android:layout_gravity="center_horizontal" />
<TextView
android:id="@+id/bottom_sheet_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginVertical="8dp"
android:text="@string/text_underline"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
<com.google.android.material.button.MaterialButtonGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginBottom="8dp"
android:gravity="center">
<com.google.android.material.button.MaterialButton
android:id="@+id/sw_underline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Widget.Material3Expressive.Button.IconButton.Tonal"
app:icon="@drawable/ic_underline"
android:checkable="true"
android:focusable="true"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/sw_dottedline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Widget.Material3Expressive.Button.IconButton.Tonal"
app:icon="@drawable/ic_dottedline"
android:checkable="true"
android:focusable="true"/>
<io.legado.app.ui.widget.AccentColorButton
android:id="@+id/btnUnderlineColor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Widget.Material3Expressive.Button.OutlinedButton"
android:text="@string/underline_color" />
</com.google.android.material.button.MaterialButtonGroup>
<io.legado.app.ui.widget.SimpleSliderView
android:id="@+id/btn_underline_height"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:title="@string/underline_height"
app:max="20" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/text_dottedline"
android:layout_marginHorizontal="16dp"
android:layout_marginVertical="8dp"
android:textSize="14sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom">
<io.legado.app.ui.widget.SimpleSliderView
android:id="@+id/btn_dotted_line_black"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginEnd="32dp"
app:title="@string/dotted_line_black"
app:max="20" />
<io.legado.app.ui.widget.SimpleSliderView
android:id="@+id/btn_dotted_line_while"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:title="@string/dotted_line_while"
app:max="20" />
</LinearLayout>
</LinearLayout>
+5 -1
View File
@@ -1325,7 +1325,7 @@
<string name="sort_new_to_old">从新到旧</string>
<string name="sort_name_asc">名称升序</string>
<string name="sort_name_desc">名称降序</string>
<string name="text_dottedline">文字下划虚线</string>
<string name="text_dottedline">下划虚线</string>
<string name="jump_to_volume">跳转到卷</string>
<string name="cancel_select">取消选择</string>
<string name="coll_volume">折叠所有卷</string>
@@ -1340,4 +1340,8 @@
<string name="text_shadow_set">阴影设置</string>
<string name="paragraph_typeface">段落样式</string>
<string name="same_name_book">已有相同书籍</string>
<string name="underline_color">下划线颜色</string>
<string name="dotted_line_black">实线段长</string>
<string name="dotted_line_while">空隙比例</string>
<string name="underline_height">线段高度</string>
</resources>
+5 -1
View File
@@ -1326,7 +1326,7 @@
<string name="sort_new_to_old">从新到旧</string>
<string name="sort_name_asc">名称升序</string>
<string name="sort_name_desc">名称降序</string>
<string name="text_dottedline">文字下划虚线</string>
<string name="text_dottedline">下划虚线</string>
<string name="jump_to_volume">跳转到卷</string>
<string name="cancel_select">取消选择</string>
<string name="coll_volume">折叠所有卷</string>
@@ -1341,4 +1341,8 @@
<string name="text_shadow_set">阴影设置</string>
<string name="paragraph_typeface">段落样式</string>
<string name="same_name_book">已有相同书籍</string>
<string name="underline_color">下划线颜色</string>
<string name="dotted_line_black">实线段长</string>
<string name="dotted_line_while">空隙比例</string>
<string name="underline_height">线段高度</string>
</resources>