mirror of
https://github.com/zxing/zxing.git
synced 2024-11-10 04:54:04 -08:00
Issue 294, add support for several address lines in parsed results
git-svn-id: https://zxing.googlecode.com/svn/trunk@1148 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
2604ca4348
commit
6271b86315
|
@ -257,10 +257,14 @@ final class QRCodeEncoder {
|
|||
newContents.append("N:").append(names[0]).append(';');
|
||||
newDisplayContents.append(names[0]);
|
||||
}
|
||||
String address = contact.getAddress();
|
||||
if (address != null && address.length() > 0) {
|
||||
newContents.append("ADR:").append(address).append(';');
|
||||
newDisplayContents.append('\n').append(address);
|
||||
String[] addresses = contact.getAddresses();
|
||||
if (addresses != null) {
|
||||
for (int x = 0; x < addresses.length; x++) {
|
||||
if (addresses[x] != null && addresses[x].length() > 0) {
|
||||
newContents.append("ADR:").append(addresses[x]).append(';');
|
||||
newDisplayContents.append('\n').append(addresses[x]);
|
||||
}
|
||||
}
|
||||
}
|
||||
String[] phoneNumbers = contact.getPhoneNumbers();
|
||||
if (phoneNumbers != null) {
|
||||
|
|
|
@ -62,8 +62,8 @@ public final class AddressBookResultHandler extends ResultHandler {
|
|||
public AddressBookResultHandler(Activity activity, ParsedResult result) {
|
||||
super(activity, result);
|
||||
AddressBookParsedResult addressResult = (AddressBookParsedResult) result;
|
||||
String address = addressResult.getAddress();
|
||||
boolean hasAddress = address != null && address.length() > 0;
|
||||
String[] addresses = addressResult.getAddresses();
|
||||
boolean hasAddress = addresses != null && addresses.length > 0 && addresses[0].length() > 0;
|
||||
String[] phoneNumbers = addressResult.getPhoneNumbers();
|
||||
boolean hasPhoneNumber = phoneNumbers != null && phoneNumbers.length > 0;
|
||||
String[] emails = addressResult.getEmails();
|
||||
|
|
|
@ -46,8 +46,9 @@ final class AddressBookAUResultParser extends ResultParser {
|
|||
String[] emails = matchMultipleValuePrefix("MAIL", 3, rawText, true);
|
||||
String note = matchSinglePrefixedField("MEMORY:", rawText, '\r', false);
|
||||
String address = matchSinglePrefixedField("ADD:", rawText, '\r', true);
|
||||
String[] addresses = address == null ? null : new String[] {address};
|
||||
return new AddressBookParsedResult(maybeWrap(name), pronunciation, phoneNumbers, emails, note,
|
||||
address, null, null, null, null);
|
||||
addresses, null, null, null, null);
|
||||
}
|
||||
|
||||
private static String[] matchMultipleValuePrefix(String prefix, int max, String rawText,
|
||||
|
|
|
@ -49,7 +49,7 @@ final class AddressBookDoCoMoResultParser extends AbstractDoCoMoResultParser {
|
|||
String[] phoneNumbers = matchDoCoMoPrefixedField("TEL:", rawText, true);
|
||||
String[] emails = matchDoCoMoPrefixedField("EMAIL:", rawText, true);
|
||||
String note = matchSingleDoCoMoPrefixedField("NOTE:", rawText, false);
|
||||
String address = matchSingleDoCoMoPrefixedField("ADR:", rawText, true);
|
||||
String[] addresses = matchDoCoMoPrefixedField("ADR:", rawText, true);
|
||||
String birthday = matchSingleDoCoMoPrefixedField("BDAY:", rawText, true);
|
||||
if (birthday != null && !isStringOfDigits(birthday, 8)) {
|
||||
// No reason to throw out the whole card because the birthday is formatted wrong.
|
||||
|
@ -66,7 +66,7 @@ final class AddressBookDoCoMoResultParser extends AbstractDoCoMoResultParser {
|
|||
phoneNumbers,
|
||||
emails,
|
||||
note,
|
||||
address,
|
||||
addresses,
|
||||
org,
|
||||
birthday,
|
||||
null,
|
||||
|
|
|
@ -26,7 +26,7 @@ public final class AddressBookParsedResult extends ParsedResult {
|
|||
private final String[] phoneNumbers;
|
||||
private final String[] emails;
|
||||
private final String note;
|
||||
private final String address;
|
||||
private final String[] addresses;
|
||||
private final String org;
|
||||
private final String birthday;
|
||||
private final String title;
|
||||
|
@ -37,7 +37,7 @@ public final class AddressBookParsedResult extends ParsedResult {
|
|||
String[] phoneNumbers,
|
||||
String[] emails,
|
||||
String note,
|
||||
String address,
|
||||
String[] addresses,
|
||||
String org,
|
||||
String birthday,
|
||||
String title,
|
||||
|
@ -48,7 +48,7 @@ public final class AddressBookParsedResult extends ParsedResult {
|
|||
this.phoneNumbers = phoneNumbers;
|
||||
this.emails = emails;
|
||||
this.note = note;
|
||||
this.address = address;
|
||||
this.addresses = addresses;
|
||||
this.org = org;
|
||||
this.birthday = birthday;
|
||||
this.title = title;
|
||||
|
@ -81,8 +81,22 @@ public final class AddressBookParsedResult extends ParsedResult {
|
|||
return note;
|
||||
}
|
||||
|
||||
public String[] getAddresses() {
|
||||
return addresses;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
if (addresses == null || addresses.length == 0) {
|
||||
return null;
|
||||
}
|
||||
StringBuffer result = new StringBuffer();
|
||||
for (int i = 0; i < addresses.length; i++) {
|
||||
if (result.length() > 0) {
|
||||
result.append(' ');
|
||||
}
|
||||
result.append(addresses[i]);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
|
@ -110,7 +124,7 @@ public final class AddressBookParsedResult extends ParsedResult {
|
|||
maybeAppend(pronunciation, result);
|
||||
maybeAppend(title, result);
|
||||
maybeAppend(org, result);
|
||||
maybeAppend(address, result);
|
||||
maybeAppend(addresses, result);
|
||||
maybeAppend(phoneNumbers, result);
|
||||
maybeAppend(emails, result);
|
||||
maybeAppend(url, result);
|
||||
|
|
|
@ -43,7 +43,7 @@ final class BizcardResultParser extends AbstractDoCoMoResultParser {
|
|||
String fullName = buildName(firstName, lastName);
|
||||
String title = matchSingleDoCoMoPrefixedField("T:", rawText, true);
|
||||
String org = matchSingleDoCoMoPrefixedField("C:", rawText, true);
|
||||
String address = matchSingleDoCoMoPrefixedField("A:", rawText, true);
|
||||
String[] addresses = matchDoCoMoPrefixedField("A:", rawText, true);
|
||||
String phoneNumber1 = matchSingleDoCoMoPrefixedField("B:", rawText, true);
|
||||
String phoneNumber2 = matchSingleDoCoMoPrefixedField("M:", rawText, true);
|
||||
String phoneNumber3 = matchSingleDoCoMoPrefixedField("F:", rawText, true);
|
||||
|
@ -54,7 +54,7 @@ final class BizcardResultParser extends AbstractDoCoMoResultParser {
|
|||
buildPhoneNumbers(phoneNumber1, phoneNumber2, phoneNumber3),
|
||||
maybeWrap(email),
|
||||
null,
|
||||
address,
|
||||
addresses,
|
||||
org,
|
||||
null,
|
||||
title,
|
||||
|
|
|
@ -48,8 +48,12 @@ final class VCardResultParser extends ResultParser {
|
|||
String[] phoneNumbers = matchVCardPrefixedField("TEL", rawText, true);
|
||||
String[] emails = matchVCardPrefixedField("EMAIL", rawText, true);
|
||||
String note = matchSingleVCardPrefixedField("NOTE", rawText, false);
|
||||
String address = matchSingleVCardPrefixedField("ADR", rawText, true);
|
||||
address = formatAddress(address);
|
||||
String[] addresses = matchVCardPrefixedField("ADR", rawText, true);
|
||||
if (addresses != null) {
|
||||
for (int i = 0; i < addresses.length; i++) {
|
||||
addresses[i] = formatAddress(addresses[i]);
|
||||
}
|
||||
}
|
||||
String org = matchSingleVCardPrefixedField("ORG", rawText, true);
|
||||
String birthday = matchSingleVCardPrefixedField("BDAY", rawText, true);
|
||||
if (!isLikeVCardDate(birthday)) {
|
||||
|
@ -57,7 +61,7 @@ final class VCardResultParser extends ResultParser {
|
|||
}
|
||||
String title = matchSingleVCardPrefixedField("TITLE", rawText, true);
|
||||
String url = matchSingleVCardPrefixedField("URL", rawText, true);
|
||||
return new AddressBookParsedResult(names, null, phoneNumbers, emails, note, address, org,
|
||||
return new AddressBookParsedResult(names, null, phoneNumbers, emails, note, addresses, org,
|
||||
birthday, title, url);
|
||||
}
|
||||
|
||||
|
|
|
@ -43,20 +43,28 @@ public final class AddressBookParsedResultTestCase extends TestCase {
|
|||
|
||||
public void testVCard() {
|
||||
doTest("BEGIN:VCARD\r\nADR;HOME:123 Main St\r\nVERSION:2.1\r\nN:Owen;Sean\r\nEND:VCARD",
|
||||
null, new String[] {"Sean Owen"}, null, "123 Main St", null, null, null, null, null, null);
|
||||
null, new String[] {"Sean Owen"}, null, new String[] {"123 Main St"}, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
public void testBizcard() {
|
||||
doTest("BIZCARD:N:Sean;X:Owen;C:Google;A:123 Main St;M:+12125551212;E:srowen@example.org;",
|
||||
null, new String[] {"Sean Owen"}, null, "123 Main St", new String[] {"srowen@example.org"},
|
||||
null, new String[] {"Sean Owen"}, null, new String[] {"123 Main St"}, new String[] {"srowen@example.org"},
|
||||
new String[] {"+12125551212"}, "Google", null, null, null);
|
||||
}
|
||||
|
||||
public void testSeveralAddresses() {
|
||||
doTest("MECARD:N:Foo Bar;ORG:Company;TEL:5555555555;EMAIL:foo.bar@xyz.com;ADR:City, 10001;" +
|
||||
"ADR:City, 10001;NOTE:This is the memo.;;",
|
||||
null, new String[] {"Foo Bar"}, null, new String[] {"City, 10001", "City, 10001"},
|
||||
new String[] {"foo.bar@xyz.com"},
|
||||
new String[] {"5555555555" }, "Company", null, null, "This is the memo.");
|
||||
}
|
||||
|
||||
private static void doTest(String contents,
|
||||
String title,
|
||||
String[] names,
|
||||
String pronunciation,
|
||||
String address,
|
||||
String[] addresses,
|
||||
String[] emails,
|
||||
String[] phoneNumbers,
|
||||
String org,
|
||||
|
@ -70,7 +78,7 @@ public final class AddressBookParsedResultTestCase extends TestCase {
|
|||
assertEquals(title, addressResult.getTitle());
|
||||
assertTrue(Arrays.equals(names, addressResult.getNames()));
|
||||
assertEquals(pronunciation, addressResult.getPronunciation());
|
||||
assertEquals(address, addressResult.getAddress());
|
||||
assertTrue(Arrays.equals(addresses, addressResult.getAddresses()));
|
||||
assertTrue(Arrays.equals(emails, addressResult.getEmails()));
|
||||
assertTrue(Arrays.equals(phoneNumbers, addressResult.getPhoneNumbers()));
|
||||
assertEquals(org, addressResult.getOrg());
|
||||
|
|
Loading…
Reference in a new issue