Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions library/src/main/api14/com/google/android/cameraview/Camera1.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,20 @@ public void onAutoFocus(boolean success, Camera camera) {

void takePictureInternal() {
if (!isPictureCaptureInProgress.getAndSet(true)) {
mCamera.takePicture(null, null, null, new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
isPictureCaptureInProgress.set(false);
mCallback.onPictureTaken(data);
camera.cancelAutoFocus();
camera.startPreview();
}
});
try {
mCamera.takePicture(null, null, null, new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
isPictureCaptureInProgress.set(false);
mCallback.onPictureTaken(data);
camera.cancelAutoFocus();
camera.startPreview();
}
});
}
catch (RuntimeException ex) {
mCallback.onTakePictureFailed(ex);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ interface Callback {

void onPictureTaken(byte[] data);

void onTakePictureFailed(Throwable throwable);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,13 @@ public void onPictureTaken(byte[] data) {
}
}

@Override
public void onTakePictureFailed(Throwable throwable) {
for (Callback callback : mCallbacks) {
callback.onTakePictureFailed(CameraView.this, throwable);
}
}

public void reserveRequestLayoutOnOpen() {
mRequestLayoutOnOpen = true;
}
Expand Down Expand Up @@ -535,6 +542,15 @@ public void onCameraClosed(CameraView cameraView) {
*/
public void onPictureTaken(CameraView cameraView, byte[] data) {
}

/**
* Called when taking a picture has failed
*
* @param cameraView The associated {@link CameraView}.
* @param throwable Exception
*/
public void onTakePictureFailed(CameraView cameraView, Throwable throwable) {
}
}

}