@@ -63,6 +63,10 @@ class SettingsDialog(val mActivity: MainActivity, themedContext: Context) :
6363 private var gridToggle: ImageView
6464 var videoQualitySpinner: Spinner
6565 private lateinit var vQAdapter: ArrayAdapter <String >
66+
67+ var imageFormatSpinner: Spinner
68+ private lateinit var imageFormatAdapter: ArrayAdapter <String >
69+
6670 private var focusTimeoutSpinner: Spinner
6771 private var timerSpinner: Spinner
6872
@@ -84,6 +88,7 @@ class SettingsDialog(val mActivity: MainActivity, themedContext: Context) :
8488 private var enableEISSetting: View
8589 private var selfIlluminationSetting: View
8690 private var videoQualitySetting: View
91+ private var imageFormatSetting: View
8792 private var timerSetting: View
8893
8994 var settingsFrame: View
@@ -226,19 +231,36 @@ class SettingsDialog(val mActivity: MainActivity, themedContext: Context) :
226231 videoQualitySpinner.onItemSelectedListener =
227232 object : AdapterView .OnItemSelectedListener {
228233 override fun onItemSelected (
229- p0 : AdapterView <* >? ,
230- p1 : View ? ,
234+ parent : AdapterView <* >? ,
235+ view : View ? ,
231236 position : Int ,
232- p3 : Long
237+ id : Long
233238 ) {
234239
235240 val choice = vQAdapter.getItem(position) as String
236241 updateVideoQuality(choice)
237242 }
238243
239- override fun onNothingSelected (p0 : AdapterView <* >? ) {}
244+ override fun onNothingSelected (parent : AdapterView <* >? ) {}
240245 }
241246
247+ imageFormatSpinner = binding.imageFormatSpinner
248+
249+ imageFormatSpinner.onItemSelectedListener = object : AdapterView .OnItemSelectedListener {
250+ override fun onItemSelected (
251+ parent : AdapterView <* >? ,
252+ view : View ? ,
253+ position : Int ,
254+ id : Long
255+ ) {
256+ val choice = imageFormatAdapter.getItem(position) as String
257+ updateOutputImageFormat(choice)
258+ }
259+
260+ override fun onNothingSelected (parent : AdapterView <* >? ) {}
261+
262+ }
263+
242264 qRadio = binding.qualityRadio
243265 lRadio = binding.latencyRadio
244266
@@ -333,6 +355,7 @@ class SettingsDialog(val mActivity: MainActivity, themedContext: Context) :
333355 enableEISSetting = binding.enableEisSetting
334356 selfIlluminationSetting = binding.selfIlluminationSetting
335357 videoQualitySetting = binding.videoQualitySetting
358+ imageFormatSetting = binding.imageFormatSetting
336359 timerSetting = binding.timerSetting
337360
338361 includeAudioToggle = binding.includeAudioSwitch
@@ -515,6 +538,21 @@ class SettingsDialog(val mActivity: MainActivity, themedContext: Context) :
515538 }
516539 }
517540
541+ fun updateOutputImageFormat (choice : String , resCam : Boolean = true) {
542+
543+ val imageFormat = titleToImageFormat(choice)
544+
545+ if (imageFormat == camConfig.outputImageFormat) return
546+
547+ camConfig.outputImageFormat = imageFormat
548+
549+ if (resCam) {
550+ camConfig.startCamera(true )
551+ } else {
552+ imageFormatSpinner.setSelection(getAvailableQTitles().indexOf(choice))
553+ }
554+ }
555+
518556 fun titleToQuality (title : String ): Quality {
519557 return when (title) {
520558 " 2160p (UHD)" -> Quality .UHD
@@ -740,6 +778,40 @@ class SettingsDialog(val mActivity: MainActivity, themedContext: Context) :
740778 }
741779 }
742780
781+ private fun getAvailableImageFormatTitles (): List <String > {
782+ val titles = arrayListOf<String >()
783+
784+ camConfig.getAvailableImageFormats().forEach { format ->
785+ titles.add(getTitleForImageFormat(format))
786+ }
787+
788+ return titles
789+ }
790+
791+ fun getTitleForImageFormat (format : Int ): String {
792+ return when (format) {
793+ ImageCapture .OUTPUT_FORMAT_RAW -> " DNG"
794+ ImageCapture .OUTPUT_FORMAT_JPEG -> " JPEG"
795+ ImageCapture .OUTPUT_FORMAT_JPEG_ULTRA_HDR -> " JPEG (UHD)"
796+ else -> {
797+ Log .e(" TAG" , " Unknown image format constant: $format " )
798+ " Unknown"
799+ }
800+ }
801+ }
802+
803+ fun titleToImageFormat (title : String ): Int {
804+ return when (title) {
805+ " DNG" -> ImageCapture .OUTPUT_FORMAT_RAW
806+ " JPEG" -> ImageCapture .OUTPUT_FORMAT_JPEG
807+ " JPEG (UHD)" -> ImageCapture .OUTPUT_FORMAT_JPEG_ULTRA_HDR
808+ else -> {
809+ Log .e(" TAG" , " Unknown title for image format: $title " )
810+ ImageCapture .OUTPUT_FORMAT_JPEG
811+ }
812+ }
813+ }
814+
743815 fun updateGridToggleUI () {
744816 mActivity.previewGrid.postInvalidate()
745817 gridToggle.setImageResource(
@@ -788,6 +860,34 @@ class SettingsDialog(val mActivity: MainActivity, themedContext: Context) :
788860 slideDialogDown()
789861 }
790862
863+ fun reloadSettings () {
864+ if (camConfig.isVideoMode) {
865+ reloadQualities()
866+ }
867+
868+ reloadImageFormats()
869+ }
870+
871+ fun reloadImageFormats () {
872+ val imageFormats = getAvailableImageFormatTitles()
873+
874+ imageFormatAdapter = ArrayAdapter <String >(
875+ mActivity,
876+ android.R .layout.simple_spinner_item,
877+ imageFormats
878+ )
879+
880+ imageFormatAdapter.setDropDownViewResource(
881+ android.R .layout.simple_spinner_dropdown_item
882+ )
883+
884+ imageFormatSpinner.adapter = imageFormatAdapter
885+
886+ imageFormatSpinner.setSelection(
887+ camConfig.getAvailableImageFormats().indexOf(camConfig.outputImageFormat)
888+ )
889+ }
890+
791891 fun reloadQualities () {
792892
793893 val titles = getAvailableQTitles()
0 commit comments