[SCM] Multi-format 1D/2D barcode image processing library branch, upstream, updated. 24d4480bc48cf9eabf7b2bd2f528248b0e458809

srowen srowen at 59b500cc-1b3d-0410-9834-0bbf25fbcc57
Wed Aug 4 01:30:50 UTC 2010


The following commit has been merged in the upstream branch:
commit 20b88c7ce65c443de9bc8d1e9f55568fd03515f5
Author: srowen <srowen at 59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Date:   Tue Apr 6 12:52:55 2010 +0000

    Issue 370, allow custom response URLs
    
    git-svn-id: http://zxing.googlecode.com/svn/trunk@1286 59b500cc-1b3d-0410-9834-0bbf25fbcc57

diff --git a/AUTHORS b/AUTHORS
index b9e3e1e..2bccccb 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -11,6 +11,7 @@ Christian Brunschen (Google)
 Daniel Switkin (Google)
 David Albert (Bug Labs)
 Diego Pierotto
+Eric Kobrin (Velocitude)
 Erik Barbara
 Fred Lin (Anobiit)
 Hannes Erven
diff --git a/android/src/com/google/zxing/client/android/CaptureActivity.java b/android/src/com/google/zxing/client/android/CaptureActivity.java
index 18b466d..ba5ca28 100755
--- a/android/src/com/google/zxing/client/android/CaptureActivity.java
+++ b/android/src/com/google/zxing/client/android/CaptureActivity.java
@@ -66,6 +66,8 @@ import android.widget.TextView;
 
 import java.io.IOException;
 import java.text.DateFormat;
+import java.util.Arrays;
+import java.util.List;
 import java.util.Date;
 import java.util.Vector;
 import java.util.regex.Pattern;
@@ -96,6 +98,8 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
   private static final String PRODUCT_SEARCH_URL_PREFIX = "http://www.google";
   private static final String PRODUCT_SEARCH_URL_SUFFIX = "/m/products/scan";
   private static final String ZXING_URL = "http://zxing.appspot.com/scan";
+  private static final String RETURN_CODE_PLACEHOLDER = "{CODE}";
+  private static final String RETURN_URL_PARAM = "ret";
 
   static final Vector<BarcodeFormat> PRODUCT_FORMATS;
   static final Vector<BarcodeFormat> ONE_D_FORMATS;
@@ -141,6 +145,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
   private boolean copyToClipboard;
   private Source source;
   private String sourceUrl;
+  private String returnUrlTemplate;
   private Vector<BarcodeFormat> decodeFormats;
   private String characterSet;
   private String versionName;
@@ -218,12 +223,14 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
         sourceUrl = dataString;
         decodeFormats = PRODUCT_FORMATS;
         resetStatusView();
-      } else if (dataString != null && dataString.equals(ZXING_URL)) {
-        // Scan all formats and handle the results ourselves.
-        // TODO: In the future we could allow the hyperlink to include a URL to send the results to.
+      } else if (dataString != null && dataString.startsWith(ZXING_URL)) {
+        // Scan formats requested in query string (all formats if none specified).
+        // If a return URL is specified, send the results there. Otherwise, handle the results ourselves.
         source = Source.ZXING_LINK;
         sourceUrl = dataString;
-        decodeFormats = null;
+        Uri inputUri = Uri.parse(sourceUrl);
+        returnUrlTemplate = inputUri.getQueryParameter(RETURN_URL_PARAM);
+        decodeFormats = parseDecodeFormats(inputUri);
         resetStatusView();
       } else {
         // Scan all formats and handle the results ourselves (launched from Home).
@@ -249,11 +256,25 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
   }
 
   private static Vector<BarcodeFormat> parseDecodeFormats(Intent intent) {
-    String scanFormats = intent.getStringExtra(Intents.Scan.SCAN_FORMATS);
+    return parseDecodeFormats(
+        Arrays.asList(COMMA_PATTERN.split(intent.getStringExtra(Intents.Scan.SCAN_FORMATS))),
+        intent.getStringExtra(Intents.Scan.MODE));
+  }
+  
+  private static Vector<BarcodeFormat> parseDecodeFormats(Uri inputUri) {
+    List<String> formats = inputUri.getQueryParameters(Intents.Scan.SCAN_FORMATS);
+    if (formats.size() == 1){
+      formats = Arrays.asList(COMMA_PATTERN.split(formats.get(0)));
+    }
+    return parseDecodeFormats(formats, inputUri.getQueryParameter(Intents.Scan.MODE));
+  }
+  
+  private static Vector<BarcodeFormat> parseDecodeFormats(List<String> scanFormats,
+                                                          String decodeMode) {
     if (scanFormats != null) {
       Vector<BarcodeFormat> formats = new Vector<BarcodeFormat>();
       try {
-        for (String format : COMMA_PATTERN.split(scanFormats)) {
+        for (String format : scanFormats) {
           formats.add(BarcodeFormat.valueOf(format));
         }
         return formats;
@@ -261,7 +282,6 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
         // ignore it then
       }
     }
-    String decodeMode = intent.getStringExtra(Intents.Scan.MODE);
     if (decodeMode != null) {
       if (Intents.Scan.PRODUCT_MODE.equals(decodeMode)) {
         return PRODUCT_FORMATS;
@@ -415,6 +435,12 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
           handleDecodeExternally(rawResult, barcode);
           break;
         case ZXING_LINK:
+          if(returnUrlTemplate == null){
+            handleDecodeInternally(rawResult, barcode);
+          } else {
+            handleDecodeExternally(rawResult, barcode);
+          }
+          break;
         case NONE:
           handleDecodeInternally(rawResult, barcode);
           break;
@@ -550,6 +576,12 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
       message.obj = sourceUrl.substring(0, end) + "?q=" +
           resultHandler.getDisplayContents().toString() + "&source=zxing";
       handler.sendMessageDelayed(message, INTENT_RESULT_DURATION);
+    } else if (source == Source.ZXING_LINK) {
+    	// Replace each occurrence of RETURN_CODE_PLACEHOLDER in the returnUrlTemplate
+    	// with the scanned code. This allows both queries and REST-style URLs to work.
+      Message message = Message.obtain(handler, R.id.launch_product_query);
+      message.obj = returnUrlTemplate.replace(RETURN_CODE_PLACEHOLDER, resultHandler.getDisplayContents().toString());
+      handler.sendMessageDelayed(message, INTENT_RESULT_DURATION);
     }
   }
 

-- 
Multi-format 1D/2D barcode image processing library



More information about the Pkg-google-commits mailing list