Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
0f0fb735
Commit
0f0fb735
authored
Dec 27, 2017
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add TextHelper.kt
parent
cdb60db5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
0 deletions
+30
-0
TextHelper.kt
app/src/main/java/chat/rocket/android/helper/TextHelper.kt
+30
-0
No files found.
app/src/main/java/chat/rocket/android/helper/TextHelper.kt
0 → 100644
View file @
0f0fb735
package
chat.rocket.android.helper
import
android.text.SpannableString
import
android.text.Spanned
import
android.text.method.LinkMovementMethod
import
android.text.style.ClickableSpan
import
android.widget.TextView
object
TextHelper
{
/**
* Adds clickable link(s) to a TextView.
*
* @param textView The TextView to add clickable links.
* @param links The TextView content(s) to act as clickable links.
* @param clickableSpans The ClickableSpan(s) to handle the onClick listener.
*/
fun
addLink
(
textView
:
TextView
,
links
:
Array
<
String
>,
clickableSpans
:
Array
<
ClickableSpan
>)
{
val
spannableString
=
SpannableString
(
textView
.
text
)
for
(
i
in
links
.
indices
)
{
val
clickableSpan
=
clickableSpans
[
i
]
val
link
=
links
[
i
]
val
startIndexOfLink
=
textView
.
text
.
indexOf
(
link
)
spannableString
.
setSpan
(
clickableSpan
,
startIndexOfLink
,
startIndexOfLink
+
link
.
length
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
)
}
textView
.
movementMethod
=
LinkMovementMethod
.
getInstance
()
textView
.
setText
(
spannableString
,
TextView
.
BufferType
.
SPANNABLE
)
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment