aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/utils
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-11-20 20:37:25 +0100
committerChristian Schneppe <christian@pix-art.de>2017-11-20 20:37:25 +0100
commitfdeeff6fd381d6f9d259d9ae0f440230731d2f71 (patch)
tree0cf209f819febfbe197b57043e2e4b25f01ec57d /src/main/java/de/pixart/messenger/utils
parent29f0af37c73f6e6305bd0667247b3c9173fb6470 (diff)
make keyword styling work in quotes
Diffstat (limited to 'src/main/java/de/pixart/messenger/utils')
-rw-r--r--src/main/java/de/pixart/messenger/utils/StylingHelper.java27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/StylingHelper.java b/src/main/java/de/pixart/messenger/utils/StylingHelper.java
index 70b714594..8d5e73ccf 100644
--- a/src/main/java/de/pixart/messenger/utils/StylingHelper.java
+++ b/src/main/java/de/pixart/messenger/utils/StylingHelper.java
@@ -45,6 +45,8 @@ import android.widget.EditText;
import java.util.Arrays;
import java.util.List;
+import de.pixart.messenger.ui.text.QuoteSpan;
+
public class StylingHelper {
private static List<? extends Class<? extends ParcelableSpan>> SPAN_CLASSES = Arrays.asList(
@@ -63,17 +65,11 @@ public class StylingHelper {
}
}
- 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)
- );
+ 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);
- 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);
+ makeKeywordOpaque(editable, style.getStart(), style.getStart() + 1, textColor);
+ makeKeywordOpaque(editable, style.getEnd(), style.getEnd() + 1, textColor);
}
}
@@ -92,6 +88,19 @@ public class StylingHelper {
}
}
+ private static void makeKeywordOpaque(final Editable editable, int start, int end, @ColorInt int fallbackTextColor) {
+ QuoteSpan[] quoteSpans = editable.getSpans(start, end, QuoteSpan.class);
+ @ColorInt int textColor = quoteSpans.length > 0 ? quoteSpans[0].getColor() : fallbackTextColor;
+ @ColorInt int keywordColor = transformColor(textColor);
+ editable.setSpan(new ForegroundColorSpan(keywordColor), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ }
+
+ private static
+ @ColorInt
+ int transformColor(@ColorInt int c) {
+ return Color.argb(Math.round(Color.alpha(c) * 0.6f), Color.red(c), Color.green(c), Color.blue(c));
+ }
+
public static class MessageEditorStyler implements TextWatcher {
private final EditText mEditText;