tag so we'll surround the html with tags.
String entext = ""+TextUtils.htmlEncode(text).replaceAll(" ", " ")+"
";
String htmltext = Colors.mircColorParser(entext);
Spanned colortext = Html2.fromHtml(htmltext);
canvas = new SpannableString(prefix + timestamp + nick);
canvas = new SpannableString(TextUtils.concat(canvas, colortext));
}
else {
canvas = new SpannableString(prefix + timestamp + nick + Colors.removeStyleAndColors(text));
}
if (hasSender()) {
int start = (prefix + timestamp).length() + 1;
int end = start + sender.length();
if (settings.showColorsNick()) {
canvas.setSpan(new ForegroundColorSpan(getSenderColor()), start, end , Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
if (hasIcon() && settings.showIcons()) {
Drawable drawable = context.getResources().getDrawable(icon);
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 on 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.getSpanStart(spans[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);
}
}
return canvas;
}
/**
* Does this message have a sender?
*
* @return
*/
private boolean hasSender()
{
return sender != null;
}
/**
* Does this message have a color assigned?
*
* @return
*/
private boolean hasColor()
{
return color != NO_COLOR;
}
/**
* Does this message have an icon assigned?
*
* @return
*/
private boolean hasIcon()
{
return icon != NO_ICON;
}
/**
* Render message as text view
*
* @param context
* @return
*/
public TextView renderTextView(Context context)
{
// XXX: We should not read settings here ALWAYS for EVERY textview
Settings settings = new Settings(context);
TextView canvas = new TextView(context);
canvas.setText(this.render(context));
canvas.setTextSize(settings.getFontSize());
canvas.setTypeface(Typeface.MONOSPACE);
canvas.setTextColor(COLOR_DEFAULT);
return canvas;
}
/**
* Generate a timestamp
*
* @param use24hFormat
* @return
*/
public String renderTimeStamp(boolean use24hFormat)
{
Date date = new Date(timestamp);
int hours = date.getHours();
int minutes = date.getMinutes();
if (!use24hFormat) {
hours = Math.abs(12 - hours);
if (hours == 12) {
hours = 0;
}
}
return "[" + (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) + "] ";
}
}