add a click listener for focusing

This commit is contained in:
tibbi 2018-05-30 17:22:36 +02:00
parent 7ff48fc880
commit dfcb72b7f6
1 changed files with 27 additions and 9 deletions

View File

@ -1,5 +1,6 @@
package com.simplemobiletools.camera.views package com.simplemobiletools.camera.views
import android.annotation.SuppressLint
import android.annotation.TargetApi import android.annotation.TargetApi
import android.content.Context import android.content.Context
import android.graphics.ImageFormat import android.graphics.ImageFormat
@ -33,6 +34,8 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
private var mSensorOrientation = 0 private var mSensorOrientation = 0
private var mRotationAtCapture = 0 private var mRotationAtCapture = 0
private var mLastClickX = 0f
private var mLastClickY = 0f
private var mIsFlashSupported = true private var mIsFlashSupported = true
private var mIsImageCaptureIntent = false private var mIsImageCaptureIntent = false
private var mIsInVideoMode = false private var mIsInVideoMode = false
@ -54,9 +57,20 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
constructor(context: Context) : super(context) constructor(context: Context) : super(context)
@SuppressLint("ClickableViewAccessibility")
constructor(activity: MainActivity, textureView: AutoFitTextureView) : super(activity) { constructor(activity: MainActivity, textureView: AutoFitTextureView) : super(activity) {
mActivity = activity mActivity = activity
mTextureView = textureView mTextureView = textureView
mTextureView.setOnTouchListener { view, event ->
mLastClickX = event.x
mLastClickY = event.y
false
}
mTextureView.setOnClickListener {
focusArea()
}
} }
override fun onResumed() { override fun onResumed() {
@ -358,15 +372,8 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
} }
} }
private fun unlockFocus() { private fun focusArea() {
try {
mPreviewRequestBuilder!!.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL)
mPreviewRequestBuilder!!.set(CaptureRequest.FLASH_MODE, getFlashlightMode(mFlashlightState))
mCaptureSession!!.capture(mPreviewRequestBuilder!!.build(), mCaptureCallback, mBackgroundHandler)
mCameraState = STATE_PREVIEW
mCaptureSession!!.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler)
} catch (e: CameraAccessException) {
}
} }
private fun lockFocus() { private fun lockFocus() {
@ -378,6 +385,17 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
} }
} }
private fun unlockFocus() {
try {
mPreviewRequestBuilder!!.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL)
mPreviewRequestBuilder!!.set(CaptureRequest.FLASH_MODE, getFlashlightMode(mFlashlightState))
mCaptureSession!!.capture(mPreviewRequestBuilder!!.build(), mCaptureCallback, mBackgroundHandler)
mCameraState = STATE_PREVIEW
mCaptureSession!!.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler)
} catch (e: CameraAccessException) {
}
}
private fun takePicture() { private fun takePicture() {
lockFocus() lockFocus()
} }