|
|
@ -768,31 +768,42 @@ class Camera1 extends CameraController { |
|
|
|
boolean startAutoFocus(@Nullable final Gesture gesture, PointF point) { |
|
|
|
boolean startAutoFocus(@Nullable final Gesture gesture, PointF point) { |
|
|
|
if (!isCameraAvailable()) return false; |
|
|
|
if (!isCameraAvailable()) return false; |
|
|
|
if (!mOptions.isAutoFocusSupported()) return false; |
|
|
|
if (!mOptions.isAutoFocusSupported()) return false; |
|
|
|
final PointF p = new PointF(point.x, point.y); // copy.
|
|
|
|
|
|
|
|
List<Camera.Area> meteringAreas2 = computeMeteringAreas(p.x, p.y); |
|
|
|
try { |
|
|
|
List<Camera.Area> meteringAreas1 = meteringAreas2.subList(0, 1); |
|
|
|
final PointF p = new PointF(point.x, point.y); // copy.
|
|
|
|
synchronized (mLock) { |
|
|
|
List<Camera.Area> meteringAreas2 = computeMeteringAreas(p.x, p.y); |
|
|
|
// At this point we are sure that camera supports auto focus... right? Look at CameraView.onTouchEvent().
|
|
|
|
List<Camera.Area> meteringAreas1 = meteringAreas2.subList(0, 1); |
|
|
|
Camera.Parameters params = mCamera.getParameters(); |
|
|
|
synchronized (mLock) { |
|
|
|
int maxAF = params.getMaxNumFocusAreas(); |
|
|
|
// At this point we are sure that camera supports auto focus... right? Look at CameraView.onTouchEvent().
|
|
|
|
int maxAE = params.getMaxNumMeteringAreas(); |
|
|
|
Camera.Parameters params = mCamera.getParameters(); |
|
|
|
if (maxAF > 0) params.setFocusAreas(maxAF > 1 ? meteringAreas2 : meteringAreas1); |
|
|
|
int maxAF = params.getMaxNumFocusAreas(); |
|
|
|
if (maxAE > 0) params.setMeteringAreas(maxAE > 1 ? meteringAreas2 : meteringAreas1); |
|
|
|
int maxAE = params.getMaxNumMeteringAreas(); |
|
|
|
params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); |
|
|
|
if (maxAF > 0) params.setFocusAreas(maxAF > 1 ? meteringAreas2 : meteringAreas1); |
|
|
|
mCamera.setParameters(params); |
|
|
|
if (maxAE > 0) params.setMeteringAreas(maxAE > 1 ? meteringAreas2 : meteringAreas1); |
|
|
|
mCameraCallbacks.dispatchOnFocusStart(gesture, p); |
|
|
|
params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); |
|
|
|
// TODO this is not guaranteed to be called... Fix.
|
|
|
|
mCamera.setParameters(params); |
|
|
|
mCamera.autoFocus(new Camera.AutoFocusCallback() { |
|
|
|
mCameraCallbacks.dispatchOnFocusStart(gesture, p); |
|
|
|
@Override |
|
|
|
// TODO this is not guaranteed to be called... Fix.
|
|
|
|
public void onAutoFocus(boolean success, Camera camera) { |
|
|
|
mCamera.autoFocus(new Camera.AutoFocusCallback() { |
|
|
|
// TODO lock auto exposure and white balance for a while
|
|
|
|
@Override |
|
|
|
mCameraCallbacks.dispatchOnFocusEnd(gesture, success, p); |
|
|
|
public void onAutoFocus(boolean success, Camera camera) { |
|
|
|
mHandler.get().removeCallbacks(mPostFocusResetRunnable); |
|
|
|
// TODO lock auto exposure and white balance for a while
|
|
|
|
mHandler.get().postDelayed(mPostFocusResetRunnable, mPostFocusResetDelay); |
|
|
|
mCameraCallbacks.dispatchOnFocusEnd(gesture, success, p); |
|
|
|
} |
|
|
|
mHandler.get().removeCallbacks(mPostFocusResetRunnable); |
|
|
|
}); |
|
|
|
mHandler.get().postDelayed(mPostFocusResetRunnable, mPostFocusResetDelay); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception e) { |
|
|
|
|
|
|
|
// at least setParameters may fail.
|
|
|
|
|
|
|
|
// TODO why does it fail and is it possible to prevent such errors?
|
|
|
|
|
|
|
|
CameraException cameraException = new CameraConfigurationFailedException("Failed to " + |
|
|
|
|
|
|
|
"start auto focus.", e); |
|
|
|
|
|
|
|
mCameraCallbacks.onError(cameraException); |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|