From 891fdc1f8c8d372a5271a002ed6f8ae8f407e61f Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 21 Feb 2020 15:26:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ContentTextView.kt | 24 +++++++++++++++++++ .../app/ui/book/read/page/ContentView.kt | 16 ++++++------- 2 files changed, 32 insertions(+), 8 deletions(-) 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?) {