First, it updates the take picture call to capture right away instead of trying to focus again. This will match closer to what the native camera does, and also what the Camera2 does. Secondly, it removes all calls to resetFocus after capturing and after a given timeout. This was causing issues when using autoFocusPointOfInterest, and it really didn't make sense to use an internal timeout to reset the focus. If anything, the user should do this from the JS side. A new method could also be exposed to do this. Lastly, it adds some error catching logic to the autoFocus call. There was a chance on some devices that calling autoFocus while the device is capturing a photo that it would fail. Tested on Google Pixel 2 (Android 9), Motorola G5 (Android 8), Samsung Grand Prime (Android 5?), and LG20 (android 6?). No issues so far.
This commit is contained in:
parent
54e7dc1fee
commit
3407533108
@ -450,17 +450,13 @@ class Camera1 extends CameraViewImpl implements MediaRecorder.OnInfoListener,
|
||||
if (!mIsPreviewActive) {
|
||||
throw new IllegalStateException("Preview is paused - resume it before taking a picture.");
|
||||
}
|
||||
if (getAutoFocus()) {
|
||||
mCamera.cancelAutoFocus();
|
||||
mCamera.autoFocus(new Camera.AutoFocusCallback() {
|
||||
@Override
|
||||
public void onAutoFocus(boolean success, Camera camera) {
|
||||
takePictureInternal(options);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
takePictureInternal(options);
|
||||
}
|
||||
|
||||
// UPDATE: Take picture right away instead of requesting/waiting for focus.
|
||||
// This will match closer what the native camera does,
|
||||
// and will capture whatever is on the preview without changing the camera focus.
|
||||
// This change will also help with autoFocusPointOfInterest not being usable to capture (Issue #2420)
|
||||
// and with takePicture never returning/resolving if the focus was reset (Issue #2421)
|
||||
takePictureInternal(options);
|
||||
}
|
||||
|
||||
int orientationEnumToRotation(int orientation) {
|
||||
@ -512,7 +508,10 @@ class Camera1 extends CameraViewImpl implements MediaRecorder.OnInfoListener,
|
||||
@Override
|
||||
public void onPictureTaken(byte[] data, Camera camera) {
|
||||
isPictureCaptureInProgress.set(false);
|
||||
camera.cancelAutoFocus();
|
||||
|
||||
// this shouldn't be needed and messes up autoFocusPointOfInterest
|
||||
// camera.cancelAutoFocus();
|
||||
|
||||
if (options.hasKey("pauseAfterCapture") && !options.getBoolean("pauseAfterCapture")) {
|
||||
camera.startPreview();
|
||||
mIsPreviewActive = true;
|
||||
@ -775,6 +774,7 @@ class Camera1 extends CameraViewImpl implements MediaRecorder.OnInfoListener,
|
||||
|
||||
List<Camera.Area> meteringAreas = new ArrayList<>();
|
||||
meteringAreas.add(new Camera.Area(rect, FOCUS_METERING_AREA_WEIGHT_DEFAULT));
|
||||
|
||||
if (parameters.getMaxNumFocusAreas() != 0 && focusMode != null &&
|
||||
(focusMode.equals(Camera.Parameters.FOCUS_MODE_AUTO) ||
|
||||
focusMode.equals(Camera.Parameters.FOCUS_MODE_MACRO) ||
|
||||
@ -795,12 +795,18 @@ class Camera1 extends CameraViewImpl implements MediaRecorder.OnInfoListener,
|
||||
catch(RuntimeException e ) {
|
||||
Log.e("CAMERA_1::", "setParameters failed", e);
|
||||
}
|
||||
mCamera.autoFocus(new Camera.AutoFocusCallback() {
|
||||
@Override
|
||||
public void onAutoFocus(boolean success, Camera camera) {
|
||||
resetFocus(success, camera);
|
||||
}
|
||||
});
|
||||
|
||||
try{
|
||||
mCamera.autoFocus(new Camera.AutoFocusCallback() {
|
||||
@Override
|
||||
public void onAutoFocus(boolean success, Camera camera) {
|
||||
//resetFocus(success, camera);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(RuntimeException e ) {
|
||||
Log.e("CAMERA_1::", "autoFocus failed", e);
|
||||
}
|
||||
} else if (parameters.getMaxNumMeteringAreas() > 0) {
|
||||
if (!parameters.getSupportedFocusModes().contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
|
||||
return; //cannot autoFocus
|
||||
@ -815,19 +821,30 @@ class Camera1 extends CameraViewImpl implements MediaRecorder.OnInfoListener,
|
||||
catch(RuntimeException e ) {
|
||||
Log.e("CAMERA_1::", "setParameters failed", e);
|
||||
}
|
||||
mCamera.autoFocus(new Camera.AutoFocusCallback() {
|
||||
@Override
|
||||
public void onAutoFocus(boolean success, Camera camera) {
|
||||
resetFocus(success, camera);
|
||||
}
|
||||
});
|
||||
|
||||
try{
|
||||
mCamera.autoFocus(new Camera.AutoFocusCallback() {
|
||||
@Override
|
||||
public void onAutoFocus(boolean success, Camera camera) {
|
||||
//resetFocus(success, camera);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(RuntimeException e ) {
|
||||
Log.e("CAMERA_1::", "autoFocus failed", e);
|
||||
}
|
||||
} else {
|
||||
mCamera.autoFocus(new Camera.AutoFocusCallback() {
|
||||
@Override
|
||||
public void onAutoFocus(boolean success, Camera camera) {
|
||||
mCamera.cancelAutoFocus();
|
||||
}
|
||||
});
|
||||
try{
|
||||
mCamera.autoFocus(new Camera.AutoFocusCallback() {
|
||||
@Override
|
||||
public void onAutoFocus(boolean success, Camera camera) {
|
||||
//mCamera.cancelAutoFocus();
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(RuntimeException e ) {
|
||||
Log.e("CAMERA_1::", "autoFocus failed", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user