mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-06-27 09:02:59 +02:00
adding some crashfixes
This commit is contained in:
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user