improve the camera behaviour at changing the resolution
This commit is contained in:
parent
f1359e1909
commit
6a1cc57c00
|
@ -117,7 +117,10 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
||||||
stopBackgroundThread()
|
stopBackgroundThread()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSurfaceTextureSizeChanged(surface: SurfaceTexture?, width: Int, height: Int) {}
|
override fun onSurfaceTextureSizeChanged(surface: SurfaceTexture?, width: Int, height: Int) {
|
||||||
|
closeCamera()
|
||||||
|
openCamera(width, height)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onSurfaceTextureUpdated(surface: SurfaceTexture?) {}
|
override fun onSurfaceTextureUpdated(surface: SurfaceTexture?) {}
|
||||||
|
|
||||||
|
@ -339,6 +342,28 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createCameraPreviewSession() {
|
private fun createCameraPreviewSession() {
|
||||||
|
val stateCallback = object : CameraCaptureSession.StateCallback() {
|
||||||
|
override fun onConfigured(cameraCaptureSession: CameraCaptureSession) {
|
||||||
|
if (mCameraDevice == null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mCaptureSession = cameraCaptureSession
|
||||||
|
mPreviewRequestBuilder!!.apply {
|
||||||
|
set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE)
|
||||||
|
setFlashAndExposure(this)
|
||||||
|
mPreviewRequest = build()
|
||||||
|
}
|
||||||
|
mCaptureSession!!.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler)
|
||||||
|
mCameraState = STATE_PREVIEW
|
||||||
|
} catch (e: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onConfigureFailed(cameraCaptureSession: CameraCaptureSession) {}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val texture = mTextureView.surfaceTexture!!
|
val texture = mTextureView.surfaceTexture!!
|
||||||
texture.setDefaultBufferSize(mPreviewSize!!.width, mPreviewSize!!.height)
|
texture.setDefaultBufferSize(mPreviewSize!!.width, mPreviewSize!!.height)
|
||||||
|
@ -347,30 +372,8 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
||||||
mPreviewRequestBuilder = mCameraDevice!!.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW)
|
mPreviewRequestBuilder = mCameraDevice!!.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW)
|
||||||
mPreviewRequestBuilder!!.addTarget(surface)
|
mPreviewRequestBuilder!!.addTarget(surface)
|
||||||
|
|
||||||
val stateCallback = object : CameraCaptureSession.StateCallback() {
|
mCameraDevice?.createCaptureSession(Arrays.asList(surface, mImageReader!!.surface), stateCallback, null)
|
||||||
override fun onConfigured(cameraCaptureSession: CameraCaptureSession) {
|
} catch (e: Exception) {
|
||||||
if (mCameraDevice == null) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
mCaptureSession = cameraCaptureSession
|
|
||||||
mPreviewRequestBuilder!!.apply {
|
|
||||||
set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE)
|
|
||||||
setFlashAndExposure(this)
|
|
||||||
mPreviewRequest = build()
|
|
||||||
}
|
|
||||||
mCaptureSession!!.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler)
|
|
||||||
mCameraState = STATE_PREVIEW
|
|
||||||
} catch (e: Exception) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onConfigureFailed(cameraCaptureSession: CameraCaptureSession) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
mCameraDevice!!.createCaptureSession(Arrays.asList(surface, mImageReader!!.surface), stateCallback, null)
|
|
||||||
} catch (e: CameraAccessException) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -603,14 +606,6 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
||||||
|
|
||||||
private fun getCameraCharacteristics(cameraId: String = mCameraId) = getCameraManager().getCameraCharacteristics(cameraId)
|
private fun getCameraCharacteristics(cameraId: String = mCameraId) = getCameraManager().getCameraCharacteristics(cameraId)
|
||||||
|
|
||||||
private fun takePicture() {
|
|
||||||
if (mIsFocusSupported) {
|
|
||||||
lockFocus()
|
|
||||||
} else {
|
|
||||||
captureStillPicture()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getFlashlightMode() = when (mFlashlightState) {
|
private fun getFlashlightMode() = when (mFlashlightState) {
|
||||||
FLASH_ON -> CameraMetadata.FLASH_MODE_TORCH
|
FLASH_ON -> CameraMetadata.FLASH_MODE_TORCH
|
||||||
else -> CameraMetadata.FLASH_MODE_OFF
|
else -> CameraMetadata.FLASH_MODE_OFF
|
||||||
|
@ -638,7 +633,8 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
||||||
val videoResolutions = ArrayList<MySize>()
|
val videoResolutions = ArrayList<MySize>()
|
||||||
ChangeResolutionDialog(mActivity, mUseFrontCamera, photoResolutions, videoResolutions) {
|
ChangeResolutionDialog(mActivity, mUseFrontCamera, photoResolutions, videoResolutions) {
|
||||||
if (oldResolution != getCurrentResolution()) {
|
if (oldResolution != getCurrentResolution()) {
|
||||||
|
closeCamera()
|
||||||
|
openCamera(mTextureView.width, mTextureView.height)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -655,7 +651,11 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun tryTakePicture() {
|
override fun tryTakePicture() {
|
||||||
takePicture()
|
if (mIsFocusSupported) {
|
||||||
|
lockFocus()
|
||||||
|
} else {
|
||||||
|
captureStillPicture()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toggleRecording(): Boolean {
|
override fun toggleRecording(): Boolean {
|
||||||
|
|
Loading…
Reference in New Issue