1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-11-25 10:22:16 -05:00

Remove color codes if the mirc colors option is off. Fixes #57

This commit is contained in:
Sebastian Kaspari 2011-04-14 22:53:38 +02:00
parent 86e0812741
commit c6dbe8cc18

View File

@ -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);
}
}