Skip to content

Commit

Permalink
Dev
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriy-budiyev committed Feb 1, 2018
1 parent 5ec8829 commit 52f6d51
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -46,7 +46,7 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 27
versionCode 36
versionCode 37
versionName libraryVersion
}

Expand All @@ -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'
}
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/com/budiyev/android/codescanner/CameraCallback.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* MIT License
*
* Copyright (c) 2017 Yuriy Budiyev [[email protected]]
*
* 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
* <br>
* Note that this method always called on a worker thread
*/
@WorkerThread
void onCameraReady(@NonNull Camera camera);
}
28 changes: 28 additions & 0 deletions src/main/java/com/budiyev/android/codescanner/CodeScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -778,6 +793,7 @@ public static final class Builder {
private int mCameraId = DEFAULT_CAMERA;
private List<BarcodeFormat> 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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 52f6d51

Please sign in to comment.