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
f91a845d
Commit
f91a845d
authored
Dec 19, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Plain Diff
FIX #82 Merge branch 'b_i_s' into develop
parents
f2e8ba00
c9806cb2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
1 deletion
+90
-1
Linkify.java
.../main/java/chat/rocket/android/widget/helper/Linkify.java
+1
-1
MarkDown.java
...main/java/chat/rocket/android/widget/helper/MarkDown.java
+87
-0
RocketChatMessageLayout.java
...ocket/android/widget/message/RocketChatMessageLayout.java
+2
-0
No files found.
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/helper/Linkify.java
View file @
f91a845d
...
@@ -28,7 +28,7 @@ public class Linkify {
...
@@ -28,7 +28,7 @@ public class Linkify {
public
static
void
markup
(
TextView
textview
)
{
public
static
void
markup
(
TextView
textview
)
{
textview
.
setMovementMethod
(
LinkMovementMethodCompat
.
getInstance
());
textview
.
setMovementMethod
(
LinkMovementMethodCompat
.
getInstance
());
final
CharSequence
text
=
textview
.
getText
()
.
toString
()
;
final
CharSequence
text
=
textview
.
getText
();
textview
.
setText
(
markupInner
(
text
));
textview
.
setText
(
markupInner
(
text
));
}
}
...
...
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/helper/MarkDown.java
0 → 100644
View file @
f91a845d
package
chat
.
rocket
.
android
.
widget
.
helper
;
import
android.graphics.Typeface
;
import
android.text.SpannableString
;
import
android.text.Spanned
;
import
android.text.style.AbsoluteSizeSpan
;
import
android.text.style.StrikethroughSpan
;
import
android.text.style.StyleSpan
;
import
android.widget.TextView
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
* supports only bold, italic, strike.
*/
public
class
MarkDown
{
/**
* transform MarkDown text into Spans.
*/
public
static
void
apply
(
TextView
textView
)
{
SpannableString
text
=
new
SpannableString
(
textView
.
getText
());
bold
(
text
);
italic
(
text
);
strike
(
text
);
textView
.
setText
(
text
);
}
private
static
void
bold
(
SpannableString
inputText
)
{
Pattern
boldPattern
=
Pattern
.
compile
(
"(^|>|[ >_~`])(\\*{1,2})[^\\*\\r\\n]+(\\*{1,2})([<_~`]|\\B|\\b|$)"
,
Pattern
.
MULTILINE
);
Matcher
matcher
=
boldPattern
.
matcher
(
inputText
);
while
(
matcher
.
find
())
{
setSpan
(
new
StyleSpan
(
Typeface
.
BOLD
),
inputText
,
matcher
.
start
()
+
matcher
.
group
(
1
).
length
(),
matcher
.
end
()
-
matcher
.
group
(
4
).
length
(),
matcher
.
group
(
2
).
length
(),
matcher
.
group
(
3
).
length
());
}
}
private
static
void
italic
(
SpannableString
inputText
)
{
Pattern
italicPattern
=
Pattern
.
compile
(
"(^|>|[ >*~`])(\\_)[^\\_\\r\\n]+(\\_)([<*~`]|\\B|\\b|$)"
,
Pattern
.
MULTILINE
);
Matcher
matcher
=
italicPattern
.
matcher
(
inputText
);
while
(
matcher
.
find
())
{
setSpan
(
new
StyleSpan
(
Typeface
.
ITALIC
),
inputText
,
matcher
.
start
()
+
matcher
.
group
(
1
).
length
(),
matcher
.
end
()
-
matcher
.
group
(
4
).
length
(),
matcher
.
group
(
2
).
length
(),
matcher
.
group
(
3
).
length
());
}
}
private
static
void
strike
(
SpannableString
inputText
)
{
Pattern
strikePattern
=
Pattern
.
compile
(
"(^|>|[ >_*`])(\\~{1,2})[^~\\r\\n]+(\\~{1,2})([<_*`]|\\B|\\b|$)"
,
Pattern
.
MULTILINE
);
Matcher
matcher
=
strikePattern
.
matcher
(
inputText
);
while
(
matcher
.
find
())
{
setSpan
(
new
StrikethroughSpan
(),
inputText
,
matcher
.
start
()
+
matcher
.
group
(
1
).
length
(),
matcher
.
end
()
-
matcher
.
group
(
4
).
length
(),
matcher
.
group
(
2
).
length
(),
matcher
.
group
(
3
).
length
());
}
}
private
static
void
setSpan
(
Object
span
,
SpannableString
inputText
,
int
start
,
int
end
,
int
markStartLen
,
int
markEndLen
)
{
if
(
markStartLen
>
0
)
{
inputText
.
setSpan
(
new
AbsoluteSizeSpan
(
0
),
start
,
start
+
markStartLen
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
}
inputText
.
setSpan
(
span
,
start
+
markStartLen
,
end
-
markEndLen
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
if
(
markEndLen
>
0
)
{
inputText
.
setSpan
(
new
AbsoluteSizeSpan
(
0
),
end
-
markEndLen
,
end
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
}
}
}
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/message/RocketChatMessageLayout.java
View file @
f91a845d
...
@@ -13,6 +13,7 @@ import com.emojione.Emojione;
...
@@ -13,6 +13,7 @@ import com.emojione.Emojione;
import
chat.rocket.android.widget.R
;
import
chat.rocket.android.widget.R
;
import
chat.rocket.android.widget.helper.InlineHightlighter
;
import
chat.rocket.android.widget.helper.InlineHightlighter
;
import
chat.rocket.android.widget.helper.Linkify
;
import
chat.rocket.android.widget.helper.Linkify
;
import
chat.rocket.android.widget.helper.MarkDown
;
/**
/**
*/
*/
...
@@ -77,6 +78,7 @@ public class RocketChatMessageLayout extends LinearLayout {
...
@@ -77,6 +78,7 @@ public class RocketChatMessageLayout extends LinearLayout {
TextView
textView
=
(
TextView
)
inflater
.
inflate
(
R
.
layout
.
message_body
,
this
,
false
);
TextView
textView
=
(
TextView
)
inflater
.
inflate
(
R
.
layout
.
message_body
,
this
,
false
);
textView
.
setText
(
Emojione
.
shortnameToUnicode
(
text
,
false
));
textView
.
setText
(
Emojione
.
shortnameToUnicode
(
text
,
false
));
MarkDown
.
apply
(
textView
);
Linkify
.
markup
(
textView
);
Linkify
.
markup
(
textView
);
InlineHightlighter
.
highlight
(
textView
);
InlineHightlighter
.
highlight
(
textView
);
...
...
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