From 4723ea0ae5598a59886c3a308980a5caac0e8a1d Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Sun, 8 Apr 2012 12:29:08 -0400 Subject: [PATCH] Possible to select email addresses from the ContactPicker Conflicts: src/com/fsck/k9/activity/MessageCompose.java src/com/fsck/k9/helper/ContactsSdk3_4.java --- AndroidManifest.xml | 5 +- res/layout/item_list.xml | 9 ++++ src/com/fsck/k9/activity/ArrayItemList.java | 46 +++++++++++++++++ src/com/fsck/k9/activity/MessageCompose.java | 54 +++++++++++++++++--- src/com/fsck/k9/helper/Contacts.java | 4 +- src/com/fsck/k9/helper/ContactsSdk5.java | 14 +++-- src/com/fsck/k9/mail/store/LocalStore.java | 36 +++++++------ 7 files changed, 137 insertions(+), 31 deletions(-) create mode 100644 res/layout/item_list.xml create mode 100644 src/com/fsck/k9/activity/ArrayItemList.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index e1fff9465..9339d7ae2 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -281,7 +281,10 @@ android:name="com.fsck.k9.activity.AccessibleEmailContentActivity" > - + + diff --git a/res/layout/item_list.xml b/res/layout/item_list.xml new file mode 100644 index 000000000..cc3d093e7 --- /dev/null +++ b/res/layout/item_list.xml @@ -0,0 +1,9 @@ + + + + diff --git a/src/com/fsck/k9/activity/ArrayItemList.java b/src/com/fsck/k9/activity/ArrayItemList.java new file mode 100644 index 000000000..ef6a03878 --- /dev/null +++ b/src/com/fsck/k9/activity/ArrayItemList.java @@ -0,0 +1,46 @@ +package com.fsck.k9.activity; + +import java.util.ArrayList; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.Toast; +import android.widget.AdapterView.OnItemClickListener; + +import com.fsck.k9.R; + +public class ArrayItemList extends K9ListActivity implements OnItemClickListener { + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.item_list); + + ArrayList pa = getIntent().getStringArrayListExtra("emailAddresses"); + if (pa == null) { + return; + } + + ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, pa); + + ListView listView = getListView(); + listView.setOnItemClickListener(this); + listView.setAdapter(adapter); + } + + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + String item = (String)parent.getItemAtPosition(position); + + Toast.makeText(ArrayItemList.this, item, Toast.LENGTH_LONG).show(); + + Intent intent = new Intent(); + intent.putExtra("EMAIL_ADDRESS", item); + setResult(RESULT_OK, intent); + finish(); + } +} diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java index e02186771..1596ed54c 100644 --- a/src/com/fsck/k9/activity/MessageCompose.java +++ b/src/com/fsck/k9/activity/MessageCompose.java @@ -135,9 +135,14 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc private static final int MSG_DISCARDED_DRAFT = 6; private static final int ACTIVITY_REQUEST_PICK_ATTACHMENT = 1; - private static final int CONTACT_PICKER_TO = 2; - private static final int CONTACT_PICKER_CC = 3; - private static final int CONTACT_PICKER_BCC = 4; + private static final int ACTIVITY_CHOOSE_IDENTITY = 2; + private static final int ACTIVITY_CHOOSE_ACCOUNT = 3; + private static final int CONTACT_PICKER_TO = 4; + private static final int CONTACT_PICKER_CC = 5; + private static final int CONTACT_PICKER_BCC = 6; + private static final int CONTACT_PICKER_TO2 = 7; + private static final int CONTACT_PICKER_CC2 = 8; + private static final int CONTACT_PICKER_BCC2 = 9; private static final Account[] EMPTY_ACCOUNT_ARRAY = new Account[0]; @@ -1791,17 +1796,37 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc case CONTACT_PICKER_TO: case CONTACT_PICKER_CC: case CONTACT_PICKER_BCC: - String email = mContacts.getEmailFromContactPicker(data); - if (email.length() == 0) { + ArrayList email = mContacts.getEmailFromContactPicker(data); + if (email.size() == 0) { Toast.makeText(this, getString(R.string.error_contact_address_not_found), Toast.LENGTH_LONG).show(); return; } + if (email.size() > 1) { + Intent i = new Intent(this, ArrayItemList.class); + i.putExtra("emailAddresses", email); + + if (requestCode == CONTACT_PICKER_TO) { + startActivityForResult(i, CONTACT_PICKER_TO2); + } else if (requestCode == CONTACT_PICKER_CC) { + startActivityForResult(i, CONTACT_PICKER_CC2); + } else if (requestCode == CONTACT_PICKER_BCC) { + startActivityForResult(i, CONTACT_PICKER_BCC2); + } + return; + } + if (K9.DEBUG) { + for (int i = 0; i < email.size(); i++) { + Log.v(K9.LOG_TAG, "email[" + i + "]: " + email.get(i)); + } + } + + if (requestCode == CONTACT_PICKER_TO) { - addAddress(mToView, new Address(email, "")); + addAddress(mToView, new Address(email.get(0), "")); } else if (requestCode == CONTACT_PICKER_CC) { - addAddress(mCcView, new Address(email, "")); + addAddress(mCcView, new Address(email.get(0), "")); } else if (requestCode == CONTACT_PICKER_BCC) { - addAddress(mBccView, new Address(email, "")); + addAddress(mBccView, new Address(email.get(0), "")); } else { return; } @@ -1809,6 +1834,19 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc break; + case CONTACT_PICKER_TO2: + case CONTACT_PICKER_CC2: + case CONTACT_PICKER_BCC2: + String emailAddr = data.getStringExtra("EMAIL_ADDRESS"); + if (requestCode == CONTACT_PICKER_TO2) { + addAddress(mToView, new Address(emailAddr, "")); + } else if (requestCode == CONTACT_PICKER_CC2) { + addAddress(mCcView, new Address(emailAddr, "")); + } else if (requestCode == CONTACT_PICKER_BCC2) { + addAddress(mBccView, new Address(emailAddr, "")); + } else { + return; + } } } diff --git a/src/com/fsck/k9/helper/Contacts.java b/src/com/fsck/k9/helper/Contacts.java index c7beb05fd..dd641d8c7 100644 --- a/src/com/fsck/k9/helper/Contacts.java +++ b/src/com/fsck/k9/helper/Contacts.java @@ -2,6 +2,8 @@ package com.fsck.k9.helper; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; + import android.content.ContentResolver; import android.content.Context; import android.database.Cursor; @@ -180,7 +182,7 @@ public abstract class Contacts { * @param intent The {@link Intent} returned by this contact picker. * @return The primary email address of the picked contact. */ - public abstract String getEmailFromContactPicker(final Intent intent); + public abstract ArrayList getEmailFromContactPicker(final Intent intent); /** * Does the device actually have a Contacts application suitable for diff --git a/src/com/fsck/k9/helper/ContactsSdk5.java b/src/com/fsck/k9/helper/ContactsSdk5.java index 74c19193a..ab80d3cc4 100644 --- a/src/com/fsck/k9/helper/ContactsSdk5.java +++ b/src/com/fsck/k9/helper/ContactsSdk5.java @@ -1,5 +1,7 @@ package com.fsck.k9.helper; +import java.util.ArrayList; + import android.content.Context; import android.content.Intent; import android.database.Cursor; @@ -191,9 +193,9 @@ public class ContactsSdk5 extends com.fsck.k9.helper.Contacts { } @Override - public String getEmailFromContactPicker(final Intent data) { + public ArrayList getEmailFromContactPicker(final Intent data) { Cursor cursor = null; - String email = ""; + ArrayList email = new ArrayList(); try { Uri result = data.getData(); @@ -204,10 +206,12 @@ public class ContactsSdk5 extends com.fsck.k9.helper.Contacts { null, Email.CONTACT_ID + "=?", new String[] { id }, null); - int emailIdx = cursor.getColumnIndex(Email.DATA); + if (cursor != null) { + int emailIdx = cursor.getColumnIndex(Email.DATA); - if (cursor.moveToFirst()) { - email = cursor.getString(emailIdx); + while (cursor.moveToNext()) { + email.add(cursor.getString(emailIdx)); + } } } catch (Exception e) { Log.e(K9.LOG_TAG, "Failed to get email data", e); diff --git a/src/com/fsck/k9/mail/store/LocalStore.java b/src/com/fsck/k9/mail/store/LocalStore.java index 64d89610c..0ecdbd1ab 100644 --- a/src/com/fsck/k9/mail/store/LocalStore.java +++ b/src/com/fsck/k9/mail/store/LocalStore.java @@ -35,6 +35,7 @@ import com.fsck.k9.AccountStats; import com.fsck.k9.K9; import com.fsck.k9.Preferences; import com.fsck.k9.R; +import com.fsck.k9.Account.MessageFormat; import com.fsck.k9.controller.MessageRemovalListener; import com.fsck.k9.controller.MessageRetrievalListener; import com.fsck.k9.helper.Utility; @@ -1587,23 +1588,26 @@ public class LocalStore extends Store implements Serializable { MimeBodyPart bp = new MimeBodyPart(body, "text/plain"); mp.addBodyPart(bp); } - if (htmlContent != null) { - TextBody body = new TextBody(htmlContent); - MimeBodyPart bp = new MimeBodyPart(body, "text/html"); - mp.addBodyPart(bp); - } - // If we have both text and html content and our MIME type - // isn't multipart/alternative, then corral them into a new - // multipart/alternative part and put that into the parent. - // If it turns out that this is the only part in the parent - // MimeMultipart, it'll get fixed below before we attach to - // the message. - if (textContent != null && htmlContent != null && !mimeType.equalsIgnoreCase("multipart/alternative")) { - MimeMultipart alternativeParts = mp; - alternativeParts.setSubType("alternative"); - mp = new MimeMultipart(); - mp.addBodyPart(new MimeBodyPart(alternativeParts)); + if (mAccount.getMessageFormat() == MessageFormat.HTML) { + if (htmlContent != null) { + TextBody body = new TextBody(htmlContent); + MimeBodyPart bp = new MimeBodyPart(body, "text/html"); + mp.addBodyPart(bp); + } + + // If we have both text and html content and our MIME type + // isn't multipart/alternative, then corral them into a new + // multipart/alternative part and put that into the parent. + // If it turns out that this is the only part in the parent + // MimeMultipart, it'll get fixed below before we attach to + // the message. + if (textContent != null && htmlContent != null && !mimeType.equalsIgnoreCase("multipart/alternative")) { + MimeMultipart alternativeParts = mp; + alternativeParts.setSubType("alternative"); + mp = new MimeMultipart(); + mp.addBodyPart(new MimeBodyPart(alternativeParts)); + } } } else if (mimeType != null && mimeType.equalsIgnoreCase("text/plain")) { // If it's text, add only the plain part. The MIME