mirror of
https://github.com/moparisthebest/k-9
synced 2025-02-25 15:11:52 -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:
parent
4723ea0ae5
commit
3a9589714b
@ -12,6 +12,7 @@ import android.widget.Toast;
|
|||||||
import android.widget.AdapterView.OnItemClickListener;
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
|
|
||||||
import com.fsck.k9.R;
|
import com.fsck.k9.R;
|
||||||
|
import com.fsck.k9.helper.ContactItem;
|
||||||
|
|
||||||
public class ArrayItemList extends K9ListActivity implements OnItemClickListener {
|
public class ArrayItemList extends K9ListActivity implements OnItemClickListener {
|
||||||
@Override
|
@Override
|
||||||
@ -20,16 +21,18 @@ public class ArrayItemList extends K9ListActivity implements OnItemClickListener
|
|||||||
|
|
||||||
setContentView(R.layout.item_list);
|
setContentView(R.layout.item_list);
|
||||||
|
|
||||||
ArrayList<String> pa = getIntent().getStringArrayListExtra("emailAddresses");
|
Intent i = getIntent();
|
||||||
if (pa == null) {
|
ContactItem contact = (ContactItem) i.getSerializableExtra("contact");
|
||||||
|
if (contact == null) {
|
||||||
return;
|
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 listView = getListView();
|
||||||
listView.setOnItemClickListener(this);
|
listView.setOnItemClickListener(this);
|
||||||
listView.setAdapter(adapter);
|
listView.setAdapter(adapter);
|
||||||
|
setTitle(contact.getDisplayName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -73,6 +73,7 @@ import com.fsck.k9.controller.MessagingController;
|
|||||||
import com.fsck.k9.controller.MessagingListener;
|
import com.fsck.k9.controller.MessagingListener;
|
||||||
import com.fsck.k9.crypto.CryptoProvider;
|
import com.fsck.k9.crypto.CryptoProvider;
|
||||||
import com.fsck.k9.crypto.PgpData;
|
import com.fsck.k9.crypto.PgpData;
|
||||||
|
import com.fsck.k9.helper.ContactItem;
|
||||||
import com.fsck.k9.helper.Contacts;
|
import com.fsck.k9.helper.Contacts;
|
||||||
import com.fsck.k9.helper.Utility;
|
import com.fsck.k9.helper.Utility;
|
||||||
import com.fsck.k9.mail.Message.RecipientType;
|
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_TO:
|
||||||
case CONTACT_PICKER_CC:
|
case CONTACT_PICKER_CC:
|
||||||
case CONTACT_PICKER_BCC:
|
case CONTACT_PICKER_BCC:
|
||||||
ArrayList<String> email = mContacts.getEmailFromContactPicker(data);
|
ContactItem contact = mContacts.getEmailFromContactPicker(data);
|
||||||
if (email.size() == 0) {
|
if (contact == null) {
|
||||||
Toast.makeText(this, getString(R.string.error_contact_address_not_found), Toast.LENGTH_LONG).show();
|
Toast.makeText(this, getString(R.string.error_contact_address_not_found), Toast.LENGTH_LONG).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (email.size() > 1) {
|
if (contact.getEmailAddresses().size() > 1) {
|
||||||
Intent i = new Intent(this, ArrayItemList.class);
|
Intent i = new Intent(this, ArrayItemList.class);
|
||||||
i.putExtra("emailAddresses", email);
|
i.putExtra("contact", contact);
|
||||||
|
|
||||||
if (requestCode == CONTACT_PICKER_TO) {
|
if (requestCode == CONTACT_PICKER_TO) {
|
||||||
startActivityForResult(i, CONTACT_PICKER_TO2);
|
startActivityForResult(i, CONTACT_PICKER_TO2);
|
||||||
@ -1815,18 +1816,20 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (K9.DEBUG) {
|
if (K9.DEBUG) {
|
||||||
for (int i = 0; i < email.size(); i++) {
|
ArrayList<String> emails = contact.getEmailAddresses();
|
||||||
Log.v(K9.LOG_TAG, "email[" + i + "]: " + email.get(i));
|
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) {
|
if (requestCode == CONTACT_PICKER_TO) {
|
||||||
addAddress(mToView, new Address(email.get(0), ""));
|
addAddress(mToView, new Address(email, ""));
|
||||||
} else if (requestCode == CONTACT_PICKER_CC) {
|
} else if (requestCode == CONTACT_PICKER_CC) {
|
||||||
addAddress(mCcView, new Address(email.get(0), ""));
|
addAddress(mCcView, new Address(email, ""));
|
||||||
} else if (requestCode == CONTACT_PICKER_BCC) {
|
} else if (requestCode == CONTACT_PICKER_BCC) {
|
||||||
addAddress(mBccView, new Address(email.get(0), ""));
|
addAddress(mBccView, new Address(email, ""));
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
24
src/com/fsck/k9/helper/ContactItem.java
Executable file
24
src/com/fsck/k9/helper/ContactItem.java
Executable 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;
|
||||||
|
}
|
||||||
|
}
|
@ -2,7 +2,6 @@ package com.fsck.k9.helper;
|
|||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -182,7 +181,7 @@ public abstract class Contacts {
|
|||||||
* @param intent The {@link Intent} returned by this contact picker.
|
* @param intent The {@link Intent} returned by this contact picker.
|
||||||
* @return The primary email address of the picked contact.
|
* @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
|
* Does the device actually have a Contacts application suitable for
|
||||||
|
@ -193,33 +193,48 @@ public class ContactsSdk5 extends com.fsck.k9.helper.Contacts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<String> getEmailFromContactPicker(final Intent data) {
|
public ContactItem getEmailFromContactPicker(final Intent data) {
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
|
Cursor cursor2 = null;
|
||||||
|
ContactItem item = new ContactItem();
|
||||||
ArrayList<String> email = new ArrayList<String>();
|
ArrayList<String> email = new ArrayList<String>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Uri result = data.getData();
|
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
|
// Get the contact id from the Uri
|
||||||
String id = result.getLastPathSegment();
|
String id = result.getLastPathSegment();
|
||||||
cursor = mContentResolver.query(Email.CONTENT_URI,
|
cursor2 = mContentResolver.query(Email.CONTENT_URI,
|
||||||
null, Email.CONTACT_ID + "=?", new String[] { id },
|
null, Email.CONTACT_ID + "=?", new String[] { id },
|
||||||
null);
|
null);
|
||||||
|
|
||||||
if (cursor != null) {
|
if (cursor2 != null) {
|
||||||
int emailIdx = cursor.getColumnIndex(Email.DATA);
|
int emailIdx = cursor2.getColumnIndex(Email.DATA);
|
||||||
|
|
||||||
while (cursor.moveToNext()) {
|
while (cursor2.moveToNext()) {
|
||||||
email.add(cursor.getString(emailIdx));
|
email.add(cursor2.getString(emailIdx));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (email.size() == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
item.setDisplayName(displayName);
|
||||||
|
item.setEmailAddresses(email);
|
||||||
|
return item;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(K9.LOG_TAG, "Failed to get email data", e);
|
Log.e(K9.LOG_TAG, "Failed to get email data", e);
|
||||||
} finally {
|
} finally {
|
||||||
Utility.closeQuietly(cursor);
|
Utility.closeQuietly(cursor);
|
||||||
|
Utility.closeQuietly(cursor2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return email;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user