From b5c248e5c71c0d9d79c26d23a455d862ed936337 Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Sat, 6 Mar 2010 20:52:54 +0100 Subject: [PATCH] Added posibility to set colors for messages --- src/org/yaaic/model/Message.java | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/org/yaaic/model/Message.java b/src/org/yaaic/model/Message.java index d904282..b9637a8 100644 --- a/src/org/yaaic/model/Message.java +++ b/src/org/yaaic/model/Message.java @@ -24,6 +24,7 @@ import android.content.Context; import android.graphics.drawable.Drawable; import android.text.Spannable; import android.text.SpannableString; +import android.text.style.ForegroundColorSpan; import android.text.style.ImageSpan; /** @@ -32,9 +33,14 @@ import android.text.style.ImageSpan; * @author Sebastian Kaspari */ public class Message { - private int icon; + public static final int COLOR_GREEN = 0xFF458509; + public static final int COLOR_RED = 0xFFcc0000; + public static final int COLOR_BLUE = 0xFF729fcf; + + private int icon = -1; private String text; private SpannableString canvas; + private int color = -1; /** * Create a new message without an icon @@ -44,7 +50,6 @@ public class Message { public Message(String text) { this.text = text; - this.icon = -1; } /** @@ -85,6 +90,14 @@ public class Message { return text; } + /** + * Set the color of this message + */ + public void setColor(int color) + { + this.color = color; + } + /** * Render message as spannable string * @@ -100,6 +113,9 @@ public class Message { drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); canvas.setSpan(new ImageSpan(drawable, ImageSpan.ALIGN_BOTTOM), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } + if (color != -1) { + canvas.setSpan(new ForegroundColorSpan(color), 0, canvas.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + } } return canvas;