Added "URLTO" format support

git-svn-id: https://zxing.googlecode.com/svn/trunk@229 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2008-02-25 22:15:36 +00:00
parent 89c20544eb
commit 848609c0c5
7 changed files with 101 additions and 13 deletions

View file

@ -182,14 +182,15 @@ public final class BarcodeReaderCaptureActivity extends Activity {
private static int getDialogTitleID(ParsedReaderResultType type) {
if (type == ParsedReaderResultType.ADDRESSBOOK) {
return R.string.title_add_contact;
} else if (type == ParsedReaderResultType.BOOKMARK) {
} else if (type == ParsedReaderResultType.URI ||
type == ParsedReaderResultType.BOOKMARK ||
type == ParsedReaderResultType.URLTO) {
return R.string.title_open_url;
} else if (type == ParsedReaderResultType.EMAIL || type == ParsedReaderResultType.EMAIL_ADDRESS) {
} else if (type == ParsedReaderResultType.EMAIL ||
type == ParsedReaderResultType.EMAIL_ADDRESS) {
return R.string.title_compose_email;
} else if (type == ParsedReaderResultType.UPC) {
return R.string.title_lookup_barcode;
} else if (type == ParsedReaderResultType.URI) {
return R.string.title_open_url;
} else {
return R.string.title_barcode_detected;
}

View file

@ -29,6 +29,7 @@ import com.google.zxing.client.result.ParsedReaderResult;
import com.google.zxing.client.result.ParsedReaderResultType;
import com.google.zxing.client.result.UPCParsedResult;
import com.google.zxing.client.result.URIParsedResult;
import com.google.zxing.client.result.URLTOResult;
import java.net.URISyntaxException;
@ -70,6 +71,13 @@ final class ResultHandler extends Handler {
} catch (URISyntaxException e) {
return;
}
} else if (type == ParsedReaderResultType.URLTO) {
try {
intent = new Intent(Intent.VIEW_ACTION,
new ContentURI(((URLTOResult) result).getURI()));
} catch (URISyntaxException e) {
return;
}
} else if (type == ParsedReaderResultType.EMAIL) {
EmailDoCoMoResult emailResult = (EmailDoCoMoResult) result;
try {

View file

@ -57,6 +57,11 @@ public abstract class ParsedReaderResult {
} catch (IllegalArgumentException iae) {
// continue
}
try {
return new URLTOResult(rawText);
} catch (IllegalArgumentException iae) {
// continue
}
try {
return new URIParsedResult(rawText);
} catch (IllegalArgumentException iae) {

View file

@ -24,16 +24,23 @@ package com.google.zxing.client.result;
*/
public final class ParsedReaderResultType {
public static final ParsedReaderResultType BOOKMARK = new ParsedReaderResultType();
public static final ParsedReaderResultType ADDRESSBOOK = new ParsedReaderResultType();
public static final ParsedReaderResultType EMAIL = new ParsedReaderResultType();
public static final ParsedReaderResultType EMAIL_ADDRESS = new ParsedReaderResultType();
public static final ParsedReaderResultType UPC = new ParsedReaderResultType();
public static final ParsedReaderResultType URI = new ParsedReaderResultType();
public static final ParsedReaderResultType TEXT = new 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 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");
private ParsedReaderResultType() {
// do nothing
private final String name;
private ParsedReaderResultType(String name) {
this.name = name;
}
public String toString() {
return name;
}
}

View file

@ -0,0 +1,57 @@
/*
* Copyright 2007 Google Inc.
*
* 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;
/**
* "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 URLTOResult extends ParsedReaderResult {
private final String title;
private final String uri;
public URLTOResult(String rawText) {
super(ParsedReaderResultType.URLTO);
if (!rawText.startsWith("URLTO:")) {
throw new IllegalArgumentException("Does not begin with URLTO");
}
int titleEnd = rawText.indexOf(':', 6);
title = rawText.substring(6, titleEnd);
uri = rawText.substring(titleEnd + 1);
}
public String getTitle() {
return title;
}
public String getURI() {
return uri;
}
public String getDisplayResult() {
if (title == null) {
return uri;
} else {
return title + '\n' + uri;
}
}
}

View file

@ -39,6 +39,12 @@ public final class ParsedReaderResultTestCase extends TestCase {
doTestResult("MEBKM:URL:HTTPS://google.com;;", ParsedReaderResultType.BOOKMARK);
}
public void testURLTOType() {
doTestResult("URLTO:foo:bar.com", ParsedReaderResultType.URLTO);
doTestResult("URLTO::bar.com", ParsedReaderResultType.URLTO);
doTestResult("URLTO::http://bar.com", ParsedReaderResultType.URLTO);
}
public void testEmailType() {
doTestResult("MATMSG:TO:srowen@example.org;;", ParsedReaderResultType.EMAIL);
doTestResult("MATMSG:TO:srowen@example.org;SUB:Stuff;;", ParsedReaderResultType.EMAIL);

View file

@ -23,6 +23,7 @@ import com.google.zxing.client.result.ParsedReaderResult;
import com.google.zxing.client.result.ParsedReaderResultType;
import com.google.zxing.client.result.UPCParsedResult;
import com.google.zxing.client.result.URIParsedResult;
import com.google.zxing.client.result.URLTOResult;
import javax.microedition.io.ConnectionNotFoundException;
import javax.microedition.lcdui.Alert;
@ -191,6 +192,9 @@ public final class ZXingMIDlet extends MIDlet {
showOpenURL("Open Web Page?", uri, uri);
} else if (type.equals(ParsedReaderResultType.BOOKMARK)) {
String uri = ((BookmarkDoCoMoResult) result).getURI();
showOpenURL("Open Web Page?", uri, uri);
} else if (type.equals(ParsedReaderResultType.URLTO)) {
String uri = ((URLTOResult) result).getURI();
showOpenURL("Open Web Page?", uri, uri);
} else if (type.equals(ParsedReaderResultType.EMAIL)) {
String email = ((EmailDoCoMoResult) result).getTo();