mirror of
				https://github.com/SimpleMobileTools/Simple-Camera.git
				synced 2025-06-27 09:02:59 +02:00 
			
		
		
		
	use the resolution index instead of the qualities
- store and use the resolution index in Config class for video capture
This commit is contained in:
		| @@ -42,7 +42,7 @@ class ChangeResolutionDialogX( | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     private fun setupPhotoResolutionPicker(view: View) { |     private fun setupPhotoResolutionPicker(view: View) { | ||||||
|         val items = photoResolutions.mapIndexed { index, resolution-> |         val items = photoResolutions.mapIndexed { index, resolution -> | ||||||
|             val megapixels = resolution.megaPixels |             val megapixels = resolution.megaPixels | ||||||
|             val aspectRatio = resolution.getAspectRatio(activity) |             val aspectRatio = resolution.getAspectRatio(activity) | ||||||
|             RadioItem(index, "${resolution.width} x ${resolution.height}  ($megapixels MP,  $aspectRatio)") |             RadioItem(index, "${resolution.width} x ${resolution.height}  ($megapixels MP,  $aspectRatio)") | ||||||
| @@ -74,24 +74,27 @@ class ChangeResolutionDialogX( | |||||||
|             RadioItem(index, "${videoQuality.width} x ${videoQuality.height}  ($megapixels MP,  $aspectRatio)") |             RadioItem(index, "${videoQuality.width} x ${videoQuality.height}  ($megapixels MP,  $aspectRatio)") | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         val videoQuality = if (isFrontCamera) config.frontVideoQuality else config.backVideoQuality |         var selectionIndex = if (isFrontCamera) config.frontVideoResIndex else config.backVideoResIndex | ||||||
|         var selectionIndex = videoResolutions.indexOf(videoQuality) |         selectionIndex = selectionIndex.coerceAtLeast(0) | ||||||
|  |         Log.i(TAG, "videoResolutions=$videoResolutions") | ||||||
|  |         Log.i(TAG, "setupVideoResolutionPicker: selectionIndex=$selectionIndex") | ||||||
|  |  | ||||||
|         view.change_resolution_video_holder.setOnClickListener { |         view.change_resolution_video_holder.setOnClickListener { | ||||||
|             RadioGroupDialog(activity, ArrayList(items), selectionIndex) { |             RadioGroupDialog(activity, ArrayList(items), selectionIndex) { | ||||||
|                 selectionIndex = it as Int |                 selectionIndex = it as Int | ||||||
|                 val selectedItem = items[selectionIndex] |                 val selectedItem = items[selectionIndex] | ||||||
|                 val selectedQuality = videoResolutions[selectionIndex] |  | ||||||
|                 view.change_resolution_video.text = selectedItem.title |                 view.change_resolution_video.text = selectedItem.title | ||||||
|                 if (isFrontCamera) { |                 if (isFrontCamera) { | ||||||
|                     config.frontVideoQuality = selectedQuality |                     config.frontVideoResIndex = selectionIndex | ||||||
|                 } else { |                 } else { | ||||||
|                     config.backVideoQuality = selectedQuality |                     config.backPhotoResIndex = selectionIndex | ||||||
|                 } |                 } | ||||||
|                 dialog.dismiss() |                 dialog.dismiss() | ||||||
|                 callback.invoke() |                 callback.invoke() | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         view.change_resolution_video.text = items.getOrNull(selectionIndex)?.title |         val selectedItem = items.getOrNull(selectionIndex) | ||||||
|  |         view.change_resolution_video.text = selectedItem?.title | ||||||
|  |         Log.i(TAG, "setupVideoResolutionPicker: selectedItem=$selectedItem") | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -3,7 +3,6 @@ package com.simplemobiletools.camera.helpers | |||||||
| import android.content.Context | import android.content.Context | ||||||
| import android.os.Environment | import android.os.Environment | ||||||
| import androidx.camera.core.CameraSelector | import androidx.camera.core.CameraSelector | ||||||
| import com.simplemobiletools.camera.models.VideoQuality |  | ||||||
| import com.simplemobiletools.commons.helpers.BaseConfig | import com.simplemobiletools.commons.helpers.BaseConfig | ||||||
| import java.io.File | import java.io.File | ||||||
|  |  | ||||||
| @@ -63,20 +62,6 @@ class Config(context: Context) : BaseConfig(context) { | |||||||
|         get() = prefs.getInt(FRONT_PHOTO_RESOLUTION_INDEX, 0) |         get() = prefs.getInt(FRONT_PHOTO_RESOLUTION_INDEX, 0) | ||||||
|         set(frontPhotoResIndex) = prefs.edit().putInt(FRONT_PHOTO_RESOLUTION_INDEX, frontPhotoResIndex).apply() |         set(frontPhotoResIndex) = prefs.edit().putInt(FRONT_PHOTO_RESOLUTION_INDEX, frontPhotoResIndex).apply() | ||||||
|  |  | ||||||
|     var backVideoQuality: VideoQuality |  | ||||||
|         get() { |  | ||||||
|             val backQuality = prefs.getString(BACK_VIDEO_QUALITY, VideoQuality.UHD.name) |  | ||||||
|             return VideoQuality.values().first { it.name == backQuality } |  | ||||||
|         } |  | ||||||
|         set(backVideoQuality) = prefs.edit().putString(BACK_VIDEO_QUALITY, backVideoQuality.name).apply() |  | ||||||
|  |  | ||||||
|     var frontVideoQuality: VideoQuality |  | ||||||
|         get() { |  | ||||||
|             val frontQuality = prefs.getString(FRONT_VIDEO_QUALITY, VideoQuality.UHD.name) |  | ||||||
|             return VideoQuality.values().first { it.name == frontQuality } |  | ||||||
|         } |  | ||||||
|         set(frontVideoQuality) = prefs.edit().putString(FRONT_VIDEO_QUALITY, frontVideoQuality.name).apply() |  | ||||||
|  |  | ||||||
|     var frontVideoResIndex: Int |     var frontVideoResIndex: Int | ||||||
|         get() = prefs.getInt(FRONT_VIDEO_RESOLUTION_INDEX, 0) |         get() = prefs.getInt(FRONT_VIDEO_RESOLUTION_INDEX, 0) | ||||||
|         set(frontVideoResIndex) = prefs.edit().putInt(FRONT_VIDEO_RESOLUTION_INDEX, frontVideoResIndex).apply() |         set(frontVideoResIndex) = prefs.edit().putInt(FRONT_VIDEO_RESOLUTION_INDEX, frontVideoResIndex).apply() | ||||||
|   | |||||||
| @@ -34,6 +34,7 @@ class VideoQualityManager(private val config: Config) { | |||||||
|                             .also { allQualities -> |                             .also { allQualities -> | ||||||
|                                 val qualities = allQualities.map { it.toVideoQuality() } |                                 val qualities = allQualities.map { it.toVideoQuality() } | ||||||
|                                 videoQualities.add(CameraSelectorVideoQualities(camSelector, qualities)) |                                 videoQualities.add(CameraSelectorVideoQualities(camSelector, qualities)) | ||||||
|  |  | ||||||
|                             } |                             } | ||||||
|                         Log.i(TAG, "bindCameraUseCases: videoQualities=$videoQualities") |                         Log.i(TAG, "bindCameraUseCases: videoQualities=$videoQualities") | ||||||
|                     } |                     } | ||||||
| @@ -45,11 +46,9 @@ class VideoQualityManager(private val config: Config) { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     fun getUserSelectedQuality(cameraSelector: CameraSelector): Quality { |     fun getUserSelectedQuality(cameraSelector: CameraSelector): Quality { | ||||||
|         return if (cameraSelector == CameraSelector.DEFAULT_FRONT_CAMERA) { |         var selectionIndex = if (cameraSelector == CameraSelector.DEFAULT_FRONT_CAMERA) config.frontVideoResIndex else config.backVideoResIndex | ||||||
|             config.frontVideoQuality.toCameraXQuality() |         selectionIndex = selectionIndex.coerceAtLeast(0) | ||||||
|         } else { |         return getSupportedQualities(cameraSelector)[selectionIndex].toCameraXQuality() | ||||||
|             config.backVideoQuality.toCameraXQuality() |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     fun getSupportedQualities(cameraSelector: CameraSelector): List<VideoQuality> { |     fun getSupportedQualities(cameraSelector: CameraSelector): List<VideoQuality> { | ||||||
|   | |||||||
| @@ -223,7 +223,7 @@ class CameraXPreview( | |||||||
|     private fun buildVideoCapture(): VideoCapture<Recorder> { |     private fun buildVideoCapture(): VideoCapture<Recorder> { | ||||||
|         val qualitySelector = QualitySelector.from( |         val qualitySelector = QualitySelector.from( | ||||||
|             videoQualityManager.getUserSelectedQuality(cameraSelector), |             videoQualityManager.getUserSelectedQuality(cameraSelector), | ||||||
|             FallbackStrategy.lowerQualityOrHigherThan(Quality.SD), |             FallbackStrategy.higherQualityOrLowerThan(Quality.SD), | ||||||
|         ) |         ) | ||||||
|         val recorder = Recorder.Builder() |         val recorder = Recorder.Builder() | ||||||
|             .setQualitySelector(qualitySelector) |             .setQualitySelector(qualitySelector) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user