Added setAutoFocusResetDelay api to control autofocus reset options (#435)

pull/431/head
Craig Neuwirt 6 years ago committed by Mattia Iavarone
parent fc4a75a24b
commit 3261b73967
  1. 5
      cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java
  2. 9
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java
  3. 21
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
  4. 2
      cameraview/src/main/res/values/attrs.xml
  5. 17
      docs/_posts/2018-12-20-more-features.md

@ -31,7 +31,6 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
private Camera mCamera;
private boolean mIsBound = false;
private final int mPostFocusResetDelay = 3000;
private Runnable mPostFocusResetRunnable = new Runnable() {
@Override
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
mCameraCallbacks.dispatchOnFocusEnd(gesture, success, p);
mHandler.get().removeCallbacks(mPostFocusResetRunnable);
mHandler.get().postDelayed(mPostFocusResetRunnable, mPostFocusResetDelay);
if (shouldResetAutoFocus()) {
mHandler.get().postDelayed(mPostFocusResetRunnable, getAutoFocusResetDelay());
}
}
});
} catch (RuntimeException e) {

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

@ -48,6 +48,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
public final static int PERMISSION_REQUEST_CODE = 16;
final static long DEFAULT_AUTOFOCUS_RESET_DELAY_MILLIS = 3000;
final static boolean DEFAULT_PLAY_SOUNDS = true;
// Self managed parameters
@ -113,6 +114,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
int videoMaxDuration = a.getInteger(R.styleable.CameraView_cameraVideoMaxDuration, 0);
int videoBitRate = a.getInteger(R.styleable.CameraView_cameraVideoBitRate, 0);
int audioBitRate = a.getInteger(R.styleable.CameraView_cameraAudioBitRate, 0);
long autoFocusResetDelay = (long) a.getInteger(R.styleable.CameraView_cameraAutoFocusResetDelay, (int) DEFAULT_AUTOFOCUS_RESET_DELAY_MILLIS);
// Picture size selector
List<SizeSelector> pictureConstraints = new ArrayList<>(3);
@ -219,6 +221,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
setVideoMaxSize(videoMaxSize);
setVideoMaxDuration(videoMaxDuration);
setVideoBitRate(videoBitRate);
setAutoFocusResetDelay(autoFocusResetDelay);
// Apply gestures
mapGesture(Gesture.TAP, tapGesture);
@ -1049,6 +1052,24 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
}
/**
* Sets the current delay in milliseconds to reset the focus after an autofocus process.
*
* @param delayMillis 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 delayMillis) {
mCameraController.setAutoFocusResetDelay(delayMillis);
}
/**
* 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
* to the view width and height.

@ -124,5 +124,7 @@
<attr name="cameraExperimental" format="boolean" />
<attr name="cameraAutoFocusResetDelay" format="integer|reference"/>
</declare-styleable>
</resources>

@ -15,7 +15,8 @@ disqus: 1
<com.otaliastudios.cameraview.CameraView
app:cameraPlaySounds="true|false"
app:cameraGrid="off|draw3x3|draw4x4|drawPhi"
app:cameraGridColor="@color/black"/>
app:cameraGridColor="@color/black"
app:cameraAutoFocusResetDelay="0"/>
```
##### cameraPlaySounds
@ -56,6 +57,20 @@ cameraView.setGridColor(Color.WHITE);
cameraView.setGridColor(Color.BLACK);
```
##### cameraAutoFocusResetDelay
Lets you control how an auto-focus operation is reset after completed.
Setting a value <= 0 or == Long.MAX_VALUE will not reset the auto-focus.
This is useful for low end devices that have slow auto-focus capabilities.
Defaults to 3 seconds.
```java
cameraView.setCameraAutoFocusResetDelay(1000); // 1 second
cameraView.setCameraAutoFocusResetDelay(0); // NO reset
cameraView.setCameraAutoFocusResetDelay(-1); // NO reset
cameraView.setCameraAutoFocusResetDelay(Long.MAX_VALUE); // NO reset
### UI Orientation
Within a Camera app, it's common to rotate buttons and other UI elements as the device is tilted around.

Loading…
Cancel
Save