From c6dbe8cc1816456a2eea41893da12cf9f64c14cf Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Thu, 14 Apr 2011 22:53:38 +0200 Subject: [PATCH] Remove color codes if the mirc colors option is off. Fixes #57 --- application/src/org/yaaic/model/Message.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/application/src/org/yaaic/model/Message.java b/application/src/org/yaaic/model/Message.java index 5dfe1c2..a9f2345 100644 --- a/application/src/org/yaaic/model/Message.java +++ b/application/src/org/yaaic/model/Message.java @@ -229,15 +229,24 @@ public class Message String prefix = hasIcon() && settings.showIcons() ? " " : ""; String nick = hasSender() ? "<" + sender + "> " : ""; String timestamp = settings.showTimestamp() ? renderTimeStamp(settings.use24hFormat()) : ""; + canvas = new SpannableString(prefix + timestamp + nick); - SpannableString renderedText = new SpannableString(text); + SpannableString renderedText; + if (settings.showMircColors()) { renderedText = MircColors.toSpannable(text); + } else { + renderedText = new SpannableString( + MircColors.removeStyleAndColors(text) + ); } + if (settings.showGraphicalSmilies()) { renderedText = Smilies.toSpannable(renderedText, context); } + canvas = new SpannableString(TextUtils.concat(canvas, renderedText)); + if (hasSender()) { int start = (prefix + timestamp).length() + 1; int end = start + sender.length(); @@ -252,14 +261,17 @@ public class Message drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); canvas.setSpan(new ImageSpan(drawable, ImageSpan.ALIGN_BOTTOM), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } + if (hasColor() && settings.showColors()) { // Only apply the foreground color to areas that don't already have a foreground color. ForegroundColorSpan[] spans = canvas.getSpans(0, canvas.length(), ForegroundColorSpan.class); int start = 0; + for (int i = 0; i < spans.length; i++) { canvas.setSpan(new ForegroundColorSpan(color), start, canvas.getSpanStart(spans[i]), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); start = canvas.getSpanEnd(spans[i]); } + canvas.setSpan(new ForegroundColorSpan(color), start, canvas.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } }