FileDocCategorySizeDatePackage
RecipientList.javaAPI DocAndroid 1.5 API12773Wed May 06 22:42:46 BST 2009com.android.mms.ui

RecipientList

public class RecipientList extends Object

Fields Summary
private final ArrayList
mRecipients
private final ArrayList
mInvalidRecipients
Constructors Summary
public RecipientList()


      
    
Methods Summary
public voidadd(com.android.mms.ui.RecipientList$Recipient r)

        if ((null != r) && Recipient.isValid(r.number)) {
            mRecipients.add(r.filter());
        } else {
            mInvalidRecipients.add(r);
        }
    
public booleancontainsBcc()

        int count = mRecipients.size();
        for (int i = 0; i < count; i++) {
            if (mRecipients.get(i).bcc) {
                return true;
            }
        }
        return false;
    
public booleancontainsEmail()

        int count = mRecipients.size();
        for (int i = 0; i < count; i++) {
            if (Mms.isEmailAddress(mRecipients.get(i).number)) {
                return true;
            }
        }
        return false;
    
public intcountInvalidRecipients()

 return mInvalidRecipients.size(); 
public static com.android.mms.ui.RecipientListfrom(java.lang.String address, android.content.Context context)

        RecipientList list = new RecipientList();
        ContactInfoCache cache = ContactInfoCache.getInstance();

        if (!TextUtils.isEmpty(address)) {
            String[] phoneNumbers = address.split(MessageSender.RECIPIENTS_SEPARATOR);
            for (String number : phoneNumbers) {
                Recipient recipient = new Recipient();
                if (number.startsWith("%bcc%")) {
                    recipient.bcc = true;
                    number = number.substring(5);
                }

                /*
                 * TODO: Consider getting the CallerInfo object asynchronously
                 * to help with ui responsiveness, instead of running the query
                 * directly from the UI thread
                 */
                ContactInfoCache.CacheEntry entry = cache.getContactInfo(context, number);
                recipient.person_id = entry.person_id;
                if (TextUtils.isEmpty(entry.name)) {
                    if (MessageUtils.isLocalNumber(entry.phoneNumber)) {
                        recipient.name = context.getString(R.string.messagelist_sender_self);
                    } else {
                        recipient.name = entry.phoneNumber;
                    }
                } else {
                    recipient.name = entry.name;
                }
                
                if (Mms.isEmailAddress(number)) {
                    recipient.number = number;
                    recipient.name = cache.getDisplayName(context, number);
                } else {
                    recipient.label = entry.phoneLabel;
                    recipient.number = (entry.phoneNumber == null) ? "" : entry.phoneNumber;
                }
                recipient.nameAndNumber = Recipient.buildNameAndNumber(recipient.name,
                        recipient.number);
                list.add(recipient.filter());
            }
        }
        return list;
    
public java.lang.String[]getBccNumbers()

        ArrayList<String> numbers = new ArrayList<String>();
        int count = mRecipients.size();
        for (int i = 0 ; i < count ; i++) {
            Recipient recipient = mRecipients.get(i);
            if (recipient.bcc && !TextUtils.isEmpty(recipient.number)) {
                numbers.add(recipient.number);
            }
        }
        return numbers.toArray(new String[numbers.size()]);
    
public java.lang.StringgetInvalidRecipientString()

        StringBuilder sb = new StringBuilder();
        int count = mInvalidRecipients.size();
        for (int i = 0 ; i < count ; i++) {
            if (i != 0) {
                sb.append(",");
            }

            Recipient recipient = mInvalidRecipients.get(i);
            if (recipient.bcc) {
                sb.append("%bcc%");
            }
            sb.append(recipient.number);
        }
        return sb.toString();
    
public java.lang.String[]getNumbers()

        int count = mRecipients.size();
        ArrayList<String> numbers = new ArrayList<String>(count);
        for (int i = 0 ; i < count ; i++) {
            numbers.add((mRecipients.get(i)).number);
        }
        return numbers.toArray(new String[numbers.size()]);
    
public com.android.mms.ui.RecipientList$RecipientgetSingleRecipient()
getSingleRecipient returns the recipient if there is a single recipient. In all other cases, it returns null.

        int count = mRecipients.size();
        if (count != 1) {
            return null;
        }
        return mRecipients.get(0);
    
public java.lang.StringgetSingleRecipientNumber()

        Recipient first = getSingleRecipient();
        if (first == null) {
            return null;
        }
        return first.number;
    
public java.lang.String[]getToNumbers()

        ArrayList<String> numbers = new ArrayList<String>();
        int count = mRecipients.size();
        for (int i = 0 ; i < count ; i++) {
            Recipient recipient = mRecipients.get(i);
            if (!recipient.bcc && !TextUtils.isEmpty(recipient.number)) {
                numbers.add(recipient.number);
            }
        }
        return numbers.toArray(new String[numbers.size()]);
    
public booleanhasInvalidRecipient()

        return !mInvalidRecipients.isEmpty();
    
public booleanhasValidRecipient()

        return !mRecipients.isEmpty();
    
public java.util.Iteratoriterator()

 return mRecipients.iterator(); 
public java.lang.Stringserialize()

        StringBuilder sb = new StringBuilder();
        int count = mRecipients.size();
        for (int i = 0 ; i < count ; i++) {
            if (i != 0) {
                sb.append(MessageSender.RECIPIENTS_SEPARATOR);
            }

            Recipient recipient = mRecipients.get(i);
            if (recipient.bcc) {
                sb.append("%bcc%");
            }
            sb.append(recipient.number);
        }
        return sb.toString();
    
public intsize()

 return mRecipients.size();