Added "URLTO" format support
authorsrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Mon, 25 Feb 2008 22:15:36 +0000 (22:15 +0000)
committersrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Mon, 25 Feb 2008 22:15:36 +0000 (22:15 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@229 59b500cc-1b3d-0410-9834-0bbf25fbcc57

android/src/com/google/zxing/client/android/BarcodeReaderCaptureActivity.java
android/src/com/google/zxing/client/android/ResultHandler.java
core/src/com/google/zxing/client/result/ParsedReaderResult.java
core/src/com/google/zxing/client/result/ParsedReaderResultType.java
core/src/com/google/zxing/client/result/URLTOResult.java [new file with mode: 0644]
core/test/src/com/google/zxing/client/result/ParsedReaderResultTestCase.java
javame/src/com/google/zxing/client/j2me/ZXingMIDlet.java

index 3b72d26..04b2a97 100644 (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;
     }
index de09fc0..2489ceb 100755 (executable)
@@ -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 {
index f80bf71..d4ec515 100644 (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) {
index ae3f43a..48225ae 100644 (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;
   }
 
 }
diff --git a/core/src/com/google/zxing/client/result/URLTOResult.java b/core/src/com/google/zxing/client/result/URLTOResult.java
new file mode 100644 (file)
index 0000000..eca1dc2
--- /dev/null
@@ -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;
+    }
+  }
+
+}
\ No newline at end of file
index a7d9ee5..b8a6e4e 100644 (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);
index 2f86245..e20544b 100644 (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();