FileDocCategorySizeDatePackage
MessageView.javaAPI DocAndroid 1.5 API6163Wed May 06 22:42:46 BST 2009com.android.im.app

MessageView

public class MessageView extends android.widget.LinearLayout

Fields Summary
private android.widget.TextView
mMessage
private android.content.res.Resources
mResources
Constructors Summary
public MessageView(android.content.Context context, android.util.AttributeSet attrs)

        super(context, attrs);
    
Methods Summary
private voidappendTimeStamp(android.text.SpannableStringBuilder buf, java.util.Date date)

        DateFormat format = new SimpleDateFormat(mResources.getString(R.string.time_stamp));
        String dateStr = format.format(date);
        SpannableString spanText = new SpannableString(dateStr);
        int len = spanText.length();
        spanText.setSpan(new StyleSpan(Typeface.ITALIC),
                0, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        spanText.setSpan(new RelativeSizeSpan(0.8f),
                0, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        spanText.setSpan(new ForegroundColorSpan(
                mResources.getColor(android.R.color.darker_gray)),
                0, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        buf.append('\n");
        buf.append(spanText);
    
public voidbindErrorMessage(int errCode)

        mMessage.setText(R.string.msg_sent_failed);
        mMessage.setTextColor(mResources.getColor(R.color.error));
    
public voidbindIncomingMessage(java.lang.String contact, java.lang.String body, java.util.Date date, Markup smileyRes, boolean scrolling)

        CharSequence message =  formatMessage(contact, body, date, smileyRes, scrolling);
        mMessage.setText(message);
        mMessage.setTextColor(mResources.getColor(R.color.chat_msg));
    
public voidbindOutgoingMessage(java.lang.String body, java.util.Date date, Markup smileyRes, boolean scrolling)

        String contact = mResources.getString(R.string.me);
        CharSequence message = formatMessage(contact, body, date, smileyRes, scrolling);
        mMessage.setText(message);
        mMessage.setTextColor(mResources.getColor(R.color.chat_msg));
    
public voidbindPresenceMessage(java.lang.String contact, int type, boolean isGroupChat, boolean scrolling)

        CharSequence message = formatPresenceUpdates(contact, type, isGroupChat, scrolling);
        mMessage.setText(message);
        mMessage.setTextColor(mResources.getColor(R.color.chat_msg_presence));
    
private java.lang.CharSequenceformatMessage(java.lang.String contact, java.lang.String body, java.util.Date date, Markup smileyRes, boolean scrolling)

        if (body.indexOf('\r") != -1) {
            // first convert \r\n pair to \n, then single \r to \n.
            // here we can't use HideReturnsTransformationMethod because
            // it does only 1 to 1 transformation and is unable to handle
            // the "\r\n" case.
            body = body.replace("\r\n", "\n").replace('\r", '\n");
        }

        SpannableStringBuilder buf = new SpannableStringBuilder(contact);
        buf.append(": ");
        if (scrolling) {
            buf.append(body);
        } else {
            buf.setSpan(ChatView.STYLE_BOLD, 0, buf.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);

            buf.append(smileyRes.markup(body));

            if (date != null) {
                appendTimeStamp(buf, date);
            }
        }
        return buf;
    
private java.lang.CharSequenceformatPresenceUpdates(java.lang.String contact, int type, boolean isGroupChat, boolean scrolling)

        String body;
        switch (type) {
            case Im.MessageType.PRESENCE_AVAILABLE:
                body = mResources.getString(isGroupChat ? R.string.contact_joined
                        : R.string.contact_online, contact);
                break;

            case Im.MessageType.PRESENCE_AWAY:
                body = mResources.getString(R.string.contact_away, contact);
                break;

            case Im.MessageType.PRESENCE_DND:
                body = mResources.getString(R.string.contact_busy, contact);
                break;

            case Im.MessageType.PRESENCE_UNAVAILABLE:
                body = mResources.getString(isGroupChat ? R.string.contact_left
                        : R.string.contact_offline, contact);
                break;

            default:
                return null;
        }

        if (scrolling) {
            return body;
        } else {
            SpannableString spanText = new SpannableString(body);
            int len = spanText.length();
            spanText.setSpan(new StyleSpan(Typeface.ITALIC),
                    0, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            spanText.setSpan(new RelativeSizeSpan((float)0.8),
                    0, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            return spanText;
        }
    
public android.text.style.URLSpan[]getMessageLinks()

        return mMessage.getUrls();
    
protected voidonFinishInflate()

        super.onFinishInflate();

        mMessage = (TextView) findViewById(R.id.message);

        mResources = getResources();