adding some crashfixes

This commit is contained in:
tibbi
2020-11-07 19:48:46 +01:00
parent 9734743705
commit 9928ed46c1
6 changed files with 23 additions and 10 deletions

View File

@ -448,7 +448,7 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener {
}
private fun showToggleCameraIfNeeded() {
toggle_camera?.beInvisibleIf(mCameraImpl.getCountOfCameras() <= 1)
toggle_camera?.beInvisibleIf(mCameraImpl.getCountOfCameras() ?: 1 <= 1)
}
private fun hasStorageAndCameraPermissions() = hasPermission(PERMISSION_WRITE_STORAGE) && hasPermission(PERMISSION_CAMERA)

View File

@ -9,8 +9,12 @@ class MyCameraImpl(val context: Context) {
fun getBackCameraId() = CameraCharacteristics.LENS_FACING_BACK
fun getCountOfCameras(): Int {
val manager = context.getSystemService(Context.CAMERA_SERVICE) as CameraManager
return manager.cameraIdList.size
fun getCountOfCameras(): Int? {
return try {
val manager = context.getSystemService(Context.CAMERA_SERVICE) as CameraManager
manager.cameraIdList.size
} catch (e: Exception) {
null
}
}
}

View File

@ -577,6 +577,10 @@ class CameraPreview : ViewGroup, TextureView.SurfaceTextureListener, MyPreview {
mRotationAtCapture = mActivity.mLastHandledOrientation
val jpegOrientation = (mSensorOrientation + compensateDeviceRotation(mRotationAtCapture)) % 360
val captureBuilder = mCameraDevice!!.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE).apply {
if (mImageReader!!.surface == null) {
return
}
addTarget(mImageReader!!.surface)
setFlashAndExposure(this)
set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE)
@ -605,7 +609,7 @@ class CameraPreview : ViewGroup, TextureView.SurfaceTextureListener, MyPreview {
abortCaptures()
capture(captureBuilder.build(), captureCallback, null)
}
} catch (e: CameraAccessException) {
} catch (e: Exception) {
mActivity.showErrorToast("Capture picture $e")
}
}
@ -845,7 +849,12 @@ class CameraPreview : ViewGroup, TextureView.SurfaceTextureListener, MyPreview {
updatePreview()
mIsRecording = true
mActivity.runOnUiThread {
mMediaRecorder?.start()
try {
mMediaRecorder?.start()
} catch (e: Exception) {
mActivity.showErrorToast(e)
mCameraState = STATE_PREVIEW
}
}
mActivity.setRecordingState(true)
mCameraState = STATE_RECORDING