1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-24 08:38:51 -05:00

Possible to select email addresses from the ContactPicker

Conflicts:

	src/com/fsck/k9/activity/MessageCompose.java
	src/com/fsck/k9/helper/ContactsSdk3_4.java
This commit is contained in:
Jesse Vincent 2012-04-08 12:29:08 -04:00
parent dd0ba7640c
commit 4723ea0ae5
7 changed files with 137 additions and 31 deletions

View File

@ -281,7 +281,10 @@
android:name="com.fsck.k9.activity.AccessibleEmailContentActivity"
>
</activity>
<activity android:name="com.fsck.k9.activity.ArrayItemList"
android:configChanges="locale"
>
</activity>
<receiver android:name="com.fsck.k9.service.BootReceiver"
android:enabled="true"
>

9
res/layout/item_list.xml Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>

View File

@ -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<String> pa = getIntent().getStringArrayListExtra("emailAddresses");
if (pa == null) {
return;
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(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();
}
}

View File

@ -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<String> 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;
}
}
}

View File

@ -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<String> getEmailFromContactPicker(final Intent intent);
/**
* Does the device actually have a Contacts application suitable for

View File

@ -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<String> getEmailFromContactPicker(final Intent data) {
Cursor cursor = null;
String email = "";
ArrayList<String> email = new ArrayList<String>();
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);

View File

@ -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