1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-11-13 20:45:12 -05:00

Added posibility to set colors for messages

This commit is contained in:
Sebastian Kaspari 2010-03-06 20:52:54 +01:00
parent 0d0173f2e6
commit b5c248e5c7

View File

@ -24,6 +24,7 @@ import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.text.Spannable; import android.text.Spannable;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.text.style.ImageSpan; import android.text.style.ImageSpan;
/** /**
@ -32,9 +33,14 @@ import android.text.style.ImageSpan;
* @author Sebastian Kaspari <sebastian@yaaic.org> * @author Sebastian Kaspari <sebastian@yaaic.org>
*/ */
public class Message { 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 String text;
private SpannableString canvas; private SpannableString canvas;
private int color = -1;
/** /**
* Create a new message without an icon * Create a new message without an icon
@ -44,7 +50,6 @@ public class Message {
public Message(String text) public Message(String text)
{ {
this.text = text; this.text = text;
this.icon = -1;
} }
/** /**
@ -85,6 +90,14 @@ public class Message {
return text; return text;
} }
/**
* Set the color of this message
*/
public void setColor(int color)
{
this.color = color;
}
/** /**
* Render message as spannable string * Render message as spannable string
* *
@ -100,6 +113,9 @@ public class Message {
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
canvas.setSpan(new ImageSpan(drawable, ImageSpan.ALIGN_BOTTOM), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 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; return canvas;