handle auto flash too
This commit is contained in:
parent
3fd08d3940
commit
3d7ec35e3b
|
@ -282,7 +282,7 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
||||||
mCaptureSession = cameraCaptureSession
|
mCaptureSession = cameraCaptureSession
|
||||||
try {
|
try {
|
||||||
mPreviewRequestBuilder!!.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE)
|
mPreviewRequestBuilder!!.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE)
|
||||||
setupPreviewProperties(mPreviewRequestBuilder!!)
|
mPreviewRequestBuilder!!.set(CaptureRequest.FLASH_MODE, getFlashlightMode(mFlashlightState))
|
||||||
mPreviewRequest = mPreviewRequestBuilder!!.build()
|
mPreviewRequest = mPreviewRequestBuilder!!.build()
|
||||||
mCaptureSession!!.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler)
|
mCaptureSession!!.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler)
|
||||||
mCameraState = STATE_PREVIEW
|
mCameraState = STATE_PREVIEW
|
||||||
|
@ -298,11 +298,6 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupPreviewProperties(requestBuilder: CaptureRequest.Builder) {
|
|
||||||
val flashMode = if (mFlashlightState == FLASH_ON) CameraMetadata.FLASH_MODE_TORCH else CameraMetadata.FLASH_MODE_OFF
|
|
||||||
requestBuilder.set(CaptureRequest.FLASH_MODE, flashMode)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val mCaptureCallback = object : CameraCaptureSession.CaptureCallback() {
|
private val mCaptureCallback = object : CameraCaptureSession.CaptureCallback() {
|
||||||
private fun process(result: CaptureResult) {
|
private fun process(result: CaptureResult) {
|
||||||
when (mCameraState) {
|
when (mCameraState) {
|
||||||
|
@ -362,10 +357,7 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
||||||
|
|
||||||
val captureBuilder = mCameraDevice!!.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE)
|
val captureBuilder = mCameraDevice!!.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE)
|
||||||
captureBuilder.addTarget(mImageReader!!.surface)
|
captureBuilder.addTarget(mImageReader!!.surface)
|
||||||
|
|
||||||
captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE)
|
captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE)
|
||||||
val flashMode = if (mFlashlightState == FLASH_ON) CameraMetadata.FLASH_MODE_TORCH else CameraMetadata.FLASH_MODE_OFF
|
|
||||||
captureBuilder.set(CaptureRequest.FLASH_MODE, flashMode)
|
|
||||||
|
|
||||||
val rotation = mActivity.windowManager.defaultDisplay.rotation
|
val rotation = mActivity.windowManager.defaultDisplay.rotation
|
||||||
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getOrientation(rotation))
|
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getOrientation(rotation))
|
||||||
|
@ -390,7 +382,7 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
||||||
private fun unlockFocus() {
|
private fun unlockFocus() {
|
||||||
try {
|
try {
|
||||||
mPreviewRequestBuilder!!.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL)
|
mPreviewRequestBuilder!!.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL)
|
||||||
setupPreviewProperties(mPreviewRequestBuilder!!)
|
mPreviewRequestBuilder!!.set(CaptureRequest.FLASH_MODE, getFlashlightMode(mFlashlightState))
|
||||||
mCaptureSession!!.capture(mPreviewRequestBuilder!!.build(), mCaptureCallback, mBackgroundHandler)
|
mCaptureSession!!.capture(mPreviewRequestBuilder!!.build(), mCaptureCallback, mBackgroundHandler)
|
||||||
mCameraState = STATE_PREVIEW
|
mCameraState = STATE_PREVIEW
|
||||||
mCaptureSession!!.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler)
|
mCaptureSession!!.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler)
|
||||||
|
@ -411,6 +403,12 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
||||||
lockFocus()
|
lockFocus()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getFlashlightMode(state: Int) = when (state) {
|
||||||
|
FLASH_OFF -> CameraMetadata.FLASH_MODE_OFF
|
||||||
|
FLASH_ON -> CameraMetadata.FLASH_MODE_TORCH
|
||||||
|
else -> CameraMetadata.FLASH_MODE_SINGLE
|
||||||
|
}
|
||||||
|
|
||||||
override fun setTargetUri(uri: Uri) {
|
override fun setTargetUri(uri: Uri) {
|
||||||
mTargetUri = uri
|
mTargetUri = uri
|
||||||
}
|
}
|
||||||
|
@ -466,8 +464,7 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
||||||
|
|
||||||
override fun checkFlashlight() {
|
override fun checkFlashlight() {
|
||||||
if (mCameraState == STATE_PREVIEW) {
|
if (mCameraState == STATE_PREVIEW) {
|
||||||
val flashMode = if (mFlashlightState == FLASH_ON) CameraMetadata.FLASH_MODE_TORCH else CameraMetadata.FLASH_MODE_OFF
|
mPreviewRequestBuilder!!.set(CaptureRequest.FLASH_MODE, getFlashlightMode(mFlashlightState))
|
||||||
mPreviewRequestBuilder!!.set(CaptureRequest.FLASH_MODE, flashMode)
|
|
||||||
mCaptureSession!!.setRepeatingRequest(mPreviewRequestBuilder!!.build(), mCaptureCallback, mBackgroundHandler)
|
mCaptureSession!!.setRepeatingRequest(mPreviewRequestBuilder!!.build(), mCaptureCallback, mBackgroundHandler)
|
||||||
mActivity.updateFlashlightState(mFlashlightState)
|
mActivity.updateFlashlightState(mFlashlightState)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue