1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-08-13 16:53:50 -04:00

Added icon support to messages

This commit is contained in:
Sebastian Kaspari 2010-03-06 18:58:27 +01:00
parent e90c438158
commit 4e97dd2295

View File

@ -20,7 +20,11 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.yaaic.model; package org.yaaic.model;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.Spannable;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.style.ImageSpan;
/** /**
* A channel or server message * A channel or server message
@ -30,7 +34,7 @@ import android.text.SpannableString;
public class Message { public class Message {
private int icon; private int icon;
private String text; private String text;
private SpannableString span; private SpannableString canvas;
/** /**
* Create a new message without an icon * Create a new message without an icon
@ -44,15 +48,11 @@ public class Message {
} }
/** /**
* Create a new message with an icon * Set the message's icon
*
* @param icon
* @param text
*/ */
public Message(int icon, String text) public void setIcon(int icon)
{ {
this.icon = icon; this.icon = icon;
this.text = text;
} }
/** /**
@ -87,16 +87,20 @@ public class Message {
/** /**
* Render message as spannable string * Render message as spannable string
*
* @return
*/ */
public SpannableString render() public SpannableString render(Context context)
{ {
if (span == null) { if (canvas == null) {
span = new SpannableString(text); canvas = new SpannableString("\n " + text);
if (hasIcon()) { if (hasIcon()) {
Drawable drawable = context.getResources().getDrawable(icon);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
canvas.setSpan(new ImageSpan(drawable), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} }
} }
return span; return canvas;
} }
} }