am 0cda5911: Make vCard composer use ContentValues object with non-empty name unless the object is not marked as IS_SUPER_PRIMARY.
Merge commit '0cda59112526c03f3b8be0eb885926b7515df756' into eclair-mr2-plus-aosp * commit '0cda59112526c03f3b8be0eb885926b7515df756': Make vCard composer use ContentValues object with non-empty name unless the object is not marked as IS_SUPER_PRIMARY.
This commit is contained in:
@@ -676,6 +676,18 @@ public class VCardComposer {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean containsNonEmptyName(ContentValues contentValues) {
|
||||
final String familyName = contentValues.getAsString(StructuredName.FAMILY_NAME);
|
||||
final String middleName = contentValues.getAsString(StructuredName.MIDDLE_NAME);
|
||||
final String givenName = contentValues.getAsString(StructuredName.GIVEN_NAME);
|
||||
final String prefix = contentValues.getAsString(StructuredName.PREFIX);
|
||||
final String suffix = contentValues.getAsString(StructuredName.SUFFIX);
|
||||
final String displayName = contentValues.getAsString(StructuredName.DISPLAY_NAME);
|
||||
return !(TextUtils.isEmpty(familyName) && TextUtils.isEmpty(middleName) &&
|
||||
TextUtils.isEmpty(givenName) && TextUtils.isEmpty(prefix) &&
|
||||
TextUtils.isEmpty(suffix) && TextUtils.isEmpty(displayName));
|
||||
}
|
||||
|
||||
private void appendStructuredNamesInternal(final StringBuilder builder,
|
||||
final List<ContentValues> contentValuesList) {
|
||||
// For safety, we'll emit just one value around StructuredName, as external importers
|
||||
@@ -695,12 +707,14 @@ public class VCardComposer {
|
||||
} else if (primaryContentValues == null) {
|
||||
// We choose the first "primary" ContentValues
|
||||
// if "super primary" ContentValues does not exist.
|
||||
Integer primary = contentValues.getAsInteger(StructuredName.IS_PRIMARY);
|
||||
if (primary != null && primary > 0) {
|
||||
Integer isPrimary = contentValues.getAsInteger(StructuredName.IS_PRIMARY);
|
||||
if (isPrimary != null && isPrimary > 0 &&
|
||||
containsNonEmptyName(contentValues)) {
|
||||
primaryContentValues = contentValues;
|
||||
// Do not break, since there may be ContentValues with "super primary"
|
||||
// afterword.
|
||||
} else if (subprimaryContentValues == null) {
|
||||
} else if (subprimaryContentValues == null &&
|
||||
containsNonEmptyName(contentValues)) {
|
||||
subprimaryContentValues = contentValues;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -903,4 +903,34 @@ public class VCardExporterTests extends VCardTestsBase {
|
||||
.addNodeWithoutOrder("TEL", "777-888-9999", new TypeSet("HOME"));
|
||||
verifier.verify();
|
||||
}
|
||||
|
||||
private void testPickUpNonEmptyContentValuesCommon(int version) {
|
||||
ExportTestResolver resolver = new ExportTestResolver();
|
||||
ContactEntry entry = resolver.buildContactEntry();
|
||||
entry.buildData(StructuredName.CONTENT_ITEM_TYPE)
|
||||
.put(StructuredName.IS_PRIMARY, 1); // Empty name. Should be ignored.
|
||||
entry.buildData(StructuredName.CONTENT_ITEM_TYPE)
|
||||
.put(StructuredName.FAMILY_NAME, "family1"); // Not primary. Should be ignored.
|
||||
entry.buildData(StructuredName.CONTENT_ITEM_TYPE)
|
||||
.put(StructuredName.IS_PRIMARY, 1)
|
||||
.put(StructuredName.FAMILY_NAME, "family2"); // This entry is what we want.
|
||||
entry.buildData(StructuredName.CONTENT_ITEM_TYPE)
|
||||
.put(StructuredName.IS_PRIMARY, 1)
|
||||
.put(StructuredName.FAMILY_NAME, "family3");
|
||||
entry.buildData(StructuredName.CONTENT_ITEM_TYPE)
|
||||
.put(StructuredName.FAMILY_NAME, "family4");
|
||||
VCardVerifier verifier = new VCardVerifier(resolver, version);
|
||||
verifier.addPropertyNodesVerifierElem()
|
||||
.addNodeWithoutOrder("N", Arrays.asList("family2", "", "", "", ""))
|
||||
.addNodeWithoutOrder("FN", "family2");
|
||||
verifier.verify();
|
||||
}
|
||||
|
||||
public void testPickUpNonEmptyContentValuesV21() {
|
||||
testPickUpNonEmptyContentValuesCommon(V21);
|
||||
}
|
||||
|
||||
public void testPickUpNonEmptyContentValuesV30() {
|
||||
testPickUpNonEmptyContentValuesCommon(V30);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user