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. 6
      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 @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. // Must get width and height from the UI thread.
int viewWidth = 0, viewHeight = 0; int viewWidth = 0, viewHeight = 0;
if (mPreview != null && mPreview.hasSurface()) { if (mPreview != null && mPreview.hasSurface()) {
@ -891,7 +891,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 (autoReset) {
mHandler.get().postDelayed(mPostFocusResetRunnable, mPostFocusResetDelay);
}
} }
}); });
} catch (RuntimeException e) { } catch (RuntimeException e) {

@ -366,7 +366,7 @@ abstract class CameraController implements
abstract void stopVideo(); 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); abstract void setPlaySounds(boolean playSounds);

@ -541,7 +541,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
case FOCUS: case FOCUS:
case FOCUS_WITH_MARKER: case FOCUS_WITH_MARKER:
mCameraController.startAutoFocus(gesture, points[0]); mCameraController.startAutoFocus(gesture, points[0], true);
break; break;
case ZOOM: case ZOOM:
@ -1055,11 +1055,12 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* *
* @param x should be between 0 and getWidth() * @param x should be between 0 and getWidth()
* @param y should be between 0 and getHeight() * @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 (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()"); 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