Skip to content

Commit

Permalink
Dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuriy Budiyev committed Sep 22, 2017
1 parent de49c39 commit a3c813f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/main/java/com/budiyev/android/codescanner/CodeScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,7 @@ public void releaseResources() {
if (mPreviewActive) {
stopPreview();
}
mInitialized = false;
mInitialization = false;
mStoppingPreview = false;
mPreviewActive = false;
mFocusing = false;
DecoderWrapper decoderWrapper = mDecoderWrapper;
decoderWrapper.getCamera().release();
decoderWrapper.getDecoder().shutdown();
mDecoderWrapper = null;
releaseResourcesInternal();
}
}

Expand Down Expand Up @@ -356,6 +348,19 @@ private void stopPreviewInternalSafe() {
}
}

private void releaseResourcesInternal() {
mInitialized = false;
mInitialization = false;
mStoppingPreview = false;
mPreviewActive = false;
mFocusing = false;
DecoderWrapper decoderWrapper = mDecoderWrapper;
if (decoderWrapper != null) {
mDecoderWrapper = null;
decoderWrapper.release();
}
}

private void setFlashEnabledInternal(boolean flashEnabled) {
try {
DecoderWrapper decoderWrapper = mDecoderWrapper;
Expand Down Expand Up @@ -519,6 +524,7 @@ public void run() {
try {
initialize();
} catch (Exception e) {
releaseResourcesInternal();
ErrorCallback errorCallback = mErrorCallback;
if (errorCallback != null) {
errorCallback.onError(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,9 @@ public boolean isAutoFocusSupported() {
public boolean isFlashSupported() {
return mFlashSupported;
}

public void release() {
mCamera.release();
mDecoder.shutdown();
}
}

0 comments on commit a3c813f

Please sign in to comment.