From 6de693fa067d5e81d717ad5cdda035a80e080ccc Mon Sep 17 00:00:00 2001 From: srowen Date: Mon, 28 Nov 2011 15:06:44 +0000 Subject: [PATCH] Issue 1079 return metadata like byte segments and more in Intent extras; add raw bytes to intent integrator code git-svn-id: https://zxing.googlecode.com/svn/trunk@2053 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../integration/android/IntentIntegrator.java | 5 +++-- .../integration/android/IntentResult.java | 15 +++++++++++++- .../zxing/client/android/CaptureActivity.java | 20 +++++++++++++++++++ .../google/zxing/client/android/Intents.java | 19 ++++++++++++++++++ 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java b/android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java index 603b0244e..19d618a13 100644 --- a/android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java +++ b/android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java @@ -291,9 +291,10 @@ public final class IntentIntegrator { if (resultCode == Activity.RESULT_OK) { String contents = intent.getStringExtra("SCAN_RESULT"); String formatName = intent.getStringExtra("SCAN_RESULT_FORMAT"); - return new IntentResult(contents, formatName); + byte[] rawBytes = intent.getByteArrayExtra("SCAN_RESULT_BYTES"); + return new IntentResult(contents, formatName, rawBytes); } - return new IntentResult(null, null); + return new IntentResult(); } return null; } diff --git a/android-integration/src/com/google/zxing/integration/android/IntentResult.java b/android-integration/src/com/google/zxing/integration/android/IntentResult.java index 5f41c9b8f..3e9578f39 100644 --- a/android-integration/src/com/google/zxing/integration/android/IntentResult.java +++ b/android-integration/src/com/google/zxing/integration/android/IntentResult.java @@ -25,10 +25,16 @@ public final class IntentResult { private final String contents; private final String formatName; + private final byte[] rawBytes; - IntentResult(String contents, String formatName) { + IntentResult() { + this(null, null, null); + } + + IntentResult(String contents, String formatName, byte[] rawBytes) { this.contents = contents; this.formatName = formatName; + this.rawBytes = rawBytes; } /** @@ -45,4 +51,11 @@ public final class IntentResult { return formatName; } + /** + * @return raw bytes of the barcode content, if applicable, or null otherwise + */ + public byte[] getRawBytes() { + return rawBytes; + } + } diff --git a/android/src/com/google/zxing/client/android/CaptureActivity.java b/android/src/com/google/zxing/client/android/CaptureActivity.java index c6d95a333..4469ba23e 100755 --- a/android/src/com/google/zxing/client/android/CaptureActivity.java +++ b/android/src/com/google/zxing/client/android/CaptureActivity.java @@ -68,6 +68,7 @@ import java.text.DateFormat; import java.util.Collection; import java.util.Date; import java.util.EnumSet; +import java.util.List; import java.util.Map; import java.util.Set; @@ -569,6 +570,25 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal if (rawBytes != null && rawBytes.length > 0) { intent.putExtra(Intents.Scan.RESULT_BYTES, rawBytes); } + Map metadata = rawResult.getResultMetadata(); + if (metadata != null) { + Integer orientation = (Integer) metadata.get(ResultMetadataType.ORIENTATION); + if (orientation != null) { + intent.putExtra(Intents.Scan.RESULT_ORIENTATION, orientation); + } + String ecLevel = (String) metadata.get(ResultMetadataType.ERROR_CORRECTION_LEVEL); + if (ecLevel != null) { + intent.putExtra(Intents.Scan.RESULT_ERROR_CORRECTION_LEVEL, ecLevel); + } + List byteSegments = (List) metadata.get(ResultMetadataType.BYTE_SEGMENTS); + if (byteSegments != null) { + int i = 0; + for (byte[] byteSegment : byteSegments) { + intent.putExtra(Intents.Scan.RESULT_BYTE_SEGMENTS_PREFIX + i, byteSegment); + i++; + } + } + } Message message = Message.obtain(handler, R.id.return_scan_result); message.obj = intent; handler.sendMessageDelayed(message, INTENT_RESULT_DURATION); diff --git a/android/src/com/google/zxing/client/android/Intents.java b/android/src/com/google/zxing/client/android/Intents.java index 0f2d1bd35..7ca6d962c 100755 --- a/android/src/com/google/zxing/client/android/Intents.java +++ b/android/src/com/google/zxing/client/android/Intents.java @@ -110,6 +110,25 @@ public final class Intents { */ public static final String RESULT_BYTES = "SCAN_RESULT_BYTES"; + /** + * Key for the value of {@link com.google.zxing.ResultMetadataType#ORIENTATION}, if available. + * Call intent.getIntExtra(RESULT_ORIENTATION). + */ + public static final String RESULT_ORIENTATION = "SCAN_RESULT_ORIENTATION"; + + /** + * Key for the value of {@link com.google.zxing.ResultMetadataType#ERROR_CORRECTION_LEVEL}, if available. + * Call intent.getStringExtra(RESULT_ERROR_CORRECTION_LEVEL). + */ + public static final String RESULT_ERROR_CORRECTION_LEVEL = "SCAN_RESULT_ERROR_CORRECTION_LEVEL"; + + /** + * Prefix for keys that map to the values of {@link com.google.zxing.ResultMetadataType#BYTE_SEGMENTS}, + * if available. The actual values will be set under a series of keys formed by adding 0, 1, 2, ... + * to this prefix. So the first byte segment is under key "SCAN_RESULT_BYTE_SEGMENTS_0" for example. + */ + public static final String RESULT_BYTE_SEGMENTS_PREFIX = "SCAN_RESULT_BYTE_SEGMENTS_"; + /** * Setting this to false will not save scanned codes in the history. */