From 29f0af37c73f6e6305bd0667247b3c9173fb6470 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Mon, 20 Nov 2017 20:34:21 +0100 Subject: changed text styling to keep the keyword --- .../de/pixart/messenger/utils/StylingHelper.java | 33 ++++++---------------- 1 file changed, 9 insertions(+), 24 deletions(-) (limited to 'src/main/java/de/pixart/messenger/utils') diff --git a/src/main/java/de/pixart/messenger/utils/StylingHelper.java b/src/main/java/de/pixart/messenger/utils/StylingHelper.java index f3c0e6eef..70b714594 100644 --- a/src/main/java/de/pixart/messenger/utils/StylingHelper.java +++ b/src/main/java/de/pixart/messenger/utils/StylingHelper.java @@ -63,25 +63,17 @@ public class StylingHelper { } } - public static void format(final Editable editable) { - format(editable, false); - } - - public static void format(final Editable editable, final boolean replaceStyleAnnotation) { - for (ImStyleParser.Style style : ImStyleParser.parse(editable)) { - editable.setSpan(createSpanForStyle(style), style.getStart(), style.getEnd(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - if (replaceStyleAnnotation) { - editable.replace(style.getStart(), style.getStart() + 1, "\u200B"); - editable.replace(style.getEnd(), style.getEnd() + 1, "\u200B"); - } - } - } - public static void format(final Editable editable, @ColorInt int color) { + final int syntaxColor = Color.argb( + Math.round(Color.alpha(color) * 0.6f), + Color.red(color), + Color.green(color), + Color.blue(color) + ); for (ImStyleParser.Style style : ImStyleParser.parse(editable)) { editable.setSpan(createSpanForStyle(style), style.getStart() + 1, style.getEnd(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - editable.setSpan(new ForegroundColorSpan(color), style.getStart(), style.getStart() + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - editable.setSpan(new ForegroundColorSpan(color), style.getEnd(), style.getEnd() + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + editable.setSpan(new ForegroundColorSpan(syntaxColor), style.getStart(), style.getStart() + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + editable.setSpan(new ForegroundColorSpan(syntaxColor), style.getEnd(), style.getEnd() + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } @@ -121,14 +113,7 @@ public class StylingHelper { @Override public void afterTextChanged(Editable editable) { clear(editable); - final int color = mEditText.getCurrentTextColor(); - final int syntaxColor = Color.argb( - Math.round(Color.alpha(color) * 0.6f), - Color.red(color), - Color.green(color), - Color.blue(color) - ); - format(editable, syntaxColor); + format(editable, mEditText.getCurrentTextColor()); } } } -- cgit v1.2.3