mirror of
				https://github.com/SimpleMobileTools/Simple-Camera.git
				synced 2025-06-27 09:02:59 +02:00 
			
		
		
		
	try filling the screen with the default back camera photo resolution
This commit is contained in:
		@@ -39,7 +39,7 @@ class Config(context: Context) : BaseConfig(context) {
 | 
			
		||||
        set(enabled) = prefs.edit().putBoolean(LAST_FLASHLIGHT_STATE, enabled).apply()
 | 
			
		||||
 | 
			
		||||
    var backPhotoResIndex: Int
 | 
			
		||||
        get() = prefs.getInt(BACK_PHOTO_RESOLUTION_INDEX, 0)
 | 
			
		||||
        get() = prefs.getInt(BACK_PHOTO_RESOLUTION_INDEX, -1)
 | 
			
		||||
        set(backPhotoResIndex) = prefs.edit().putInt(BACK_PHOTO_RESOLUTION_INDEX, backPhotoResIndex).apply()
 | 
			
		||||
 | 
			
		||||
    var backVideoResIndex: Int
 | 
			
		||||
 
 | 
			
		||||
@@ -164,13 +164,17 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun getSelectedResolution(): Camera.Size {
 | 
			
		||||
        val index = getResolutionIndex()
 | 
			
		||||
        var index = getResolutionIndex()
 | 
			
		||||
        val resolutions = if (mIsVideoMode) {
 | 
			
		||||
            mParameters!!.supportedVideoSizes ?: mParameters!!.supportedPreviewSizes
 | 
			
		||||
        } else {
 | 
			
		||||
            mParameters!!.supportedPictureSizes
 | 
			
		||||
        }.sortedByDescending { it.width * it.height }
 | 
			
		||||
 | 
			
		||||
        if (index == -1) {
 | 
			
		||||
            index = getDefaultFullscreenResolution(resolutions) ?: 0
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return resolutions[index]
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -183,6 +187,18 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun getDefaultFullscreenResolution(resolutions: List<Camera.Size>): Int? {
 | 
			
		||||
        val screenAspectRatio = mActivity.realScreenSize.y / mActivity.realScreenSize.x.toFloat()
 | 
			
		||||
        resolutions.forEachIndexed { index, size ->
 | 
			
		||||
            val diff = screenAspectRatio - (size.width / size.height.toFloat())
 | 
			
		||||
            if (Math.abs(diff) < RATIO_TOLERANCE) {
 | 
			
		||||
                config.backPhotoResIndex = index
 | 
			
		||||
                return index
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return null
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun setTargetUri(uri: Uri) {
 | 
			
		||||
        mTargetUri = uri
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@ import android.content.Context
 | 
			
		||||
import android.hardware.Camera
 | 
			
		||||
import com.simplemobiletools.camera.R
 | 
			
		||||
 | 
			
		||||
private val RATIO_TOLERANCE = 0.1f
 | 
			
		||||
val RATIO_TOLERANCE = 0.1f
 | 
			
		||||
 | 
			
		||||
fun Camera.Size.isSixteenToNine(): Boolean {
 | 
			
		||||
    val selectedRatio = Math.abs(width / height.toFloat())
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user