Added support for encoding multiple email addresses and phone numbers using the new constants I added to the Contacts app for Android 1.1.

git-svn-id: https://zxing.googlecode.com/svn/trunk@750 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
dswitkin 2008-11-20 19:58:33 +00:00
parent dab0c22347
commit 960a169da7
3 changed files with 39 additions and 27 deletions

View file

@ -16,6 +16,7 @@
package com.google.zxing.client.android;
import android.provider.Contacts;
public final class Contents {
@ -80,4 +81,24 @@ public final class Contents {
public static final String LOCATION = "LOCATION_TYPE";
}
// These are new constants in Contacts.Intents.Insert for Android 1.1.
// TODO: Remove these constants once we can build against the 1.1 SDK.
private static final String SECONDARY_PHONE = "secondary_phone";
private static final String TERTIARY_PHONE = "tertiary_phone";
private static final String SECONDARY_EMAIL = "secondary_email";
private static final String TERTIARY_EMAIL = "tertiary_email";
/**
* When using Type.CONTACT, these arrays provide the keys for adding or retrieving multiple
* phone numbers and addresses.
*/
public static final String[] PHONE_KEYS = {
Contacts.Intents.Insert.PHONE, SECONDARY_PHONE, TERTIARY_PHONE
};
public static final String[] EMAIL_KEYS = {
Contacts.Intents.Insert.EMAIL, SECONDARY_EMAIL, TERTIARY_EMAIL
};
}

View file

@ -108,15 +108,19 @@ public final class QRCodeEncoder {
mContents += "ADR:" + address + ";";
mDisplayContents += "\n" + address;
}
String phone = bundle.getString(Contacts.Intents.Insert.PHONE);
if (phone != null && phone.length() > 0) {
mContents += "TEL:" + phone + ";";
mDisplayContents += "\n" + phone;
for (int x = 0; x < Contents.PHONE_KEYS.length; x++) {
String phone = bundle.getString(Contents.PHONE_KEYS[x]);
if (phone != null && phone.length() > 0) {
mContents += "TEL:" + phone + ";";
mDisplayContents += "\n" + phone;
}
}
String email = bundle.getString(Contacts.Intents.Insert.EMAIL);
if (email != null && email.length() > 0) {
mContents += "EMAIL:" + email + ";";
mDisplayContents += "\n" + email;
for (int x = 0; x < Contents.EMAIL_KEYS.length; x++) {
String email = bundle.getString(Contents.EMAIL_KEYS[x]);
if (email != null && email.length() > 0) {
mContents += "EMAIL:" + email + ";";
mDisplayContents += "\n" + email;
}
}
mContents += ";";
mTitle = mActivity.getString(R.string.contents_contact);

View file

@ -24,6 +24,7 @@ import com.google.zxing.client.android.Intents;
import com.google.zxing.client.android.R;
import com.google.zxing.client.android.SearchBookContentsActivity;
import com.google.zxing.client.android.LocaleManager;
import com.google.zxing.client.android.Contents;
import com.google.zxing.client.result.ParsedResult;
import com.google.zxing.client.result.ParsedResultType;
@ -38,21 +39,6 @@ public abstract class ResultHandler {
public static final int MAX_BUTTON_COUNT = 4;
// These are new constants in Contacts.Intents.Insert for Android 1.1.
// TODO: Remove these constants once we can build against the 1.1 SDK.
private static final String SECONDARY_PHONE = "secondary_phone";
private static final String TERTIARY_PHONE = "tertiary_phone";
private static final String SECONDARY_EMAIL = "secondary_email";
private static final String TERTIARY_EMAIL = "tertiary_email";
private static final String[] PHONE_INTENTS = {
Contacts.Intents.Insert.PHONE, SECONDARY_PHONE, TERTIARY_PHONE
};
private static final String[] EMAIL_INTENTS = {
Contacts.Intents.Insert.EMAIL, SECONDARY_EMAIL, TERTIARY_EMAIL
};
protected final ParsedResult mResult;
private final Activity mActivity;
@ -157,14 +143,15 @@ public abstract class ResultHandler {
Intent intent = new Intent(Contacts.Intents.Insert.ACTION, Contacts.People.CONTENT_URI);
putExtra(intent, Contacts.Intents.Insert.NAME, names);
int phoneCount = Math.min((phoneNumbers != null) ? phoneNumbers.length : 0, PHONE_INTENTS.length);
int phoneCount = Math.min((phoneNumbers != null) ? phoneNumbers.length : 0,
Contents.PHONE_KEYS.length);
for (int x = 0; x < phoneCount; x++) {
putExtra(intent, PHONE_INTENTS[x], phoneNumbers[x]);
putExtra(intent, Contents.PHONE_KEYS[x], phoneNumbers[x]);
}
int emailCount = Math.min((emails != null) ? emails.length : 0, EMAIL_INTENTS.length);
int emailCount = Math.min((emails != null) ? emails.length : 0, Contents.EMAIL_KEYS.length);
for (int x = 0; x < emailCount; x++) {
putExtra(intent, EMAIL_INTENTS[x], emails[x]);
putExtra(intent, Contents.EMAIL_KEYS[x], emails[x]);
}
putExtra(intent, Contacts.Intents.Insert.NOTES, note);