mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Support GEO, NICKNAME from vCard (add as a 'note' in Android)
git-svn-id: https://zxing.googlecode.com/svn/trunk@2551 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
2d135af9c9
commit
b89f3d5e35
|
@ -123,6 +123,7 @@ public final class AddressBookResultHandler extends ResultHandler {
|
|||
switch (action) {
|
||||
case 0:
|
||||
addContact(addressResult.getNames(),
|
||||
addressResult.getNicknames(),
|
||||
addressResult.getPronunciation(),
|
||||
addressResult.getPhoneNumbers(),
|
||||
addressResult.getPhoneTypes(),
|
||||
|
@ -135,7 +136,8 @@ public final class AddressBookResultHandler extends ResultHandler {
|
|||
addressResult.getOrg(),
|
||||
addressResult.getTitle(),
|
||||
addressResult.getURL(),
|
||||
addressResult.getBirthday());
|
||||
addressResult.getBirthday(),
|
||||
addressResult.getGeo());
|
||||
break;
|
||||
case 1:
|
||||
String[] names = addressResult.getNames();
|
||||
|
|
|
@ -203,14 +203,15 @@ public abstract class ResultHandler {
|
|||
}
|
||||
|
||||
final void addPhoneOnlyContact(String[] phoneNumbers,String[] phoneTypes) {
|
||||
addContact(null, null, phoneNumbers, phoneTypes, null, null, null, null, null, null, null, null, null, null);
|
||||
addContact(null, null, null, phoneNumbers, phoneTypes, null, null, null, null, null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
final void addEmailOnlyContact(String[] emails, String[] emailTypes) {
|
||||
addContact(null, null, null, null, emails, emailTypes, null, null, null, null, null, null, null, null);
|
||||
addContact(null, null, null, null, null, emails, emailTypes, null, null, null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
final void addContact(String[] names,
|
||||
String[] nicknames,
|
||||
String pronunciation,
|
||||
String[] phoneNumbers,
|
||||
String[] phoneTypes,
|
||||
|
@ -223,7 +224,8 @@ public abstract class ResultHandler {
|
|||
String org,
|
||||
String title,
|
||||
String url,
|
||||
String birthday) {
|
||||
String birthday,
|
||||
String[] geo) {
|
||||
|
||||
// Only use the first name in the array, if present.
|
||||
Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT, ContactsContract.Contacts.CONTENT_URI);
|
||||
|
@ -258,14 +260,21 @@ public abstract class ResultHandler {
|
|||
StringBuilder aggregatedNotes = new StringBuilder();
|
||||
for (String aNote : new String[] { url, birthday, note }) {
|
||||
if (aNote != null) {
|
||||
if (aggregatedNotes.length() > 0) {
|
||||
aggregatedNotes.append('\n');
|
||||
}
|
||||
aggregatedNotes.append(aNote);
|
||||
aggregatedNotes.append('\n').append(aNote);
|
||||
}
|
||||
}
|
||||
if (nicknames != null) {
|
||||
for (String nickname : nicknames) {
|
||||
aggregatedNotes.append('\n').append(nickname);
|
||||
}
|
||||
}
|
||||
if (geo != null) {
|
||||
aggregatedNotes.append('\n').append(geo[0]).append(',').append(geo[1]);
|
||||
}
|
||||
|
||||
if (aggregatedNotes.length() > 0) {
|
||||
putExtra(intent, ContactsContract.Intents.Insert.NOTES, aggregatedNotes.toString());
|
||||
// Remove extra leading '\n'
|
||||
putExtra(intent, ContactsContract.Intents.Insert.NOTES, aggregatedNotes.substring(1));
|
||||
}
|
||||
|
||||
putExtra(intent, ContactsContract.Intents.Insert.IM_HANDLE, instantMessenger);
|
||||
|
|
|
@ -50,6 +50,7 @@ public final class AddressBookAUResultParser extends ResultParser {
|
|||
String address = matchSinglePrefixedField("ADD:", rawText, '\r', true);
|
||||
String[] addresses = address == null ? null : new String[] {address};
|
||||
return new AddressBookParsedResult(maybeWrap(name),
|
||||
null,
|
||||
pronunciation,
|
||||
phoneNumbers,
|
||||
null,
|
||||
|
@ -62,6 +63,7 @@ public final class AddressBookAUResultParser extends ResultParser {
|
|||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null);
|
||||
}
|
||||
|
||||
|
|
|
@ -63,6 +63,7 @@ public final class AddressBookDoCoMoResultParser extends AbstractDoCoMoResultPar
|
|||
String org = matchSingleDoCoMoPrefixedField("ORG:", rawText, true);
|
||||
|
||||
return new AddressBookParsedResult(maybeWrap(name),
|
||||
null,
|
||||
pronunciation,
|
||||
phoneNumbers,
|
||||
null,
|
||||
|
@ -75,7 +76,8 @@ public final class AddressBookDoCoMoResultParser extends AbstractDoCoMoResultPar
|
|||
org,
|
||||
birthday,
|
||||
null,
|
||||
url);
|
||||
url,
|
||||
null);
|
||||
}
|
||||
|
||||
private static String parseName(String name) {
|
||||
|
|
|
@ -22,6 +22,7 @@ package com.google.zxing.client.result;
|
|||
public final class AddressBookParsedResult extends ParsedResult {
|
||||
|
||||
private final String[] names;
|
||||
private final String[] nicknames;
|
||||
private final String pronunciation;
|
||||
private final String[] phoneNumbers;
|
||||
private final String[] phoneTypes;
|
||||
|
@ -35,8 +36,35 @@ public final class AddressBookParsedResult extends ParsedResult {
|
|||
private final String birthday;
|
||||
private final String title;
|
||||
private final String url;
|
||||
private final String[] geo;
|
||||
|
||||
public AddressBookParsedResult(String[] names,
|
||||
String[] phoneNumbers,
|
||||
String[] phoneTypes,
|
||||
String[] emails,
|
||||
String[] emailTypes,
|
||||
String[] addresses,
|
||||
String[] addressTypes) {
|
||||
this(names,
|
||||
null,
|
||||
null,
|
||||
phoneNumbers,
|
||||
phoneTypes,
|
||||
emails,
|
||||
emailTypes,
|
||||
null,
|
||||
null,
|
||||
addresses,
|
||||
addressTypes,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null);
|
||||
}
|
||||
|
||||
public AddressBookParsedResult(String[] names,
|
||||
String[] nicknames,
|
||||
String pronunciation,
|
||||
String[] phoneNumbers,
|
||||
String[] phoneTypes,
|
||||
|
@ -49,9 +77,11 @@ public final class AddressBookParsedResult extends ParsedResult {
|
|||
String org,
|
||||
String birthday,
|
||||
String title,
|
||||
String url) {
|
||||
String url,
|
||||
String[] geo) {
|
||||
super(ParsedResultType.ADDRESSBOOK);
|
||||
this.names = names;
|
||||
this.nicknames = nicknames;
|
||||
this.pronunciation = pronunciation;
|
||||
this.phoneNumbers = phoneNumbers;
|
||||
this.phoneTypes = phoneTypes;
|
||||
|
@ -65,12 +95,17 @@ public final class AddressBookParsedResult extends ParsedResult {
|
|||
this.birthday = birthday;
|
||||
this.title = title;
|
||||
this.url = url;
|
||||
this.geo = geo;
|
||||
}
|
||||
|
||||
public String[] getNames() {
|
||||
return names;
|
||||
}
|
||||
|
||||
public String[] getNicknames() {
|
||||
return nicknames;
|
||||
}
|
||||
|
||||
/**
|
||||
* In Japanese, the name is written in kanji, which can have multiple readings. Therefore a hint
|
||||
* is often provided, called furigana, which spells the name phonetically.
|
||||
|
@ -144,10 +179,18 @@ public final class AddressBookParsedResult extends ParsedResult {
|
|||
return birthday;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a location as a latitude/longitude pair
|
||||
*/
|
||||
public String[] getGeo() {
|
||||
return geo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayResult() {
|
||||
StringBuilder result = new StringBuilder(100);
|
||||
maybeAppend(names, result);
|
||||
maybeAppend(nicknames, result);
|
||||
maybeAppend(pronunciation, result);
|
||||
maybeAppend(title, result);
|
||||
maybeAppend(org, result);
|
||||
|
@ -157,6 +200,7 @@ public final class AddressBookParsedResult extends ParsedResult {
|
|||
maybeAppend(instantMessenger, result);
|
||||
maybeAppend(url, result);
|
||||
maybeAppend(birthday, result);
|
||||
maybeAppend(geo, result);
|
||||
maybeAppend(note, result);
|
||||
return result.toString();
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ public final class BizcardResultParser extends AbstractDoCoMoResultParser {
|
|||
String email = matchSingleDoCoMoPrefixedField("E:", rawText, true);
|
||||
|
||||
return new AddressBookParsedResult(maybeWrap(fullName),
|
||||
null,
|
||||
null,
|
||||
buildPhoneNumbers(phoneNumber1, phoneNumber2, phoneNumber3),
|
||||
null,
|
||||
|
@ -64,6 +65,7 @@ public final class BizcardResultParser extends AbstractDoCoMoResultParser {
|
|||
org,
|
||||
null,
|
||||
title,
|
||||
null,
|
||||
null);
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,8 @@ public final class VCardResultParser extends ResultParser {
|
|||
private static final Pattern EQUALS = Pattern.compile("=");
|
||||
private static final Pattern SEMICOLON = Pattern.compile(";");
|
||||
private static final Pattern UNESCAPED_SEMICOLONS = Pattern.compile("(?<!\\\\);+");
|
||||
private static final Pattern COMMA = Pattern.compile(",");
|
||||
private static final Pattern SEMICOLON_OR_COMMA = Pattern.compile("[;,]");
|
||||
|
||||
@Override
|
||||
public AddressBookParsedResult parse(Result result) {
|
||||
|
@ -59,6 +61,8 @@ public final class VCardResultParser extends ResultParser {
|
|||
names = matchVCardPrefixedField("N", rawText, true, false);
|
||||
formatNames(names);
|
||||
}
|
||||
List<String> nicknameString = matchSingleVCardPrefixedField("NICKNAME", rawText, true, false);
|
||||
String[] nicknames = nicknameString == null ? null : COMMA.split(nicknameString.get(0));
|
||||
List<List<String>> phoneNumbers = matchVCardPrefixedField("TEL", rawText, true, false);
|
||||
List<List<String>> emails = matchVCardPrefixedField("EMAIL", rawText, true, false);
|
||||
List<String> note = matchSingleVCardPrefixedField("NOTE", rawText, false, false);
|
||||
|
@ -71,7 +75,13 @@ public final class VCardResultParser extends ResultParser {
|
|||
List<String> title = matchSingleVCardPrefixedField("TITLE", rawText, true, false);
|
||||
List<String> url = matchSingleVCardPrefixedField("URL", rawText, true, false);
|
||||
List<String> instantMessenger = matchSingleVCardPrefixedField("IMPP", rawText, true, false);
|
||||
return new AddressBookParsedResult(toPrimaryValues(names),
|
||||
List<String> geoString = matchSingleVCardPrefixedField("GEO", rawText, true, false);
|
||||
String[] geo = geoString == null ? null : SEMICOLON_OR_COMMA.split(geoString.get(0));
|
||||
if (geo != null && geo.length != 2) {
|
||||
geo = null;
|
||||
}
|
||||
return new AddressBookParsedResult(toPrimaryValues(names),
|
||||
nicknames,
|
||||
null,
|
||||
toPrimaryValues(phoneNumbers),
|
||||
toTypes(phoneNumbers),
|
||||
|
@ -84,7 +94,8 @@ public final class VCardResultParser extends ResultParser {
|
|||
toPrimaryValue(org),
|
||||
toPrimaryValue(birthday),
|
||||
toPrimaryValue(title),
|
||||
toPrimaryValue(url));
|
||||
toPrimaryValue(url),
|
||||
geo);
|
||||
}
|
||||
|
||||
static List<List<String>> matchVCardPrefixedField(CharSequence prefix,
|
||||
|
|
Loading…
Reference in a new issue