diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/camera/helpers/Config.kt index c93b1aa5..540e2446 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/helpers/Config.kt @@ -2,7 +2,6 @@ package com.simplemobiletools.camera.helpers import android.content.Context import android.os.Environment -import com.simplemobiletools.camera.extensions.getMyCamera import com.simplemobiletools.commons.helpers.BaseConfig import java.io.File @@ -47,7 +46,7 @@ class Config(context: Context) : BaseConfig(context) { set(flipPhotos) = prefs.edit().putBoolean(FLIP_PHOTOS, flipPhotos).apply() var lastUsedCamera: String - get() = prefs.getString(LAST_USED_CAMERA, context.getMyCamera().getBackCameraId().toString()) + get() = prefs.getString(LAST_USED_CAMERA, "0") set(cameraId) = prefs.edit().putString(LAST_USED_CAMERA, cameraId).apply() var initPhotoMode: Boolean diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/views/PreviewCameraTwo.kt b/app/src/main/kotlin/com/simplemobiletools/camera/views/PreviewCameraTwo.kt index 1ebdcb70..1bcfd31c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/views/PreviewCameraTwo.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/views/PreviewCameraTwo.kt @@ -34,9 +34,15 @@ import com.simplemobiletools.camera.interfaces.MyPreview import com.simplemobiletools.camera.models.FocusArea import com.simplemobiletools.camera.models.MySize import com.simplemobiletools.commons.helpers.isJellyBean1Plus +import java.lang.IllegalArgumentException +import java.lang.InterruptedException +import java.lang.Math +import java.lang.System +import java.lang.Thread import java.util.* import java.util.concurrent.Semaphore import java.util.concurrent.TimeUnit +import kotlin.RuntimeException // based on the Android Camera2 photo sample at https://github.com/googlesamples/android-Camera2Basic // and video sample at https://github.com/googlesamples/android-Camera2Video @@ -109,7 +115,14 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie constructor(activity: MainActivity, textureView: AutoFitTextureView) : super(activity) { mActivity = activity mTextureView = textureView - mUseFrontCamera = !activity.config.alwaysOpenBackCamera && activity.config.lastUsedCamera == activity.getMyCamera().getFrontCameraId().toString() + val cameraCharacteristics = try { + getCameraCharacteristics(activity.config.lastUsedCamera) + } catch (e: IllegalArgumentException) { + null + } + + val isFrontCamera = cameraCharacteristics?.get(CameraCharacteristics.LENS_FACING).toString() == activity.getMyCamera().getFrontCameraId().toString() + mUseFrontCamera = !activity.config.alwaysOpenBackCamera && isFrontCamera mIsInVideoMode = !activity.config.initPhotoMode loadSounds()