mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Big refactoring of ParsedResult: now split into ResultParser and ParsedResult classes, per Christian's suggestion. This unifies the parsed results that are produced from various input, simplifying client handling of different types.
git-svn-id: https://zxing.googlecode.com/svn/trunk@482 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
7780ada5ad
commit
011e6e9cee
|
@ -17,23 +17,23 @@
|
|||
package com.google.zxing.client.android;
|
||||
|
||||
import android.content.Intent;
|
||||
import com.google.zxing.client.result.ParsedReaderResult;
|
||||
import com.google.zxing.client.result.ParsedReaderResultType;
|
||||
import com.google.zxing.client.result.ParsedResult;
|
||||
import com.google.zxing.client.result.ParsedResultType;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
/**
|
||||
* A {@link ParsedReaderResult} derived from a URI that encodes an Android
|
||||
* A {@link com.google.zxing.client.result.ParsedResult} derived from a URI that encodes an Android
|
||||
* {@link Intent}, and which should presumably trigger that intent on Android.
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class AndroidIntentParsedResult extends ParsedReaderResult {
|
||||
public final class AndroidIntentParsedResult extends ParsedResult {
|
||||
|
||||
private final Intent intent;
|
||||
|
||||
private AndroidIntentParsedResult(Intent intent) {
|
||||
super(ParsedReaderResultType.ANDROID_INTENT);
|
||||
super(ParsedResultType.ANDROID_INTENT);
|
||||
this.intent = intent;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,8 +31,9 @@ import android.view.Window;
|
|||
import android.widget.TextView;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.client.result.ParsedReaderResult;
|
||||
import com.google.zxing.client.result.ParsedReaderResultType;
|
||||
import com.google.zxing.client.result.ParsedResult;
|
||||
import com.google.zxing.client.result.ParsedResultType;
|
||||
import com.google.zxing.client.result.ResultParser;
|
||||
|
||||
/**
|
||||
* The barcode reader activity itself. This is loosely based on the CameraPreview
|
||||
|
@ -182,15 +183,15 @@ public final class BarcodeReaderCaptureActivity extends Activity {
|
|||
}
|
||||
|
||||
TextView textView = (TextView) findViewById(R.id.status_text_view);
|
||||
ParsedReaderResult readerResult = parseReaderResult(rawResult);
|
||||
textView.setText(readerResult.getDisplayResult() + " (" + duration + " ms)");
|
||||
ParsedResult result = parseReaderResult(rawResult);
|
||||
textView.setText(result.getDisplayResult() + " (" + duration + " ms)");
|
||||
|
||||
TextView actionButton = (TextView) findViewById(R.id.status_action_button);
|
||||
int buttonText = getActionButtonText(readerResult.getType());
|
||||
int buttonText = getActionButtonText(result.getType());
|
||||
if (buttonText != 0) {
|
||||
actionButton.setVisibility(View.VISIBLE);
|
||||
actionButton.setText(buttonText);
|
||||
View.OnClickListener handler = new ResultHandler(this, readerResult);
|
||||
View.OnClickListener handler = new ResultHandler(this, result);
|
||||
actionButton.setOnClickListener(handler);
|
||||
actionButton.requestFocus();
|
||||
} else {
|
||||
|
@ -227,9 +228,9 @@ public final class BarcodeReaderCaptureActivity extends Activity {
|
|||
statusView.setBackgroundColor(0x50000000);
|
||||
}
|
||||
|
||||
private static ParsedReaderResult parseReaderResult(Result rawResult) {
|
||||
ParsedReaderResult readerResult = ParsedReaderResult.parseReaderResult(rawResult);
|
||||
if (readerResult.getType().equals(ParsedReaderResultType.TEXT)) {
|
||||
private static ParsedResult parseReaderResult(Result rawResult) {
|
||||
ParsedResult result = ResultParser.parseReaderResult(rawResult);
|
||||
if (result.getType().equals(ParsedResultType.TEXT)) {
|
||||
String rawText = rawResult.getText();
|
||||
AndroidIntentParsedResult androidResult = AndroidIntentParsedResult.parse(rawText);
|
||||
if (androidResult != null) {
|
||||
|
@ -237,29 +238,26 @@ public final class BarcodeReaderCaptureActivity extends Activity {
|
|||
if (!Intent.VIEW_ACTION.equals(intent.getAction())) {
|
||||
// For now, don't take anything that just parses as a View action. A lot
|
||||
// of things are accepted as a View action by default.
|
||||
readerResult = androidResult;
|
||||
result = androidResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
return readerResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int getActionButtonText(ParsedReaderResultType type) {
|
||||
private static int getActionButtonText(ParsedResultType type) {
|
||||
int buttonText;
|
||||
if (type.equals(ParsedReaderResultType.ADDRESSBOOK)) {
|
||||
if (type.equals(ParsedResultType.ADDRESSBOOK)) {
|
||||
buttonText = R.string.button_add_contact;
|
||||
} else if (type.equals(ParsedReaderResultType.URI) ||
|
||||
type.equals(ParsedReaderResultType.BOOKMARK) ||
|
||||
type.equals(ParsedReaderResultType.URLTO)) {
|
||||
} else if (type.equals(ParsedResultType.URI)) {
|
||||
buttonText = R.string.button_open_browser;
|
||||
} else if (type.equals(ParsedReaderResultType.EMAIL) ||
|
||||
type.equals(ParsedReaderResultType.EMAIL_ADDRESS)) {
|
||||
} else if (type.equals(ParsedResultType.EMAIL_ADDRESS)) {
|
||||
buttonText = R.string.button_email;
|
||||
} else if (type.equals(ParsedReaderResultType.UPC)) {
|
||||
} else if (type.equals(ParsedResultType.UPC)) {
|
||||
buttonText = R.string.button_lookup_product;
|
||||
} else if (type.equals(ParsedReaderResultType.TEL)) {
|
||||
} else if (type.equals(ParsedResultType.TEL)) {
|
||||
buttonText = R.string.button_dial;
|
||||
} else if (type.equals(ParsedReaderResultType.GEO)) {
|
||||
} else if (type.equals(ParsedResultType.GEO)) {
|
||||
buttonText = R.string.button_show_map;
|
||||
} else {
|
||||
buttonText = 0;
|
||||
|
|
|
@ -21,20 +21,15 @@ import android.net.Uri;
|
|||
import android.provider.Contacts;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import com.google.zxing.client.result.AddressBookAUParsedResult;
|
||||
import com.google.zxing.client.result.AddressBookDoCoMoParsedResult;
|
||||
import com.google.zxing.client.result.BookmarkDoCoMoParsedResult;
|
||||
import com.google.zxing.client.result.AddressBookParsedResult;
|
||||
import com.google.zxing.client.result.EmailAddressParsedResult;
|
||||
import com.google.zxing.client.result.EmailDoCoMoParsedResult;
|
||||
import com.google.zxing.client.result.GeoParsedResult;
|
||||
import com.google.zxing.client.result.ParsedReaderResult;
|
||||
import com.google.zxing.client.result.ParsedReaderResultType;
|
||||
import com.google.zxing.client.result.ParsedResult;
|
||||
import com.google.zxing.client.result.ParsedResultType;
|
||||
import com.google.zxing.client.result.SMSParsedResult;
|
||||
import com.google.zxing.client.result.SMSTOParsedResult;
|
||||
import com.google.zxing.client.result.TelParsedResult;
|
||||
import com.google.zxing.client.result.UPCParsedResult;
|
||||
import com.google.zxing.client.result.URIParsedResult;
|
||||
import com.google.zxing.client.result.URLTOParsedResult;
|
||||
|
||||
/**
|
||||
* Handles the result of barcode decoding in the context of the Android platform,
|
||||
|
@ -48,65 +43,44 @@ final class ResultHandler implements Button.OnClickListener {
|
|||
private final Intent intent;
|
||||
private final BarcodeReaderCaptureActivity captureActivity;
|
||||
|
||||
ResultHandler(BarcodeReaderCaptureActivity captureActivity, ParsedReaderResult result) {
|
||||
ResultHandler(BarcodeReaderCaptureActivity captureActivity, ParsedResult result) {
|
||||
this.captureActivity = captureActivity;
|
||||
this.intent = resultToIntent(result);
|
||||
}
|
||||
|
||||
private static Intent resultToIntent(ParsedReaderResult result) {
|
||||
private static Intent resultToIntent(ParsedResult result) {
|
||||
Intent intent = null;
|
||||
ParsedReaderResultType type = result.getType();
|
||||
if (type.equals(ParsedReaderResultType.ADDRESSBOOK)) {
|
||||
AddressBookDoCoMoParsedResult addressResult = (AddressBookDoCoMoParsedResult) result;
|
||||
intent = new Intent(Contacts.Intents.Insert.ACTION, Contacts.People.CONTENT_URI);
|
||||
putExtra(intent, Contacts.Intents.Insert.NAME, addressResult.getName());
|
||||
putExtra(intent, Contacts.Intents.Insert.PHONE, addressResult.getPhoneNumbers());
|
||||
putExtra(intent, Contacts.Intents.Insert.EMAIL, addressResult.getEmail());
|
||||
putExtra(intent, Contacts.Intents.Insert.NOTES, addressResult.getNote());
|
||||
putExtra(intent, Contacts.Intents.Insert.POSTAL, addressResult.getAddress());
|
||||
} else if (type.equals(ParsedReaderResultType.ADDRESSBOOK_AU)) {
|
||||
AddressBookAUParsedResult addressResult = (AddressBookAUParsedResult) result;
|
||||
ParsedResultType type = result.getType();
|
||||
if (type.equals(ParsedResultType.ADDRESSBOOK)) {
|
||||
AddressBookParsedResult addressResult = (AddressBookParsedResult) result;
|
||||
intent = new Intent(Contacts.Intents.Insert.ACTION, Contacts.People.CONTENT_URI);
|
||||
putExtra(intent, Contacts.Intents.Insert.NAME, addressResult.getNames());
|
||||
putExtra(intent, Contacts.Intents.Insert.PHONE, addressResult.getPhoneNumbers());
|
||||
putExtra(intent, Contacts.Intents.Insert.EMAIL, addressResult.getEmails());
|
||||
putExtra(intent, Contacts.Intents.Insert.NOTES, addressResult.getNote());
|
||||
putExtra(intent, Contacts.Intents.Insert.POSTAL, addressResult.getAddress());
|
||||
} else if (type.equals(ParsedReaderResultType.BOOKMARK)) {
|
||||
// For now, we can only open the browser, and not actually add a bookmark
|
||||
intent = new Intent(Intent.VIEW_ACTION, Uri.parse(((BookmarkDoCoMoParsedResult) result).getURI()));
|
||||
} else if (type.equals(ParsedReaderResultType.URLTO)) {
|
||||
intent = new Intent(Intent.VIEW_ACTION, Uri.parse(((URLTOParsedResult) result).getURI()));
|
||||
} else if (type.equals(ParsedReaderResultType.EMAIL)) {
|
||||
EmailDoCoMoParsedResult emailResult = (EmailDoCoMoParsedResult) result;
|
||||
intent = new Intent(Intent.SENDTO_ACTION, Uri.parse(emailResult.getMailtoURI()));
|
||||
putExtra(intent, "subject", emailResult.getSubject());
|
||||
putExtra(intent, "body", emailResult.getBody());
|
||||
} else if (type.equals(ParsedReaderResultType.EMAIL_ADDRESS)) {
|
||||
} else if (type.equals(ParsedResultType.EMAIL_ADDRESS)) {
|
||||
EmailAddressParsedResult emailResult = (EmailAddressParsedResult) result;
|
||||
intent = new Intent(Intent.SENDTO_ACTION, Uri.parse(emailResult.getMailtoURI()));
|
||||
putExtra(intent, "subject", emailResult.getSubject());
|
||||
putExtra(intent, "body", emailResult.getBody());
|
||||
} else if (type.equals(ParsedReaderResultType.SMS)) {
|
||||
} else if (type.equals(ParsedResultType.SMS)) {
|
||||
SMSParsedResult smsResult = (SMSParsedResult) result;
|
||||
intent = new Intent(Intent.SENDTO_ACTION, Uri.parse(smsResult.getSMSURI()));
|
||||
} else if (type.equals(ParsedReaderResultType.SMSTO)) {
|
||||
SMSTOParsedResult smsToResult = (SMSTOParsedResult) result;
|
||||
intent = new Intent(Intent.SENDTO_ACTION, Uri.parse(smsToResult.getSMSURI()));
|
||||
} else if (type.equals(ParsedReaderResultType.TEL)) {
|
||||
} else if (type.equals(ParsedResultType.TEL)) {
|
||||
TelParsedResult telResult = (TelParsedResult) result;
|
||||
intent = new Intent(Intent.DIAL_ACTION, Uri.parse(telResult.getTelURI()));
|
||||
} else if (type.equals(ParsedReaderResultType.GEO)) {
|
||||
} else if (type.equals(ParsedResultType.GEO)) {
|
||||
GeoParsedResult geoResult = (GeoParsedResult) result;
|
||||
intent = new Intent(Intent.VIEW_ACTION, Uri.parse(geoResult.getGeoURI()));
|
||||
} else if (type.equals(ParsedReaderResultType.UPC)) {
|
||||
} else if (type.equals(ParsedResultType.UPC)) {
|
||||
UPCParsedResult upcResult = (UPCParsedResult) result;
|
||||
Uri uri = Uri.parse("http://www.upcdatabase.com/item.asp?upc=" + upcResult.getUPC());
|
||||
intent = new Intent(Intent.VIEW_ACTION, uri);
|
||||
} else if (type.equals(ParsedReaderResultType.URI)) {
|
||||
} else if (type.equals(ParsedResultType.URI)) {
|
||||
URIParsedResult uriResult = (URIParsedResult) result;
|
||||
intent = new Intent(Intent.VIEW_ACTION, Uri.parse(uriResult.getURI()));
|
||||
} else if (type.equals(ParsedReaderResultType.ANDROID_INTENT)) {
|
||||
} else if (type.equals(ParsedResultType.ANDROID_INTENT)) {
|
||||
intent = ((AndroidIntentParsedResult) result).getIntent();
|
||||
}
|
||||
return intent;
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* <p>See
|
||||
* <a href="http://www.nttdocomo.co.jp/english/service/imode/make/content/barcode/about/s2.html">
|
||||
|
@ -28,78 +26,10 @@ import java.util.Vector;
|
|||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
abstract class AbstractDoCoMoParsedResult extends ParsedReaderResult {
|
||||
abstract class AbstractDoCoMoParsedResult extends ParsedResult {
|
||||
|
||||
AbstractDoCoMoParsedResult(ParsedReaderResultType type) {
|
||||
AbstractDoCoMoParsedResult(ParsedResultType type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
// This could as well be implemented with java.util.regex. It was already implemented partially
|
||||
// to run in a J2ME enviroment, where this unavailable.
|
||||
|
||||
static String[] matchPrefixedField(String prefix, String rawText) {
|
||||
return matchPrefixedField(prefix, rawText, ';');
|
||||
}
|
||||
|
||||
private static String[] matchPrefixedField(String prefix, String rawText, char endChar) {
|
||||
Vector matches = null;
|
||||
int i = 0;
|
||||
int max = rawText.length();
|
||||
while (i < max) {
|
||||
i = rawText.indexOf(prefix, i);
|
||||
if (i < 0) {
|
||||
break;
|
||||
}
|
||||
i += prefix.length(); // Skip past this prefix we found to start
|
||||
int start = i; // Found the start of a match here
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
i = rawText.indexOf((int) endChar, i);
|
||||
if (i < 0) {
|
||||
// No terminating end character? uh, done. Set i such that loop terminates and break
|
||||
i = rawText.length();
|
||||
done = true;
|
||||
} else if (rawText.charAt(i - 1) == '\\') {
|
||||
// semicolon was escaped so continue
|
||||
i++;
|
||||
} else {
|
||||
// found a match
|
||||
if (matches == null) {
|
||||
matches = new Vector(3); // lazy init
|
||||
}
|
||||
matches.addElement(unescapeBackslash(rawText.substring(start, i)));
|
||||
i++;
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (matches == null || matches.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
int size = matches.size();
|
||||
String[] result = new String[size];
|
||||
for (int j = 0; j < size; j++) {
|
||||
result[j] = (String) matches.elementAt(j);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static String matchSinglePrefixedField(String prefix, String rawText) {
|
||||
return matchSinglePrefixedField(prefix, rawText, ';');
|
||||
}
|
||||
|
||||
static String matchSinglePrefixedField(String prefix, String rawText, char endChar) {
|
||||
String[] matches = matchPrefixedField(prefix, rawText, endChar);
|
||||
return matches == null ? null : matches[0];
|
||||
}
|
||||
|
||||
static void maybeAppend(String[] value, StringBuffer result) {
|
||||
if (value != null) {
|
||||
for (int i = 0; i < value.length; i++) {
|
||||
result.append('\n');
|
||||
result.append(value[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright 2007 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* <p>See
|
||||
* <a href="http://www.nttdocomo.co.jp/english/service/imode/make/content/barcode/about/s2.html">
|
||||
* DoCoMo's documentation</a> about the result types represented by subclasses of this class.</p>
|
||||
*
|
||||
* <p>Thanks to Jeff Griffin for proposing rewrite of these classes that relies less
|
||||
* on exception-based mechanisms during parsing.</p>
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
abstract class AbstractDoCoMoResultParser extends ResultParser {
|
||||
|
||||
// This could as well be implemented with java.util.regex. It was already implemented partially
|
||||
// to run in a J2ME enviroment, where this unavailable.
|
||||
|
||||
static String[] matchPrefixedField(String prefix, String rawText) {
|
||||
return matchPrefixedField(prefix, rawText, ';');
|
||||
}
|
||||
|
||||
static String[] matchPrefixedField(String prefix, String rawText, char endChar) {
|
||||
Vector matches = null;
|
||||
int i = 0;
|
||||
int max = rawText.length();
|
||||
while (i < max) {
|
||||
i = rawText.indexOf(prefix, i);
|
||||
if (i < 0) {
|
||||
break;
|
||||
}
|
||||
i += prefix.length(); // Skip past this prefix we found to start
|
||||
int start = i; // Found the start of a match here
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
i = rawText.indexOf((int) endChar, i);
|
||||
if (i < 0) {
|
||||
// No terminating end character? uh, done. Set i such that loop terminates and break
|
||||
i = rawText.length();
|
||||
done = true;
|
||||
} else if (rawText.charAt(i - 1) == '\\') {
|
||||
// semicolon was escaped so continue
|
||||
i++;
|
||||
} else {
|
||||
// found a match
|
||||
if (matches == null) {
|
||||
matches = new Vector(3); // lazy init
|
||||
}
|
||||
matches.addElement(unescapeBackslash(rawText.substring(start, i)));
|
||||
i++;
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (matches == null || matches.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
int size = matches.size();
|
||||
String[] result = new String[size];
|
||||
for (int j = 0; j < size; j++) {
|
||||
result[j] = (String) matches.elementAt(j);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static String matchSinglePrefixedField(String prefix, String rawText) {
|
||||
return matchSinglePrefixedField(prefix, rawText, ';');
|
||||
}
|
||||
|
||||
static String matchSinglePrefixedField(String prefix, String rawText, char endChar) {
|
||||
String[] matches = matchPrefixedField(prefix, rawText, endChar);
|
||||
return matches == null ? null : matches[0];
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -28,24 +28,9 @@ import java.util.Vector;
|
|||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class AddressBookAUParsedResult extends ParsedReaderResult {
|
||||
public final class AddressBookAUResultParser extends ResultParser {
|
||||
|
||||
private final String[] names;
|
||||
private final String[] phoneNumbers;
|
||||
private final String[] emails;
|
||||
private final String note;
|
||||
private final String address;
|
||||
|
||||
private AddressBookAUParsedResult(String[] names, String[] phoneNumbers, String[] emails, String note, String address) {
|
||||
super(ParsedReaderResultType.ADDRESSBOOK_AU);
|
||||
this.names = names;
|
||||
this.phoneNumbers = phoneNumbers;
|
||||
this.emails = emails;
|
||||
this.note = note;
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public static AddressBookAUParsedResult parse(Result result) {
|
||||
public static AddressBookParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
// MEMORY is mandatory; seems like a decent indicator, as does end-of-record separator CR/LF
|
||||
if (rawText == null || rawText.indexOf("MEMORY") < 0 || rawText.indexOf("\r\n") < 0) {
|
||||
|
@ -54,15 +39,15 @@ public final class AddressBookAUParsedResult extends ParsedReaderResult {
|
|||
String[] names = matchMultipleValuePrefix("NAME", 2, rawText);
|
||||
String[] phoneNumbers = matchMultipleValuePrefix("TEL", 3, rawText);
|
||||
String[] emails = matchMultipleValuePrefix("MAIL", 3, rawText);
|
||||
String note = AbstractDoCoMoParsedResult.matchSinglePrefixedField("MEMORY:", rawText, '\r');
|
||||
String address = AbstractDoCoMoParsedResult.matchSinglePrefixedField("ADD:", rawText, '\r');
|
||||
return new AddressBookAUParsedResult(names, phoneNumbers, emails, note, address);
|
||||
String note = AbstractDoCoMoResultParser.matchSinglePrefixedField("MEMORY:", rawText, '\r');
|
||||
String address = AbstractDoCoMoResultParser.matchSinglePrefixedField("ADD:", rawText, '\r');
|
||||
return new AddressBookParsedResult(names, phoneNumbers, emails, note, address, null, null, null);
|
||||
}
|
||||
|
||||
private static String[] matchMultipleValuePrefix(String prefix, int max, String rawText) {
|
||||
Vector values = null;
|
||||
for (int i = 1; i <= max; i++) {
|
||||
String value = AbstractDoCoMoParsedResult.matchSinglePrefixedField(prefix + i + ':', rawText, '\r');
|
||||
String value = AbstractDoCoMoResultParser.matchSinglePrefixedField(prefix + i + ':', rawText, '\r');
|
||||
if (value == null) {
|
||||
break;
|
||||
}
|
||||
|
@ -81,34 +66,5 @@ public final class AddressBookAUParsedResult extends ParsedReaderResult {
|
|||
return result;
|
||||
}
|
||||
|
||||
public String[] getNames() {
|
||||
return names;
|
||||
}
|
||||
|
||||
public String[] getPhoneNumbers() {
|
||||
return phoneNumbers;
|
||||
}
|
||||
|
||||
public String[] getEmails() {
|
||||
return emails;
|
||||
}
|
||||
|
||||
public String getNote() {
|
||||
return note;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
StringBuffer result = new StringBuffer();
|
||||
AbstractDoCoMoParsedResult.maybeAppend(names, result);
|
||||
AbstractDoCoMoParsedResult.maybeAppend(emails, result);
|
||||
AbstractDoCoMoParsedResult.maybeAppend(address, result);
|
||||
AbstractDoCoMoParsedResult.maybeAppend(phoneNumbers, result);
|
||||
AbstractDoCoMoParsedResult.maybeAppend(note, result);
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -28,24 +28,9 @@ import com.google.zxing.Result;
|
|||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class AddressBookDoCoMoParsedResult extends AbstractDoCoMoParsedResult {
|
||||
public final class AddressBookDoCoMoResultParser extends AbstractDoCoMoResultParser {
|
||||
|
||||
private final String name;
|
||||
private final String[] phoneNumbers;
|
||||
private final String email;
|
||||
private final String note;
|
||||
private final String address;
|
||||
|
||||
private AddressBookDoCoMoParsedResult(String name, String[] phoneNumbers, String email, String note, String address) {
|
||||
super(ParsedReaderResultType.ADDRESSBOOK);
|
||||
this.name = name;
|
||||
this.phoneNumbers = phoneNumbers;
|
||||
this.email = email;
|
||||
this.note = note;
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public static AddressBookDoCoMoParsedResult parse(Result result) {
|
||||
public static AddressBookParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (rawText == null || !rawText.startsWith("MECARD:")) {
|
||||
return null;
|
||||
|
@ -59,36 +44,14 @@ public final class AddressBookDoCoMoParsedResult extends AbstractDoCoMoParsedRes
|
|||
String email = matchSinglePrefixedField("EMAIL:", rawText);
|
||||
String note = matchSinglePrefixedField("NOTE:", rawText);
|
||||
String address = matchSinglePrefixedField("ADR:", rawText);
|
||||
return new AddressBookDoCoMoParsedResult(name, phoneNumbers, email, note, address);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String[] getPhoneNumbers() {
|
||||
return phoneNumbers;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public String getNote() {
|
||||
return note;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
StringBuffer result = new StringBuffer(name);
|
||||
maybeAppend(email, result);
|
||||
maybeAppend(address, result);
|
||||
maybeAppend(phoneNumbers, result);
|
||||
maybeAppend(note, result);
|
||||
return result.toString();
|
||||
return new AddressBookParsedResult(new String[] {name},
|
||||
phoneNumbers,
|
||||
new String[] {email},
|
||||
note,
|
||||
address,
|
||||
null,
|
||||
null,
|
||||
null);
|
||||
}
|
||||
|
||||
private static String parseName(String name) {
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* Copyright 2007 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
/**
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class AddressBookParsedResult extends AbstractDoCoMoParsedResult {
|
||||
|
||||
private final String[] names;
|
||||
private final String[] phoneNumbers;
|
||||
private final String[] emails;
|
||||
private final String note;
|
||||
private final String address;
|
||||
private final String org;
|
||||
private final String birthday;
|
||||
private final String title;
|
||||
|
||||
public AddressBookParsedResult(String[] names,
|
||||
String[] phoneNumbers,
|
||||
String[] emails,
|
||||
String note,
|
||||
String address,
|
||||
String org,
|
||||
String birthday,
|
||||
String title) {
|
||||
super(ParsedResultType.ADDRESSBOOK);
|
||||
this.names = names;
|
||||
this.phoneNumbers = phoneNumbers;
|
||||
this.emails = emails;
|
||||
this.note = note;
|
||||
this.address = address;
|
||||
this.org = org;
|
||||
this.birthday = birthday;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String[] getNames() {
|
||||
return names;
|
||||
}
|
||||
|
||||
public String[] getPhoneNumbers() {
|
||||
return phoneNumbers;
|
||||
}
|
||||
|
||||
public String[] getEmails() {
|
||||
return emails;
|
||||
}
|
||||
|
||||
public String getNote() {
|
||||
return note;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getOrg() {
|
||||
return org;
|
||||
}
|
||||
|
||||
public String getBirthday() {
|
||||
return birthday;
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
StringBuffer result = new StringBuffer();
|
||||
maybeAppend(names, result);
|
||||
maybeAppend(emails, result);
|
||||
maybeAppend(address, result);
|
||||
maybeAppend(phoneNumbers, result);
|
||||
maybeAppend(note, result);
|
||||
maybeAppend(org, result);
|
||||
maybeAppend(birthday, result);
|
||||
maybeAppend(title, result);
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -21,18 +21,12 @@ import com.google.zxing.Result;
|
|||
/**
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class BookmarkDoCoMoParsedResult extends AbstractDoCoMoParsedResult {
|
||||
public final class BookmarkDoCoMoResultParser extends AbstractDoCoMoResultParser {
|
||||
|
||||
private final String title;
|
||||
private final String uri;
|
||||
|
||||
private BookmarkDoCoMoParsedResult(String title, String uri) {
|
||||
super(ParsedReaderResultType.BOOKMARK);
|
||||
this.title = title;
|
||||
this.uri = uri;
|
||||
private BookmarkDoCoMoResultParser() {
|
||||
}
|
||||
|
||||
public static BookmarkDoCoMoParsedResult parse(Result result) {
|
||||
public static URIParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (rawText == null || !rawText.startsWith("MEBKM:")) {
|
||||
return null;
|
||||
|
@ -43,26 +37,10 @@ public final class BookmarkDoCoMoParsedResult extends AbstractDoCoMoParsedResult
|
|||
return null;
|
||||
}
|
||||
String uri = rawUri[0];
|
||||
if (!URIParsedResult.isBasicallyValidURI(uri)) {
|
||||
if (!URIResultParser.isBasicallyValidURI(uri)) {
|
||||
return null;
|
||||
}
|
||||
return new BookmarkDoCoMoParsedResult(title, uri);
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getURI() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
if (title == null) {
|
||||
return uri;
|
||||
} else {
|
||||
return title + '\n' + uri;
|
||||
}
|
||||
return new URIParsedResult(uri, title);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
/**
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class CalendarParsedResult extends ParsedResult {
|
||||
|
||||
private final String summary;
|
||||
private final String start;
|
||||
private final String end;
|
||||
private final String location;
|
||||
private final String attendee;
|
||||
private final String title;
|
||||
|
||||
public CalendarParsedResult(String summary,
|
||||
String start,
|
||||
String end,
|
||||
String location,
|
||||
String attendee,
|
||||
String title) {
|
||||
super(ParsedResultType.CALENDAR);
|
||||
this.summary = summary;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.location = location;
|
||||
this.attendee = attendee;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getSummary() {
|
||||
return summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>We would return the start and end date as a {@link java.util.Date} except that this code
|
||||
* needs to work under JavaME / MIDP and there is no date parsing library available there, such
|
||||
* as <code>java.text.SimpleDateFormat</code>.</p>
|
||||
*
|
||||
* <p>Instead this is a String formatted as YYYYMMdd'T'HHmmss'Z'.</p>
|
||||
*/
|
||||
public String getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #getStart()
|
||||
*/
|
||||
public String getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public String getAttendee() {
|
||||
return attendee;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
StringBuffer result = new StringBuffer(summary);
|
||||
maybeAppend(start, result);
|
||||
maybeAppend(end, result);
|
||||
maybeAppend(location, result);
|
||||
maybeAppend(attendee, result);
|
||||
maybeAppend(title, result);
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -16,14 +16,7 @@
|
|||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* Represents a result that encodes an e-mail address, either as a plain address
|
||||
* like "joe@example.org" or a mailto: URL like "mailto:joe@example.org".
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class EmailAddressParsedResult extends AbstractDoCoMoParsedResult {
|
||||
|
@ -33,47 +26,14 @@ public final class EmailAddressParsedResult extends AbstractDoCoMoParsedResult {
|
|||
private final String body;
|
||||
private final String mailtoURI;
|
||||
|
||||
private EmailAddressParsedResult(String emailAddress, String subject, String body, String mailtoURI) {
|
||||
super(ParsedReaderResultType.EMAIL_ADDRESS);
|
||||
EmailAddressParsedResult(String emailAddress, String subject, String body, String mailtoURI) {
|
||||
super(ParsedResultType.EMAIL_ADDRESS);
|
||||
this.emailAddress = emailAddress;
|
||||
this.subject = subject;
|
||||
this.body = body;
|
||||
this.mailtoURI = mailtoURI;
|
||||
}
|
||||
|
||||
public static EmailAddressParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (rawText == null) {
|
||||
return null;
|
||||
}
|
||||
String emailAddress;
|
||||
if (rawText.startsWith("mailto:")) {
|
||||
// If it starts with mailto:, assume it is definitely trying to be an email address
|
||||
emailAddress = rawText.substring(7);
|
||||
int queryStart = emailAddress.indexOf('?');
|
||||
if (queryStart >= 0) {
|
||||
emailAddress = emailAddress.substring(0, queryStart);
|
||||
}
|
||||
Hashtable nameValues = parseNameValuePairs(rawText);
|
||||
String subject = null;
|
||||
String body = null;
|
||||
if (nameValues != null) {
|
||||
if (emailAddress.length() == 0) {
|
||||
emailAddress = (String) nameValues.get("to");
|
||||
}
|
||||
subject = (String) nameValues.get("subject");
|
||||
body = (String) nameValues.get("body");
|
||||
}
|
||||
return new EmailAddressParsedResult(emailAddress, subject, body, rawText);
|
||||
} else {
|
||||
if (!EmailDoCoMoParsedResult.isBasicallyValidEmailAddress(rawText)) {
|
||||
return null;
|
||||
}
|
||||
emailAddress = rawText;
|
||||
return new EmailAddressParsedResult(emailAddress, null, null, "mailto:" + emailAddress);
|
||||
}
|
||||
}
|
||||
|
||||
public String getEmailAddress() {
|
||||
return emailAddress;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright 2007 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* Represents a result that encodes an e-mail address, either as a plain address
|
||||
* like "joe@example.org" or a mailto: URL like "mailto:joe@example.org".
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class EmailAddressResultParser extends ResultParser {
|
||||
|
||||
public static EmailAddressParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (rawText == null) {
|
||||
return null;
|
||||
}
|
||||
String emailAddress;
|
||||
if (rawText.startsWith("mailto:")) {
|
||||
// If it starts with mailto:, assume it is definitely trying to be an email address
|
||||
emailAddress = rawText.substring(7);
|
||||
int queryStart = emailAddress.indexOf('?');
|
||||
if (queryStart >= 0) {
|
||||
emailAddress = emailAddress.substring(0, queryStart);
|
||||
}
|
||||
Hashtable nameValues = parseNameValuePairs(rawText);
|
||||
String subject = null;
|
||||
String body = null;
|
||||
if (nameValues != null) {
|
||||
if (emailAddress.length() == 0) {
|
||||
emailAddress = (String) nameValues.get("to");
|
||||
}
|
||||
subject = (String) nameValues.get("subject");
|
||||
body = (String) nameValues.get("body");
|
||||
}
|
||||
return new EmailAddressParsedResult(emailAddress, subject, body, rawText);
|
||||
} else {
|
||||
if (!EmailDoCoMoResultParser.isBasicallyValidEmailAddress(rawText)) {
|
||||
return null;
|
||||
}
|
||||
emailAddress = rawText;
|
||||
return new EmailAddressParsedResult(emailAddress, null, null, "mailto:" + emailAddress);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -25,20 +25,9 @@ import com.google.zxing.Result;
|
|||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class EmailDoCoMoParsedResult extends AbstractDoCoMoParsedResult {
|
||||
public final class EmailDoCoMoResultParser extends AbstractDoCoMoResultParser {
|
||||
|
||||
private final String to;
|
||||
private final String subject;
|
||||
private final String body;
|
||||
|
||||
private EmailDoCoMoParsedResult(String to, String subject, String body) {
|
||||
super(ParsedReaderResultType.EMAIL);
|
||||
this.to = to;
|
||||
this.subject = subject;
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public static EmailDoCoMoParsedResult parse(Result result) {
|
||||
public static EmailAddressParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (rawText == null || !rawText.startsWith("MATMSG:")) {
|
||||
return null;
|
||||
|
@ -53,46 +42,7 @@ public final class EmailDoCoMoParsedResult extends AbstractDoCoMoParsedResult {
|
|||
}
|
||||
String subject = matchSinglePrefixedField("SUB:", rawText);
|
||||
String body = matchSinglePrefixedField("BODY:", rawText);
|
||||
return new EmailDoCoMoParsedResult(to, subject, body);
|
||||
}
|
||||
|
||||
public String getTo() {
|
||||
return to;
|
||||
}
|
||||
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public String getMailtoURI() {
|
||||
StringBuffer result = new StringBuffer(to);
|
||||
boolean hasParams = false;
|
||||
if (subject != null) {
|
||||
result.append(hasParams ? '&' : '?');
|
||||
hasParams = true;
|
||||
result.append("subject=");
|
||||
result.append(subject);
|
||||
// TODO we need to escape this?
|
||||
}
|
||||
if (body != null) {
|
||||
result.append(hasParams ? '&' : '?');
|
||||
hasParams = true;
|
||||
result.append("body=");
|
||||
result.append(body);
|
||||
// TODO we need to escape this?
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
StringBuffer result = new StringBuffer(to);
|
||||
maybeAppend(subject, result);
|
||||
maybeAppend(body, result);
|
||||
return result.toString();
|
||||
return new EmailAddressParsedResult(to, subject, body, "mailto:" + to);
|
||||
}
|
||||
|
||||
/**
|
|
@ -16,62 +16,24 @@
|
|||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* Represents a "geo:" URI result, which specifices a location on the surface of
|
||||
* the Earth as well as an optional altitude above the surface. See
|
||||
* <a href="http://tools.ietf.org/html/draft-mayrhofer-geo-uri-00">
|
||||
* http://tools.ietf.org/html/draft-mayrhofer-geo-uri-00</a>.
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class GeoParsedResult extends ParsedReaderResult {
|
||||
public final class GeoParsedResult extends ParsedResult {
|
||||
|
||||
private final String geoURI;
|
||||
private final float latitude;
|
||||
private final float longitude;
|
||||
private final float altitude;
|
||||
|
||||
private GeoParsedResult(String geoURI, float latitude, float longitude, float altitude) {
|
||||
super(ParsedReaderResultType.GEO);
|
||||
GeoParsedResult(String geoURI, float latitude, float longitude, float altitude) {
|
||||
super(ParsedResultType.GEO);
|
||||
this.geoURI = geoURI;
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
this.altitude = altitude;
|
||||
}
|
||||
|
||||
public static GeoParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (rawText == null || !rawText.startsWith("geo:")) {
|
||||
return null;
|
||||
}
|
||||
// Drop geo, query portion
|
||||
int queryStart = rawText.indexOf('?', 4);
|
||||
String geoURIWithoutQuery;
|
||||
if (queryStart < 0) {
|
||||
geoURIWithoutQuery = rawText.substring(4);
|
||||
} else {
|
||||
geoURIWithoutQuery = rawText.substring(4, queryStart);
|
||||
}
|
||||
int latitudeEnd = geoURIWithoutQuery.indexOf(',');
|
||||
if (latitudeEnd < 0) {
|
||||
return null;
|
||||
}
|
||||
float latitude = Float.parseFloat(geoURIWithoutQuery.substring(0, latitudeEnd));
|
||||
int longitudeEnd = geoURIWithoutQuery.indexOf(',', latitudeEnd + 1);
|
||||
float longitude;
|
||||
float altitude; // in meters
|
||||
if (longitudeEnd < 0) {
|
||||
longitude = Float.parseFloat(geoURIWithoutQuery.substring(latitudeEnd + 1));
|
||||
altitude = 0.0f;
|
||||
} else {
|
||||
longitude = Float.parseFloat(geoURIWithoutQuery.substring(latitudeEnd + 1, longitudeEnd));
|
||||
altitude = Float.parseFloat(geoURIWithoutQuery.substring(longitudeEnd + 1));
|
||||
}
|
||||
return new GeoParsedResult(rawText, latitude, longitude, altitude);
|
||||
}
|
||||
|
||||
public String getGeoURI() {
|
||||
return geoURI;
|
||||
}
|
||||
|
|
65
core/src/com/google/zxing/client/result/GeoResultParser.java
Normal file
65
core/src/com/google/zxing/client/result/GeoResultParser.java
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* Parses a "geo:" URI result, which specifices a location on the surface of
|
||||
* the Earth as well as an optional altitude above the surface. See
|
||||
* <a href="http://tools.ietf.org/html/draft-mayrhofer-geo-uri-00">
|
||||
* http://tools.ietf.org/html/draft-mayrhofer-geo-uri-00</a>.
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class GeoResultParser extends ResultParser {
|
||||
|
||||
private GeoResultParser() {
|
||||
}
|
||||
|
||||
public static GeoParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (rawText == null || !rawText.startsWith("geo:")) {
|
||||
return null;
|
||||
}
|
||||
// Drop geo, query portion
|
||||
int queryStart = rawText.indexOf('?', 4);
|
||||
String geoURIWithoutQuery;
|
||||
if (queryStart < 0) {
|
||||
geoURIWithoutQuery = rawText.substring(4);
|
||||
} else {
|
||||
geoURIWithoutQuery = rawText.substring(4, queryStart);
|
||||
}
|
||||
int latitudeEnd = geoURIWithoutQuery.indexOf(',');
|
||||
if (latitudeEnd < 0) {
|
||||
return null;
|
||||
}
|
||||
float latitude = Float.parseFloat(geoURIWithoutQuery.substring(0, latitudeEnd));
|
||||
int longitudeEnd = geoURIWithoutQuery.indexOf(',', latitudeEnd + 1);
|
||||
float longitude;
|
||||
float altitude; // in meters
|
||||
if (longitudeEnd < 0) {
|
||||
longitude = Float.parseFloat(geoURIWithoutQuery.substring(latitudeEnd + 1));
|
||||
altitude = 0.0f;
|
||||
} else {
|
||||
longitude = Float.parseFloat(geoURIWithoutQuery.substring(latitudeEnd + 1, longitudeEnd));
|
||||
altitude = Float.parseFloat(geoURIWithoutQuery.substring(longitudeEnd + 1));
|
||||
}
|
||||
return new GeoParsedResult(rawText, latitude, longitude, altitude);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
/**
|
||||
* Represents the type of data encoded by a barcode -- from plain text, to a
|
||||
* URI, to an e-mail address, etc.
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class ParsedReaderResultType {
|
||||
|
||||
public static final ParsedReaderResultType BOOKMARK = new ParsedReaderResultType("BOOKMARK");
|
||||
public static final ParsedReaderResultType URLTO = new ParsedReaderResultType("URLTO");
|
||||
public static final ParsedReaderResultType ADDRESSBOOK = new ParsedReaderResultType("ADDRESSBOOK");
|
||||
public static final ParsedReaderResultType ADDRESSBOOK_AU = new ParsedReaderResultType("ADDRESSBOOK_AU");
|
||||
public static final ParsedReaderResultType EMAIL = new ParsedReaderResultType("EMAIL");
|
||||
public static final ParsedReaderResultType EMAIL_ADDRESS = new ParsedReaderResultType("EMAIL_ADDRESS");
|
||||
public static final ParsedReaderResultType UPC = new ParsedReaderResultType("UPC");
|
||||
public static final ParsedReaderResultType URI = new ParsedReaderResultType("URI");
|
||||
public static final ParsedReaderResultType TEXT = new ParsedReaderResultType("TEXT");
|
||||
public static final ParsedReaderResultType ANDROID_INTENT = new ParsedReaderResultType("ANDROID_INTENT");
|
||||
public static final ParsedReaderResultType GEO = new ParsedReaderResultType("GEO");
|
||||
public static final ParsedReaderResultType TEL = new ParsedReaderResultType("TEL");
|
||||
public static final ParsedReaderResultType SMS = new ParsedReaderResultType("SMS");
|
||||
public static final ParsedReaderResultType SMSTO = new ParsedReaderResultType("SMSTO");
|
||||
|
||||
// "optional" types
|
||||
public static final ParsedReaderResultType NDEF_TEXT = new ParsedReaderResultType("NDEF_TEXT");
|
||||
public static final ParsedReaderResultType NDEF_URI = new ParsedReaderResultType("NDEF_URI");
|
||||
public static final ParsedReaderResultType NDEF_SMART_POSTER = new ParsedReaderResultType("NDEF_SMART_POSTER");
|
||||
public static final ParsedReaderResultType MOBILETAG_TEL = new ParsedReaderResultType("MOBILETAG_TEL");
|
||||
public static final ParsedReaderResultType MOBILETAG_SMS = new ParsedReaderResultType("MOBILETAG_SMS");
|
||||
public static final ParsedReaderResultType MOBILETAG_MMS = new ParsedReaderResultType("MOBILETAG_MMS");
|
||||
public static final ParsedReaderResultType MOBILETAG_SIMPLE_WEB = new ParsedReaderResultType("MOBILETAG_SIMPLE_WEB");
|
||||
public static final ParsedReaderResultType MOBILETAG_SIMPLE_CONTACT =
|
||||
new ParsedReaderResultType("MOBILETAG_SIMPLE_CONTACT");
|
||||
public static final ParsedReaderResultType MOBILETAG_SIMPLE_CALENDAR =
|
||||
new ParsedReaderResultType("MOBILETAG_SIMPLE_CALENDAR");
|
||||
public static final ParsedReaderResultType MOBILETAG_RICH_WEB = new ParsedReaderResultType("MOBILETAG_RICH_WEB");
|
||||
|
||||
private final String name;
|
||||
|
||||
private ParsedReaderResultType(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
67
core/src/com/google/zxing/client/result/ParsedResult.java
Normal file
67
core/src/com/google/zxing/client/result/ParsedResult.java
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright 2007 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* <p>Abstract class representing the result of decoding a barcode, as more than
|
||||
* a String -- as some type of structured data. This might be a subclass which represents
|
||||
* a URL, or an e-mail address. {@link #parseReaderResult(Result)} will turn a raw
|
||||
* decoded string into the most appropriate type of structured representation.</p>
|
||||
*
|
||||
* <p>Thanks to Jeff Griffin for proposing rewrite of these classes that relies less
|
||||
* on exception-based mechanisms during parsing.</p>
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public abstract class ParsedResult {
|
||||
|
||||
private final ParsedResultType type;
|
||||
|
||||
protected ParsedResult(ParsedResultType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public ParsedResultType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public abstract String getDisplayResult();
|
||||
|
||||
|
||||
public String toString() {
|
||||
return getDisplayResult();
|
||||
}
|
||||
|
||||
protected static void maybeAppend(String value, StringBuffer result) {
|
||||
if (value != null) {
|
||||
result.append('\n');
|
||||
result.append(value);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void maybeAppend(String[] value, StringBuffer result) {
|
||||
if (value != null) {
|
||||
for (int i = 0; i < value.length; i++) {
|
||||
result.append('\n');
|
||||
result.append(value[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright 2007 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
/**
|
||||
* Represents the type of data encoded by a barcode -- from plain text, to a
|
||||
* URI, to an e-mail address, etc.
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class ParsedResultType {
|
||||
|
||||
public static final ParsedResultType ADDRESSBOOK = new ParsedResultType("ADDRESSBOOK");
|
||||
public static final ParsedResultType EMAIL_ADDRESS = new ParsedResultType("EMAIL_ADDRESS");
|
||||
public static final ParsedResultType UPC = new ParsedResultType("UPC");
|
||||
public static final ParsedResultType URI = new ParsedResultType("URI");
|
||||
public static final ParsedResultType TEXT = new ParsedResultType("TEXT");
|
||||
public static final ParsedResultType ANDROID_INTENT = new ParsedResultType("ANDROID_INTENT");
|
||||
public static final ParsedResultType GEO = new ParsedResultType("GEO");
|
||||
public static final ParsedResultType TEL = new ParsedResultType("TEL");
|
||||
public static final ParsedResultType SMS = new ParsedResultType("SMS");
|
||||
public static final ParsedResultType CALENDAR = new ParsedResultType("CALENDAR");
|
||||
// "optional" types
|
||||
public static final ParsedResultType NDEF_SMART_POSTER = new ParsedResultType("NDEF_SMART_POSTER");
|
||||
public static final ParsedResultType MOBILETAG_RICH_WEB = new ParsedResultType("MOBILETAG_RICH_WEB");
|
||||
|
||||
private final String name;
|
||||
|
||||
private ParsedResultType(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
|
@ -23,7 +23,7 @@ import java.util.Hashtable;
|
|||
/**
|
||||
* <p>Abstract class representing the result of decoding a barcode, as more than
|
||||
* a String -- as some type of structured data. This might be a subclass which represents
|
||||
* a URL, or an e-mail address. {@link #parseReaderResult(Result)} will turn a raw
|
||||
* a URL, or an e-mail address. {@link #parseReaderResult(com.google.zxing.Result)} will turn a raw
|
||||
* decoded string into the most appropriate type of structured representation.</p>
|
||||
*
|
||||
* <p>Thanks to Jeff Griffin for proposing rewrite of these classes that relies less
|
||||
|
@ -31,55 +31,39 @@ import java.util.Hashtable;
|
|||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public abstract class ParsedReaderResult {
|
||||
public abstract class ResultParser {
|
||||
|
||||
private final ParsedReaderResultType type;
|
||||
|
||||
protected ParsedReaderResult(ParsedReaderResultType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public ParsedReaderResultType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public abstract String getDisplayResult();
|
||||
|
||||
public static ParsedReaderResult parseReaderResult(Result theResult) {
|
||||
public static ParsedResult parseReaderResult(Result theResult) {
|
||||
// This is a bit messy, but given limited options in MIDP / CLDC, this may well be the simplest
|
||||
// way to go about this. For example, we have no reflection available, really.
|
||||
// Order is important here.
|
||||
ParsedReaderResult result;
|
||||
if ((result = BookmarkDoCoMoParsedResult.parse(theResult)) != null) {
|
||||
ParsedResult result;
|
||||
if ((result = BookmarkDoCoMoResultParser.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = AddressBookDoCoMoParsedResult.parse(theResult)) != null) {
|
||||
} else if ((result = AddressBookDoCoMoResultParser.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = EmailDoCoMoParsedResult.parse(theResult)) != null) {
|
||||
} else if ((result = EmailDoCoMoResultParser.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = EmailAddressParsedResult.parse(theResult)) != null) {
|
||||
} else if ((result = EmailAddressResultParser.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = AddressBookAUParsedResult.parse(theResult)) != null) {
|
||||
} else if ((result = AddressBookAUResultParser.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = TelParsedResult.parse(theResult)) != null) {
|
||||
} else if ((result = TelResultParser.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = SMSParsedResult.parse(theResult)) != null) {
|
||||
} else if ((result = SMSResultParser.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = SMSTOParsedResult.parse(theResult)) != null) {
|
||||
} else if ((result = SMSTOResultParser.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = GeoParsedResult.parse(theResult)) != null) {
|
||||
} else if ((result = GeoResultParser.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = URLTOParsedResult.parse(theResult)) != null) {
|
||||
} else if ((result = URLTOResultParser.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = URIParsedResult.parse(theResult)) != null) {
|
||||
} else if ((result = URIResultParser.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = UPCParsedResult.parse(theResult)) != null) {
|
||||
} else if ((result = UPCResultParser.parse(theResult)) != null) {
|
||||
return result;
|
||||
}
|
||||
return TextParsedResult.parse(theResult);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getDisplayResult();
|
||||
return new TextParsedResult(theResult.getText(), null);
|
||||
}
|
||||
|
||||
protected static void maybeAppend(String value, StringBuffer result) {
|
||||
|
@ -89,6 +73,15 @@ public abstract class ParsedReaderResult {
|
|||
}
|
||||
}
|
||||
|
||||
protected static void maybeAppend(String[] value, StringBuffer result) {
|
||||
if (value != null) {
|
||||
for (int i = 0; i < value.length; i++) {
|
||||
result.append('\n');
|
||||
result.append(value[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static String unescapeBackslash(String escaped) {
|
||||
if (escaped != null) {
|
||||
int backslash = escaped.indexOf((int) '\\');
|
||||
|
@ -217,4 +210,4 @@ public abstract class ParsedReaderResult {
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -16,57 +16,26 @@
|
|||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* Represents a "sms:" URI result, which specifies a number to SMS and optional
|
||||
* "via" number. See <a href="http://gbiv.com/protocols/uri/drafts/draft-antti-gsm-sms-url-04.txt">
|
||||
* the IETF draft</a> on this.
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class SMSParsedResult extends ParsedReaderResult {
|
||||
public final class SMSParsedResult extends ParsedResult {
|
||||
|
||||
private final String smsURI;
|
||||
private final String number;
|
||||
private final String via;
|
||||
private final String subject;
|
||||
private final String body;
|
||||
private final String title;
|
||||
|
||||
private SMSParsedResult(String smsURI, String number, String via) {
|
||||
super(ParsedReaderResultType.SMS);
|
||||
public SMSParsedResult(String smsURI, String number, String via, String subject, String body, String title) {
|
||||
super(ParsedResultType.SMS);
|
||||
this.smsURI = smsURI;
|
||||
this.number = number;
|
||||
this.via = via;
|
||||
}
|
||||
|
||||
public static SMSParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (rawText == null || !rawText.startsWith("sms:")) {
|
||||
return null;
|
||||
}
|
||||
// Drop sms, query portion
|
||||
int queryStart = rawText.indexOf('?', 4);
|
||||
String smsURIWithoutQuery;
|
||||
if (queryStart < 0) {
|
||||
smsURIWithoutQuery = rawText.substring(4);
|
||||
} else {
|
||||
smsURIWithoutQuery = rawText.substring(4, queryStart);
|
||||
}
|
||||
int numberEnd = smsURIWithoutQuery.indexOf(';');
|
||||
String number;
|
||||
String via;
|
||||
if (numberEnd < 0) {
|
||||
number = smsURIWithoutQuery;
|
||||
via = null;
|
||||
} else {
|
||||
number = smsURIWithoutQuery.substring(0, numberEnd);
|
||||
String maybeVia = smsURIWithoutQuery.substring(numberEnd + 1);
|
||||
if (maybeVia.startsWith("via=")) {
|
||||
via = maybeVia.substring(4);
|
||||
} else {
|
||||
via = null;
|
||||
}
|
||||
}
|
||||
return new SMSParsedResult(rawText, number, via);
|
||||
this.subject = subject;
|
||||
this.body = body;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getSMSURI() {
|
||||
|
@ -81,6 +50,18 @@ public final class SMSParsedResult extends ParsedReaderResult {
|
|||
return via;
|
||||
}
|
||||
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
return number;
|
||||
}
|
||||
|
|
64
core/src/com/google/zxing/client/result/SMSResultParser.java
Normal file
64
core/src/com/google/zxing/client/result/SMSResultParser.java
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* Parses an "sms:" URI result, which specifies a number to SMS and optional
|
||||
* "via" number. See <a href="http://gbiv.com/protocols/uri/drafts/draft-antti-gsm-sms-url-04.txt">
|
||||
* the IETF draft</a> on this.
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class SMSResultParser extends ResultParser {
|
||||
|
||||
private SMSResultParser() {
|
||||
}
|
||||
|
||||
public static SMSParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (rawText == null || !rawText.startsWith("sms:")) {
|
||||
return null;
|
||||
}
|
||||
// Drop sms, query portion
|
||||
int queryStart = rawText.indexOf('?', 4);
|
||||
String smsURIWithoutQuery;
|
||||
if (queryStart < 0) {
|
||||
smsURIWithoutQuery = rawText.substring(4);
|
||||
} else {
|
||||
smsURIWithoutQuery = rawText.substring(4, queryStart);
|
||||
}
|
||||
int numberEnd = smsURIWithoutQuery.indexOf(';');
|
||||
String number;
|
||||
String via;
|
||||
if (numberEnd < 0) {
|
||||
number = smsURIWithoutQuery;
|
||||
via = null;
|
||||
} else {
|
||||
number = smsURIWithoutQuery.substring(0, numberEnd);
|
||||
String maybeVia = smsURIWithoutQuery.substring(numberEnd + 1);
|
||||
if (maybeVia.startsWith("via=")) {
|
||||
via = maybeVia.substring(4);
|
||||
} else {
|
||||
via = null;
|
||||
}
|
||||
}
|
||||
return new SMSParsedResult(rawText, number, via, null, null, null);
|
||||
}
|
||||
|
||||
}
|
|
@ -19,38 +19,22 @@ package com.google.zxing.client.result;
|
|||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* Represents a "SMSTO:" result, which specifies a number to SMS.
|
||||
* Parses an "SMSTO:" result, which specifies a number to SMS.
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class SMSTOParsedResult extends ParsedReaderResult {
|
||||
public final class SMSTOResultParser extends ResultParser {
|
||||
|
||||
private final String number;
|
||||
|
||||
private SMSTOParsedResult(String number) {
|
||||
super(ParsedReaderResultType.SMSTO);
|
||||
this.number = number;
|
||||
private SMSTOResultParser() {
|
||||
}
|
||||
|
||||
public static SMSTOParsedResult parse(Result result) {
|
||||
public static SMSParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (rawText == null || !rawText.startsWith("SMSTO:")) {
|
||||
return null;
|
||||
}
|
||||
String number = rawText.substring(6);
|
||||
return new SMSTOParsedResult(number);
|
||||
}
|
||||
|
||||
public String getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public String getSMSURI() {
|
||||
return "sms:" + number;
|
||||
return new SMSParsedResult("sms:" + number, number, null, null, null, null);
|
||||
}
|
||||
|
||||
}
|
|
@ -16,38 +16,20 @@
|
|||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* Represents a "tel:" URI result, which specifies a phone number.
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class TelParsedResult extends ParsedReaderResult {
|
||||
public final class TelParsedResult extends ParsedResult {
|
||||
|
||||
private final String number;
|
||||
private final String telURI;
|
||||
private final String title;
|
||||
|
||||
private TelParsedResult(String number, String telURI) {
|
||||
super(ParsedReaderResultType.TEL);
|
||||
public TelParsedResult(String number, String telURI, String title) {
|
||||
super(ParsedResultType.TEL);
|
||||
this.number = number;
|
||||
this.telURI = telURI;
|
||||
}
|
||||
|
||||
public static TelParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (rawText == null || !rawText.startsWith("tel:")) {
|
||||
return null;
|
||||
}
|
||||
String telURI = rawText;
|
||||
// Drop tel, query portion
|
||||
int queryStart = rawText.indexOf('?', 4);
|
||||
if (queryStart < 0) {
|
||||
rawText = rawText.substring(4);
|
||||
} else {
|
||||
rawText = rawText.substring(4, queryStart);
|
||||
}
|
||||
return new TelParsedResult(rawText, telURI);
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getNumber() {
|
||||
|
@ -58,6 +40,10 @@ public final class TelParsedResult extends ParsedReaderResult {
|
|||
return telURI;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
return number;
|
||||
}
|
||||
|
|
47
core/src/com/google/zxing/client/result/TelResultParser.java
Normal file
47
core/src/com/google/zxing/client/result/TelResultParser.java
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* Parses a "tel:" URI result, which specifies a phone number.
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class TelResultParser extends ResultParser {
|
||||
|
||||
private TelResultParser() {
|
||||
}
|
||||
|
||||
public static TelParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (rawText == null || !rawText.startsWith("tel:")) {
|
||||
return null;
|
||||
}
|
||||
String telURI = rawText;
|
||||
// Drop tel, query portion
|
||||
int queryStart = rawText.indexOf('?', 4);
|
||||
if (queryStart < 0) {
|
||||
rawText = rawText.substring(4);
|
||||
} else {
|
||||
rawText = rawText.substring(4, queryStart);
|
||||
}
|
||||
return new TelParsedResult(rawText, telURI, null);
|
||||
}
|
||||
|
||||
}
|
|
@ -16,28 +16,31 @@
|
|||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* A simple result type encapsulating a string that has no further
|
||||
* interpretation.
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class TextParsedResult extends ParsedReaderResult {
|
||||
public final class TextParsedResult extends ParsedResult {
|
||||
|
||||
private final String text;
|
||||
private final String language;
|
||||
|
||||
private TextParsedResult(String text) {
|
||||
super(ParsedReaderResultType.TEXT);
|
||||
public TextParsedResult(String text, String language) {
|
||||
super(ParsedResultType.TEXT);
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public static TextParsedResult parse(Result result) {
|
||||
return new TextParsedResult(result.getText());
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
return text;
|
||||
}
|
||||
|
|
|
@ -16,46 +16,18 @@
|
|||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class UPCParsedResult extends ParsedReaderResult {
|
||||
public final class UPCParsedResult extends ParsedResult {
|
||||
|
||||
private final String upc;
|
||||
|
||||
private UPCParsedResult(String upc) {
|
||||
super(ParsedReaderResultType.UPC);
|
||||
UPCParsedResult(String upc) {
|
||||
super(ParsedResultType.UPC);
|
||||
this.upc = upc;
|
||||
}
|
||||
|
||||
// Treat all UPC and EAN variants as UPCs, in the sense that they are all product barcodes.
|
||||
public static UPCParsedResult parse(Result result) {
|
||||
BarcodeFormat format = result.getBarcodeFormat();
|
||||
if (!BarcodeFormat.UPC_A.equals(format) && !BarcodeFormat.UPC_E.equals(format) &&
|
||||
!BarcodeFormat.EAN_8.equals(format) && !BarcodeFormat.EAN_13.equals(format)) {
|
||||
return null;
|
||||
}
|
||||
String rawText = result.getText();
|
||||
if (rawText == null) {
|
||||
return null;
|
||||
}
|
||||
int length = rawText.length();
|
||||
if (length != 12 && length != 13) {
|
||||
return null;
|
||||
}
|
||||
for (int x = 0; x < length; x++) {
|
||||
char c = rawText.charAt(x);
|
||||
if (c < '0' || c > '9') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// Not actually checking the checkusm again here
|
||||
return new UPCParsedResult(rawText);
|
||||
}
|
||||
|
||||
public String getUPC() {
|
||||
return upc;
|
||||
}
|
||||
|
|
57
core/src/com/google/zxing/client/result/UPCResultParser.java
Normal file
57
core/src/com/google/zxing/client/result/UPCResultParser.java
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright 2007 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* Parses strings of digits that repesent a UPC code.
|
||||
*
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class UPCResultParser extends ResultParser {
|
||||
|
||||
private UPCResultParser() {
|
||||
}
|
||||
|
||||
// Treat all UPC and EAN variants as UPCs, in the sense that they are all product barcodes.
|
||||
public static UPCParsedResult parse(Result result) {
|
||||
BarcodeFormat format = result.getBarcodeFormat();
|
||||
if (!BarcodeFormat.UPC_A.equals(format) && !BarcodeFormat.UPC_E.equals(format) &&
|
||||
!BarcodeFormat.EAN_8.equals(format) && !BarcodeFormat.EAN_13.equals(format)) {
|
||||
return null;
|
||||
}
|
||||
String rawText = result.getText();
|
||||
if (rawText == null) {
|
||||
return null;
|
||||
}
|
||||
int length = rawText.length();
|
||||
if (length != 12 && length != 13) {
|
||||
return null;
|
||||
}
|
||||
for (int x = 0; x < length; x++) {
|
||||
char c = rawText.charAt(x);
|
||||
if (c < '0' || c > '9') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// Not actually checking the checkusm again here
|
||||
return new UPCParsedResult(rawText);
|
||||
}
|
||||
|
||||
}
|
|
@ -16,65 +16,35 @@
|
|||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class URIParsedResult extends ParsedReaderResult {
|
||||
public final class URIParsedResult extends ParsedResult {
|
||||
|
||||
private final String uri;
|
||||
private final String title;
|
||||
|
||||
private URIParsedResult(String uri) {
|
||||
super(ParsedReaderResultType.URI);
|
||||
public URIParsedResult(String uri, String title) {
|
||||
super(ParsedResultType.URI);
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
public static URIParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (!isBasicallyValidURI(rawText)) {
|
||||
return null;
|
||||
}
|
||||
String uri = massagePossibleURI(rawText);
|
||||
return new URIParsedResult(uri);
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getURI() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a string that possibly represents a URI into something more proper, by adding or canonicalizing
|
||||
* the protocol.
|
||||
*/
|
||||
private static String massagePossibleURI(String uri) {
|
||||
// Take off leading "URL:" if present
|
||||
if (uri.startsWith("URL:")) {
|
||||
uri = uri.substring(4);
|
||||
}
|
||||
int protocolEnd = uri.indexOf(':');
|
||||
if (protocolEnd < 0) {
|
||||
// No protocol, assume http
|
||||
uri = "http://" + uri;
|
||||
if (title == null) {
|
||||
return uri;
|
||||
} else {
|
||||
// Lowercase protocol to avoid problems
|
||||
uri = uri.substring(0, protocolEnd).toLowerCase() + uri.substring(protocolEnd);
|
||||
// TODO this logic isn't quite right for URIs like "example.org:443/foo"
|
||||
return title + '\n' + uri;
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a string is not obviously not a URI. This implements crude checks; this class does not
|
||||
* intend to strictly check URIs as its only function is to represent what is in a barcode, but, it does
|
||||
* need to know when a string is obviously not a URI.
|
||||
*/
|
||||
static boolean isBasicallyValidURI(String uri) {
|
||||
return uri != null && uri.indexOf(' ') < 0 && (uri.indexOf(':') >= 0 || uri.indexOf('.') >= 0);
|
||||
}
|
||||
|
||||
}
|
70
core/src/com/google/zxing/client/result/URIResultParser.java
Normal file
70
core/src/com/google/zxing/client/result/URIResultParser.java
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Copyright 2007 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* Tries to parse results that are a URI of some kind.
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class URIResultParser extends ResultParser {
|
||||
|
||||
private URIResultParser() {
|
||||
}
|
||||
|
||||
public static URIParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (!isBasicallyValidURI(rawText)) {
|
||||
return null;
|
||||
}
|
||||
String uri = massagePossibleURI(rawText);
|
||||
return new URIParsedResult(uri, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a string that possibly represents a URI into something more proper, by adding or canonicalizing
|
||||
* the protocol.
|
||||
*/
|
||||
private static String massagePossibleURI(String uri) {
|
||||
// Take off leading "URL:" if present
|
||||
if (uri.startsWith("URL:")) {
|
||||
uri = uri.substring(4);
|
||||
}
|
||||
int protocolEnd = uri.indexOf(':');
|
||||
if (protocolEnd < 0) {
|
||||
// No protocol, assume http
|
||||
uri = "http://" + uri;
|
||||
} else {
|
||||
// Lowercase protocol to avoid problems
|
||||
uri = uri.substring(0, protocolEnd).toLowerCase() + uri.substring(protocolEnd);
|
||||
// TODO this logic isn't quite right for URIs like "example.org:443/foo"
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a string is not obviously not a URI. This implements crude checks; this class does not
|
||||
* intend to strictly check URIs as its only function is to represent what is in a barcode, but, it does
|
||||
* need to know when a string is obviously not a URI.
|
||||
*/
|
||||
static boolean isBasicallyValidURI(String uri) {
|
||||
return uri != null && uri.indexOf(' ') < 0 && (uri.indexOf(':') >= 0 || uri.indexOf('.') >= 0);
|
||||
}
|
||||
|
||||
}
|
|
@ -19,24 +19,18 @@ package com.google.zxing.client.result;
|
|||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* "URLTO" result format, which is of the form "URLTO:[title]:[url]".
|
||||
* Parses the "URLTO" result format, which is of the form "URLTO:[title]:[url]".
|
||||
* This seems to be used sometimes, but I am not able to find documentation
|
||||
* on its origin or official format?
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class URLTOParsedResult extends ParsedReaderResult {
|
||||
public final class URLTOResultParser {
|
||||
|
||||
private final String title;
|
||||
private final String uri;
|
||||
|
||||
private URLTOParsedResult(String title, String uri) {
|
||||
super(ParsedReaderResultType.URLTO);
|
||||
this.title = title;
|
||||
this.uri = uri;
|
||||
private URLTOResultParser() {
|
||||
}
|
||||
|
||||
public static URLTOParsedResult parse(Result result) {
|
||||
public static URIParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (rawText == null || !rawText.startsWith("URLTO:")) {
|
||||
return null;
|
||||
|
@ -47,23 +41,7 @@ public final class URLTOParsedResult extends ParsedReaderResult {
|
|||
}
|
||||
String title = rawText.substring(6, titleEnd);
|
||||
String uri = rawText.substring(titleEnd + 1);
|
||||
return new URLTOParsedResult(title, uri);
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getURI() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
if (title == null) {
|
||||
return uri;
|
||||
} else {
|
||||
return title + '\n' + uri;
|
||||
}
|
||||
return new URIParsedResult(uri, title);
|
||||
}
|
||||
|
||||
}
|
|
@ -16,8 +16,7 @@
|
|||
|
||||
package com.google.zxing.client.result.optional;
|
||||
|
||||
import com.google.zxing.client.result.ParsedReaderResult;
|
||||
import com.google.zxing.client.result.ParsedReaderResultType;
|
||||
import com.google.zxing.client.result.ResultParser;
|
||||
|
||||
/**
|
||||
* <p>Superclass for classes encapsulating reader results encoded according
|
||||
|
@ -25,16 +24,12 @@ import com.google.zxing.client.result.ParsedReaderResultType;
|
|||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
abstract class AbstractMobileTagParsedResult extends ParsedReaderResult {
|
||||
abstract class AbstractMobileTagResultParser extends ResultParser {
|
||||
|
||||
public static final int ACTION_DO = 1;
|
||||
public static final int ACTION_EDIT = 2;
|
||||
public static final int ACTION_SAVE = 4;
|
||||
|
||||
AbstractMobileTagParsedResult(ParsedReaderResultType type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
static String[] matchDelimitedFields(String rawText, int maxItems) {
|
||||
String[] result = new String[maxItems];
|
||||
int item = 0;
|
|
@ -16,8 +16,7 @@
|
|||
|
||||
package com.google.zxing.client.result.optional;
|
||||
|
||||
import com.google.zxing.client.result.ParsedReaderResult;
|
||||
import com.google.zxing.client.result.ParsedReaderResultType;
|
||||
import com.google.zxing.client.result.ResultParser;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
|
@ -31,11 +30,7 @@ import java.io.UnsupportedEncodingException;
|
|||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
abstract class AbstractNDEFParsedResult extends ParsedReaderResult {
|
||||
|
||||
AbstractNDEFParsedResult(ParsedReaderResultType type) {
|
||||
super(type);
|
||||
}
|
||||
abstract class AbstractNDEFResultParser extends ResultParser {
|
||||
|
||||
static String bytesToString(byte[] bytes, int offset, int length, String encoding) {
|
||||
try {
|
|
@ -18,7 +18,7 @@ package com.google.zxing.client.result.optional;
|
|||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.client.result.ParsedReaderResultType;
|
||||
import com.google.zxing.client.result.SMSParsedResult;
|
||||
|
||||
/**
|
||||
* <p>Represents a "MMS" result encoded according to section 4.7 of the
|
||||
|
@ -26,24 +26,11 @@ import com.google.zxing.client.result.ParsedReaderResultType;
|
|||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class MobileTagMMSParsedResult extends AbstractMobileTagParsedResult {
|
||||
public final class MobileTagMMSResultParser extends AbstractMobileTagResultParser {
|
||||
|
||||
public static final String SERVICE_TYPE = "05";
|
||||
|
||||
private final String to;
|
||||
private final String subject;
|
||||
private final String body;
|
||||
private final String title;
|
||||
|
||||
private MobileTagMMSParsedResult(String to, String subject, String body, String title) {
|
||||
super(ParsedReaderResultType.MOBILETAG_MMS);
|
||||
this.to = to;
|
||||
this.subject = subject;
|
||||
this.body = body;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public static MobileTagMMSParsedResult parse(Result result) {
|
||||
public static SMSParsedResult parse(Result result) {
|
||||
if (!result.getBarcodeFormat().equals(BarcodeFormat.DATAMATRIX)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -61,31 +48,7 @@ public final class MobileTagMMSParsedResult extends AbstractMobileTagParsedResul
|
|||
String body = matches[2];
|
||||
String title = matches[3];
|
||||
|
||||
return new MobileTagMMSParsedResult(to, subject, body, title);
|
||||
}
|
||||
|
||||
public String getTo() {
|
||||
return to;
|
||||
}
|
||||
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
StringBuffer result = new StringBuffer(to);
|
||||
maybeAppend(subject, result);
|
||||
maybeAppend(title, result);
|
||||
maybeAppend(body, result);
|
||||
return result.toString();
|
||||
return new SMSParsedResult("sms:" + to, to, null, subject, body, title);
|
||||
}
|
||||
|
||||
}
|
|
@ -16,64 +16,26 @@
|
|||
|
||||
package com.google.zxing.client.result.optional;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.client.result.ParsedReaderResultType;
|
||||
import com.google.zxing.client.result.ParsedResult;
|
||||
import com.google.zxing.client.result.ParsedResultType;
|
||||
|
||||
/**
|
||||
* <p>Represents a "rich web" result encoded according to section 5 of the
|
||||
* MobileTag Reader International Specification.</p>
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class MobileTagRichWebParsedResult extends AbstractMobileTagParsedResult {
|
||||
public final class MobileTagRichWebParsedResult extends ParsedResult {
|
||||
|
||||
public static final String SERVICE_TYPE = "54";
|
||||
|
||||
private static final int DEFAULT_ACTION = ACTION_DO;
|
||||
// Example: "http://www.tagserver.com/script.asp?id="
|
||||
private static final String TAGSERVER_URI_PREFIX = System.getProperty("zxing.mobiletag.tagserver");
|
||||
static final String TAGSERVER_URI_PREFIX = System.getProperty("zxing.mobiletag.tagserver");
|
||||
|
||||
private final String id;
|
||||
private final int action;
|
||||
|
||||
private MobileTagRichWebParsedResult(String id, int action) {
|
||||
super(ParsedReaderResultType.MOBILETAG_RICH_WEB);
|
||||
MobileTagRichWebParsedResult(String id, int action) {
|
||||
super(ParsedResultType.MOBILETAG_RICH_WEB);
|
||||
this.id = id;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public static MobileTagRichWebParsedResult parse(Result result) {
|
||||
if (TAGSERVER_URI_PREFIX == null) {
|
||||
return null;
|
||||
}
|
||||
if (!result.getBarcodeFormat().equals(BarcodeFormat.DATAMATRIX)) {
|
||||
return null;
|
||||
}
|
||||
String rawText = result.getText();
|
||||
if (!rawText.startsWith(SERVICE_TYPE)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int length = rawText.length();
|
||||
if (!isDigits(rawText, length)) {
|
||||
return null;
|
||||
}
|
||||
int action;
|
||||
String id;
|
||||
if (length == 15) {
|
||||
action = DEFAULT_ACTION;
|
||||
id = rawText.substring(0, 2) + action + rawText.substring(2);
|
||||
} else if (length == 16) {
|
||||
action = rawText.charAt(2) - '0';
|
||||
id = rawText;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new MobileTagRichWebParsedResult(id, action);
|
||||
}
|
||||
|
||||
public static String getTagserverURIPrefix() {
|
||||
return TAGSERVER_URI_PREFIX;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.result.optional;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* <p>Represents a "rich web" result encoded according to section 5 of the
|
||||
* MobileTag Reader International Specification.</p>
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class MobileTagRichWebResultParser extends AbstractMobileTagResultParser {
|
||||
|
||||
public static final String SERVICE_TYPE = "54";
|
||||
|
||||
private static final int DEFAULT_ACTION = ACTION_DO;
|
||||
|
||||
public static MobileTagRichWebParsedResult parse(Result result) {
|
||||
if (MobileTagRichWebParsedResult.TAGSERVER_URI_PREFIX == null) {
|
||||
return null;
|
||||
}
|
||||
if (!result.getBarcodeFormat().equals(BarcodeFormat.DATAMATRIX)) {
|
||||
return null;
|
||||
}
|
||||
String rawText = result.getText();
|
||||
if (!rawText.startsWith(SERVICE_TYPE)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int length = rawText.length();
|
||||
if (!isDigits(rawText, length)) {
|
||||
return null;
|
||||
}
|
||||
int action;
|
||||
String id;
|
||||
if (length == 15) {
|
||||
action = DEFAULT_ACTION;
|
||||
id = rawText.substring(0, 2) + action + rawText.substring(2);
|
||||
} else if (length == 16) {
|
||||
action = rawText.charAt(2) - '0';
|
||||
id = rawText;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new MobileTagRichWebParsedResult(id, action);
|
||||
}
|
||||
|
||||
}
|
|
@ -18,7 +18,7 @@ package com.google.zxing.client.result.optional;
|
|||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.client.result.ParsedReaderResultType;
|
||||
import com.google.zxing.client.result.SMSParsedResult;
|
||||
|
||||
/**
|
||||
* <p>Represents a "SMS" result encoded according to section 4.6 of the
|
||||
|
@ -26,22 +26,11 @@ import com.google.zxing.client.result.ParsedReaderResultType;
|
|||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class MobileTagSMSParsedResult extends AbstractMobileTagParsedResult {
|
||||
public final class MobileTagSMSResultParser extends AbstractMobileTagResultParser {
|
||||
|
||||
public static final String SERVICE_TYPE = "03";
|
||||
|
||||
private final String to;
|
||||
private final String body;
|
||||
private final String title;
|
||||
|
||||
private MobileTagSMSParsedResult(String to, String body, String title) {
|
||||
super(ParsedReaderResultType.MOBILETAG_SMS);
|
||||
this.to = to;
|
||||
this.body = body;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public static MobileTagSMSParsedResult parse(Result result) {
|
||||
public static SMSParsedResult parse(Result result) {
|
||||
if (!result.getBarcodeFormat().equals(BarcodeFormat.DATAMATRIX)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -58,26 +47,7 @@ public final class MobileTagSMSParsedResult extends AbstractMobileTagParsedResul
|
|||
String body = matches[1];
|
||||
String title = matches[2];
|
||||
|
||||
return new MobileTagSMSParsedResult(to, body, title);
|
||||
}
|
||||
|
||||
public String getTo() {
|
||||
return to;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
StringBuffer result = new StringBuffer(to);
|
||||
maybeAppend(title, result);
|
||||
maybeAppend(body, result);
|
||||
return result.toString();
|
||||
return new SMSParsedResult("sms:" + to, to, null, null, body, title);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,131 +0,0 @@
|
|||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.result.optional;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.client.result.ParsedReaderResultType;
|
||||
|
||||
/**
|
||||
* <p>Represents a "simple calendar" result encoded according to section 4.9 of the
|
||||
* MobileTag Reader International Specification.</p>
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class MobileTagSimpleCalendarParsedResult extends AbstractMobileTagParsedResult {
|
||||
|
||||
public static final String SERVICE_TYPE = "07";
|
||||
|
||||
private final String summary;
|
||||
private final String start;
|
||||
private final String end;
|
||||
private final String location;
|
||||
private final String attendee;
|
||||
private final String title;
|
||||
|
||||
private MobileTagSimpleCalendarParsedResult(String summary,
|
||||
String start,
|
||||
String end,
|
||||
String location,
|
||||
String attendee,
|
||||
String title) {
|
||||
super(ParsedReaderResultType.MOBILETAG_SIMPLE_CALENDAR);
|
||||
this.summary = summary;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.location = location;
|
||||
this.attendee = attendee;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public static MobileTagSimpleCalendarParsedResult parse(Result result) {
|
||||
if (!result.getBarcodeFormat().equals(BarcodeFormat.DATAMATRIX)) {
|
||||
return null;
|
||||
}
|
||||
String rawText = result.getText();
|
||||
if (!rawText.startsWith(SERVICE_TYPE)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String[] matches = matchDelimitedFields(rawText.substring(2), 6);
|
||||
if (matches == null || !isDigits(matches[1], 10) || !isDigits(matches[2], 10)) {
|
||||
return null;
|
||||
}
|
||||
String summary = matches[0];
|
||||
String start = expandDateString(matches[1]);
|
||||
String end = expandDateString(matches[2]);
|
||||
String location = matches[3];
|
||||
String attendee = matches[4];
|
||||
String title = matches[5];
|
||||
|
||||
return new MobileTagSimpleCalendarParsedResult(summary, start, end, location, attendee, title);
|
||||
}
|
||||
|
||||
public String getSummary() {
|
||||
return summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>We would return the start and end date as a {@link java.util.Date} except that this code
|
||||
* needs to work under JavaME / MIDP and there is no date parsing library available there, such
|
||||
* as <code>java.text.SimpleDateFormat</code>.</p>
|
||||
*
|
||||
* <p>However we do translate the date from its encoded format of, say, "0602212156" to its full
|
||||
* text representation of "20060221T215600Z", per the specification.</p>
|
||||
*/
|
||||
public String getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #getStart()
|
||||
*/
|
||||
public String getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public String getAttendee() {
|
||||
return attendee;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
StringBuffer result = new StringBuffer(summary);
|
||||
maybeAppend(start, result);
|
||||
maybeAppend(end, result);
|
||||
maybeAppend(location, result);
|
||||
maybeAppend(attendee, result);
|
||||
maybeAppend(title, result);
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private static String expandDateString(String date) {
|
||||
if (date == null) {
|
||||
return null;
|
||||
}
|
||||
// Input is of form YYMMddHHmmss, and needs to be YYYYMMdd'T'HHmmss'Z'
|
||||
return "20" + date.substring(0, 6) + 'T' + date.substring(6) + "00Z";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.result.optional;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.client.result.CalendarParsedResult;
|
||||
|
||||
/**
|
||||
* <p>Represents a "simple calendar" result encoded according to section 4.9 of the
|
||||
* MobileTag Reader International Specification.</p>
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class MobileTagSimpleCalendarResultParser extends AbstractMobileTagResultParser {
|
||||
|
||||
public static final String SERVICE_TYPE = "07";
|
||||
|
||||
public static CalendarParsedResult parse(Result result) {
|
||||
if (!result.getBarcodeFormat().equals(BarcodeFormat.DATAMATRIX)) {
|
||||
return null;
|
||||
}
|
||||
String rawText = result.getText();
|
||||
if (!rawText.startsWith(SERVICE_TYPE)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String[] matches = matchDelimitedFields(rawText.substring(2), 6);
|
||||
if (matches == null || !isDigits(matches[1], 10) || !isDigits(matches[2], 10)) {
|
||||
return null;
|
||||
}
|
||||
String summary = matches[0];
|
||||
String start = expandDateString(matches[1]);
|
||||
String end = expandDateString(matches[2]);
|
||||
String location = matches[3];
|
||||
String attendee = matches[4];
|
||||
String title = matches[5];
|
||||
|
||||
return new CalendarParsedResult(summary, start, end, location, attendee, title);
|
||||
}
|
||||
|
||||
private static String expandDateString(String date) {
|
||||
if (date == null) {
|
||||
return null;
|
||||
}
|
||||
// Input is of form YYMMddHHmmss, and needs to be YYYYMMdd'T'HHmmss'Z'
|
||||
return "20" + date.substring(0, 6) + 'T' + date.substring(6) + "00Z";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,148 +0,0 @@
|
|||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.result.optional;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.client.result.ParsedReaderResultType;
|
||||
|
||||
/**
|
||||
* <p>Represents a "simple contact" result encoded according to section 4.8 of the
|
||||
* MobileTag Reader International Specification.</p>
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class MobileTagSimpleContactParsedResult extends AbstractMobileTagParsedResult {
|
||||
|
||||
public static final String SERVICE_TYPE = "02";
|
||||
|
||||
private final String fullName;
|
||||
private final String telephoneCell;
|
||||
private final String telephone;
|
||||
private final String email1;
|
||||
private final String email2;
|
||||
private final String address;
|
||||
private final String org;
|
||||
private final String birthday;
|
||||
private final String title;
|
||||
|
||||
private MobileTagSimpleContactParsedResult(String fullName,
|
||||
String telephoneCell,
|
||||
String telephone,
|
||||
String email1,
|
||||
String email2,
|
||||
String address,
|
||||
String org,
|
||||
String birthday,
|
||||
String title) {
|
||||
super(ParsedReaderResultType.MOBILETAG_SIMPLE_CONTACT);
|
||||
this.fullName = fullName;
|
||||
this.telephoneCell = telephoneCell;
|
||||
this.telephone = telephone;
|
||||
this.email1 = email1;
|
||||
this.email2 = email2;
|
||||
this.address = address;
|
||||
this.org = org;
|
||||
this.birthday = birthday;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public static MobileTagSimpleContactParsedResult parse(Result result) {
|
||||
if (!result.getBarcodeFormat().equals(BarcodeFormat.DATAMATRIX)) {
|
||||
return null;
|
||||
}
|
||||
String rawText = result.getText();
|
||||
if (!rawText.startsWith(SERVICE_TYPE)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String[] matches = matchDelimitedFields(rawText.substring(2), 9);
|
||||
if (matches == null || !isDigits(matches[7], 8)) {
|
||||
return null;
|
||||
}
|
||||
String fullName = matches[0];
|
||||
String telephoneCell = matches[1];
|
||||
String telephone = matches[2];
|
||||
String email1 = matches[3];
|
||||
String email2 = matches[4];
|
||||
String address = matches[5];
|
||||
String org = matches[6];
|
||||
String birthday = matches[7];
|
||||
String title = matches[8];
|
||||
|
||||
return new MobileTagSimpleContactParsedResult(fullName,
|
||||
telephoneCell,
|
||||
telephone,
|
||||
email1,
|
||||
email2,
|
||||
address,
|
||||
org,
|
||||
birthday,
|
||||
title);
|
||||
}
|
||||
|
||||
|
||||
public String getFullName() {
|
||||
return fullName;
|
||||
}
|
||||
|
||||
public String getTelephoneCell() {
|
||||
return telephoneCell;
|
||||
}
|
||||
|
||||
public String getTelephone() {
|
||||
return telephone;
|
||||
}
|
||||
|
||||
public String getEmail1() {
|
||||
return email1;
|
||||
}
|
||||
|
||||
public String getEmail2() {
|
||||
return email2;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public String getOrg() {
|
||||
return org;
|
||||
}
|
||||
|
||||
public String getBirthday() {
|
||||
return birthday;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
StringBuffer result = new StringBuffer(fullName);
|
||||
maybeAppend(telephoneCell, result);
|
||||
maybeAppend(telephone, result);
|
||||
maybeAppend(email1, result);
|
||||
maybeAppend(email2, result);
|
||||
maybeAppend(address, result);
|
||||
maybeAppend(org, result);
|
||||
maybeAppend(birthday, result);
|
||||
maybeAppend(title, result);
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.result.optional;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.client.result.AddressBookParsedResult;
|
||||
|
||||
/**
|
||||
* <p>Represents a "simple contact" result encoded according to section 4.8 of the
|
||||
* MobileTag Reader International Specification.</p>
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class MobileTagSimpleContactResultParser extends AbstractMobileTagResultParser {
|
||||
|
||||
public static final String SERVICE_TYPE = "02";
|
||||
|
||||
public static AddressBookParsedResult parse(Result result) {
|
||||
if (!result.getBarcodeFormat().equals(BarcodeFormat.DATAMATRIX)) {
|
||||
return null;
|
||||
}
|
||||
String rawText = result.getText();
|
||||
if (!rawText.startsWith(SERVICE_TYPE)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String[] matches = matchDelimitedFields(rawText.substring(2), 9);
|
||||
if (matches == null || !isDigits(matches[7], 8)) {
|
||||
return null;
|
||||
}
|
||||
String fullName = matches[0];
|
||||
String telephoneCell = matches[1];
|
||||
String telephone = matches[2];
|
||||
String email1 = matches[3];
|
||||
String email2 = matches[4];
|
||||
String address = matches[5];
|
||||
String org = matches[6];
|
||||
String birthday = matches[7];
|
||||
String title = matches[8];
|
||||
|
||||
return new AddressBookParsedResult(new String[] {fullName},
|
||||
new String[] {telephoneCell, telephone},
|
||||
new String[] {email1, email2},
|
||||
null,
|
||||
address,
|
||||
org,
|
||||
birthday,
|
||||
title);
|
||||
}
|
||||
|
||||
}
|
|
@ -18,7 +18,7 @@ package com.google.zxing.client.result.optional;
|
|||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.client.result.ParsedReaderResultType;
|
||||
import com.google.zxing.client.result.URIParsedResult;
|
||||
|
||||
/**
|
||||
* <p>Represents a "simple web" result encoded according to section 4.11 of the
|
||||
|
@ -26,7 +26,7 @@ import com.google.zxing.client.result.ParsedReaderResultType;
|
|||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class MobileTagSimpleWebParsedResult extends AbstractMobileTagParsedResult {
|
||||
public final class MobileTagSimpleWebResultParser extends AbstractMobileTagResultParser {
|
||||
|
||||
public static final String SERVICE_TYPE = "04";
|
||||
private static final String[] URI_PREFIXES = {
|
||||
|
@ -38,16 +38,7 @@ public final class MobileTagSimpleWebParsedResult extends AbstractMobileTagParse
|
|||
"rtsp://",
|
||||
};
|
||||
|
||||
private final String title;
|
||||
private final String uri;
|
||||
|
||||
private MobileTagSimpleWebParsedResult(String title, String uri) {
|
||||
super(ParsedReaderResultType.MOBILETAG_SIMPLE_WEB);
|
||||
this.title = title;
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
public static MobileTagSimpleWebParsedResult parse(Result result) {
|
||||
public static URIParsedResult parse(Result result) {
|
||||
if (!result.getBarcodeFormat().equals(BarcodeFormat.DATAMATRIX)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -74,23 +65,7 @@ public final class MobileTagSimpleWebParsedResult extends AbstractMobileTagParse
|
|||
}
|
||||
}
|
||||
|
||||
return new MobileTagSimpleWebParsedResult(title, uri);
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getURI() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
if (title == null) {
|
||||
return uri;
|
||||
} else {
|
||||
return title + '\n' + uri;
|
||||
}
|
||||
return new URIParsedResult(uri, title);
|
||||
}
|
||||
|
||||
}
|
|
@ -18,28 +18,19 @@ package com.google.zxing.client.result.optional;
|
|||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.client.result.ParsedReaderResultType;
|
||||
import com.google.zxing.client.result.TelParsedResult;
|
||||
|
||||
/**
|
||||
* <p>Represents a "TEL" result encoded according to section 4.4 of the
|
||||
* MobileTag Reader International Specification.</p>
|
||||
*
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class MobileTagTelParsedResult extends AbstractMobileTagParsedResult {
|
||||
public final class MobileTagTelResultParser extends AbstractMobileTagResultParser {
|
||||
|
||||
public static final String SERVICE_TYPE = "01";
|
||||
|
||||
private final String number;
|
||||
private final String title;
|
||||
|
||||
private MobileTagTelParsedResult(String number, String title) {
|
||||
super(ParsedReaderResultType.MOBILETAG_TEL);
|
||||
this.number = number;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public static MobileTagTelParsedResult parse(Result result) {
|
||||
public static TelParsedResult parse(Result result) {
|
||||
if (!result.getBarcodeFormat().equals(BarcodeFormat.DATAMATRIX)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -55,23 +46,7 @@ public final class MobileTagTelParsedResult extends AbstractMobileTagParsedResul
|
|||
String number = matches[0];
|
||||
String title = matches[1];
|
||||
|
||||
return new MobileTagTelParsedResult(number, title);
|
||||
}
|
||||
|
||||
public String getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
if (title == null) {
|
||||
return number;
|
||||
} else {
|
||||
return title + '\n' + number;
|
||||
}
|
||||
return new TelParsedResult(number, "tel:" + number, title);
|
||||
}
|
||||
|
||||
}
|
|
@ -56,7 +56,7 @@ final class NDEFRecord {
|
|||
|
||||
int payloadLength = bytes[offset + 2] & 0xFF;
|
||||
|
||||
String type = AbstractNDEFParsedResult.bytesToString(bytes, offset + 3, typeLength, "US-ASCII");
|
||||
String type = AbstractNDEFResultParser.bytesToString(bytes, offset + 3, typeLength, "US-ASCII");
|
||||
|
||||
byte[] payload = new byte[payloadLength];
|
||||
System.arraycopy(bytes, offset + 3 + typeLength, payload, 0, payloadLength);
|
||||
|
|
|
@ -16,21 +16,13 @@
|
|||
|
||||
package com.google.zxing.client.result.optional;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.client.result.ParsedReaderResultType;
|
||||
import com.google.zxing.client.result.ParsedResult;
|
||||
import com.google.zxing.client.result.ParsedResultType;
|
||||
|
||||
/**
|
||||
* <p>Recognizes an NDEF message that encodes information according to the
|
||||
* "Smart Poster Record Type Definition" specification.</p>
|
||||
*
|
||||
* <p>This actually only supports some parts of the Smart Poster format: title,
|
||||
* URI, and action records. Icon records are not supported because the size
|
||||
* of these records are infeasibly large for barcodes. Size and type records
|
||||
* are not supported. Multiple titles are not supported.</p>
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class NDEFSmartPosterParsedResult extends AbstractNDEFParsedResult {
|
||||
public final class NDEFSmartPosterParsedResult extends ParsedResult {
|
||||
|
||||
public static final int ACTION_UNSPECIFIED = -1;
|
||||
public static final int ACTION_DO = 0;
|
||||
|
@ -41,53 +33,11 @@ public final class NDEFSmartPosterParsedResult extends AbstractNDEFParsedResult
|
|||
private String uri;
|
||||
private int action;
|
||||
|
||||
private NDEFSmartPosterParsedResult() {
|
||||
super(ParsedReaderResultType.NDEF_SMART_POSTER);
|
||||
action = ACTION_UNSPECIFIED;
|
||||
}
|
||||
|
||||
public static NDEFSmartPosterParsedResult parse(Result result) {
|
||||
byte[] bytes = result.getRawBytes();
|
||||
if (bytes == null) {
|
||||
return null;
|
||||
}
|
||||
NDEFRecord headerRecord = NDEFRecord.readRecord(bytes, 0);
|
||||
// Yes, header record starts and ends a message
|
||||
if (headerRecord == null || !headerRecord.isMessageBegin() || !headerRecord.isMessageEnd()) {
|
||||
return null;
|
||||
}
|
||||
if (!headerRecord.getType().equals(NDEFRecord.SMART_POSTER_WELL_KNOWN_TYPE)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int offset = 0;
|
||||
int recordNumber = 0;
|
||||
NDEFRecord ndefRecord = null;
|
||||
byte[] payload = headerRecord.getPayload();
|
||||
NDEFSmartPosterParsedResult smartPosterParsedResult = new NDEFSmartPosterParsedResult();
|
||||
|
||||
while (offset < payload.length && (ndefRecord = NDEFRecord.readRecord(payload, offset)) != null) {
|
||||
if (recordNumber == 0 && !ndefRecord.isMessageBegin()) {
|
||||
return null;
|
||||
}
|
||||
String type = ndefRecord.getType();
|
||||
if (NDEFRecord.TEXT_WELL_KNOWN_TYPE.equals(type)) {
|
||||
String[] languageText = NDEFTextParsedResult.decodeTextPayload(ndefRecord.getPayload());
|
||||
smartPosterParsedResult.title = languageText[1];
|
||||
} else if (NDEFRecord.URI_WELL_KNOWN_TYPE.equals(type)) {
|
||||
smartPosterParsedResult.uri = NDEFURIParsedResult.decodeURIPayload(ndefRecord.getPayload());
|
||||
} else if (NDEFRecord.ACTION_WELL_KNOWN_TYPE.equals(type)) {
|
||||
smartPosterParsedResult.action = ndefRecord.getPayload()[0];
|
||||
}
|
||||
recordNumber++;
|
||||
offset += ndefRecord.getTotalRecordLength();
|
||||
}
|
||||
|
||||
if (recordNumber == 0 || (ndefRecord != null && !ndefRecord.isMessageEnd())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return smartPosterParsedResult;
|
||||
NDEFSmartPosterParsedResult(int action, String uri, String title) {
|
||||
super(ParsedResultType.NDEF_SMART_POSTER);
|
||||
this.action = action;
|
||||
this.uri = uri;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.result.optional;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* <p>Recognizes an NDEF message that encodes information according to the
|
||||
* "Smart Poster Record Type Definition" specification.</p>
|
||||
*
|
||||
* <p>This actually only supports some parts of the Smart Poster format: title,
|
||||
* URI, and action records. Icon records are not supported because the size
|
||||
* of these records are infeasibly large for barcodes. Size and type records
|
||||
* are not supported. Multiple titles are not supported.</p>
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class NDEFSmartPosterResultParser extends AbstractNDEFResultParser {
|
||||
|
||||
public static NDEFSmartPosterParsedResult parse(Result result) {
|
||||
byte[] bytes = result.getRawBytes();
|
||||
if (bytes == null) {
|
||||
return null;
|
||||
}
|
||||
NDEFRecord headerRecord = NDEFRecord.readRecord(bytes, 0);
|
||||
// Yes, header record starts and ends a message
|
||||
if (headerRecord == null || !headerRecord.isMessageBegin() || !headerRecord.isMessageEnd()) {
|
||||
return null;
|
||||
}
|
||||
if (!headerRecord.getType().equals(NDEFRecord.SMART_POSTER_WELL_KNOWN_TYPE)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int offset = 0;
|
||||
int recordNumber = 0;
|
||||
NDEFRecord ndefRecord = null;
|
||||
byte[] payload = headerRecord.getPayload();
|
||||
int action = NDEFSmartPosterParsedResult.ACTION_UNSPECIFIED;
|
||||
String title = null;
|
||||
String uri = null;
|
||||
|
||||
while (offset < payload.length && (ndefRecord = NDEFRecord.readRecord(payload, offset)) != null) {
|
||||
if (recordNumber == 0 && !ndefRecord.isMessageBegin()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String type = ndefRecord.getType();
|
||||
if (NDEFRecord.TEXT_WELL_KNOWN_TYPE.equals(type)) {
|
||||
String[] languageText = NDEFTextResultParser.decodeTextPayload(ndefRecord.getPayload());
|
||||
title = languageText[1];
|
||||
} else if (NDEFRecord.URI_WELL_KNOWN_TYPE.equals(type)) {
|
||||
uri = NDEFURIResultParser.decodeURIPayload(ndefRecord.getPayload());
|
||||
} else if (NDEFRecord.ACTION_WELL_KNOWN_TYPE.equals(type)) {
|
||||
action = ndefRecord.getPayload()[0];
|
||||
}
|
||||
recordNumber++;
|
||||
offset += ndefRecord.getTotalRecordLength();
|
||||
}
|
||||
|
||||
if (recordNumber == 0 || (ndefRecord != null && !ndefRecord.isMessageEnd())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new NDEFSmartPosterParsedResult(action, uri, title);
|
||||
}
|
||||
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
package com.google.zxing.client.result.optional;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.client.result.ParsedReaderResultType;
|
||||
import com.google.zxing.client.result.TextParsedResult;
|
||||
|
||||
/**
|
||||
* Recognizes an NDEF message that encodes text according to the
|
||||
|
@ -25,18 +25,9 @@ import com.google.zxing.client.result.ParsedReaderResultType;
|
|||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class NDEFTextParsedResult extends AbstractNDEFParsedResult {
|
||||
public final class NDEFTextResultParser extends AbstractNDEFResultParser {
|
||||
|
||||
private final String language;
|
||||
private final String text;
|
||||
|
||||
private NDEFTextParsedResult(String language, String text) {
|
||||
super(ParsedReaderResultType.NDEF_TEXT);
|
||||
this.language = language;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public static NDEFTextParsedResult parse(Result result) {
|
||||
public static TextParsedResult parse(Result result) {
|
||||
byte[] bytes = result.getRawBytes();
|
||||
if (bytes == null) {
|
||||
return null;
|
||||
|
@ -49,7 +40,7 @@ public final class NDEFTextParsedResult extends AbstractNDEFParsedResult {
|
|||
return null;
|
||||
}
|
||||
String[] languageText = decodeTextPayload(ndefRecord.getPayload());
|
||||
return new NDEFTextParsedResult(languageText[0], languageText[1]);
|
||||
return new TextParsedResult(languageText[0], languageText[1]);
|
||||
}
|
||||
|
||||
static String[] decodeTextPayload(byte[] payload) {
|
||||
|
@ -63,16 +54,4 @@ public final class NDEFTextParsedResult extends AbstractNDEFParsedResult {
|
|||
return new String[] { language, text };
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
return text;
|
||||
}
|
||||
|
||||
}
|
|
@ -17,15 +17,15 @@
|
|||
package com.google.zxing.client.result.optional;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.client.result.ParsedReaderResultType;
|
||||
import com.google.zxing.client.result.URIParsedResult;
|
||||
|
||||
/**
|
||||
* Recognizes an NDEF message that encodes a URI according to the
|
||||
* "URI Record Type Definition" specification.
|
||||
*
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class NDEFURIParsedResult extends AbstractNDEFParsedResult {
|
||||
public final class NDEFURIResultParser extends AbstractNDEFResultParser {
|
||||
|
||||
private static final String[] URI_PREFIXES = {
|
||||
null,
|
||||
|
@ -66,14 +66,7 @@ public final class NDEFURIParsedResult extends AbstractNDEFParsedResult {
|
|||
"urn:nfc:",
|
||||
};
|
||||
|
||||
private final String uri;
|
||||
|
||||
private NDEFURIParsedResult(String uri) {
|
||||
super(ParsedReaderResultType.NDEF_URI);
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
public static NDEFURIParsedResult parse(Result result) {
|
||||
public static URIParsedResult parse(Result result) {
|
||||
byte[] bytes = result.getRawBytes();
|
||||
if (bytes == null) {
|
||||
return null;
|
||||
|
@ -86,7 +79,7 @@ public final class NDEFURIParsedResult extends AbstractNDEFParsedResult {
|
|||
return null;
|
||||
}
|
||||
String fullURI = decodeURIPayload(ndefRecord.getPayload());
|
||||
return new NDEFURIParsedResult(fullURI);
|
||||
return new URIParsedResult(fullURI, null);
|
||||
}
|
||||
|
||||
static String decodeURIPayload(byte[] payload) {
|
||||
|
@ -99,12 +92,4 @@ public final class NDEFURIParsedResult extends AbstractNDEFParsedResult {
|
|||
return prefix == null ? restOfURI : prefix + restOfURI;
|
||||
}
|
||||
|
||||
public String getURI() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
}
|
|
@ -21,89 +21,89 @@ import com.google.zxing.Result;
|
|||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Tests {@link ParsedReaderResult}.
|
||||
* Tests {@link ParsedResult}.
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class ParsedReaderResultTestCase extends TestCase {
|
||||
|
||||
public void testTextType() {
|
||||
doTestResult("foo", ParsedReaderResultType.TEXT);
|
||||
doTestResult("", ParsedReaderResultType.TEXT);
|
||||
doTestResult("This is a test", ParsedReaderResultType.TEXT);
|
||||
doTestResult("foo", ParsedResultType.TEXT);
|
||||
doTestResult("", ParsedResultType.TEXT);
|
||||
doTestResult("This is a test", ParsedResultType.TEXT);
|
||||
}
|
||||
|
||||
public void testBookmarkType() {
|
||||
doTestResult("MEBKM:URL:google.com;;", ParsedReaderResultType.BOOKMARK);
|
||||
doTestResult("MEBKM:URL:google.com;TITLE:Google;;", ParsedReaderResultType.BOOKMARK);
|
||||
doTestResult("MEBKM:TITLE:Google;URL:google.com;;", ParsedReaderResultType.BOOKMARK);
|
||||
doTestResult("MEBKM:URL:http://google.com;;", ParsedReaderResultType.BOOKMARK);
|
||||
doTestResult("MEBKM:URL:HTTPS://google.com;;", ParsedReaderResultType.BOOKMARK);
|
||||
doTestResult("MEBKM:URL:google.com;;", ParsedResultType.URI);
|
||||
doTestResult("MEBKM:URL:google.com;TITLE:Google;;", ParsedResultType.URI);
|
||||
doTestResult("MEBKM:TITLE:Google;URL:google.com;;", ParsedResultType.URI);
|
||||
doTestResult("MEBKM:URL:http://google.com;;", ParsedResultType.URI);
|
||||
doTestResult("MEBKM:URL:HTTPS://google.com;;", ParsedResultType.URI);
|
||||
}
|
||||
|
||||
public void testURLTOType() {
|
||||
doTestResult("URLTO:foo:bar.com", ParsedReaderResultType.URLTO);
|
||||
doTestResult("URLTO::bar.com", ParsedReaderResultType.URLTO);
|
||||
doTestResult("URLTO::http://bar.com", ParsedReaderResultType.URLTO);
|
||||
doTestResult("URLTO:foo:bar.com", ParsedResultType.URI);
|
||||
doTestResult("URLTO::bar.com", ParsedResultType.URI);
|
||||
doTestResult("URLTO::http://bar.com", ParsedResultType.URI);
|
||||
}
|
||||
|
||||
public void testEmailType() {
|
||||
doTestResult("MATMSG:TO:srowen@example.org;;", ParsedReaderResultType.EMAIL);
|
||||
doTestResult("MATMSG:TO:srowen@example.org;SUB:Stuff;;", ParsedReaderResultType.EMAIL);
|
||||
doTestResult("MATMSG:TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;", ParsedReaderResultType.EMAIL);
|
||||
doTestResult("MATMSG:SUB:Stuff;BODY:This is some text;TO:srowen@example.org;;", ParsedReaderResultType.EMAIL);
|
||||
doTestResult("TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;", ParsedReaderResultType.TEXT);
|
||||
doTestResult("MATMSG:TO:srowen@example.org;;", ParsedResultType.EMAIL_ADDRESS);
|
||||
doTestResult("MATMSG:TO:srowen@example.org;SUB:Stuff;;", ParsedResultType.EMAIL_ADDRESS);
|
||||
doTestResult("MATMSG:TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;", ParsedResultType.EMAIL_ADDRESS);
|
||||
doTestResult("MATMSG:SUB:Stuff;BODY:This is some text;TO:srowen@example.org;;", ParsedResultType.EMAIL_ADDRESS);
|
||||
doTestResult("TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;", ParsedResultType.TEXT);
|
||||
}
|
||||
|
||||
public void testEmailAddressType() {
|
||||
doTestResult("srowen@example.org", ParsedReaderResultType.EMAIL_ADDRESS);
|
||||
doTestResult("mailto:srowen@example.org", ParsedReaderResultType.EMAIL_ADDRESS);
|
||||
doTestResult("srowen@example", ParsedReaderResultType.TEXT);
|
||||
doTestResult("srowen", ParsedReaderResultType.TEXT);
|
||||
doTestResult("Let's meet @ 2", ParsedReaderResultType.TEXT);
|
||||
doTestResult("srowen@example.org", ParsedResultType.EMAIL_ADDRESS);
|
||||
doTestResult("mailto:srowen@example.org", ParsedResultType.EMAIL_ADDRESS);
|
||||
doTestResult("srowen@example", ParsedResultType.TEXT);
|
||||
doTestResult("srowen", ParsedResultType.TEXT);
|
||||
doTestResult("Let's meet @ 2", ParsedResultType.TEXT);
|
||||
}
|
||||
|
||||
public void testAddressBookType() {
|
||||
doTestResult("MECARD:N:Sean Owen;;", ParsedReaderResultType.ADDRESSBOOK);
|
||||
doTestResult("MECARD:TEL:+12125551212;N:Sean Owen;;", ParsedReaderResultType.ADDRESSBOOK);
|
||||
doTestResult("MECARD:TEL:+12125551212;N:Sean Owen;URL:google.com;;", ParsedReaderResultType.ADDRESSBOOK);
|
||||
doTestResult("TEL:+12125551212;N:Sean Owen;;", ParsedReaderResultType.TEXT);
|
||||
doTestResult("MECARD:N:Sean Owen;;", ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("MECARD:TEL:+12125551212;N:Sean Owen;;", ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("MECARD:TEL:+12125551212;N:Sean Owen;URL:google.com;;", ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("TEL:+12125551212;N:Sean Owen;;", ParsedResultType.TEXT);
|
||||
}
|
||||
|
||||
public void testAddressBookAUType() {
|
||||
doTestResult("MEMORY:\r\n", ParsedReaderResultType.ADDRESSBOOK_AU);
|
||||
doTestResult("MEMORY:foo\r\nNAME1:Sean\r\n", ParsedReaderResultType.ADDRESSBOOK_AU);
|
||||
doTestResult("TEL1:+12125551212\r\nMEMORY:\r\n", ParsedReaderResultType.ADDRESSBOOK_AU);
|
||||
doTestResult("MEMORY:\r\n", ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("MEMORY:foo\r\nNAME1:Sean\r\n", ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("TEL1:+12125551212\r\nMEMORY:\r\n", ParsedResultType.ADDRESSBOOK);
|
||||
}
|
||||
|
||||
public void testUPC() {
|
||||
doTestResult("123456789012", ParsedReaderResultType.UPC, BarcodeFormat.UPC_A);
|
||||
doTestResult("1234567890123", ParsedReaderResultType.UPC, BarcodeFormat.UPC_A);
|
||||
doTestResult("12345678901", ParsedReaderResultType.TEXT);
|
||||
doTestResult("123456789012", ParsedResultType.UPC, BarcodeFormat.UPC_A);
|
||||
doTestResult("1234567890123", ParsedResultType.UPC, BarcodeFormat.UPC_A);
|
||||
doTestResult("12345678901", ParsedResultType.TEXT);
|
||||
}
|
||||
|
||||
public void testURI() {
|
||||
doTestResult("http://google.com", ParsedReaderResultType.URI);
|
||||
doTestResult("google.com", ParsedReaderResultType.URI);
|
||||
doTestResult("https://google.com", ParsedReaderResultType.URI);
|
||||
doTestResult("HTTP://google.com", ParsedReaderResultType.URI);
|
||||
doTestResult("http://google.com/foobar", ParsedReaderResultType.URI);
|
||||
doTestResult("https://google.com:443/foobar", ParsedReaderResultType.URI);
|
||||
doTestResult("google.com:443/foobar", ParsedReaderResultType.URI);
|
||||
doTestResult("http://google.com", ParsedResultType.URI);
|
||||
doTestResult("google.com", ParsedResultType.URI);
|
||||
doTestResult("https://google.com", ParsedResultType.URI);
|
||||
doTestResult("HTTP://google.com", ParsedResultType.URI);
|
||||
doTestResult("http://google.com/foobar", ParsedResultType.URI);
|
||||
doTestResult("https://google.com:443/foobar", ParsedResultType.URI);
|
||||
doTestResult("google.com:443/foobar", ParsedResultType.URI);
|
||||
}
|
||||
|
||||
public void testGeo() {
|
||||
doTestResult("geo:1,2", ParsedReaderResultType.GEO);
|
||||
doTestResult("geo:1,2,3", ParsedReaderResultType.GEO);
|
||||
doTestResult("geo:100.33,-32.3344,3.35", ParsedReaderResultType.GEO);
|
||||
doTestResult("geography", ParsedReaderResultType.TEXT);
|
||||
doTestResult("geo:1,2", ParsedResultType.GEO);
|
||||
doTestResult("geo:1,2,3", ParsedResultType.GEO);
|
||||
doTestResult("geo:100.33,-32.3344,3.35", ParsedResultType.GEO);
|
||||
doTestResult("geography", ParsedResultType.TEXT);
|
||||
}
|
||||
|
||||
public void testTel() {
|
||||
doTestResult("tel:+15551212", ParsedReaderResultType.TEL);
|
||||
doTestResult("tel:212 555 1212", ParsedReaderResultType.TEL);
|
||||
doTestResult("tel:2125551212", ParsedReaderResultType.TEL);
|
||||
doTestResult("telephone", ParsedReaderResultType.TEXT);
|
||||
doTestResult("tel:+15551212", ParsedResultType.TEL);
|
||||
doTestResult("tel:212 555 1212", ParsedResultType.TEL);
|
||||
doTestResult("tel:2125551212", ParsedResultType.TEL);
|
||||
doTestResult("telephone", ParsedResultType.TEXT);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -111,14 +111,14 @@ public final class ParsedReaderResultTestCase extends TestCase {
|
|||
doTestResult(new byte[] {(byte)0xD1,(byte)0x01,(byte)0x05,(byte)0x54,
|
||||
(byte)0x02,(byte)0x65,(byte)0x6E,(byte)0x68,
|
||||
(byte)0x69},
|
||||
ParsedReaderResultType.NDEF_TEXT);
|
||||
ParsedResultType.NDEF_TEXT);
|
||||
}
|
||||
|
||||
public void testNDEFURI() {
|
||||
doTestResult(new byte[] {(byte)0xD1,(byte)0x01,(byte)0x08,(byte)0x55,
|
||||
(byte)0x01,(byte)0x6E,(byte)0x66,(byte)0x63,
|
||||
(byte)0x2E,(byte)0x63,(byte)0x6F,(byte)0x6D},
|
||||
ParsedReaderResultType.NDEF_URI);
|
||||
ParsedResultType.NDEF_URI);
|
||||
}
|
||||
|
||||
public void testNDEFSmartPoster() {
|
||||
|
@ -135,24 +135,24 @@ public final class ParsedReaderResultTestCase extends TestCase {
|
|||
(byte)0x48,(byte)0x65,(byte)0x6C,(byte)0x6C,
|
||||
(byte)0x6F,(byte)0x2C,(byte)0x20,(byte)0x77,
|
||||
(byte)0x6F,(byte)0x72,(byte)0x6C,(byte)0x64},
|
||||
ParsedReaderResultType.NDEF_SMART_POSTER);
|
||||
ParsedResultType.NDEF_SMART_POSTER);
|
||||
}
|
||||
*/
|
||||
|
||||
private static void doTestResult(String text, ParsedReaderResultType type) {
|
||||
private static void doTestResult(String text, ParsedResultType type) {
|
||||
doTestResult(text, type, null);
|
||||
}
|
||||
|
||||
private static void doTestResult(String text, ParsedReaderResultType type, BarcodeFormat format) {
|
||||
private static void doTestResult(String text, ParsedResultType type, BarcodeFormat format) {
|
||||
Result fakeResult = new Result(text, null, null, format);
|
||||
ParsedReaderResult result = ParsedReaderResult.parseReaderResult(fakeResult);
|
||||
ParsedResult result = ResultParser.parseReaderResult(fakeResult);
|
||||
assertNotNull(result);
|
||||
assertEquals(type, result.getType());
|
||||
}
|
||||
|
||||
private static void doTestResult(byte[] rawBytes, ParsedReaderResultType type) {
|
||||
private static void doTestResult(byte[] rawBytes, ParsedResultType type) {
|
||||
Result fakeResult = new Result(null, rawBytes, null, null);
|
||||
ParsedReaderResult result = ParsedReaderResult.parseReaderResult(fakeResult);
|
||||
ParsedResult result = ResultParser.parseReaderResult(fakeResult);
|
||||
assertNotNull(result);
|
||||
assertEquals(type, result.getType());
|
||||
}
|
||||
|
|
|
@ -17,17 +17,14 @@
|
|||
package com.google.zxing.client.j2me;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.client.result.BookmarkDoCoMoParsedResult;
|
||||
import com.google.zxing.client.result.EmailAddressParsedResult;
|
||||
import com.google.zxing.client.result.EmailDoCoMoParsedResult;
|
||||
import com.google.zxing.client.result.ParsedReaderResult;
|
||||
import com.google.zxing.client.result.ParsedReaderResultType;
|
||||
import com.google.zxing.client.result.ParsedResult;
|
||||
import com.google.zxing.client.result.ParsedResultType;
|
||||
import com.google.zxing.client.result.ResultParser;
|
||||
import com.google.zxing.client.result.SMSParsedResult;
|
||||
import com.google.zxing.client.result.SMSTOParsedResult;
|
||||
import com.google.zxing.client.result.TelParsedResult;
|
||||
import com.google.zxing.client.result.UPCParsedResult;
|
||||
import com.google.zxing.client.result.URIParsedResult;
|
||||
import com.google.zxing.client.result.URLTOParsedResult;
|
||||
|
||||
import javax.microedition.io.ConnectionNotFoundException;
|
||||
import javax.microedition.lcdui.Alert;
|
||||
|
@ -195,34 +192,22 @@ public final class ZXingMIDlet extends MIDlet {
|
|||
}
|
||||
|
||||
void handleDecodedText(Result theResult) {
|
||||
ParsedReaderResult result = ParsedReaderResult.parseReaderResult(theResult);
|
||||
ParsedReaderResultType type = result.getType();
|
||||
if (type.equals(ParsedReaderResultType.URI)) {
|
||||
ParsedResult result = ResultParser.parseReaderResult(theResult);
|
||||
ParsedResultType type = result.getType();
|
||||
if (type.equals(ParsedResultType.URI)) {
|
||||
String uri = ((URIParsedResult) result).getURI();
|
||||
showOpenURL("Open Web Page?", uri, uri);
|
||||
} else if (type.equals(ParsedReaderResultType.BOOKMARK)) {
|
||||
String uri = ((BookmarkDoCoMoParsedResult) result).getURI();
|
||||
showOpenURL("Open Web Page?", uri, uri);
|
||||
} else if (type.equals(ParsedReaderResultType.URLTO)) {
|
||||
String uri = ((URLTOParsedResult) result).getURI();
|
||||
showOpenURL("Open Web Page?", uri, uri);
|
||||
} else if (type.equals(ParsedReaderResultType.EMAIL)) {
|
||||
EmailDoCoMoParsedResult emailResult = (EmailDoCoMoParsedResult) result;
|
||||
showOpenURL("Compose E-mail?", emailResult.getTo(), emailResult.getMailtoURI());
|
||||
} else if (type.equals(ParsedReaderResultType.EMAIL_ADDRESS)) {
|
||||
} else if (type.equals(ParsedResultType.EMAIL_ADDRESS)) {
|
||||
EmailAddressParsedResult emailResult = (EmailAddressParsedResult) result;
|
||||
showOpenURL("Compose E-mail?", emailResult.getEmailAddress(), emailResult.getMailtoURI());
|
||||
} else if (type.equals(ParsedReaderResultType.SMS)) {
|
||||
} else if (type.equals(ParsedResultType.SMS)) {
|
||||
SMSParsedResult smsResult = (SMSParsedResult) result;
|
||||
showOpenURL("Compose SMS?", smsResult.getNumber(), smsResult.getSMSURI());
|
||||
} else if (type.equals(ParsedReaderResultType.SMSTO)) {
|
||||
SMSTOParsedResult smsToResult = (SMSTOParsedResult) result;
|
||||
showOpenURL("Compose SMS?", smsToResult.getNumber(), smsToResult.getSMSURI());
|
||||
} else if (type.equals(ParsedReaderResultType.UPC)) {
|
||||
} else if (type.equals(ParsedResultType.UPC)) {
|
||||
String upc = ((UPCParsedResult) result).getUPC();
|
||||
String uri = "http://www.upcdatabase.com/item.asp?upc=" + upc;
|
||||
showOpenURL("Look Up Barcode Online?", upc, uri);
|
||||
} else if (type.equals(ParsedReaderResultType.TEL)) {
|
||||
} else if (type.equals(ParsedResultType.TEL)) {
|
||||
TelParsedResult telResult = (TelParsedResult) result;
|
||||
showOpenURL("Dial Number?", telResult.getNumber(), telResult.getTelURI());
|
||||
} else {
|
||||
|
|
|
@ -22,7 +22,8 @@ import com.google.zxing.Reader;
|
|||
import com.google.zxing.ReaderException;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.client.j2se.BufferedImageMonochromeBitmapSource;
|
||||
import com.google.zxing.client.result.ParsedReaderResult;
|
||||
import com.google.zxing.client.result.ParsedResult;
|
||||
import com.google.zxing.client.result.ResultParser;
|
||||
import org.apache.commons.fileupload.FileItem;
|
||||
import org.apache.commons.fileupload.FileUploadException;
|
||||
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||
|
@ -243,8 +244,8 @@ public final class DecodeServlet extends HttpServlet {
|
|||
} else {
|
||||
request.setAttribute("rawBytesString", "(Not applicable)");
|
||||
}
|
||||
ParsedReaderResult parsedReaderResult = ParsedReaderResult.parseReaderResult(result);
|
||||
request.setAttribute("parsedReaderResult", parsedReaderResult);
|
||||
ParsedResult parsedResult = ResultParser.parseReaderResult(result);
|
||||
request.setAttribute("parsedResult", parsedResult);
|
||||
request.getRequestDispatcher("decoderesult.jspx").forward(request, response);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
<jsp:directive.page contentType="application/xhtml+xml" session="false"/>
|
||||
<jsp:scriptlet>response.setHeader("Cache-Control", "no-cache");</jsp:scriptlet>
|
||||
<jsp:useBean id="result" scope="request" type="com.google.zxing.Result"/>
|
||||
<jsp:useBean id="parsedReaderResult" scope="request" type="com.google.zxing.client.result.ParsedReaderResult"/>
|
||||
<jsp:useBean id="parsedResult" scope="request" type="com.google.zxing.client.result.ParsedResult"/>
|
||||
<jsp:useBean id="rawBytesString" scope="request" type="java.lang.String"/>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
||||
<head>
|
||||
|
|
Loading…
Reference in a new issue