mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-22 16:40:31 +02:00
current stand
This commit is contained in:
parent
da1438c989
commit
ec1f91e483
@ -21,6 +21,7 @@ import app.myzel394.alibi.ui.models.VideoRecorderModel
|
|||||||
import app.myzel394.alibi.ui.utils.getOptimalPreviewSize
|
import app.myzel394.alibi.ui.utils.getOptimalPreviewSize
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.lang.Float.max
|
||||||
|
|
||||||
@SuppressLint("MissingPermission", "NewApi")
|
@SuppressLint("MissingPermission", "NewApi")
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@ -50,31 +51,28 @@ fun RecorderScreen(
|
|||||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||||
val width = resolveSize(suggestedMinimumWidth, widthMeasureSpec);
|
val width = resolveSize(suggestedMinimumWidth, widthMeasureSpec);
|
||||||
val height = resolveSize(suggestedMinimumHeight, heightMeasureSpec);
|
val height = resolveSize(suggestedMinimumHeight, heightMeasureSpec);
|
||||||
setMeasuredDimension(width, height);
|
|
||||||
|
|
||||||
val supportedPreviewSizes = camera!!
|
val supportedPreviewSizes = camera!!
|
||||||
.characteristics
|
.characteristics
|
||||||
.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP)!!
|
.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP)!!
|
||||||
.getOutputSizes(SurfaceHolder::class.java)
|
.getOutputSizes(SurfaceHolder::class.java)
|
||||||
|
|
||||||
|
// Make sure preview is in `cover` mode and not `contain` mode
|
||||||
|
|
||||||
if (supportedPreviewSizes != null) {
|
if (supportedPreviewSizes != null) {
|
||||||
val previewSize = getOptimalPreviewSize(supportedPreviewSizes, width, height);
|
val previewSize = getOptimalPreviewSize(supportedPreviewSizes, width, height);
|
||||||
|
|
||||||
val ratio = if (previewSize.height >= previewSize.width)
|
val optimalWidth = previewSize.width
|
||||||
(previewSize.height / previewSize.width).toFloat()
|
val optimalHeight = previewSize.height
|
||||||
else (previewSize.width / previewSize.height).toFloat()
|
|
||||||
|
|
||||||
val optimalWidth = width
|
|
||||||
val optimalHeight = (width * ratio).toInt()
|
|
||||||
|
|
||||||
// Make sure the camera preview uses the whole screen
|
// Make sure the camera preview uses the whole screen
|
||||||
|
val widthScaleRatio = 1f ?: width.toFloat() / optimalWidth
|
||||||
|
val heightScaleUpRatio = 1f ?: height.toFloat() / optimalHeight
|
||||||
|
|
||||||
val metrics = context.resources.displayMetrics
|
setMeasuredDimension(
|
||||||
layoutParams.width = metrics.widthPixels
|
(optimalWidth * widthScaleRatio).toInt(),
|
||||||
layoutParams.height = metrics.heightPixels
|
(optimalHeight * heightScaleUpRatio).toInt()
|
||||||
|
)
|
||||||
setMeasuredDimension(optimalWidth, optimalHeight)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user