From 0fdb544d658e127049154bc661ab40b4ed75f799 Mon Sep 17 00:00:00 2001 From: tateisu Date: Wed, 5 Sep 2018 23:47:31 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=AF=E3=83=A9=E3=83=83=E3=82=B7=E3=83=A5?= =?UTF-8?q?=E3=83=AC=E3=83=9D=E3=83=BC=E3=83=88=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/dictionaries/tateisu.xml | 2 ++ .../subwaytooter/view/MyLinkMovementMethod.kt | 33 ++++++++++++------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/.idea/dictionaries/tateisu.xml b/.idea/dictionaries/tateisu.xml index 00a5ea3a..c966e073 100644 --- a/.idea/dictionaries/tateisu.xml +++ b/.idea/dictionaries/tateisu.xml @@ -68,6 +68,7 @@ tateisu thru timelines + tissot tootsearch unarist unboost @@ -79,6 +80,7 @@ userkey utoken workarea + xiaomi \ No newline at end of file diff --git a/app/src/main/java/jp/juggler/subwaytooter/view/MyLinkMovementMethod.kt b/app/src/main/java/jp/juggler/subwaytooter/view/MyLinkMovementMethod.kt index e13b9ad4..d192d591 100644 --- a/app/src/main/java/jp/juggler/subwaytooter/view/MyLinkMovementMethod.kt +++ b/app/src/main/java/jp/juggler/subwaytooter/view/MyLinkMovementMethod.kt @@ -6,9 +6,12 @@ import android.text.method.Touch import android.text.style.ClickableSpan import android.view.MotionEvent import android.widget.TextView +import jp.juggler.subwaytooter.util.LogCategory object MyLinkMovementMethod : LinkMovementMethod() { + private val log = LogCategory("MyLinkMovementMethod") + // 改行より右をタッチしても反応しないようにする override fun onTouchEvent(widget : TextView, buffer : Spannable, event : MotionEvent) : Boolean { @@ -36,18 +39,26 @@ object MyLinkMovementMethod : LinkMovementMethod() { val line_right = layout.getLineRight(line) if(line_left <= x && x <= line_right) { - val offset = layout.getOffsetForHorizontal(line, x.toFloat()) - - val link = buffer.getSpans(offset, offset, ClickableSpan::class.java) - if(link != null && link.isNotEmpty()) { - - if(action == MotionEvent.ACTION_UP) { - link[0].onClick(widget) + val offset = try{ + layout.getOffsetForHorizontal(line, x.toFloat()) + }catch(ex:Throwable){ + // getOffsetForHorizontal raises error on Xiaomi Mi A1(tissot_sprout), Android 8.1 + log.trace(ex,"getOffsetForHorizontal failed.") + null + } + + if( offset != null){ + val link = buffer.getSpans(offset, offset, ClickableSpan::class.java) + if(link != null && link.isNotEmpty()) { + + if(action == MotionEvent.ACTION_UP) { + link[0].onClick(widget) + } + if(widget is MyTextView) { + widget.linkHit = true + } + return true } - if(widget is MyTextView) { - widget.linkHit = true - } - return true } } }