Added parameter to startAutoFocus to determine if it should be reset automatically

pull/433/head
Craig Neuwirt 7 years ago committed by Cori Drew
parent fc4a75a24b
commit 7fd8ef2b90
  1. 4
      cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java
  2. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java
  3. 7
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java

@ -855,7 +855,7 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
@Override
void startAutoFocus(@Nullable final Gesture gesture, @NonNull final PointF point) {
void startAutoFocus(@Nullable final Gesture gesture, @NonNull final PointF point, final Boolean autoReset) {
// Must get width and height from the UI thread.
int viewWidth = 0, viewHeight = 0;
if (mPreview != null && mPreview.hasSurface()) {
@ -891,8 +891,10 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
// TODO lock auto exposure and white balance for a while
mCameraCallbacks.dispatchOnFocusEnd(gesture, success, p);
mHandler.get().removeCallbacks(mPostFocusResetRunnable);
if (autoReset) {
mHandler.get().postDelayed(mPostFocusResetRunnable, mPostFocusResetDelay);
}
}
});
} catch (RuntimeException e) {
// Handling random auto-focus exception on some devices

@ -366,7 +366,7 @@ abstract class CameraController implements
abstract void stopVideo();
abstract void startAutoFocus(@Nullable Gesture gesture, @NonNull PointF point);
abstract void startAutoFocus(@Nullable Gesture gesture, @NonNull PointF point, Boolean autoReset);
abstract void setPlaySounds(boolean playSounds);

@ -541,7 +541,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
case FOCUS:
case FOCUS_WITH_MARKER:
mCameraController.startAutoFocus(gesture, points[0]);
mCameraController.startAutoFocus(gesture, points[0], true);
break;
case ZOOM:
@ -1055,11 +1055,12 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
*
* @param x should be between 0 and getWidth()
* @param y should be between 0 and getHeight()
* @param autoCancel true if auto focus should be cancelled once focused
*/
public void startAutoFocus(float x, float y) {
public void startAutoFocus(float x, float y, Boolean autoCancel) {
if (x < 0 || x > getWidth()) throw new IllegalArgumentException("x should be >= 0 and <= getWidth()");
if (y < 0 || y > getHeight()) throw new IllegalArgumentException("y should be >= 0 and <= getHeight()");
mCameraController.startAutoFocus(null, new PointF(x, y));
mCameraController.startAutoFocus(null, new PointF(x, y), autoCancel);
}

Loading…
Cancel
Save