fix a glitch at remembering front/back camera

This commit is contained in:
tibbi 2018-06-10 23:42:18 +02:00
parent 594c024cd1
commit 3daa79590f
2 changed files with 15 additions and 3 deletions

View File

@ -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

View File

@ -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()