From 406236cb2eec4a9c5c745bd3f712229310a54843 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 21 Oct 2017 21:37:13 +0200 Subject: [PATCH] fix #76, add a toggle for always opening the back camera at startup --- .../com/simplemobiletools/camera/Config.kt | 4 ++++ .../com/simplemobiletools/camera/Constants.kt | 1 + .../camera/activities/MainActivity.kt | 3 +++ .../camera/activities/SettingsActivity.kt | 9 +++++++++ app/src/main/res/layout/activity_settings.xml | 20 +++++++++++++++++++ 5 files changed, 37 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/Config.kt b/app/src/main/kotlin/com/simplemobiletools/camera/Config.kt index 42ad2707..87174d21 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/Config.kt @@ -77,4 +77,8 @@ class Config(context: Context) : BaseConfig(context) { var keepSettingsVisible: Boolean get() = prefs.getBoolean(KEEP_SETTINGS_VISIBLE, false) set(keepSettingsVisible) = prefs.edit().putBoolean(KEEP_SETTINGS_VISIBLE, keepSettingsVisible).apply() + + var alwaysOpenBackCamera: Boolean + get() = prefs.getBoolean(ALWAYS_OPEN_BACK_CAMERA, false) + set(alwaysOpenBackCamera) = prefs.edit().putBoolean(ALWAYS_OPEN_BACK_CAMERA, alwaysOpenBackCamera).apply() } diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/camera/Constants.kt index ad9bde73..68584ad6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/Constants.kt @@ -20,6 +20,7 @@ val FRONT_PHOTO_RESOLUTION_INDEX = "front_photo_resolution_index" val FRONT_VIDEO_RESOLUTION_INDEX = "front_video_resolution_index" val PHOTO_PREVIEW_HINT_SHOWN = "photo_preview_hint_shown" val KEEP_SETTINGS_VISIBLE = "keep_settings_visible" +val ALWAYS_OPEN_BACK_CAMERA = "always_open_back_camera" val FLASH_OFF = 0 val FLASH_ON = 1 diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt index b734add4..067e6cd2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt @@ -56,6 +56,9 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave super.onCreate(savedInstanceState) requestWindowFeature(Window.FEATURE_NO_TITLE) window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN) + if (config.alwaysOpenBackCamera) + config.lastUsedCamera = Camera.CameraInfo.CAMERA_FACING_BACK + initVariables() tryInitCamera() supportActionBar?.hide() diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/camera/activities/SettingsActivity.kt index 0453a153..59b2c3ab 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/activities/SettingsActivity.kt @@ -32,6 +32,7 @@ class SettingsActivity : SimpleActivity() { setupTurnFlashOffAtStartup() setupFlipPhotos() setupKeepSettingsVisible() + setupAlwaysOpenBackCamera() updateTextColors(settings_holder) } @@ -126,4 +127,12 @@ class SettingsActivity : SimpleActivity() { config.keepSettingsVisible = settings_keep_settings_visible.isChecked } } + + private fun setupAlwaysOpenBackCamera() { + settings_always_open_back_camera.isChecked = config.alwaysOpenBackCamera + settings_always_open_back_camera_holder.setOnClickListener { + settings_always_open_back_camera.toggle() + config.alwaysOpenBackCamera = settings_always_open_back_camera.isChecked + } + } } diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 3f12f989..da4a2c63 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -204,5 +204,25 @@ android:text="@string/keep_settings_visible"/> + + + + + +