diff --git a/README.md b/README.md index 2277fbc..bbee2f9 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Code scanner library for [Android](https://developer.android.com), based on [ZXi Add dependency: ```gradle dependencies { - implementation 'com.budiyev.android:code-scanner:1.7.5' + implementation 'com.budiyev.android:code-scanner:1.7.6' } ``` Add camera permission to AndroidManifest.xml (Don't forget about dynamic permissions on API >= 23): diff --git a/build.gradle b/build.gradle index 904e7a8..d90ba8d 100644 --- a/build.gradle +++ b/build.gradle @@ -25,7 +25,7 @@ apply plugin: 'com.jfrog.bintray' ext { libraryName = 'CodeScanner' libraryDescription = 'Code scanner library for Android, based on ZXing' - libraryVersion = '1.7.5' + libraryVersion = '1.7.6' artifact = 'code-scanner' developerId = 'yuriy-budiyev' developerName = 'Yuriy Budiyev' @@ -46,7 +46,7 @@ android { defaultConfig { minSdkVersion 14 targetSdkVersion 27 - versionCode 36 + versionCode 37 versionName libraryVersion } @@ -63,7 +63,7 @@ android { } dependencies { - api 'com.google.zxing:core:3.3.1' + api 'com.google.zxing:core:3.3.2' api 'com.google.zxing:android-core:3.3.0' api 'com.android.support:support-annotations:27.0.2' } diff --git a/src/main/java/com/budiyev/android/codescanner/CameraCallback.java b/src/main/java/com/budiyev/android/codescanner/CameraCallback.java new file mode 100644 index 0000000..e1e7d4a --- /dev/null +++ b/src/main/java/com/budiyev/android/codescanner/CameraCallback.java @@ -0,0 +1,42 @@ +/* + * MIT License + * + * Copyright (c) 2017 Yuriy Budiyev [yuriy.budiyev@yandex.ru] + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.budiyev.android.codescanner; + +import android.hardware.Camera; +import android.support.annotation.NonNull; +import android.support.annotation.WorkerThread; + +/** + * Code scanner camera initialization callback + */ +public interface CameraCallback { + /** + * Called when camera has initialized and ready to use by scanner, + * each time when code scanner initializes camera + *
+ * Note that this method always called on a worker thread + */ + @WorkerThread + void onCameraReady(@NonNull Camera camera); +} diff --git a/src/main/java/com/budiyev/android/codescanner/CodeScanner.java b/src/main/java/com/budiyev/android/codescanner/CodeScanner.java index e8a965d..e55b0cf 100644 --- a/src/main/java/com/budiyev/android/codescanner/CodeScanner.java +++ b/src/main/java/com/budiyev/android/codescanner/CodeScanner.java @@ -84,6 +84,7 @@ public class CodeScanner { private volatile ScanMode mScanMode = DEFAULT_SCAN_MODE; private volatile AutoFocusMode mAutoFocusMode = DEFAULT_AUTO_FOCUS_MODE; private volatile DecodeCallback mDecodeCallback; + private volatile CameraCallback mCameraCallback; private volatile ErrorCallback mErrorCallback; private volatile DecoderWrapper mDecoderWrapper; private volatile boolean mInitialization; @@ -225,6 +226,16 @@ public void setDecodeCallback(@Nullable DecodeCallback decodeCallback) { } } + /** + * Camera initialization callback + * + * @param cameraCallback Callback + * @see CameraCallback + */ + public void setCameraCallback(@Nullable CameraCallback cameraCallback) { + mCameraCallback = cameraCallback; + } + /** * Camera initialization error callback. * If not set, an exception will be thrown when error will occur. @@ -700,6 +711,10 @@ private void initialize() { CameraConfigurationUtils.setBestExposure(parameters, mFlashEnabled); camera.setParameters(parameters); camera.setDisplayOrientation(orientation); + CameraCallback cameraCallback = mCameraCallback; + if (cameraCallback != null) { + cameraCallback.onCameraReady(camera); + } mInitializeLock.lock(); try { Decoder decoder = new Decoder(mDecoderStateListener, mFormats, mDecodeCallback); @@ -778,6 +793,7 @@ public static final class Builder { private int mCameraId = DEFAULT_CAMERA; private List mFormats = DEFAULT_FORMATS; private DecodeCallback mDecodeCallback; + private CameraCallback mCameraCallback; private ErrorCallback mErrorCallback; private boolean mAutoFocusEnabled = DEFAULT_AUTO_FOCUS_ENABLED; private ScanMode mScanMode = DEFAULT_SCAN_MODE; @@ -860,6 +876,17 @@ public Builder onDecoded(@Nullable DecodeCallback callback) { return this; } + /** + * Camera initialization callback + * + * @param callback Callback + */ + @NonNull + public Builder onCameraReady(@Nullable CameraCallback callback) { + mCameraCallback = callback; + return this; + } + /** * Camera initialization error callback. * If not set, an exception will be thrown when error will occur. @@ -946,6 +973,7 @@ public CodeScanner build(@NonNull Context context, @NonNull CodeScannerView view scanner.mCameraId = mCameraId; scanner.mFormats = mFormats; scanner.mDecodeCallback = mDecodeCallback; + scanner.mCameraCallback = mCameraCallback; scanner.mErrorCallback = mErrorCallback; scanner.mAutoFocusEnabled = mAutoFocusEnabled; scanner.mSafeAutoFocusInterval = mAutoFocusInterval;