/*
 * Derived from com.android.mms.data.ContactList
 * (tag android-4.4.4_r2.0.1)
 */

package ca.bmaupin.merge.sms.data;

import java.util.ArrayList;

import android.text.TextUtils;

public class ContactList extends ArrayList<Contact> {
	private static final long serialVersionUID = 1L;
	
    public String formatNames(String separator) {
        String[] names = new String[size()];
        int i = 0;
        for (Contact c : this) {
            names[i++] = c.getName();
        }
        return TextUtils.join(separator, names);
    }
    
    /**
     * Returns a ContactList for the corresponding recipient ids passed in. This method will
     * create the contact if it doesn't exist, and would inject the recipient id into the contact.
     */
    public static ContactList getByIds(String spaceSepIds, boolean canBlock) {
        ContactList list = new ContactList();
        for (RecipientIdCache.Entry entry : RecipientIdCache.getAddresses(spaceSepIds)) {
            if (entry != null && !TextUtils.isEmpty(entry.number)) {
                Contact contact = Contact.get(entry.number, canBlock);
                contact.setRecipientId(entry.id);
                list.add(contact);
            }
        }
        return list;
    }
}

@@ -144,16 +144,84 @@
 ayList;%0A
+import java.util.List;%0A%0Aimport ca.bmaupin.merge.sms.ui.MessageUtils;
 %0Aimport 
@@ -1305,10 +1305,1452 @@
 ;%0A    %7D%0A
+    %0A    public String serialize() %7B%0A        return TextUtils.join(%22;%22, getNumbers());%0A    %7D%0A    %0A    public String%5B%5D getNumbers() %7B%0A        return getNumbers(false /* don't scrub for MMS address */);%0A    %7D%0A%0A    public String%5B%5D getNumbers(boolean scrubForMmsAddress) %7B%0A        List%3CString%3E numbers = new ArrayList%3CString%3E();%0A        String number;%0A        for (Contact c : this) %7B%0A            number = c.getNumber();%0A%0A            if (scrubForMmsAddress) %7B%0A                // parse/scrub the address for valid MMS address. The returned number%0A                // could be null if it's not a valid MMS address. We don't want to send%0A                // a message to an invalid number, as the network may do its own stripping,%0A                // and end up sending the message to a different number!%0A                number = MessageUtils.parseMmsAddress(number);%0A            %7D%0A%0A            // Don't add duplicate numbers. This can happen if a contact name has a comma.%0A            // Since we use a comma as a delimiter between contacts, the code will consider%0A            // the same recipient has been added twice. The recipients UI still works correctly.%0A            // It's easiest to just make sure we only send to the same recipient once.%0A            if (!TextUtils.isEmpty(number) && !numbers.contains(number)) %7B%0A                numbers.add(number);%0A            %7D%0A        %7D%0A        return numbers.toArray(new String%5Bnumbers.size()%5D);%0A    %7D%0A
 %7D%0A

Add serialize() for ComposeMessageActivity