{
+ @NonNull
+ @Override
+ public Intent createIntent(@NonNull Context context, ScanOptions input) {
+ return input.createScanIntent(context);
+ }
+
+ @Override
+ public ScanIntentResult parseResult(int resultCode, @Nullable Intent intent) {
+ return ScanIntentResult.parseActivityResult(resultCode, intent);
+ }
+}
diff --git a/zxing-android-embedded/src/com/journeyapps/barcodescanner/ScanIntentResult.java b/zxing-android-embedded/src/com/journeyapps/barcodescanner/ScanIntentResult.java
new file mode 100644
index 000000000..0adde4bed
--- /dev/null
+++ b/zxing-android-embedded/src/com/journeyapps/barcodescanner/ScanIntentResult.java
@@ -0,0 +1,155 @@
+/*
+ * Based on IntentResult.
+ *
+ * Copyright 2009 ZXing authors
+ *
+ * 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.journeyapps.barcodescanner;
+
+import android.app.Activity;
+import android.content.Intent;
+
+import com.google.zxing.client.android.Intents;
+import com.google.zxing.integration.android.IntentResult;
+
+/**
+ * Encapsulates the result of a barcode scan invoked through {@link ScanContract}.
+ *
+ * @author Sean Owen
+ */
+public final class ScanIntentResult {
+
+ private final String contents;
+ private final String formatName;
+ private final byte[] rawBytes;
+ private final Integer orientation;
+ private final String errorCorrectionLevel;
+ private final String barcodeImagePath;
+ private final Intent originalIntent;
+
+ ScanIntentResult() {
+ this(null, null, null, null, null, null, null);
+ }
+
+ ScanIntentResult(Intent intent) {
+ this(null, null, null, null, null, null, intent);
+ }
+
+ ScanIntentResult(String contents,
+ String formatName,
+ byte[] rawBytes,
+ Integer orientation,
+ String errorCorrectionLevel,
+ String barcodeImagePath,
+ Intent originalIntent) {
+ this.contents = contents;
+ this.formatName = formatName;
+ this.rawBytes = rawBytes;
+ this.orientation = orientation;
+ this.errorCorrectionLevel = errorCorrectionLevel;
+ this.barcodeImagePath = barcodeImagePath;
+ this.originalIntent = originalIntent;
+ }
+
+ /**
+ * @return raw content of barcode
+ */
+ public String getContents() {
+ return contents;
+ }
+
+ /**
+ * @return name of format, like "QR_CODE", "UPC_A". See {@code BarcodeFormat} for more format names.
+ */
+ public String getFormatName() {
+ return formatName;
+ }
+
+ /**
+ * @return raw bytes of the barcode content, if applicable, or null otherwise
+ */
+ public byte[] getRawBytes() {
+ return rawBytes;
+ }
+
+ /**
+ * @return rotation of the image, in degrees, which resulted in a successful scan. May be null.
+ */
+ public Integer getOrientation() {
+ return orientation;
+ }
+
+ /**
+ * @return name of the error correction level used in the barcode, if applicable
+ */
+ public String getErrorCorrectionLevel() {
+ return errorCorrectionLevel;
+ }
+
+ /**
+ * @return path to a temporary file containing the barcode image, if applicable, or null otherwise
+ */
+ public String getBarcodeImagePath() {
+ return barcodeImagePath;
+ }
+
+ /**
+ * @return the original intent
+ */
+ public Intent getOriginalIntent() {
+ return originalIntent;
+ }
+
+ @Override
+ public String toString() {
+ int rawBytesLength = rawBytes == null ? 0 : rawBytes.length;
+ return "Format: " + formatName + '\n' +
+ "Contents: " + contents + '\n' +
+ "Raw bytes: (" + rawBytesLength + " bytes)\n" +
+ "Orientation: " + orientation + '\n' +
+ "EC level: " + errorCorrectionLevel + '\n' +
+ "Barcode image: " + barcodeImagePath + '\n' +
+ "Original intent: " + originalIntent + '\n';
+ }
+
+
+ /**
+ * Parse activity result, without checking the request code.
+ *
+ * @param resultCode result code from {@code onActivityResult()}
+ * @param intent {@link Intent} from {@code onActivityResult()}
+ * @return an {@link IntentResult} containing the result of the scan. If the user cancelled scanning,
+ * the fields will be null.
+ */
+ public static ScanIntentResult parseActivityResult(int resultCode, Intent intent) {
+ if (resultCode == Activity.RESULT_OK) {
+ String contents = intent.getStringExtra(Intents.Scan.RESULT);
+ String formatName = intent.getStringExtra(Intents.Scan.RESULT_FORMAT);
+ byte[] rawBytes = intent.getByteArrayExtra(Intents.Scan.RESULT_BYTES);
+ int intentOrientation = intent.getIntExtra(Intents.Scan.RESULT_ORIENTATION, Integer.MIN_VALUE);
+ Integer orientation = intentOrientation == Integer.MIN_VALUE ? null : intentOrientation;
+ String errorCorrectionLevel = intent.getStringExtra(Intents.Scan.RESULT_ERROR_CORRECTION_LEVEL);
+ String barcodeImagePath = intent.getStringExtra(Intents.Scan.RESULT_BARCODE_IMAGE_PATH);
+ return new ScanIntentResult(contents,
+ formatName,
+ rawBytes,
+ orientation,
+ errorCorrectionLevel,
+ barcodeImagePath,
+ intent);
+ }
+ return new ScanIntentResult(intent);
+ }
+}
diff --git a/zxing-android-embedded/src/com/journeyapps/barcodescanner/ScanOptions.java b/zxing-android-embedded/src/com/journeyapps/barcodescanner/ScanOptions.java
new file mode 100644
index 000000000..2362317df
--- /dev/null
+++ b/zxing-android-embedded/src/com/journeyapps/barcodescanner/ScanOptions.java
@@ -0,0 +1,262 @@
+/*
+ * Based on IntentIntegrator, Copyright 2009 ZXing authors.
+ *
+ */
+package com.journeyapps.barcodescanner;
+
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+
+import com.google.zxing.client.android.Intents;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class ScanOptions {
+ // supported barcode formats
+
+ // Product Codes
+ public static final String UPC_A = "UPC_A";
+ public static final String UPC_E = "UPC_E";
+ public static final String EAN_8 = "EAN_8";
+ public static final String EAN_13 = "EAN_13";
+ public static final String RSS_14 = "RSS_14";
+
+ // Other 1D
+ public static final String CODE_39 = "CODE_39";
+ public static final String CODE_93 = "CODE_93";
+ public static final String CODE_128 = "CODE_128";
+ public static final String ITF = "ITF";
+
+ public static final String RSS_EXPANDED = "RSS_EXPANDED";
+
+ // 2D
+ public static final String QR_CODE = "QR_CODE";
+ public static final String DATA_MATRIX = "DATA_MATRIX";
+ public static final String PDF_417 = "PDF_417";
+
+
+ public static final Collection PRODUCT_CODE_TYPES = list(UPC_A, UPC_E, EAN_8, EAN_13, RSS_14);
+ public static final Collection ONE_D_CODE_TYPES =
+ list(UPC_A, UPC_E, EAN_8, EAN_13, RSS_14, CODE_39, CODE_93, CODE_128,
+ ITF, RSS_14, RSS_EXPANDED);
+
+ public static final Collection ALL_CODE_TYPES = null;
+
+ private final Map moreExtras = new HashMap<>(3);
+
+ private Collection desiredBarcodeFormats;
+
+ private Class> captureActivity;
+
+
+ protected Class> getDefaultCaptureActivity() {
+ return CaptureActivity.class;
+ }
+
+ public ScanOptions() {
+
+ }
+
+
+ public Class> getCaptureActivity() {
+ if (captureActivity == null) {
+ captureActivity = getDefaultCaptureActivity();
+ }
+ return captureActivity;
+ }
+
+ /**
+ * Set the Activity class to use. It can be any activity, but should handle the intent extras
+ * as used here.
+ *
+ * @param captureActivity the class
+ */
+ public ScanOptions setCaptureActivity(Class> captureActivity) {
+ this.captureActivity = captureActivity;
+ return this;
+ }
+
+ public Map getMoreExtras() {
+ return moreExtras;
+ }
+
+ public final ScanOptions addExtra(String key, Object value) {
+ moreExtras.put(key, value);
+ return this;
+ }
+
+ /**
+ * Set a prompt to display on the capture screen, instead of using the default.
+ *
+ * @param prompt the prompt to display
+ */
+ public final ScanOptions setPrompt(String prompt) {
+ if (prompt != null) {
+ addExtra(Intents.Scan.PROMPT_MESSAGE, prompt);
+ }
+ return this;
+ }
+
+ /**
+ * By default, the orientation is locked. Set to false to not lock.
+ *
+ * @param locked true to lock orientation
+ */
+ public ScanOptions setOrientationLocked(boolean locked) {
+ addExtra(Intents.Scan.ORIENTATION_LOCKED, locked);
+ return this;
+ }
+
+ /**
+ * Use the specified camera ID.
+ *
+ * @param cameraId camera ID of the camera to use. A negative value means "no preference".
+ * @return this
+ */
+ public ScanOptions setCameraId(int cameraId) {
+ if (cameraId >= 0) {
+ addExtra(Intents.Scan.CAMERA_ID, cameraId);
+ }
+ return this;
+ }
+
+ /**
+ * Set to true to enable initial torch
+ *
+ * @param enabled true to enable initial torch
+ * @return this
+ */
+ public ScanOptions setTorchEnabled(boolean enabled) {
+ addExtra(Intents.Scan.TORCH_ENABLED, enabled);
+ return this;
+ }
+
+
+ /**
+ * Set to false to disable beep on scan.
+ *
+ * @param enabled false to disable beep
+ * @return this
+ */
+ public ScanOptions setBeepEnabled(boolean enabled) {
+ addExtra(Intents.Scan.BEEP_ENABLED, enabled);
+ return this;
+ }
+
+ /**
+ * Set to true to enable saving the barcode image and sending its path in the result Intent.
+ *
+ * @param enabled true to enable barcode image
+ * @return this
+ */
+ public ScanOptions setBarcodeImageEnabled(boolean enabled) {
+ addExtra(Intents.Scan.BARCODE_IMAGE_ENABLED, enabled);
+ return this;
+ }
+
+ /**
+ * Set the desired barcode formats to scan.
+ *
+ * @param desiredBarcodeFormats names of {@code BarcodeFormat}s to scan for
+ * @return this
+ */
+ public ScanOptions setDesiredBarcodeFormats(Collection desiredBarcodeFormats) {
+ this.desiredBarcodeFormats = desiredBarcodeFormats;
+ return this;
+ }
+
+ /**
+ * Set the desired barcode formats to scan.
+ *
+ * @param desiredBarcodeFormats names of {@code BarcodeFormat}s to scan for
+ * @return this
+ */
+ public ScanOptions setDesiredBarcodeFormats(String... desiredBarcodeFormats) {
+ this.desiredBarcodeFormats = Arrays.asList(desiredBarcodeFormats);
+ return this;
+ }
+
+ /**
+ * Initiates a scan for all known barcode types with the default camera.
+ * And starts a timer to finish on timeout
+ *
+ * @return Activity.RESULT_CANCELED and true on parameter TIMEOUT.
+ */
+ public ScanOptions setTimeout(long timeout) {
+ addExtra(Intents.Scan.TIMEOUT, timeout);
+ return this;
+ }
+
+ /**
+ * Create an scan intent with the specified options.
+ *
+ * @return the intent
+ */
+ public Intent createScanIntent(Context context) {
+ Intent intentScan = new Intent(context, getCaptureActivity());
+ intentScan.setAction(Intents.Scan.ACTION);
+
+ // check which types of codes to scan for
+ if (desiredBarcodeFormats != null) {
+ // set the desired barcode types
+ StringBuilder joinedByComma = new StringBuilder();
+ for (String format : desiredBarcodeFormats) {
+ if (joinedByComma.length() > 0) {
+ joinedByComma.append(',');
+ }
+ joinedByComma.append(format);
+ }
+ intentScan.putExtra(Intents.Scan.FORMATS, joinedByComma.toString());
+ }
+
+ intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
+ attachMoreExtras(intentScan);
+ return intentScan;
+ }
+
+ private static List list(String... values) {
+ return Collections.unmodifiableList(Arrays.asList(values));
+ }
+
+ private void attachMoreExtras(Intent intent) {
+ for (Map.Entry entry : moreExtras.entrySet()) {
+ String key = entry.getKey();
+ Object value = entry.getValue();
+ // Kind of hacky
+ if (value instanceof Integer) {
+ intent.putExtra(key, (Integer) value);
+ } else if (value instanceof Long) {
+ intent.putExtra(key, (Long) value);
+ } else if (value instanceof Boolean) {
+ intent.putExtra(key, (Boolean) value);
+ } else if (value instanceof Double) {
+ intent.putExtra(key, (Double) value);
+ } else if (value instanceof Float) {
+ intent.putExtra(key, (Float) value);
+ } else if (value instanceof Bundle) {
+ intent.putExtra(key, (Bundle) value);
+ } else if (value instanceof int[]) {
+ intent.putExtra(key, (int[]) value);
+ } else if (value instanceof long[]) {
+ intent.putExtra(key, (long[]) value);
+ } else if (value instanceof boolean[]) {
+ intent.putExtra(key, (boolean[]) value);
+ } else if (value instanceof double[]) {
+ intent.putExtra(key, (double[]) value);
+ } else if (value instanceof float[]) {
+ intent.putExtra(key, (float[]) value);
+ } else if (value instanceof String[]) {
+ intent.putExtra(key, (String[]) value);
+ } else {
+ intent.putExtra(key, value.toString());
+ }
+ }
+ }
+}
diff --git a/zxing-android-embedded/src/com/journeyapps/barcodescanner/ViewfinderView.java b/zxing-android-embedded/src/com/journeyapps/barcodescanner/ViewfinderView.java
index cdaeb9aa1..4bd023786 100755
--- a/zxing-android-embedded/src/com/journeyapps/barcodescanner/ViewfinderView.java
+++ b/zxing-android-embedded/src/com/journeyapps/barcodescanner/ViewfinderView.java
@@ -16,7 +16,6 @@
package com.journeyapps.barcodescanner;
-import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
@@ -74,7 +73,7 @@ public ViewfinderView(Context context, AttributeSet attrs) {
Resources resources = getResources();
- // Get setted attributes on view
+ // Get set attributes on view
TypedArray attributes = getContext().obtainStyledAttributes(attrs, R.styleable.zxing_finder);
this.maskColor = attributes.getColor(R.styleable.zxing_finder_zxing_viewfinder_mask,
@@ -148,8 +147,8 @@ public void onDraw(Canvas canvas) {
final Rect frame = framingRect;
final Size previewSize = this.previewSize;
- final int width = canvas.getWidth();
- final int height = canvas.getHeight();
+ final int width = getWidth();
+ final int height = getHeight();
// Draw the exterior (i.e. outside the framing rect) darkened
paint.setColor(resultBitmap != null ? resultColor : maskColor);
diff --git a/zxing-android-embedded/src/com/journeyapps/barcodescanner/camera/CameraManager.java b/zxing-android-embedded/src/com/journeyapps/barcodescanner/camera/CameraManager.java
index 77ba879aa..d541df566 100755
--- a/zxing-android-embedded/src/com/journeyapps/barcodescanner/camera/CameraManager.java
+++ b/zxing-android-embedded/src/com/journeyapps/barcodescanner/camera/CameraManager.java
@@ -280,11 +280,9 @@ private void setDesiredParameters(boolean safeMode) {
}
if (settings.isMeteringEnabled()) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
- CameraConfigurationUtils.setVideoStabilization(parameters);
- CameraConfigurationUtils.setFocusArea(parameters);
- CameraConfigurationUtils.setMetering(parameters);
- }
+ CameraConfigurationUtils.setVideoStabilization(parameters);
+ CameraConfigurationUtils.setFocusArea(parameters);
+ CameraConfigurationUtils.setMetering(parameters);
}
}