Add: 3 second focus delay to resolve setParameters crash on Samsung.

pull/165/head
Nick Hope 7 years ago
parent 9bb5a7c289
commit 6dedf7a841
  1. 7
      cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java

@ -30,12 +30,17 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
private Camera mCamera; private Camera mCamera;
private boolean mIsBound = false; private boolean mIsBound = false;
private boolean mDelayRunnable = false;
private final int mPostFocusResetDelay = 3000; private final int mPostFocusResetDelay = 3000;
private Runnable mPostFocusResetRunnable = new Runnable() { private Runnable mPostFocusResetRunnable = new Runnable() {
@Override @Override
public void run() { public void run() {
if (!isCameraAvailable()) return; if (!isCameraAvailable()) return;
if (mDelayRunnable) {
mDelayRunnable = false; // Delay focus further - fixes Samsung devices
return;
}
mCamera.cancelAutoFocus(); mCamera.cancelAutoFocus();
Camera.Parameters params = mCamera.getParameters(); Camera.Parameters params = mCamera.getParameters();
params.setFocusAreas(null); params.setFocusAreas(null);
@ -493,6 +498,7 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
if (mIsCapturingVideo && !mCameraOptions.isVideoSnapshotSupported()) return; if (mIsCapturingVideo && !mCameraOptions.isVideoSnapshotSupported()) return;
mIsCapturingImage = true; mIsCapturingImage = true;
mDelayRunnable = true; // delaying focus (fixes crash on samsung)
final int sensorToOutput = computeSensorToOutputOffset(); final int sensorToOutput = computeSensorToOutputOffset();
final int sensorToView = computeSensorToViewOffset(); final int sensorToView = computeSensorToViewOffset();
final boolean outputMatchesView = (sensorToOutput + sensorToView + 180) % 180 == 0; final boolean outputMatchesView = (sensorToOutput + sensorToView + 180) % 180 == 0;
@ -805,6 +811,7 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
mCamera.setParameters(params); mCamera.setParameters(params);
mCameraCallbacks.dispatchOnFocusStart(gesture, p); mCameraCallbacks.dispatchOnFocusStart(gesture, p);
// TODO this is not guaranteed to be called... Fix. // TODO this is not guaranteed to be called... Fix.
// TODO Updated: Kind of fixed with mDelayRunnable on image capture
mCamera.autoFocus(new Camera.AutoFocusCallback() { mCamera.autoFocus(new Camera.AutoFocusCallback() {
@Override @Override
public void onAutoFocus(boolean success, Camera camera) { public void onAutoFocus(boolean success, Camera camera) {

Loading…
Cancel
Save