Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LinkMovementMethod with text gravity and singleLine issue #9

Open
2dxgujun opened this issue Nov 2, 2018 · 0 comments
Open

LinkMovementMethod with text gravity and singleLine issue #9

2dxgujun opened this issue Nov 2, 2018 · 0 comments

Comments

@2dxgujun
Copy link
Owner

2dxgujun commented Nov 2, 2018

private class LinkMovementMethodTouchListener : View.OnTouchListener {
    override fun onTouch(
      v: View,
      event: MotionEvent
    ): Boolean {
      val widget = v as TextView
      val action = event.action
      if (widget.text is SpannedString && action == MotionEvent.ACTION_UP) {
        var x = event.x.toInt()
        var y = event.y.toInt()
         x -= widget.totalPaddingLeft
        y -= widget.totalPaddingTop
         x += widget.scrollX
        y += widget.scrollY
         val layout = widget.layout
        val line = layout.getLineForVertical(y)
        val off = layout.getOffsetForHorizontal(line, x.toFloat())
         val links = (widget.text as SpannedString).getSpans(off, off, ClickableSpan::class.java)
         if (links.isNotEmpty()) {
          links[0].onClick(widget)
          return true
        }
      }
      return true
    }
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant