remember which camera was used last, open it by default

This commit is contained in:
tibbi 2018-06-05 22:19:27 +02:00
parent 3f23f017d2
commit 045328daa3
5 changed files with 11 additions and 8 deletions

View File

@ -119,7 +119,7 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener {
mCameraImpl = getMyCamera()
if (config.alwaysOpenBackCamera) {
config.lastUsedCamera = mCameraImpl.getBackCameraId()
config.lastUsedCamera = mCameraImpl.getBackCameraId().toString()
}
}
@ -196,7 +196,7 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener {
mPreview = if (isLollipopPlus()) PreviewCameraTwo(this, camera_texture_view) else PreviewCameraOne(this, camera_surface_view)
view_holder.addView(mPreview as ViewGroup)
val imageDrawable = if (config.lastUsedCamera == mCameraImpl.getBackCameraId()) R.drawable.ic_camera_front else R.drawable.ic_camera_rear
val imageDrawable = if (config.lastUsedCamera == mCameraImpl.getBackCameraId().toString()) R.drawable.ic_camera_front else R.drawable.ic_camera_rear
toggle_camera.setImageResource(imageDrawable)
mFocusCircleView = FocusCircleView(applicationContext)

View File

@ -46,9 +46,9 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getBoolean(FLIP_PHOTOS, true)
set(flipPhotos) = prefs.edit().putBoolean(FLIP_PHOTOS, flipPhotos).apply()
var lastUsedCamera: Int
get() = prefs.getInt(LAST_USED_CAMERA, context.getMyCamera().getBackCameraId())
set(cameraId) = prefs.edit().putInt(LAST_USED_CAMERA, cameraId).apply()
var lastUsedCamera: String
get() = prefs.getString(LAST_USED_CAMERA, context.getMyCamera().getBackCameraId().toString())
set(cameraId) = prefs.edit().putString(LAST_USED_CAMERA, cameraId).apply()
var flashlightState: Int
get() = prefs.getInt(FLASHLIGHT_STATE, FLASH_OFF)

View File

@ -13,7 +13,7 @@ const val FOCUS_BEFORE_CAPTURE = "focus_before_capture"
const val VOLUME_BUTTONS_AS_SHUTTER = "volume_buttons_as_shutter"
const val TURN_FLASH_OFF_AT_STARTUP = "turn_flash_off_at_startup"
const val FLIP_PHOTOS = "flip_photos"
const val LAST_USED_CAMERA = "last_used_camera"
const val LAST_USED_CAMERA = "last_used_camera_2"
const val FLASHLIGHT_STATE = "flashlight_state"
const val BACK_PHOTO_RESOLUTION_INDEX = "back_photo_resolution_index_2"
const val BACK_VIDEO_RESOLUTION_INDEX = "back_video_resolution_index_2"

View File

@ -202,7 +202,7 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MyPreview {
mCameraImpl!!.getBackCameraId()
}
mConfig.lastUsedCamera = mCurrCameraId
mConfig.lastUsedCamera = mCurrCameraId.toString()
releaseCamera()
if (resumeCamera()) {
setFlashlightState(FLASH_OFF)
@ -243,7 +243,7 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MyPreview {
}
private fun getResolutionIndex(): Int {
val isBackCamera = mConfig.lastUsedCamera == Camera.CameraInfo.CAMERA_FACING_BACK
val isBackCamera = mConfig.lastUsedCamera == Camera.CameraInfo.CAMERA_FACING_BACK.toString()
return if (mIsInVideoMode) {
if (isBackCamera) mConfig.backVideoResIndex else mConfig.frontVideoResIndex
} else {

View File

@ -23,6 +23,7 @@ import android.view.ViewGroup
import com.simplemobiletools.camera.activities.MainActivity
import com.simplemobiletools.camera.dialogs.ChangeResolutionDialog
import com.simplemobiletools.camera.extensions.config
import com.simplemobiletools.camera.extensions.getMyCamera
import com.simplemobiletools.camera.helpers.*
import com.simplemobiletools.camera.interfaces.MyPreview
import com.simplemobiletools.camera.models.FocusArea
@ -81,6 +82,7 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
constructor(activity: MainActivity, textureView: AutoFitTextureView) : super(activity) {
mActivity = activity
mTextureView = textureView
mUseFrontCamera = activity.config.lastUsedCamera == activity.getMyCamera().getBackCameraId().toString()
mTextureView.setOnTouchListener { view, event ->
if (event.action == MotionEvent.ACTION_DOWN) {
@ -241,6 +243,7 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
}
mCameraId = cameraId
mActivity.config.lastUsedCamera = mCameraId
val configMap = getCameraCharacteristics().get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP)
val currentResolution = getCurrentResolution()