diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-11-20 20:34:21 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-11-20 20:34:21 +0100 |
commit | 29f0af37c73f6e6305bd0667247b3c9173fb6470 (patch) | |
tree | 39e758a1a4aa29bbd7829686ecb6e10109a2effa /src/main/java/de/pixart/messenger | |
parent | c9b4799d0ee97163e17a89425fffa8c5234379cc (diff) |
changed text styling to keep the keyword
Diffstat (limited to '')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java | 14 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/utils/StylingHelper.java | 33 |
2 files changed, 16 insertions, 31 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java index 59f054b69..a1961dbe2 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java @@ -454,12 +454,16 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie return startsWithQuote; } - private void displayTextMessage(final ViewHolder viewHolder, final Message message, boolean darkBackground) { + private void displayTextMessage(final ViewHolder viewHolder, final Message message, boolean darkBackground, int type) { if (viewHolder.download_button != null) { viewHolder.download_button.setVisibility(View.GONE); } viewHolder.image.setVisibility(View.GONE); viewHolder.messageBody.setVisibility(View.VISIBLE); + viewHolder.messageBody.setTextColor(this.getMessageTextColor(darkBackground, true)); + viewHolder.messageBody.setLinkTextColor(this.getMessageTextColor(darkBackground, true)); + viewHolder.messageBody.setHighlightColor(ContextCompat.getColor(activity, darkBackground ? R.color.grey800 : R.color.grey500)); + viewHolder.messageBody.setTypeface(null, Typeface.NORMAL); if (message.getBody() != null) { final String nick = UIHelper.getMessageDisplayName(message); SpannableStringBuilder body = message.getMergedBody(); @@ -518,7 +522,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie body.setSpan(new StyleSpan(Typeface.BOLD), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } - StylingHelper.format(body, true); + StylingHelper.format(body, viewHolder.messageBody.getCurrentTextColor()); Linkify.addLinks(body, XMPP_PATTERN, "xmpp"); Linkify.addLinks(body, Patterns.AUTOLINK_WEB_URL, "http", WEBURL_MATCH_FILTER, WEBURL_TRANSFORM_FILTER); Linkify.addLinks(body, GeoHelper.GEO_URI, "geo"); @@ -532,10 +536,6 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie viewHolder.messageBody.setText(""); viewHolder.messageBody.setTextIsSelectable(false); } - viewHolder.messageBody.setTextColor(this.getMessageTextColor(darkBackground, true)); - viewHolder.messageBody.setLinkTextColor(this.getMessageTextColor(darkBackground, true)); - viewHolder.messageBody.setHighlightColor(ContextCompat.getColor(activity, darkBackground ? R.color.grey800 : R.color.grey500)); - viewHolder.messageBody.setTypeface(null, Typeface.NORMAL); } private void displayDownloadableMessage(ViewHolder viewHolder, final Message message, String text) { @@ -936,7 +936,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie UIHelper.getFileDescriptionString(activity, message))); } } else { - displayTextMessage(viewHolder, message, darkBackground); + displayTextMessage(viewHolder, message, darkBackground, type); } } 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()); } } } |