} else if (type.equals(Contents.Type.CONTACT)) {
Bundle bundle = intent.getBundleExtra(Intents.Encode.DATA);
if (bundle != null) {
- mContents = "MECARD:";
- mDisplayContents = "";
+ StringBuilder newContents = new StringBuilder();
+ StringBuilder newDisplayContents = new StringBuilder();
+ newContents.append("MECARD:");
String name = bundle.getString(Contacts.Intents.Insert.NAME);
if (name != null && name.length() > 0) {
- mContents = "N:" + name + ';';
- mDisplayContents += name;
+ newContents.append("N:").append(name).append(';');
+ newDisplayContents.append(name);
}
String address = bundle.getString(Contacts.Intents.Insert.POSTAL);
if (address != null && address.length() > 0) {
- mContents += "ADR:" + address + ';';
- mDisplayContents += '\n' + address;
+ newContents.append("ADR:").append(address).append(';');
+ newDisplayContents.append('\n').append(address);
}
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' + PhoneNumberUtils.formatNumber(phone);
+ newContents.append("TEL:").append(phone).append(';');
+ newDisplayContents.append('\n').append(PhoneNumberUtils.formatNumber(phone));
}
}
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;
+ newContents.append("EMAIL:").append(email).append(';');
+ newDisplayContents.append('\n').append(email);
}
}
// Make sure we've encoded at least one field.
- if (mDisplayContents.length() > 0) {
- mContents += ";";
+ if (newDisplayContents.length() > 0) {
+ newContents.append(';');
+ mContents = newContents.toString();
+ mDisplayContents = newDisplayContents.toString();
mTitle = mActivity.getString(R.string.contents_contact);
} else {
mContents = null;
+ mDisplayContents = null;
}
}
} else if (type.equals(Contents.Type.LOCATION)) {
mPixelResolution = pixelResolution;
}
+ @Override
public void run() {
try {
ByteMatrix result = new MultiFormatWriter().encode(mContents, BarcodeFormat.QR_CODE,
// Don't require a name to be present, this contact might be just a phone number.
if (name != null && name.length() > 0) {
- bundle.putString(Contacts.Intents.Insert.NAME, name);
+ bundle.putString(Contacts.Intents.Insert.NAME, massageContactData(name));
}
contactCursor.close();
while (phonesCursor.moveToNext()) {
String number = phonesCursor.getString(PHONES_NUMBER_COLUMN);
if (foundPhone < Contents.PHONE_KEYS.length) {
- bundle.putString(Contents.PHONE_KEYS[foundPhone], number);
+ bundle.putString(Contents.PHONE_KEYS[foundPhone], massageContactData(number));
foundPhone++;
}
}
switch (kind) {
case Contacts.KIND_EMAIL:
if (foundEmail < Contents.EMAIL_KEYS.length) {
- bundle.putString(Contents.EMAIL_KEYS[foundEmail], data);
+ bundle.putString(Contents.EMAIL_KEYS[foundEmail], massageContactData(data));
foundEmail++;
}
break;
case Contacts.KIND_POSTAL:
if (!foundPostal) {
- bundle.putString(Contacts.Intents.Insert.POSTAL, data);
+ bundle.putString(Contacts.Intents.Insert.POSTAL, massageContactData(data));
foundPostal = true;
}
break;
}
}
+ private static String massageContactData(String data) {
+ // For now -- make sure we don't put newlines in shared contact data. It messes up
+ // any known encoding of contact data. Replace with space.
+ if (data.indexOf('\n') >= 0) {
+ data = data.replace("\n", " ");
+ }
+ if (data.indexOf('\r') >= 0) {
+ data = data.replace("\r", " ");
+ }
+ return data;
+ }
+
}