updated content text view
This commit is contained in:
parent
b89d3c198e
commit
a383fb5e47
|
@ -29,6 +29,7 @@ import android.view.MotionEvent
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import org.mariotaku.chameleon.view.ChameleonTextView
|
import org.mariotaku.chameleon.view.ChameleonTextView
|
||||||
import org.mariotaku.twidere.extension.setupEmojiFactory
|
import org.mariotaku.twidere.extension.setupEmojiFactory
|
||||||
|
import java.lang.ref.WeakReference
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true when not clicking links
|
* Returns true when not clicking links
|
||||||
|
@ -85,11 +86,9 @@ class TimelineContentTextView(
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class InternalMovementMethod : BaseMovementMethod() {
|
internal class InternalMovementMethod : BaseMovementMethod() {
|
||||||
private var targetSpan: ClickableSpan? = null
|
private var targetSpan: WeakReference<ClickableSpan?>? = null
|
||||||
|
|
||||||
override fun initialize(widget: TextView, text: Spannable) {
|
override fun canSelectArbitrarily() = true
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onTouchEvent(widget: TextView, text: Spannable, event: MotionEvent): Boolean {
|
override fun onTouchEvent(widget: TextView, text: Spannable, event: MotionEvent): Boolean {
|
||||||
when (event.actionMasked) {
|
when (event.actionMasked) {
|
||||||
|
@ -100,22 +99,22 @@ class TimelineContentTextView(
|
||||||
val line = layout.getLineForVertical(Math.round(y))
|
val line = layout.getLineForVertical(Math.round(y))
|
||||||
val offset = layout.getOffsetForHorizontal(line, x)
|
val offset = layout.getOffsetForHorizontal(line, x)
|
||||||
if (x <= layout.getLineWidth(line)) {
|
if (x <= layout.getLineWidth(line)) {
|
||||||
targetSpan = text.getSpans(offset, offset, ClickableSpan::class.java).firstOrNull()
|
targetSpan = WeakReference(text.getSpans(offset, offset, ClickableSpan::class.java).firstOrNull())
|
||||||
} else {
|
} else {
|
||||||
targetSpan = null
|
targetSpan = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MotionEvent.ACTION_UP -> {
|
MotionEvent.ACTION_UP -> {
|
||||||
targetSpan?.onClick(widget)
|
val span = targetSpan?.get() ?: return false
|
||||||
val handled = targetSpan != null
|
span.onClick(widget)
|
||||||
targetSpan = null
|
targetSpan = null
|
||||||
return handled
|
return true
|
||||||
}
|
}
|
||||||
MotionEvent.ACTION_CANCEL -> {
|
MotionEvent.ACTION_CANCEL -> {
|
||||||
targetSpan = null
|
targetSpan = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return targetSpan != null
|
return targetSpan?.get() != null
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue