am 6ba23c59: Handle cases where TYPE can be undefined, such as EAS.

Merge commit '6ba23c59f24b443cd21c6289fa0aac3df8f17017' into eclair-plus-aosp

* commit '6ba23c59f24b443cd21c6289fa0aac3df8f17017':
  Handle cases where TYPE can be undefined, such as EAS.
This commit is contained in:
Jeff Sharkey
2009-09-09 23:14:39 -07:00
committed by Android Git Automerger
2 changed files with 35 additions and 30 deletions

View File

@@ -871,11 +871,10 @@ public class VCardComposer {
} }
private boolean appendPostalsForDoCoMoInternal(final StringBuilder builder, private boolean appendPostalsForDoCoMoInternal(final StringBuilder builder,
final List<ContentValues> contentValuesList, int preferedType) { final List<ContentValues> contentValuesList, Integer preferedType) {
for (ContentValues contentValues : contentValuesList) { for (ContentValues contentValues : contentValuesList) {
final int type = contentValues.getAsInteger(StructuredPostal.TYPE); final Integer type = contentValues.getAsInteger(StructuredPostal.TYPE);
final String label = contentValues final String label = contentValues.getAsString(StructuredPostal.LABEL);
.getAsString(StructuredPostal.LABEL);
if (type == preferedType) { if (type == preferedType) {
appendVCardPostalLine(builder, type, label, contentValues); appendVCardPostalLine(builder, type, label, contentValues);
return true; return true;
@@ -887,9 +886,8 @@ public class VCardComposer {
private void appendPostalsForGeneric(final StringBuilder builder, private void appendPostalsForGeneric(final StringBuilder builder,
final List<ContentValues> contentValuesList) { final List<ContentValues> contentValuesList) {
for (ContentValues contentValues : contentValuesList) { for (ContentValues contentValues : contentValuesList) {
final int type = contentValues.getAsInteger(StructuredPostal.TYPE); final Integer type = contentValues.getAsInteger(StructuredPostal.TYPE);
final String label = contentValues final String label = contentValues.getAsString(StructuredPostal.LABEL);
.getAsString(StructuredPostal.LABEL);
appendVCardPostalLine(builder, type, label, contentValues); appendVCardPostalLine(builder, type, label, contentValues);
} }
} }
@@ -900,15 +898,10 @@ public class VCardComposer {
.get(Im.CONTENT_ITEM_TYPE); .get(Im.CONTENT_ITEM_TYPE);
if (contentValuesList != null) { if (contentValuesList != null) {
for (ContentValues contentValues : contentValuesList) { for (ContentValues contentValues : contentValuesList) {
int type = contentValues.getAsInteger(Im.PROTOCOL); Integer protocol = contentValues.getAsInteger(Im.PROTOCOL);
String data = contentValues.getAsString(Im.DATA); String data = contentValues.getAsString(Im.DATA);
Log.d("@@@", "Im information. protocol=\"" + type +
"\", data=\"" + data + "\", protocol=\"" +
contentValues.getAsString(Im.PROTOCOL) + "\", custom_protocol=\"" +
contentValues.getAsString(Im.CUSTOM_PROTOCOL) + "\"");
if (type == Im.PROTOCOL_GOOGLE_TALK) { if (protocol != null && protocol == Im.PROTOCOL_GOOGLE_TALK) {
if (VCardConfig.usesAndroidSpecificProperty(mVCardType)) { if (VCardConfig.usesAndroidSpecificProperty(mVCardType)) {
appendVCardLine(builder, Constants.PROPERTY_X_GOOGLE_TALK, data); appendVCardLine(builder, Constants.PROPERTY_X_GOOGLE_TALK, data);
} }
@@ -1129,8 +1122,8 @@ public class VCardComposer {
builder.append(VCARD_COL_SEPARATOR); builder.append(VCARD_COL_SEPARATOR);
} }
private void appendVCardPostalLine(StringBuilder builder, int type, private void appendVCardPostalLine(StringBuilder builder, Integer type, String label,
String label, final ContentValues contentValues) { final ContentValues contentValues) {
builder.append(VCARD_PROPERTY_ADR); builder.append(VCARD_PROPERTY_ADR);
builder.append(VCARD_ATTR_SEPARATOR); builder.append(VCARD_ATTR_SEPARATOR);
@@ -1150,6 +1143,10 @@ public class VCardComposer {
} }
} }
if (type == null) {
type = StructuredPostal.TYPE_OTHER;
}
boolean typeIsAppended = false; boolean typeIsAppended = false;
switch (type) { switch (type) {
case StructuredPostal.TYPE_HOME: case StructuredPostal.TYPE_HOME:
@@ -1161,7 +1158,8 @@ public class VCardComposer {
typeIsAppended = true; typeIsAppended = true;
break; break;
case StructuredPostal.TYPE_CUSTOM: case StructuredPostal.TYPE_CUSTOM:
if (mUsesAndroidProperty && VCardUtils.containsOnlyAlphaDigitHyphen(label)){ if (mUsesAndroidProperty && !TextUtils.isEmpty(label)
&& VCardUtils.containsOnlyAlphaDigitHyphen(label)) {
// We're not sure whether the label is valid in the spec ("IANA-token" in the vCard 3.1 // We're not sure whether the label is valid in the spec ("IANA-token" in the vCard 3.1
// is unclear...) // is unclear...)
// Just for safety, we add "X-" at the beggining of each label. // Just for safety, we add "X-" at the beggining of each label.
@@ -1216,17 +1214,21 @@ public class VCardComposer {
builder.append(VCARD_COL_SEPARATOR); builder.append(VCARD_COL_SEPARATOR);
} }
private void appendVCardEmailLine(StringBuilder builder, int type, private void appendVCardEmailLine(StringBuilder builder, Integer type, String label, String data) {
String label, String data) {
builder.append(VCARD_PROPERTY_EMAIL); builder.append(VCARD_PROPERTY_EMAIL);
builder.append(VCARD_ATTR_SEPARATOR); builder.append(VCARD_ATTR_SEPARATOR);
if (type == null) {
type = Email.TYPE_OTHER;
}
switch (type) { switch (type) {
case Email.TYPE_CUSTOM: case Email.TYPE_CUSTOM:
if (label.equals( if (android.provider.Contacts.ContactMethodsColumns.MOBILE_EMAIL_TYPE_NAME
android.provider.Contacts.ContactMethodsColumns.MOBILE_EMAIL_TYPE_NAME)) { .equals(label)) {
builder.append(Constants.ATTR_TYPE_CELL); builder.append(Constants.ATTR_TYPE_CELL);
} else if (mUsesAndroidProperty && VCardUtils.containsOnlyAlphaDigitHyphen(label)){ } else if (mUsesAndroidProperty && !TextUtils.isEmpty(label)
&& VCardUtils.containsOnlyAlphaDigitHyphen(label)) {
builder.append("X-"); builder.append("X-");
builder.append(label); builder.append(label);
} else { } else {
@@ -1257,11 +1259,15 @@ public class VCardComposer {
builder.append(VCARD_COL_SEPARATOR); builder.append(VCARD_COL_SEPARATOR);
} }
private void appendVCardTelephoneLine(StringBuilder builder, int type, private void appendVCardTelephoneLine(StringBuilder builder, Integer type, String label,
String label, String encodedData) { String encodedData) {
builder.append(VCARD_PROPERTY_TEL); builder.append(VCARD_PROPERTY_TEL);
builder.append(VCARD_ATTR_SEPARATOR); builder.append(VCARD_ATTR_SEPARATOR);
if (type == null) {
type = Phone.TYPE_OTHER;
}
switch (type) { switch (type) {
case Phone.TYPE_HOME: case Phone.TYPE_HOME:
appendTypeAttributes(builder, Arrays.asList( appendTypeAttributes(builder, Arrays.asList(
@@ -1295,8 +1301,8 @@ public class VCardComposer {
builder.append(Constants.ATTR_TYPE_VOICE); builder.append(Constants.ATTR_TYPE_VOICE);
break; break;
case Phone.TYPE_CUSTOM: case Phone.TYPE_CUSTOM:
if (mUsesAndroidProperty) { if (mUsesAndroidProperty && !TextUtils.isEmpty(label)
VCardUtils.containsOnlyAlphaDigitHyphen(label); && VCardUtils.containsOnlyAlphaDigitHyphen(label)) {
builder.append("X-" + label); builder.append("X-" + label);
} else { } else {
// Just ignore the custom type. // Just ignore the custom type.
@@ -1316,11 +1322,10 @@ public class VCardComposer {
/** /**
* Appends phone type string which may not be available in some devices. * Appends phone type string which may not be available in some devices.
*/ */
private void appendUncommonPhoneType(StringBuilder builder, int type) { private void appendUncommonPhoneType(StringBuilder builder, Integer type) {
if (mIsDoCoMo) { if (mIsDoCoMo) {
// The previous implementation for DoCoMo had been conservative // The previous implementation for DoCoMo had been conservative
// about // about miscellaneous types.
// miscellaneous types.
builder.append(Constants.ATTR_TYPE_VOICE); builder.append(Constants.ATTR_TYPE_VOICE);
} else { } else {
String phoneAttribute = VCardUtils.getPhoneAttributeString(type); String phoneAttribute = VCardUtils.getPhoneAttributeString(type);

View File

@@ -75,7 +75,7 @@ public class VCardUtils {
sPhoneTypesSetUnknownToContacts.add(Constants.ATTR_TYPE_VIDEO); sPhoneTypesSetUnknownToContacts.add(Constants.ATTR_TYPE_VIDEO);
} }
public static String getPhoneAttributeString(int type) { public static String getPhoneAttributeString(Integer type) {
return sKnownPhoneTypesMap_ItoS.get(type); return sKnownPhoneTypesMap_ItoS.get(type);
} }