Merge pull request #357 from KryptKode/feat/capture-mode-toggle

add settings option for capture mode
This commit is contained in:
Tibor Kaputa 2022-10-24 16:31:26 +02:00 committed by GitHub
commit 237421646d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 73 additions and 6 deletions

View File

@ -5,6 +5,7 @@ import android.os.Bundle
import com.simplemobiletools.camera.BuildConfig
import com.simplemobiletools.camera.R
import com.simplemobiletools.camera.extensions.config
import com.simplemobiletools.camera.models.CaptureMode
import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.*
@ -13,9 +14,9 @@ import com.simplemobiletools.commons.helpers.NavigationIcon
import com.simplemobiletools.commons.helpers.isTiramisuPlus
import com.simplemobiletools.commons.models.FAQItem
import com.simplemobiletools.commons.models.RadioItem
import kotlinx.android.synthetic.main.activity_settings.*
import java.util.*
import java.util.Locale
import kotlin.system.exitProcess
import kotlinx.android.synthetic.main.activity_settings.*
class SettingsActivity : SimpleActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
@ -38,6 +39,7 @@ class SettingsActivity : SimpleActivity() {
setupSavePhotoMetadata()
setupSavePhotosFolder()
setupPhotoQuality()
setupCaptureMode()
updateTextColors(settings_holder)
val properPrimaryColor = getProperPrimaryColor()
@ -209,4 +211,23 @@ class SettingsActivity : SimpleActivity() {
private fun updatePhotoQuality(quality: Int) {
settings_photo_quality.text = "$quality%"
}
private fun setupCaptureMode() {
updateCaptureMode(config.captureMode)
settings_capture_mode_holder.setOnClickListener {
val items = CaptureMode.values().mapIndexed { index, captureMode ->
RadioItem(index, getString(captureMode.stringResId), captureMode)
}
RadioGroupDialog(this@SettingsActivity, ArrayList(items), config.captureMode.ordinal) {
config.captureMode = it as CaptureMode
updateCaptureMode(it)
}
}
}
private fun updateCaptureMode(captureMode: CaptureMode) {
settings_capture_mode.text = getString(captureMode.stringResId)
}
}

View File

@ -3,6 +3,7 @@ package com.simplemobiletools.camera.helpers
import android.content.Context
import android.os.Environment
import androidx.camera.core.CameraSelector
import com.simplemobiletools.camera.models.CaptureMode
import com.simplemobiletools.commons.helpers.BaseConfig
import java.io.File
@ -73,4 +74,9 @@ class Config(context: Context) : BaseConfig(context) {
var photoQuality: Int
get() = prefs.getInt(PHOTO_QUALITY, 80)
set(photoQuality) = prefs.edit().putInt(PHOTO_QUALITY, photoQuality).apply()
var captureMode: CaptureMode
get() = CaptureMode.values()[prefs.getInt(CAPTURE_MODE, CaptureMode.MINIMISE_LATENCY.ordinal)]
set(captureMode) = prefs.edit().putInt(CAPTURE_MODE, captureMode.ordinal).apply()
}

View File

@ -19,6 +19,7 @@ const val FRONT_PHOTO_RESOLUTION_INDEX = "front_photo_resolution_index_3"
const val FRONT_VIDEO_RESOLUTION_INDEX = "front_video_resolution_index_3"
const val SAVE_PHOTO_METADATA = "save_photo_metadata"
const val PHOTO_QUALITY = "photo_quality"
const val CAPTURE_MODE = "capture_mode"
const val FLASH_OFF = 0
const val FLASH_ON = 1

View File

@ -26,6 +26,7 @@ import com.simplemobiletools.camera.R
import com.simplemobiletools.camera.extensions.*
import com.simplemobiletools.camera.helpers.*
import com.simplemobiletools.camera.interfaces.MyPreview
import com.simplemobiletools.camera.models.CaptureMode
import com.simplemobiletools.camera.models.MediaOutput
import com.simplemobiletools.camera.models.MySize
import com.simplemobiletools.camera.models.ResolutionOption
@ -209,7 +210,7 @@ class CameraXPreview(
private fun buildImageCapture(resolution: Size, rotation: Int): ImageCapture {
return Builder()
.setCaptureMode(CAPTURE_MODE_MINIMIZE_LATENCY)
.setCaptureMode(getCaptureMode())
.setFlashMode(flashMode)
.setJpegQuality(config.photoQuality)
.setTargetRotation(rotation)
@ -217,6 +218,13 @@ class CameraXPreview(
.build()
}
private fun getCaptureMode(): Int {
return when (config.captureMode) {
CaptureMode.MINIMISE_LATENCY -> CAPTURE_MODE_MINIMIZE_LATENCY
CaptureMode.MAXIMISE_QUALITY -> CAPTURE_MODE_MAXIMIZE_QUALITY
}
}
private fun buildVideoCapture(): VideoCapture<Recorder> {
val qualitySelector = QualitySelector.from(
videoQualityManager.getUserSelectedQuality(cameraSelector).toCameraXQuality(),

View File

@ -0,0 +1,9 @@
package com.simplemobiletools.camera.models
import androidx.annotation.StringRes
import com.simplemobiletools.camera.R
enum class CaptureMode(@StringRes val stringResId: Int) {
MINIMISE_LATENCY(R.string.minimize_latency),
MAXIMISE_QUALITY(R.string.maximize_quality)
}

View File

@ -82,8 +82,6 @@ class ShadowDrawable(context: Context, private val drawable: Drawable, @StyleRes
}
shadowPaint.isAntiAlias = true
shadowPaint.isFilterBitmap = true
shadowPaint.isAntiAlias = true
shadowPaint.isFilterBitmap = true
}
override fun draw(canvas: Canvas) {

View File

@ -265,7 +265,7 @@
style="@style/SettingsHolderTextViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ripple_bottom_corners">
android:background="@drawable/ripple_background">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_photo_quality_label"
@ -283,6 +283,30 @@
tools:text="80%" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_capture_mode_holder"
style="@style/SettingsHolderTextViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ripple_bottom_corners">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_capture_mode_label"
style="@style/SettingsTextLabelStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/capture_mode" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_capture_mode"
style="@style/SettingsTextValueStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/settings_capture_mode_label"
tools:text="@string/minimize_latency" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>