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
57e89ce8
Commit
57e89ce8
authored
Dec 21, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make Pattern objects to static
parent
f4a8ccd2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
21 deletions
+23
-21
InlineHightlighter.java
...chat/rocket/android/widget/helper/InlineHightlighter.java
+4
-3
MarkDown.java
...main/java/chat/rocket/android/widget/helper/MarkDown.java
+19
-18
No files found.
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/helper/InlineHightlighter.java
View file @
57e89ce8
...
@@ -40,12 +40,13 @@ public class InlineHightlighter {
...
@@ -40,12 +40,13 @@ public class InlineHightlighter {
return
new
ForegroundColorSpan
(
Color
.
TRANSPARENT
);
return
new
ForegroundColorSpan
(
Color
.
TRANSPARENT
);
}
}
private
static
final
Pattern
HIGHLIGHT_PATTERN
=
Pattern
.
compile
(
"(^|>|[ >_*~])\\`([^`\\r\\n]+)\\`([<_*~]|\\B|\\b|$)"
,
Pattern
.
MULTILINE
);
private
static
CharSequence
highlightInner
(
final
Context
context
,
final
CharSequence
text
)
{
private
static
CharSequence
highlightInner
(
final
Context
context
,
final
CharSequence
text
)
{
final
SpannableString
inputText
=
new
SpannableString
(
text
);
final
SpannableString
inputText
=
new
SpannableString
(
text
);
Pattern
highlightPattern
=
Pattern
.
compile
(
Matcher
matcher
=
HIGHLIGHT_PATTERN
.
matcher
(
inputText
);
"(^|>|[ >_*~])\\`([^`\\r\\n]+)\\`([<_*~]|\\B|\\b|$)"
,
Pattern
.
MULTILINE
);
Matcher
matcher
=
highlightPattern
.
matcher
(
inputText
);
while
(
matcher
.
find
())
{
while
(
matcher
.
find
())
{
setSpan
(
inputText
,
context
,
setSpan
(
inputText
,
context
,
...
...
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/helper/MarkDown.java
View file @
57e89ce8
...
@@ -38,10 +38,10 @@ public class MarkDown {
...
@@ -38,10 +38,10 @@ public class MarkDown {
textView
.
setText
(
text
);
textView
.
setText
(
text
);
}
}
private
static
void
removeImage
(
SpannableString
inputText
)
{
private
static
final
Pattern
IMAGE_PATTERN
=
Pattern
.
compile
(
Pattern
imagePattern
=
Pattern
.
compile
(
"!\\[([^\\]]+)\\]\\(((?:http|https):\\/\\/[^\\)]+)\\)"
,
Pattern
.
MULTILINE
);
"!\\[([^\\]]+)\\]\\(((?:http|https):\\/\\/[^\\)]+)\\)"
,
Pattern
.
MULTILINE
);
Matcher
matcher
=
imagePattern
.
matcher
(
inputText
);
private
static
void
removeImage
(
SpannableString
inputText
)
{
Matcher
matcher
=
IMAGE_PATTERN
.
matcher
(
inputText
);
while
(
matcher
.
find
())
{
while
(
matcher
.
find
())
{
inputText
.
setSpan
(
new
AbsoluteSizeSpan
(
0
),
inputText
.
setSpan
(
new
AbsoluteSizeSpan
(
0
),
matcher
.
start
(),
matcher
.
end
(),
matcher
.
start
(),
matcher
.
end
(),
...
@@ -49,10 +49,11 @@ public class MarkDown {
...
@@ -49,10 +49,11 @@ public class MarkDown {
}
}
}
}
private
static
void
highlightLink1
(
SpannableString
inputText
)
{
Pattern
linkPattern
=
Pattern
.
compile
(
private
static
final
Pattern
LINK_PATTERN
=
Pattern
.
compile
(
"\\[([^\\]]+)\\]\\(((?:http|https):\\/\\/[^\\)]+)\\)"
,
Pattern
.
MULTILINE
);
"\\[([^\\]]+)\\]\\(((?:http|https):\\/\\/[^\\)]+)\\)"
,
Pattern
.
MULTILINE
);
final
Matcher
matcher
=
linkPattern
.
matcher
(
inputText
);
private
static
void
highlightLink1
(
SpannableString
inputText
)
{
final
Matcher
matcher
=
LINK_PATTERN
.
matcher
(
inputText
);
while
(
matcher
.
find
())
{
while
(
matcher
.
find
())
{
ClickableSpan
span
=
createLinkSpan
(
matcher
.
group
(
2
));
ClickableSpan
span
=
createLinkSpan
(
matcher
.
group
(
2
));
setSpan
(
span
,
inputText
,
setSpan
(
span
,
inputText
,
...
@@ -61,10 +62,10 @@ public class MarkDown {
...
@@ -61,10 +62,10 @@ public class MarkDown {
}
}
}
}
private
static
void
highlightLink2
(
SpannableString
inputText
)
{
private
static
final
Pattern
LINK_PATTERN2
=
Pattern
.
compile
(
Pattern
linkPattern
=
Pattern
.
compile
(
"((?:<|<))((?:http|https):\\/\\/[^\\|]+)\\|(.+?)((?=>|>)(?:>|>))"
,
Pattern
.
MULTILINE
);
"((?:<|<))((?:http|https):\\/\\/[^\\|]+)\\|(.+?)((?=>|>)(?:>|>))"
,
Pattern
.
MULTILINE
);
Matcher
matcher
=
linkPattern
.
matcher
(
inputText
);
private
static
void
highlightLink2
(
SpannableString
inputText
)
{
Matcher
matcher
=
LINK_PATTERN2
.
matcher
(
inputText
);
while
(
matcher
.
find
())
{
while
(
matcher
.
find
())
{
ClickableSpan
span
=
createLinkSpan
(
matcher
.
group
(
2
));
ClickableSpan
span
=
createLinkSpan
(
matcher
.
group
(
2
));
setSpan
(
span
,
inputText
,
setSpan
(
span
,
inputText
,
...
@@ -74,10 +75,10 @@ public class MarkDown {
...
@@ -74,10 +75,10 @@ public class MarkDown {
}
}
}
}
private
static
void
bold
(
SpannableString
inputText
)
{
private
static
final
Pattern
BOLD_PATTERN
=
Pattern
.
compile
(
Pattern
boldPattern
=
Pattern
.
compile
(
"(^|>|[ >_~`])(\\*{1,2})[^\\*\\r\\n]+(\\*{1,2})([<_~`]|\\B|\\b|$)"
,
Pattern
.
MULTILINE
);
"(^|>|[ >_~`])(\\*{1,2})[^\\*\\r\\n]+(\\*{1,2})([<_~`]|\\B|\\b|$)"
,
Pattern
.
MULTILINE
);
Matcher
matcher
=
boldPattern
.
matcher
(
inputText
);
private
static
void
bold
(
SpannableString
inputText
)
{
Matcher
matcher
=
BOLD_PATTERN
.
matcher
(
inputText
);
while
(
matcher
.
find
())
{
while
(
matcher
.
find
())
{
setSpan
(
new
StyleSpan
(
Typeface
.
BOLD
),
inputText
,
setSpan
(
new
StyleSpan
(
Typeface
.
BOLD
),
inputText
,
matcher
.
start
()
+
matcher
.
group
(
1
).
length
(),
matcher
.
start
()
+
matcher
.
group
(
1
).
length
(),
...
@@ -87,10 +88,10 @@ public class MarkDown {
...
@@ -87,10 +88,10 @@ public class MarkDown {
}
}
}
}
private
static
void
italic
(
SpannableString
inputText
)
{
private
static
final
Pattern
ITALIC_PATTERN
=
Pattern
.
compile
(
Pattern
italicPattern
=
Pattern
.
compile
(
"(^|>|[ >*~`])(\\_)[^\\_\\r\\n]+(\\_)([<*~`]|\\B|\\b|$)"
,
Pattern
.
MULTILINE
);
"(^|>|[ >*~`])(\\_)[^\\_\\r\\n]+(\\_)([<*~`]|\\B|\\b|$)"
,
Pattern
.
MULTILINE
);
Matcher
matcher
=
italicPattern
.
matcher
(
inputText
);
private
static
void
italic
(
SpannableString
inputText
)
{
Matcher
matcher
=
ITALIC_PATTERN
.
matcher
(
inputText
);
while
(
matcher
.
find
())
{
while
(
matcher
.
find
())
{
setSpan
(
new
StyleSpan
(
Typeface
.
ITALIC
),
inputText
,
setSpan
(
new
StyleSpan
(
Typeface
.
ITALIC
),
inputText
,
matcher
.
start
()
+
matcher
.
group
(
1
).
length
(),
matcher
.
start
()
+
matcher
.
group
(
1
).
length
(),
...
@@ -100,10 +101,10 @@ public class MarkDown {
...
@@ -100,10 +101,10 @@ public class MarkDown {
}
}
}
}
private
static
void
strike
(
SpannableString
inputText
)
{
private
static
final
Pattern
STRIKE_PATTERN
=
Pattern
.
compile
(
Pattern
strikePattern
=
Pattern
.
compile
(
"(^|>|[ >_*`])(\\~{1,2})[^~\\r\\n]+(\\~{1,2})([<_*`]|\\B|\\b|$)"
,
Pattern
.
MULTILINE
);
"(^|>|[ >_*`])(\\~{1,2})[^~\\r\\n]+(\\~{1,2})([<_*`]|\\B|\\b|$)"
,
Pattern
.
MULTILINE
);
Matcher
matcher
=
strikePattern
.
matcher
(
inputText
);
private
static
void
strike
(
SpannableString
inputText
)
{
Matcher
matcher
=
STRIKE_PATTERN
.
matcher
(
inputText
);
while
(
matcher
.
find
())
{
while
(
matcher
.
find
())
{
setSpan
(
new
StrikethroughSpan
(),
inputText
,
setSpan
(
new
StrikethroughSpan
(),
inputText
,
matcher
.
start
()
+
matcher
.
group
(
1
).
length
(),
matcher
.
start
()
+
matcher
.
group
(
1
).
length
(),
...
...
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