From cc3b58a8677e4bdc0c61858c18c719920ea02e6c Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 21 Feb 2020 17:06: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 --- .../io/legado/app/ui/book/read/ReadBookActivity.kt | 12 ++++++++---- .../legado/app/ui/book/read/page/ContentTextView.kt | 11 ++++++++--- .../io/legado/app/ui/book/read/page/ContentView.kt | 4 ++-- .../java/io/legado/app/ui/book/read/page/PageView.kt | 4 ++-- .../app/ui/book/read/page/delegate/PageDelegate.kt | 3 +++ .../app/ui/book/read/page/entities/SelectPoint.kt | 8 ++++++++ 6 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/book/read/page/entities/SelectPoint.kt diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 44c67ba8b..0fc887307 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -35,7 +35,7 @@ import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.TEXT_COLOR import io.legado.app.ui.book.read.page.ChapterProvider import io.legado.app.ui.book.read.page.PageView import io.legado.app.ui.book.read.page.delegate.PageDelegate -import io.legado.app.ui.book.read.page.entities.TextChar +import io.legado.app.ui.book.read.page.entities.SelectPoint import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.changesource.ChangeSourceDialog import io.legado.app.ui.chapterlist.ChapterListActivity @@ -390,9 +390,13 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo } } - override fun selectText(textChar: TextChar) { - cursor_left - cursor_right + override fun selectText(selectPoint: SelectPoint) { + cursor_left.x = selectPoint.startX - cursor_left.width + cursor_left.y = selectPoint.startY + cursor_right.x = selectPoint.endX + cursor_right.y = selectPoint.endY + cursor_left.visible() + cursor_right.visible() } override fun showReadAloudDialog() { 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 78844b583..12c692307 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,7 +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.SelectPoint import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.utils.getCompatColor import io.legado.app.utils.getPrefBoolean @@ -82,7 +82,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } - fun selectText(x: Float, y: Float): TextChar? { + fun selectText(x: Float, y: Float): SelectPoint? { textPage?.let { textPage -> for (textLine in textPage.textLines) { if (y > textLine.lineTop && y < textLine.lineBottom) { @@ -90,7 +90,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (x > textChar.leftBottomPosition.x && x < textChar.rightTopPosition.x) { textChar.selected = true invalidate() - return textChar + return SelectPoint( + textChar.leftBottomPosition.x, + textChar.leftBottomPosition.y.toFloat(), + textChar.rightTopPosition.x, + textChar.leftBottomPosition.y.toFloat() + ) } } 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 621010ee7..734ce2ab7 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,7 +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.SelectPoint import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.utils.* import kotlinx.android.synthetic.main.view_book_page.view.* @@ -111,7 +111,7 @@ class ContentView : FrameLayout { content_text_view.selectAble = selectAble } - fun selectText(e: MotionEvent): TextChar? { + fun selectText(e: MotionEvent): SelectPoint? { val y = e.y - headerHeight return content_text_view.selectText(e.x, y) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index 68708c725..fe478f36c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -10,8 +10,8 @@ import io.legado.app.constant.PreferKey import io.legado.app.help.ReadBookConfig import io.legado.app.service.help.ReadBook import io.legado.app.ui.book.read.page.delegate.* +import io.legado.app.ui.book.read.page.entities.SelectPoint import io.legado.app.ui.book.read.page.entities.TextChapter -import io.legado.app.ui.book.read.page.entities.TextChar import io.legado.app.utils.activity import io.legado.app.utils.getPrefInt @@ -256,6 +256,6 @@ class PageView(context: Context, attrs: AttributeSet) : fun screenOffTimerStart() - fun selectText(textChar: TextChar) + fun selectText(selectPoint: SelectPoint) } } 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 aa525f948..dc3b9dddd 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 @@ -266,6 +266,9 @@ abstract class PageDelegate(protected val pageView: PageView) : return true } + /** + * 长按选择 + */ override fun onLongPress(e: MotionEvent) { val textChar = curPage.selectText(e) textChar?.let { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/SelectPoint.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/SelectPoint.kt new file mode 100644 index 000000000..0be88dae6 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/SelectPoint.kt @@ -0,0 +1,8 @@ +package io.legado.app.ui.book.read.page.entities + +data class SelectPoint( + var startX: Float, + var startY: Float, + var endX: Float, + var endY: Float +) \ No newline at end of file