From 7abe222dad1858deb0100d04341915e3f4ea9374 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 21 Feb 2020 15:38:57 +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 --- .../java/io/legado/app/ui/book/read/page/ContentTextView.kt | 6 ++++-- .../java/io/legado/app/ui/book/read/page/ContentView.kt | 5 +++-- .../legado/app/ui/book/read/page/delegate/PageDelegate.kt | 2 +- 3 files changed, 8 insertions(+), 5 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 8cfa9ebb5..78844b583 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 @@ -11,6 +11,7 @@ import io.legado.app.R import io.legado.app.constant.PreferKey import io.legado.app.help.ReadBookConfig import io.legado.app.lib.theme.accentColor +import io.legado.app.ui.book.read.page.entities.TextChar import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.utils.getCompatColor import io.legado.app.utils.getPrefBoolean @@ -81,7 +82,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } - fun selectText(x: Float, y: Float) { + fun selectText(x: Float, y: Float): TextChar? { textPage?.let { textPage -> for (textLine in textPage.textLines) { if (y > textLine.lineTop && y < textLine.lineBottom) { @@ -89,12 +90,13 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (x > textChar.leftBottomPosition.x && x < textChar.rightTopPosition.x) { textChar.selected = true invalidate() - break + return textChar } } break } } } + return null } } 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 3e19ba1b7..621010ee7 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 @@ -10,6 +10,7 @@ import io.legado.app.R import io.legado.app.constant.AppConst.TIME_FORMAT import io.legado.app.constant.PreferKey import io.legado.app.help.ReadBookConfig +import io.legado.app.ui.book.read.page.entities.TextChar import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.utils.* import kotlinx.android.synthetic.main.view_book_page.view.* @@ -110,9 +111,9 @@ class ContentView : FrameLayout { content_text_view.selectAble = selectAble } - fun selectText(e: MotionEvent) { + fun selectText(e: MotionEvent): TextChar? { val y = e.y - headerHeight - content_text_view.selectText(e.x, y) + return content_text_view.selectText(e.x, y) } fun scrollTo(pos: Int?) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt index f655928d7..15ea770d7 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt @@ -267,7 +267,7 @@ abstract class PageDelegate(protected val pageView: PageView) : } override fun onLongPress(e: MotionEvent) { - curPage.selectText(e) + val textChar = curPage.selectText(e) } /**