Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.
Open
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: 15 additions & 8 deletions library/src/main/api14/com/google/android/cameraview/Camera1.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.hardware.Camera;
import android.os.Build;
import android.support.v4.util.SparseArrayCompat;
import android.util.Log;
import android.view.SurfaceHolder;

import java.io.IOException;
Expand All @@ -31,6 +32,8 @@
@SuppressWarnings("deprecation")
class Camera1 extends CameraViewImpl {

private static final String TAG = "Camera1";

private static final int INVALID_CAMERA_ID = -1;

private static final SparseArrayCompat<String> FLASH_MODES = new SparseArrayCompat<>();
Expand Down Expand Up @@ -227,14 +230,18 @@ public void onAutoFocus(boolean success, Camera camera) {
}

void takePictureInternal() {
mCamera.takePicture(null, null, null, new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
mCallback.onPictureTaken(data);
camera.cancelAutoFocus();
camera.startPreview();
}
});
try {
mCamera.takePicture(null, null, null, new Camera.PictureCallback() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about to move this callback instantiation to outside of the try/catch?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your suggestion. Could you please specify what kind of effect will this change have?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jydimir Thanks for sharing this!

@Override
public void onPictureTaken(byte[] data, Camera camera) {
mCallback.onPictureTaken(data);
camera.cancelAutoFocus();
camera.startPreview();
}
});
} catch (RuntimeException re) {
Log.e(TAG, "takePicture failed", re);
}
}

@Override
Expand Down