am eb114de5: Merge change I639b0f03 into eclair-mr2
Merge commit 'eb114de5037bba89333bd7d57d305ae989727096' into eclair-mr2-plus-aosp
* commit 'eb114de5037bba89333bd7d57d305ae989727096':
Make vCard exporter append neighborhood to locality field instead of extended address,
diff --git a/core/java/android/pim/vcard/VCardBuilder.java b/core/java/android/pim/vcard/VCardBuilder.java
index 408d0ce..3980940 100644
--- a/core/java/android/pim/vcard/VCardBuilder.java
+++ b/core/java/android/pim/vcard/VCardBuilder.java
@@ -839,14 +839,14 @@
// ; PO Box, Extended Address, Street, Locality, Region, Postal
// ; Code, Country Name
final String rawPoBox = contentValues.getAsString(StructuredPostal.POBOX);
- final String rawExtendedAddress = contentValues.getAsString(StructuredPostal.NEIGHBORHOOD);
+ final String rawNeighborhood = contentValues.getAsString(StructuredPostal.NEIGHBORHOOD);
final String rawStreet = contentValues.getAsString(StructuredPostal.STREET);
final String rawLocality = contentValues.getAsString(StructuredPostal.CITY);
final String rawRegion = contentValues.getAsString(StructuredPostal.REGION);
final String rawPostalCode = contentValues.getAsString(StructuredPostal.POSTCODE);
final String rawCountry = contentValues.getAsString(StructuredPostal.COUNTRY);
final String[] rawAddressArray = new String[]{
- rawPoBox, rawExtendedAddress, rawStreet, rawLocality,
+ rawPoBox, rawNeighborhood, rawStreet, rawLocality,
rawRegion, rawPostalCode, rawCountry};
if (!VCardUtils.areAllEmpty(rawAddressArray)) {
final boolean reallyUseQuotedPrintable =
@@ -855,33 +855,55 @@
final boolean appendCharset =
!VCardUtils.containsOnlyPrintableAscii(rawAddressArray);
final String encodedPoBox;
- final String encodedExtendedAddress;
final String encodedStreet;
final String encodedLocality;
final String encodedRegion;
final String encodedPostalCode;
final String encodedCountry;
+ final String encodedNeighborhood;
+
+ final String rawLocality2;
+ // This looks inefficient since we encode rawLocality and rawNeighborhood twice,
+ // but this is intentional.
+ //
+ // QP encoding may add line feeds when needed and the result of
+ // - encodeQuotedPrintable(rawLocality + " " + rawNeighborhood)
+ // may be different from
+ // - encodedLocality + " " + encodedNeighborhood.
+ //
+ // We use safer way.
+ if (TextUtils.isEmpty(rawLocality)) {
+ if (TextUtils.isEmpty(rawNeighborhood)) {
+ rawLocality2 = "";
+ } else {
+ rawLocality2 = rawNeighborhood;
+ }
+ } else {
+ if (TextUtils.isEmpty(rawNeighborhood)) {
+ rawLocality2 = rawLocality;
+ } else {
+ rawLocality2 = rawLocality + " " + rawNeighborhood;
+ }
+ }
if (reallyUseQuotedPrintable) {
encodedPoBox = encodeQuotedPrintable(rawPoBox);
- encodedExtendedAddress = encodeQuotedPrintable(rawExtendedAddress);
encodedStreet = encodeQuotedPrintable(rawStreet);
- encodedLocality = encodeQuotedPrintable(rawLocality);
+ encodedLocality = encodeQuotedPrintable(rawLocality2);
encodedRegion = encodeQuotedPrintable(rawRegion);
encodedPostalCode = encodeQuotedPrintable(rawPostalCode);
encodedCountry = encodeQuotedPrintable(rawCountry);
} else {
encodedPoBox = escapeCharacters(rawPoBox);
- encodedExtendedAddress = escapeCharacters(rawExtendedAddress);
encodedStreet = escapeCharacters(rawStreet);
- encodedLocality = escapeCharacters(rawLocality);
+ encodedLocality = escapeCharacters(rawLocality2);
encodedRegion = escapeCharacters(rawRegion);
encodedPostalCode = escapeCharacters(rawPostalCode);
encodedCountry = escapeCharacters(rawCountry);
+ encodedNeighborhood = escapeCharacters(rawNeighborhood);
}
final StringBuffer addressBuffer = new StringBuffer();
addressBuffer.append(encodedPoBox);
addressBuffer.append(VCARD_ITEM_SEPARATOR);
- addressBuffer.append(encodedExtendedAddress);
addressBuffer.append(VCARD_ITEM_SEPARATOR);
addressBuffer.append(encodedStreet);
addressBuffer.append(VCARD_ITEM_SEPARATOR);
diff --git a/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardExporterTests.java b/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardExporterTests.java
index 616d451..212795b 100644
--- a/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardExporterTests.java
+++ b/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardExporterTests.java
@@ -563,9 +563,11 @@
// adr-value = 0*6(text-value ";") text-value
// ; PO Box, Extended Address, Street, Locality, Region, Postal Code,
// ; Country Name
+ //
+ // The NEIGHBORHOOD field is appended after the CITY field.
verifier.addPropertyNodesVerifierElemWithEmptyName()
.addNodeWithoutOrder("ADR",
- Arrays.asList("Pobox", "Neighborhood", "Street", "City",
+ Arrays.asList("Pobox", "", "Street", "City Neighborhood",
"Region", "100", "Country"), new TypeSet("WORK"));
verifier.verify();
}
@@ -578,6 +580,44 @@
testPostalAddressCommon(V30);
}
+ private void testPostalAddressNonNeighborhood(int vcardType) {
+ VCardVerifier verifier = new VCardVerifier(vcardType);
+ ContactEntry entry = verifier.addInputEntry();
+ entry.buildData(StructuredPostal.CONTENT_ITEM_TYPE)
+ .put(StructuredPostal.CITY, "City");
+ verifier.addPropertyNodesVerifierElemWithEmptyName()
+ .addNodeWithoutOrder("ADR",
+ Arrays.asList("", "", "", "City", "", "", ""), new TypeSet("HOME"));
+ verifier.verify();
+ }
+
+ public void testPostalAddressNonNeighborhoodV21() {
+ testPostalAddressNonNeighborhood(V21);
+ }
+
+ public void testPostalAddressNonNeighborhoodV30() {
+ testPostalAddressNonNeighborhood(V30);
+ }
+
+ private void testPostalAddressNonCity(int vcardType) {
+ VCardVerifier verifier = new VCardVerifier(vcardType);
+ ContactEntry entry = verifier.addInputEntry();
+ entry.buildData(StructuredPostal.CONTENT_ITEM_TYPE)
+ .put(StructuredPostal.NEIGHBORHOOD, "Neighborhood");
+ verifier.addPropertyNodesVerifierElemWithEmptyName()
+ .addNodeWithoutOrder("ADR",
+ Arrays.asList("", "", "", "Neighborhood", "", "", ""), new TypeSet("HOME"));
+ verifier.verify();
+ }
+
+ public void testPostalAddressNonCityV21() {
+ testPostalAddressNonCity(V21);
+ }
+
+ public void testPostalAddressNonCityV30() {
+ testPostalAddressNonCity(V30);
+ }
+
private void testPostalOnlyWithFormattedAddressCommon(int vcardType) {
VCardVerifier verifier = new VCardVerifier(vcardType);
ContactEntry entry = verifier.addInputEntry();
diff --git a/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardJapanizationTests.java b/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardJapanizationTests.java
index a54c958..5ce0dee 100644
--- a/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardJapanizationTests.java
+++ b/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardJapanizationTests.java
@@ -210,8 +210,6 @@
ContactEntry entry = verifier.addInputEntry();
entry.buildData(StructuredPostal.CONTENT_ITEM_TYPE)
.put(StructuredPostal.POBOX, "\u79C1\u66F8\u7BB107")
- .put(StructuredPostal.NEIGHBORHOOD,
- "\u30A2\u30D1\u30FC\u30C8\u0020\u0033\u0034\u53F7\u5BA4")
.put(StructuredPostal.STREET, "\u96DB\u898B\u6CA2\u6751")
.put(StructuredPostal.CITY, "\u9E7F\u9AA8\u5E02")
.put(StructuredPostal.REGION, "\u00D7\u00D7\u770C")
@@ -233,29 +231,22 @@
// LABEL must be ignored in vCard 2.1. As for vCard 3.0, the current behavior is
// same as that in vCard 3.0, which can be changed in the future.
elem.addNodeWithoutOrder("ADR", Arrays.asList("\u79C1\u66F8\u7BB107",
- "\u30A2\u30D1\u30FC\u30C8\u0020\u0033\u0034\u53F7\u5BA4",
- "\u96DB\u898B\u6CA2\u6751", "\u9E7F\u9AA8\u5E02", "\u00D7\u00D7\u770C",
+ "", "\u96DB\u898B\u6CA2\u6751", "\u9E7F\u9AA8\u5E02", "\u00D7\u00D7\u770C",
"494-1313", "\u65E5\u672C"),
contentValues);
- // NEIGHBORHOOD is "not" used. Instead, "Extended address" is appended into the
- // other field with a space.
verifier.addImportVerifier().addExpected(StructuredPostal.CONTENT_ITEM_TYPE)
.put(StructuredPostal.POBOX, "\u79C1\u66F8\u7BB107")
- .put(StructuredPostal.STREET, "\u96DB\u898B\u6CA2\u6751 "
- + "\u30A2\u30D1\u30FC\u30C8\u0020\u0033\u0034\u53F7\u5BA4")
- .put(StructuredPostal.CITY, "\u9E7F\u9AA8\u5E02")
+ .put(StructuredPostal.STREET, "\u96DB\u898B\u6CA2\u6751")
+ .put(StructuredPostal.CITY, "\u9E7F\u9AA8\u5E02")
.put(StructuredPostal.REGION, "\u00D7\u00D7\u770C")
.put(StructuredPostal.POSTCODE, "494-1313")
.put(StructuredPostal.COUNTRY, "\u65E5\u672C")
.put(StructuredPostal.FORMATTED_ADDRESS,
"\u65E5\u672C 494-1313 \u00D7\u00D7\u770C \u9E7F\u9AA8\u5E02 " +
- "\u96DB\u898B\u6CA2\u6751 "
- + "\u30A2\u30D1\u30FC\u30C8\u0020\u0033\u0034\u53F7\u5BA4 " +
- "\u79C1\u66F8\u7BB107")
+ "\u96DB\u898B\u6CA2\u6751 " + "\u79C1\u66F8\u7BB107")
.put(StructuredPostal.TYPE, StructuredPostal.TYPE_HOME);
verifier.verify();
}
-
public void testPostalAddresswithJapaneseV21() {
testPostalAddressWithJapaneseCommon(VCardConfig.VCARD_TYPE_V21_JAPANESE_SJIS);
}