1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-30 13:12:25 -05:00

added the ContactItem class for picked item from ContactPicker.

Conflicts:

	src/com/fsck/k9/helper/ContactsSdk3_4.java
	src/com/fsck/k9/helper/ContactsSdk5.java
This commit is contained in:
Jesse Vincent 2012-04-08 12:32:04 -04:00
parent 4723ea0ae5
commit 3a9589714b
5 changed files with 65 additions and 21 deletions

View File

@ -12,6 +12,7 @@ import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import com.fsck.k9.R;
import com.fsck.k9.helper.ContactItem;
public class ArrayItemList extends K9ListActivity implements OnItemClickListener {
@Override
@ -20,16 +21,18 @@ public class ArrayItemList extends K9ListActivity implements OnItemClickListener
setContentView(R.layout.item_list);
ArrayList<String> pa = getIntent().getStringArrayListExtra("emailAddresses");
if (pa == null) {
Intent i = getIntent();
ContactItem contact = (ContactItem) i.getSerializableExtra("contact");
if (contact == null) {
return;
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, pa);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, contact.getEmailAddresses());
ListView listView = getListView();
listView.setOnItemClickListener(this);
listView.setAdapter(adapter);
setTitle(contact.getDisplayName());
}
@Override

View File

@ -73,6 +73,7 @@ import com.fsck.k9.controller.MessagingController;
import com.fsck.k9.controller.MessagingListener;
import com.fsck.k9.crypto.CryptoProvider;
import com.fsck.k9.crypto.PgpData;
import com.fsck.k9.helper.ContactItem;
import com.fsck.k9.helper.Contacts;
import com.fsck.k9.helper.Utility;
import com.fsck.k9.mail.Message.RecipientType;
@ -1796,14 +1797,14 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
case CONTACT_PICKER_TO:
case CONTACT_PICKER_CC:
case CONTACT_PICKER_BCC:
ArrayList<String> email = mContacts.getEmailFromContactPicker(data);
if (email.size() == 0) {
ContactItem contact = mContacts.getEmailFromContactPicker(data);
if (contact == null) {
Toast.makeText(this, getString(R.string.error_contact_address_not_found), Toast.LENGTH_LONG).show();
return;
}
if (email.size() > 1) {
if (contact.getEmailAddresses().size() > 1) {
Intent i = new Intent(this, ArrayItemList.class);
i.putExtra("emailAddresses", email);
i.putExtra("contact", contact);
if (requestCode == CONTACT_PICKER_TO) {
startActivityForResult(i, CONTACT_PICKER_TO2);
@ -1815,18 +1816,20 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
return;
}
if (K9.DEBUG) {
for (int i = 0; i < email.size(); i++) {
Log.v(K9.LOG_TAG, "email[" + i + "]: " + email.get(i));
ArrayList<String> emails = contact.getEmailAddresses();
for (int i = 0; i < emails.size(); i++) {
Log.v(K9.LOG_TAG, "email[" + i + "]: " + emails.get(i));
}
}
String email = contact.getEmailAddresses().get(0);
if (requestCode == CONTACT_PICKER_TO) {
addAddress(mToView, new Address(email.get(0), ""));
addAddress(mToView, new Address(email, ""));
} else if (requestCode == CONTACT_PICKER_CC) {
addAddress(mCcView, new Address(email.get(0), ""));
addAddress(mCcView, new Address(email, ""));
} else if (requestCode == CONTACT_PICKER_BCC) {
addAddress(mBccView, new Address(email.get(0), ""));
addAddress(mBccView, new Address(email, ""));
} else {
return;
}

View File

@ -0,0 +1,24 @@
package com.fsck.k9.helper;
import java.io.Serializable;
import java.util.ArrayList;
public class ContactItem implements Serializable {
private static final long serialVersionUID = 4893328130147843375L;
private String displayName = null;
private ArrayList<String> emailAddresses = null;
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public ArrayList<String> getEmailAddresses() {
return emailAddresses;
}
public void setEmailAddresses(ArrayList<String> emailAddresses) {
this.emailAddresses = emailAddresses;
}
}

View File

@ -2,7 +2,6 @@ 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;
@ -182,7 +181,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 ArrayList<String> getEmailFromContactPicker(final Intent intent);
public abstract ContactItem getEmailFromContactPicker(final Intent intent);
/**
* Does the device actually have a Contacts application suitable for

View File

@ -193,33 +193,48 @@ public class ContactsSdk5 extends com.fsck.k9.helper.Contacts {
}
@Override
public ArrayList<String> getEmailFromContactPicker(final Intent data) {
public ContactItem getEmailFromContactPicker(final Intent data) {
Cursor cursor = null;
Cursor cursor2 = null;
ContactItem item = new ContactItem();
ArrayList<String> email = new ArrayList<String>();
try {
Uri result = data.getData();
String displayName = null;
cursor = mContentResolver.query(result, null, null, null, null);
if (cursor.moveToFirst()) {
displayName = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
}
// Get the contact id from the Uri
String id = result.getLastPathSegment();
cursor = mContentResolver.query(Email.CONTENT_URI,
cursor2 = mContentResolver.query(Email.CONTENT_URI,
null, Email.CONTACT_ID + "=?", new String[] { id },
null);
if (cursor != null) {
int emailIdx = cursor.getColumnIndex(Email.DATA);
if (cursor2 != null) {
int emailIdx = cursor2.getColumnIndex(Email.DATA);
while (cursor.moveToNext()) {
email.add(cursor.getString(emailIdx));
while (cursor2.moveToNext()) {
email.add(cursor2.getString(emailIdx));
}
if (email.size() == 0) {
return null;
}
item.setDisplayName(displayName);
item.setEmailAddresses(email);
return item;
}
} catch (Exception e) {
Log.e(K9.LOG_TAG, "Failed to get email data", e);
} finally {
Utility.closeQuietly(cursor);
Utility.closeQuietly(cursor2);
}
return email;
return null;
}
/**