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

@ -57,6 +57,6 @@ android {
} }
dependencies { dependencies {
implementation 'com.simplemobiletools:commons:5.30.12' implementation 'com.simplemobiletools:commons:5.31.25'
implementation 'androidx.documentfile:documentfile:1.0.1' implementation 'androidx.documentfile:documentfile:1.0.1'
} }

View File

@ -448,7 +448,7 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener {
} }
private fun showToggleCameraIfNeeded() { 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) 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 getBackCameraId() = CameraCharacteristics.LENS_FACING_BACK
fun getCountOfCameras(): Int { fun getCountOfCameras(): Int? {
return try {
val manager = context.getSystemService(Context.CAMERA_SERVICE) as CameraManager val manager = context.getSystemService(Context.CAMERA_SERVICE) as CameraManager
return manager.cameraIdList.size manager.cameraIdList.size
} catch (e: Exception) {
null
}
} }
} }

View File

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

View File

@ -9,7 +9,7 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:4.0.1' classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong

View File

@ -1,6 +1,6 @@
#Sat Sep 05 21:36:09 CEST 2020 #Sat Nov 07 19:34:59 CET 2020
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip