From 6dedf7a8419497496d5087f6bf4b23dc95b5f451 Mon Sep 17 00:00:00 2001 From: Nick Hope Date: Tue, 27 Feb 2018 11:30:00 +0000 Subject: [PATCH] Add: 3 second focus delay to resolve setParameters crash on Samsung. --- .../main/java/com/otaliastudios/cameraview/Camera1.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java b/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java index 39d01df2..6f40412a 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java +++ b/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 boolean mIsBound = false; + private boolean mDelayRunnable = false; private final int mPostFocusResetDelay = 3000; private Runnable mPostFocusResetRunnable = new Runnable() { @Override public void run() { if (!isCameraAvailable()) return; + if (mDelayRunnable) { + mDelayRunnable = false; // Delay focus further - fixes Samsung devices + return; + } mCamera.cancelAutoFocus(); Camera.Parameters params = mCamera.getParameters(); params.setFocusAreas(null); @@ -493,6 +498,7 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera if (mIsCapturingVideo && !mCameraOptions.isVideoSnapshotSupported()) return; mIsCapturingImage = true; + mDelayRunnable = true; // delaying focus (fixes crash on samsung) final int sensorToOutput = computeSensorToOutputOffset(); final int sensorToView = computeSensorToViewOffset(); final boolean outputMatchesView = (sensorToOutput + sensorToView + 180) % 180 == 0; @@ -805,6 +811,7 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera mCamera.setParameters(params); mCameraCallbacks.dispatchOnFocusStart(gesture, p); // TODO this is not guaranteed to be called... Fix. + // TODO Updated: Kind of fixed with mDelayRunnable on image capture mCamera.autoFocus(new Camera.AutoFocusCallback() { @Override public void onAutoFocus(boolean success, Camera camera) {