aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/utils/StylingHelper.java
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-11-20 20:51:04 +0100
committerChristian Schneppe <christian@pix-art.de>2017-11-20 20:51:04 +0100
commit7949c0ac2947ead64615d90cf9e7867297e53427 (patch)
treeaeccfbafa650b5f56187b61d7d0e5521e4f6a702 /src/main/java/de/pixart/messenger/utils/StylingHelper.java
parent3f4baf530f36a55dbba8d5e60a103dc1577188dc (diff)
styling: introduce support for code blocks
Diffstat (limited to '')
-rw-r--r--src/main/java/de/pixart/messenger/utils/StylingHelper.java18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/StylingHelper.java b/src/main/java/de/pixart/messenger/utils/StylingHelper.java
index 8d5e73ccf..b04a1f8a2 100644
--- a/src/main/java/de/pixart/messenger/utils/StylingHelper.java
+++ b/src/main/java/de/pixart/messenger/utils/StylingHelper.java
@@ -67,21 +67,23 @@ public class StylingHelper {
public static void format(final Editable editable, @ColorInt int textColor) {
for (ImStyleParser.Style style : ImStyleParser.parse(editable)) {
- editable.setSpan(createSpanForStyle(style), style.getStart() + 1, style.getEnd(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
- makeKeywordOpaque(editable, style.getStart(), style.getStart() + 1, textColor);
- makeKeywordOpaque(editable, style.getEnd(), style.getEnd() + 1, textColor);
+ final int keywordLength = style.getKeyword().length();
+ editable.setSpan(createSpanForStyle(style), style.getStart() + keywordLength, style.getEnd() - keywordLength + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ makeKeywordOpaque(editable, style.getStart(), style.getStart() + keywordLength, textColor);
+ makeKeywordOpaque(editable, style.getEnd() - keywordLength + 1, style.getEnd() + 1, textColor);
}
}
private static ParcelableSpan createSpanForStyle(ImStyleParser.Style style) {
- switch (style.getCharacter()) {
- case '*':
+ switch (style.getKeyword()) {
+ case "*":
return new StyleSpan(Typeface.BOLD);
- case '_':
+ case "_":
return new StyleSpan(Typeface.ITALIC);
- case '~':
+ case "~":
return new StrikethroughSpan();
- case '`':
+ case "`":
+ case "```":
return new TypefaceSpan("monospace");
default:
throw new AssertionError("Unknown Style");