move the aspect ratio check in a Size extension
This commit is contained in:
parent
60f2cf9e1a
commit
0fe47acc4e
|
@ -27,7 +27,6 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
|
||||||
var mCamera: Camera? = null
|
var mCamera: Camera? = null
|
||||||
private val TAG = Preview::class.java.simpleName
|
private val TAG = Preview::class.java.simpleName
|
||||||
private val FOCUS_AREA_SIZE = 100
|
private val FOCUS_AREA_SIZE = 100
|
||||||
private val RATIO_TOLERANCE = 0.2f
|
|
||||||
|
|
||||||
lateinit var mSurfaceHolder: SurfaceHolder
|
lateinit var mSurfaceHolder: SurfaceHolder
|
||||||
lateinit var mSurfaceView: SurfaceView
|
lateinit var mSurfaceView: SurfaceView
|
||||||
|
@ -158,20 +157,12 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun refreshPreview() {
|
private fun refreshPreview() {
|
||||||
mIsSixteenToNine = isSixteenToNine()
|
mIsSixteenToNine = getSelectedResolution().isSixteenToNine()
|
||||||
mSetupPreviewAfterMeasure = true
|
mSetupPreviewAfterMeasure = true
|
||||||
requestLayout()
|
requestLayout()
|
||||||
invalidate()
|
invalidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isSixteenToNine(): Boolean {
|
|
||||||
val selectedSize = getSelectedResolution()
|
|
||||||
val selectedRatio = Math.abs(selectedSize.width / selectedSize.height.toFloat())
|
|
||||||
val checkedRatio = 16 / 9.toFloat()
|
|
||||||
val diff = Math.abs(selectedRatio - checkedRatio)
|
|
||||||
return diff < RATIO_TOLERANCE
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getSelectedResolution(): Camera.Size {
|
private fun getSelectedResolution(): Camera.Size {
|
||||||
val index = getResolutionIndex()
|
val index = getResolutionIndex()
|
||||||
val resolutions = if (mIsVideoMode) {
|
val resolutions = if (mIsVideoMode) {
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.simplemobiletools.camera.extensions
|
||||||
|
|
||||||
|
import android.hardware.Camera
|
||||||
|
|
||||||
|
private val RATIO_TOLERANCE = 0.2f
|
||||||
|
|
||||||
|
fun Camera.Size.isSixteenToNine(): Boolean {
|
||||||
|
val selectedRatio = Math.abs(width / height.toFloat())
|
||||||
|
val checkedRatio = 16 / 9.toFloat()
|
||||||
|
val diff = Math.abs(selectedRatio - checkedRatio)
|
||||||
|
return diff < RATIO_TOLERANCE
|
||||||
|
}
|
Loading…
Reference in New Issue