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

ContactView

public class ContactView extends android.widget.LinearLayout

Fields Summary
static final String[]
CONTACT_PROJECTION
static final int
COLUMN_CONTACT_ID
static final int
COLUMN_CONTACT_PROVIDER
static final int
COLUMN_CONTACT_ACCOUNT
static final int
COLUMN_CONTACT_USERNAME
static final int
COLUMN_CONTACT_NICKNAME
static final int
COLUMN_CONTACT_TYPE
static final int
COLUMN_SUBSCRIPTION_TYPE
static final int
COLUMN_SUBSCRIPTION_STATUS
static final int
COLUMN_CONTACT_PRESENCE_STATUS
static final int
COLUMN_CONTACT_CUSTOM_STATUS
static final int
COLUMN_LAST_MESSAGE_DATE
static final int
COLUMN_LAST_MESSAGE
private android.widget.TextView
mLine1
private android.widget.TextView
mLine2
private android.widget.TextView
mTimeStamp
Constructors Summary
public ContactView(android.content.Context context, android.util.AttributeSet attrs)


         
        super(context, attrs);
    
Methods Summary
public voidbind(android.database.Cursor cursor, java.lang.String underLineText, boolean scrolling)

        bind(cursor, underLineText, true, scrolling);
    
public voidbind(android.database.Cursor cursor, java.lang.String underLineText, boolean showChatMsg, boolean scrolling)

        Resources r = getResources();
        long providerId = cursor.getLong(COLUMN_CONTACT_PROVIDER);
        String username = cursor.getString(COLUMN_CONTACT_USERNAME);
        String nickname = cursor.getString(COLUMN_CONTACT_NICKNAME);
        int type = cursor.getInt(COLUMN_CONTACT_TYPE);
        String statusText = cursor.getString(COLUMN_CONTACT_CUSTOM_STATUS);
        String lastMsg = cursor.getString(COLUMN_LAST_MESSAGE);

        boolean hasChat = !cursor.isNull(COLUMN_LAST_MESSAGE_DATE);

        ImApp app = ImApp.getApplication((Activity)mContext);
        BrandingResources brandingRes = app.getBrandingResource(providerId);

        int presence = cursor.getInt(COLUMN_CONTACT_PRESENCE_STATUS);
        int iconId = 0;

        // status icon

        if (Im.Contacts.TYPE_GROUP == type) {
            iconId = lastMsg == null ? R.drawable.group_chat : R.drawable.group_chat_new;
        } else if (hasChat) {
            iconId = lastMsg == null ? BrandingResourceIDs.DRAWABLE_READ_CHAT
                    : BrandingResourceIDs.DRAWABLE_UNREAD_CHAT;
        } else {
            iconId = PresenceUtils.getStatusIconId(presence);
        }

        //mPresence.setImageDrawable(brandingRes.getDrawable(iconId));
        Drawable presenceIcon = brandingRes.getDrawable(iconId);

        // line1
        CharSequence line1;
        if (Im.Contacts.TYPE_GROUP == type) {
            ContentResolver resolver = getContext().getContentResolver();
            long id = cursor.getLong(ContactView.COLUMN_CONTACT_ID);
            line1 = queryGroupMembers(resolver, id);
        } else {
            line1 = TextUtils.isEmpty(nickname) ?
                    ImpsAddressUtils.getDisplayableAddress(username) : nickname;

            if (!TextUtils.isEmpty(underLineText)) {
                // highlight/underline the word being searched
                String lowercase = line1.toString().toLowerCase();
                int start = lowercase.indexOf(underLineText.toLowerCase());
                if (start >= 0) {
                    int end = start + underLineText.length();
                    SpannableString str = new SpannableString(line1);
                    str.setSpan(new UnderlineSpan(), start, end,
                            Spannable.SPAN_INCLUSIVE_INCLUSIVE);
                    line1 = str;
                }
            }

            if (Im.Contacts.TYPE_TEMPORARY == type) {
                // Add a mark at the front of name if it's only a temporary
                // contact.
                SpannableStringBuilder str = new SpannableStringBuilder(
                        r.getText(R.string.unknown_contact));
                str.setSpan(new RelativeSizeSpan(0.8f), 0, str.length(),
                        Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
                str.append(line1);
                line1 = str;
            }
        }
        mLine1.setText(line1);

        // time stamp
        if (showChatMsg && hasChat) {
            mTimeStamp.setVisibility(VISIBLE);
            Calendar cal = Calendar.getInstance();
            cal.setTimeInMillis(cursor.getLong(COLUMN_LAST_MESSAGE_DATE));
            DateFormat formatter = DateFormat.getTimeInstance(DateFormat.SHORT);
            mTimeStamp.setText(formatter.format(cal.getTime()));
        } else {
            mTimeStamp.setVisibility(GONE);
        }

        // line2
        CharSequence line2 = null;
        if (showChatMsg) {
            line2 = lastMsg;
        }

        if (TextUtils.isEmpty(line2)){
            if (Im.Contacts.TYPE_GROUP == type) {
                // Show nothing in line2 if it's a group and don't
                // have any unread message.
                line2 = null;
            } else {
                // Show the custom status text if there's no new message.
                line2 = statusText;
            }
        }

        if (TextUtils.isEmpty(line2)) {
            // Show a string of presence if there is neither new message nor
            // custom status text.
            line2 = brandingRes.getString(PresenceUtils.getStatusStringRes(presence));
        }

        mLine2.setText(line2);
        mLine2.setCompoundDrawablesWithIntrinsicBounds(null, null, presenceIcon, null);


        View contactInfoPanel = findViewById(R.id.contactInfo);
        if (hasChat && showChatMsg) {
            contactInfoPanel.setBackgroundResource(R.drawable.bubble);
            mLine1.setTextColor(r.getColor(R.color.chat_contact));
        } else {
            contactInfoPanel.setBackgroundDrawable(null);
            contactInfoPanel.setPadding(4, 0, 0, 0);
            mLine1.setTextColor(r.getColor(R.color.nonchat_contact));
        }
    
protected voidonFinishInflate()

        super.onFinishInflate();

        //mPresence = (ImageView) findViewById(R.id.presence);
        mLine1 = (TextView) findViewById(R.id.line1);
        mLine2 = (TextView) findViewById(R.id.line2);
        mLine2.setCompoundDrawablePadding(5);
        mTimeStamp = (TextView)findViewById(R.id.timestamp);
    
private java.lang.StringqueryGroupMembers(android.content.ContentResolver resolver, long groupId)

        String[] projection = { Im.GroupMembers.NICKNAME };
        Uri uri = ContentUris.withAppendedId(Im.GroupMembers.CONTENT_URI, groupId);
        Cursor c = resolver.query(uri, projection, null, null, null);
        StringBuilder buf = new StringBuilder();
        if(c != null) {
            while(c.moveToNext()) {
                buf.append(c.getString(0));
                if(!c.isLast()) {
                    buf.append(',");
                }
            }
            c.close();
        }
        return buf.toString();