Added setAutoFocusResetDelay to api to control autofocus reset options

pull/435/head
Craig Neuwirt 6 years ago
parent fc4a75a24b
commit be8e609358
  1. 5
      cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java
  2. 9
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java
  3. 19
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java

@ -31,7 +31,6 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
private Camera mCamera; private Camera mCamera;
private boolean mIsBound = false; private boolean mIsBound = false;
private final int mPostFocusResetDelay = 3000;
private Runnable mPostFocusResetRunnable = new Runnable() { private Runnable mPostFocusResetRunnable = new Runnable() {
@Override @Override
public void run() { public void run() {
@ -891,7 +890,9 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
// TODO lock auto exposure and white balance for a while // TODO lock auto exposure and white balance for a while
mCameraCallbacks.dispatchOnFocusEnd(gesture, success, p); mCameraCallbacks.dispatchOnFocusEnd(gesture, success, p);
mHandler.get().removeCallbacks(mPostFocusResetRunnable); mHandler.get().removeCallbacks(mPostFocusResetRunnable);
mHandler.get().postDelayed(mPostFocusResetRunnable, mPostFocusResetDelay); if (shouldResetAutoFocus()) {
mHandler.get().postDelayed(mPostFocusResetRunnable, getAutoFocusResetDelay());
}
} }
}); });
} catch (RuntimeException e) { } catch (RuntimeException e) {

@ -72,6 +72,7 @@ abstract class CameraController implements
protected Size mCaptureSize; protected Size mCaptureSize;
protected Size mPreviewStreamSize; protected Size mPreviewStreamSize;
protected int mPreviewFormat; protected int mPreviewFormat;
protected long mAutoFocusResetDelayMillis = CameraView.DEFAULT_AUTOFOCUS_RESET_DELAY_MILLIS;
protected int mSensorOffset; protected int mSensorOffset;
private int mDisplayOffset; private int mDisplayOffset;
@ -325,6 +326,8 @@ abstract class CameraController implements
mSnapshotMaxHeight = maxHeight; mSnapshotMaxHeight = maxHeight;
} }
final void setAutoFocusResetDelay(long delayMillis) { mAutoFocusResetDelayMillis = delayMillis; }
//endregion //endregion
//region Abstract setters and APIs //region Abstract setters and APIs
@ -465,6 +468,12 @@ abstract class CameraController implements
return mPictureRecorder != null; return mPictureRecorder != null;
} }
final long getAutoFocusResetDelay() { return mAutoFocusResetDelayMillis; }
final boolean shouldResetAutoFocus() {
return mAutoFocusResetDelayMillis > 0 && mAutoFocusResetDelayMillis != Long.MAX_VALUE;
}
//endregion //endregion
//region Orientation utils //region Orientation utils

@ -47,6 +47,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
private static final CameraLogger LOG = CameraLogger.create(TAG); private static final CameraLogger LOG = CameraLogger.create(TAG);
public final static int PERMISSION_REQUEST_CODE = 16; public final static int PERMISSION_REQUEST_CODE = 16;
public final static long DEFAULT_AUTOFOCUS_RESET_DELAY_MILLIS = 3000;
final static boolean DEFAULT_PLAY_SOUNDS = true; final static boolean DEFAULT_PLAY_SOUNDS = true;
@ -1049,6 +1050,24 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
} }
/**
* the current delay in milliseconds to reset the focus after an autofocus process.
*
* @param cameraAutoFocusResetDelayMillis desired delay (in milliseconds). If the delay
* is less than or equal to 0 or equal to Long.MAX_VALUE,
* the autofocus will not be reset.
*/
public void setAutoFocusResetDelay(long cameraAutoFocusResetDelayMillis) {
mCameraController.setAutoFocusResetDelay(cameraAutoFocusResetDelayMillis);
}
/**
* Returns the current delay in milliseconds to reset the focus after an autofocus process.
* @return the current autofocus reset delay in milliseconds.
*/
public long getAutoFocusResetDelay() { return mCameraController.getAutoFocusResetDelay(); }
/** /**
* Starts an autofocus process at the given coordinates, with respect * Starts an autofocus process at the given coordinates, with respect
* to the view width and height. * to the view width and height.

Loading…
Cancel
Save