feat: 优化代码

pull/111/head
kunfei 5 years ago
parent 40452715e7
commit 59cef5f5a7
  1. 49
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  2. 2
      app/src/main/java/io/legado/app/ui/widget/checkbox/SmoothCheckBox.kt
  3. 59
      app/src/main/res/layout/dialog_read_book_style.xml
  4. 2
      app/src/main/res/values/strings.xml

@ -114,11 +114,56 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
}
fun selectStartMove(x: Float, y: Float) {
textPage?.let { textPage ->
for ((lineIndex, textLine) in textPage.textLines.withIndex()) {
if (y > textLine.lineTop && y < textLine.lineBottom) {
for ((charIndex, textChar) in textLine.textChars.withIndex()) {
if (x > textChar.leftBottomPosition.x && x < textChar.rightTopPosition.x) {
textChar.selected = true
invalidate()
selectStartLine = lineIndex
selectStartChar = charIndex
selectEndLine = lineIndex
selectEndChar = charIndex
SelectPoint(
textChar.leftBottomPosition.x,
textChar.leftBottomPosition.y.toFloat(),
textChar.rightTopPosition.x,
textChar.leftBottomPosition.y.toFloat()
)
break
}
}
break
}
}
}
}
fun selectEndMove(x: Float, y: Float) {
textPage?.let { textPage ->
for ((lineIndex, textLine) in textPage.textLines.withIndex()) {
if (y > textLine.lineTop && y < textLine.lineBottom) {
for ((charIndex, textChar) in textLine.textChars.withIndex()) {
if (x > textChar.leftBottomPosition.x && x < textChar.rightTopPosition.x) {
textChar.selected = true
invalidate()
selectStartLine = lineIndex
selectStartChar = charIndex
selectEndLine = lineIndex
selectEndChar = charIndex
SelectPoint(
textChar.leftBottomPosition.x,
textChar.leftBottomPosition.y.toFloat(),
textChar.rightTopPosition.x,
textChar.leftBottomPosition.y.toFloat()
)
}
}
break
}
}
}
}
}

@ -45,7 +45,7 @@ class SmoothCheckBox @JvmOverloads constructor(
init {
val ta = context.obtainStyledAttributes(attrs, R.styleable.SmoothCheckBox)
var tickColor = ThemeStore.accentColor(context)
mCheckedColor = context.getCompatColor(R.color.background_card)
mCheckedColor = context.getCompatColor(R.color.background_menu)
mUnCheckedColor = context.getCompatColor(R.color.background_menu)
mFloorColor = context.getCompatColor(R.color.transparent30)
tickColor = ta.getColor(R.styleable.SmoothCheckBox_color_tick, tickColor)

@ -1,12 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background"
android:padding="10dp">
<io.legado.app.ui.widget.text.StrokeTextView
android:id="@+id/tv_title_center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:text="@string/title_center"
android:gravity="center"
android:textSize="14sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<io.legado.app.ui.widget.text.StrokeTextView
android:id="@+id/tv_text_bold"
android:layout_width="wrap_content"
@ -18,7 +33,7 @@
android:text="@string/text_bold"
android:gravity="center"
android:textSize="14sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintLeft_toRightOf="@+id/tv_title_center"
app:layout_constraintRight_toLeftOf="@+id/tv_text_font"
app:layout_constraintTop_toTopOf="parent" />
@ -77,7 +92,6 @@
android:paddingBottom="3dp"
android:gravity="center"
android:textSize="14sp"
app:layout_constraintLeft_toRightOf="@+id/tv_padding"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
@ -133,8 +147,8 @@
android:id="@+id/tv_page_anim"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:paddingStart="6dp"
android:paddingEnd="6dp"
android:text="@string/page_anim"
app:layout_constraintTop_toBottomOf="@+id/vw_bg_fg" />
@ -142,8 +156,8 @@
android:id="@+id/rg_page_anim"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:orientation="horizontal"
android:gravity="center"
app:layout_constraintTop_toBottomOf="@id/tv_page_anim">
@ -219,12 +233,37 @@
<TextView
android:id="@+id/tv_bg_ts"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:paddingStart="6dp"
android:paddingEnd="6dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:text="@string/text_bg_style"
app:layout_constraintTop_toBottomOf="@+id/vw_bg_fg1" />
app:layout_constraintTop_toBottomOf="@+id/vw_bg_fg1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/tv_share_layout" />
<io.legado.app.ui.widget.checkbox.SmoothCheckBox
android:id="@+id/cb_share_layout"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginRight="6dp"
app:layout_constraintTop_toTopOf="@id/tv_bg_ts"
app:layout_constraintBottom_toBottomOf="@id/tv_bg_ts"
app:layout_constraintRight_toRightOf="parent"
tools:ignore="RtlHardcoded" />
<TextView
android:id="@+id/tv_share_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:text="@string/share_layout"
app:layout_constraintTop_toTopOf="@+id/tv_bg_ts"
app:layout_constraintBottom_toBottomOf="@+id/tv_bg_ts"
app:layout_constraintRight_toLeftOf="@+id/cb_share_layout" />
<io.legado.app.ui.widget.image.CircleImageView
android:id="@+id/bg0"

@ -617,4 +617,6 @@
<string name="footer">页角</string>
<string name="select_end">文本选择结束位置</string>
<string name="select_start">文本选择开始位置</string>
<string name="share_layout">共用布局</string>
<string name="title_center">标题居中</string>
</resources>

Loading…
Cancel
Save