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,14 +342,6 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createCameraPreviewSession() {
|
private fun createCameraPreviewSession() {
|
||||||
try {
|
|
||||||
val texture = mTextureView.surfaceTexture!!
|
|
||||||
texture.setDefaultBufferSize(mPreviewSize!!.width, mPreviewSize!!.height)
|
|
||||||
|
|
||||||
val surface = Surface(texture)
|
|
||||||
mPreviewRequestBuilder = mCameraDevice!!.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW)
|
|
||||||
mPreviewRequestBuilder!!.addTarget(surface)
|
|
||||||
|
|
||||||
val stateCallback = object : CameraCaptureSession.StateCallback() {
|
val stateCallback = object : CameraCaptureSession.StateCallback() {
|
||||||
override fun onConfigured(cameraCaptureSession: CameraCaptureSession) {
|
override fun onConfigured(cameraCaptureSession: CameraCaptureSession) {
|
||||||
if (mCameraDevice == null) {
|
if (mCameraDevice == null) {
|
||||||
|
@ -369,8 +364,16 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
||||||
override fun onConfigureFailed(cameraCaptureSession: CameraCaptureSession) {}
|
override fun onConfigureFailed(cameraCaptureSession: CameraCaptureSession) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
mCameraDevice!!.createCaptureSession(Arrays.asList(surface, mImageReader!!.surface), stateCallback, null)
|
try {
|
||||||
} catch (e: CameraAccessException) {
|
val texture = mTextureView.surfaceTexture!!
|
||||||
|
texture.setDefaultBufferSize(mPreviewSize!!.width, mPreviewSize!!.height)
|
||||||
|
|
||||||
|
val surface = Surface(texture)
|
||||||
|
mPreviewRequestBuilder = mCameraDevice!!.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW)
|
||||||
|
mPreviewRequestBuilder!!.addTarget(surface)
|
||||||
|
|
||||||
|
mCameraDevice?.createCaptureSession(Arrays.asList(surface, mImageReader!!.surface), stateCallback, null)
|
||||||
|
} catch (e: Exception) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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