diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/de/pixart/messenger/utils/ImStyleParser.java | 2 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/utils/StylingHelper.java | 15 |
2 files changed, 14 insertions, 3 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/ImStyleParser.java b/src/main/java/de/pixart/messenger/utils/ImStyleParser.java index 6f65b1552..46f8cec10 100644 --- a/src/main/java/de/pixart/messenger/utils/ImStyleParser.java +++ b/src/main/java/de/pixart/messenger/utils/ImStyleParser.java @@ -43,7 +43,7 @@ public class ImStyleParser { return parse(text, 0, text.length() - 1); } - private static List<Style> parse(CharSequence text, int start, int end) { + public static List<Style> parse(CharSequence text, int start, int end) { List<Style> styles = new ArrayList<>(); for (int i = start; i <= end; ++i) { char c = text.charAt(i); diff --git a/src/main/java/de/pixart/messenger/utils/StylingHelper.java b/src/main/java/de/pixart/messenger/utils/StylingHelper.java index b04a1f8a2..1f553b827 100644 --- a/src/main/java/de/pixart/messenger/utils/StylingHelper.java +++ b/src/main/java/de/pixart/messenger/utils/StylingHelper.java @@ -45,6 +45,7 @@ import android.widget.EditText; import java.util.Arrays; import java.util.List; +import de.pixart.messenger.entities.Message; import de.pixart.messenger.ui.text.QuoteSpan; public class StylingHelper { @@ -65,8 +66,8 @@ public class StylingHelper { } } - public static void format(final Editable editable, @ColorInt int textColor) { - for (ImStyleParser.Style style : ImStyleParser.parse(editable)) { + public static void format(final Editable editable, int start, int end, @ColorInt int textColor) { + for (ImStyleParser.Style style : ImStyleParser.parse(editable, start, end)) { 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); @@ -74,6 +75,16 @@ public class StylingHelper { } } + public static void format(final Editable editable, @ColorInt int textColor) { + int end = 0; + Message.MergeSeparator[] spans = editable.getSpans(0, editable.length() - 1, Message.MergeSeparator.class); + for (Message.MergeSeparator span : spans) { + format(editable, end, editable.getSpanStart(span), textColor); + end = editable.getSpanEnd(span); + } + format(editable, end, editable.length() - 1, textColor); + } + private static ParcelableSpan createSpanForStyle(ImStyleParser.Style style) { switch (style.getKeyword()) { case "*": |