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
33 changes: 23 additions & 10 deletions library/src/main/api21/com/google/android/cameraview/Camera2.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ public void onClosed(@NonNull CameraCaptureSession session) {

@Override
public void onPrecaptureRequired() {
if (mPreviewRequestBuilder == null || mCaptureSession == null) {
return;
}
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);
setState(STATE_PRECAPTURE);
Expand Down Expand Up @@ -580,6 +583,10 @@ void updateFlash() {
* Locks the focus as the first step for a still image capture.
*/
private void lockFocus() {
if (mPreviewRequestBuilder == null || mCaptureCallback == null || mCaptureSession == null) {
return;
}

mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
CaptureRequest.CONTROL_AF_TRIGGER_START);
try {
Expand Down Expand Up @@ -635,16 +642,18 @@ void captureStillPicture() {
mDisplayOrientation * (mFacing == Constants.FACING_FRONT ? 1 : -1) +
360) % 360);
// Stop preview and capture a still picture.
mCaptureSession.stopRepeating();
mCaptureSession.capture(captureRequestBuilder.build(),
new CameraCaptureSession.CaptureCallback() {
@Override
public void onCaptureCompleted(@NonNull CameraCaptureSession session,
@NonNull CaptureRequest request,
@NonNull TotalCaptureResult result) {
unlockFocus();
}
}, null);
if (mCaptureSession != null) {
mCaptureSession.stopRepeating();
mCaptureSession.capture(captureRequestBuilder.build(),
new CameraCaptureSession.CaptureCallback() {
@Override
public void onCaptureCompleted(@NonNull CameraCaptureSession session,
@NonNull CaptureRequest request,
@NonNull TotalCaptureResult result) {
unlockFocus();
}
}, null);
}
} catch (CameraAccessException e) {
Log.e(TAG, "Cannot capture a still picture.", e);
}
Expand All @@ -655,6 +664,10 @@ public void onCaptureCompleted(@NonNull CameraCaptureSession session,
* capturing a still picture.
*/
void unlockFocus() {
if (mPreviewRequestBuilder == null || mCaptureCallback == null || mCaptureSession == null) {
return;
}

mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
CaptureRequest.CONTROL_AF_TRIGGER_CANCEL);
try {
Expand Down