diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index e1913943b..8cfa9ebb5 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -1,9 +1,11 @@ package io.legado.app.ui.book.read.page +import android.annotation.SuppressLint import android.content.Context import android.graphics.Canvas import android.graphics.Paint import android.util.AttributeSet +import android.view.MotionEvent import android.view.View import io.legado.app.R import io.legado.app.constant.PreferKey @@ -38,6 +40,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } + @SuppressLint("ClickableViewAccessibility") + override fun onTouchEvent(event: MotionEvent?): Boolean { + + return true + } + override fun onDraw(canvas: Canvas) { super.onDraw(canvas) textPage?.let { textPage -> @@ -73,4 +81,20 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } + fun selectText(x: Float, y: Float) { + textPage?.let { textPage -> + for (textLine in textPage.textLines) { + if (y > textLine.lineTop && y < textLine.lineBottom) { + for (textChar in textLine.textChars) { + if (x > textChar.leftBottomPosition.x && x < textChar.rightTopPosition.x) { + textChar.selected = true + invalidate() + break + } + } + break + } + } + } + } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt index d8d25ae2a..3e19ba1b7 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt @@ -18,11 +18,10 @@ import java.util.* class ContentView : FrameLayout { var callBack: CallBack? = null - private var isScroll: Boolean = false + var headerHeight = 0 private var pageSize: Int = 0 constructor(context: Context) : super(context) { - this.isScroll = true init() } @@ -40,7 +39,7 @@ class ContentView : FrameLayout { fun upStyle() { ReadBookConfig.durConfig.apply { - val rootPaddingTop = if (context.getPrefBoolean(PreferKey.hideStatusBar, false)) { + if (context.getPrefBoolean(PreferKey.hideStatusBar, false)) { //显示状态栏时隐藏header ll_header.visible() ll_header.layoutParams = @@ -51,12 +50,13 @@ class ContentView : FrameLayout { headerPaddingRight.dp, headerPaddingBottom.dp ) - 0 + headerHeight = ll_header.height + page_panel.setPadding(0, 0, 0, 0) } else { ll_header.gone() - context.getStatusBarHeight() + headerHeight = context.getStatusBarHeight() + page_panel.setPadding(0, headerHeight, 0, 0) } - page_panel.setPadding(0, rootPaddingTop, 0, 0) content_text_view.setPadding( paddingLeft.dp, paddingTop.dp, @@ -111,8 +111,8 @@ class ContentView : FrameLayout { } fun selectText(e: MotionEvent) { - - + val y = e.y - headerHeight + content_text_view.selectText(e.x, y) } fun scrollTo(pos: Int?) {