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;
}
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;
} 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 {
} catch (IllegalArgumentException iae) {
// continue
}
+ try {
+ return new URLTOResult(rawText);
+ } catch (IllegalArgumentException iae) {
+ // continue
+ }
try {
return new URIParsedResult(rawText);
} catch (IllegalArgumentException iae) {
*/
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;
}
}
--- /dev/null
+/*
+ * 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;
+ }
+ }
+
+}
\ No newline at end of file
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);
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;
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();