From 45177dd7d93e8d336868f472704f323831cf2f51 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 11 Jun 2018 14:30:35 +0200 Subject: [PATCH] move the autofocus cancelling code in an own function --- .../simplemobiletools/camera/views/PreviewCameraTwo.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/views/PreviewCameraTwo.kt b/app/src/main/kotlin/com/simplemobiletools/camera/views/PreviewCameraTwo.kt index 709fca6a..8c7d6272 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/views/PreviewCameraTwo.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/views/PreviewCameraTwo.kt @@ -598,10 +598,8 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie } mCaptureSession!!.stopRepeating() + cancelAutoFocus() mPreviewRequestBuilder!!.apply { - set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL) - mCaptureSession!!.capture(build(), captureCallbackHandler, mBackgroundHandler) - // touch-to-focus inspired by OpenCamera val characteristics = getCameraCharacteristics() if (characteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AF) >= 1) { @@ -620,6 +618,12 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie } } + private fun cancelAutoFocus() { + val cancelRequest = mPreviewRequestBuilder + cancelRequest!!.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_IDLE) + mCaptureSession!!.capture(cancelRequest.build(), null, mBackgroundHandler) + } + private fun convertAreaToMeteringRectangle(sensorRect: Rect, focusArea: FocusArea): MeteringRectangle { val camera2Rect = convertRectToCamera2(sensorRect, focusArea.rect) return MeteringRectangle(camera2Rect, focusArea.weight)