recheck the previews aspect ratio on resolution change

This commit is contained in:
tibbi 2017-03-21 21:23:15 +01:00
parent c8af745297
commit 4a13d766f0
2 changed files with 13 additions and 7 deletions

View File

@ -132,10 +132,7 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
mMaxZoom = mParameters!!.maxZoom mMaxZoom = mParameters!!.maxZoom
mZoomRatios = mParameters!!.zoomRatios mZoomRatios = mParameters!!.zoomRatios
mSupportedPreviewSizes = mParameters!!.supportedPreviewSizes.sortedByDescending { it.width * it.height } mSupportedPreviewSizes = mParameters!!.supportedPreviewSizes.sortedByDescending { it.width * it.height }
mIsSixteenToNine = isSixteenToNine() refreshPreview()
requestLayout()
invalidate()
mSetupPreviewAfterMeasure = true
val focusModes = mParameters!!.supportedFocusModes val focusModes = mParameters!!.supportedFocusModes
if (focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) if (focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE))
@ -163,6 +160,13 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
return true return true
} }
private fun refreshPreview() {
mIsSixteenToNine = isSixteenToNine()
mSetupPreviewAfterMeasure = true
requestLayout()
invalidate()
}
private fun isSixteenToNine(): Boolean { private fun isSixteenToNine(): Boolean {
val selectedSize = getSelectedResolution() val selectedSize = getSelectedResolution()
val selectedRatio = Math.abs(selectedSize.width / selectedSize.height.toFloat()) val selectedRatio = Math.abs(selectedSize.width / selectedSize.height.toFloat())
@ -287,8 +291,6 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
mCanTakePicture = true mCanTakePicture = true
} }
fun getSupportedVideoSizes(): List<Camera.Size> = mParameters!!.supportedVideoSizes ?: mParameters!!.supportedPreviewSizes
private fun focusArea(takePictureAfter: Boolean) { private fun focusArea(takePictureAfter: Boolean) {
if (mCamera == null) if (mCamera == null)
return return
@ -332,9 +334,12 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
} }
fun showChangeResolutionDialog() { fun showChangeResolutionDialog() {
val oldResolution = getSelectedResolution()
if (mCamera != null) { if (mCamera != null) {
ChangeResolutionDialog(mActivity, config.lastUsedCamera == Camera.CameraInfo.CAMERA_FACING_BACK, mCamera!!) { ChangeResolutionDialog(mActivity, config.lastUsedCamera == Camera.CameraInfo.CAMERA_FACING_BACK, mCamera!!) {
if (oldResolution != getSelectedResolution()) {
refreshPreview()
}
} }
} }
} }

View File

@ -21,6 +21,7 @@ class ChangeResolutionDialog(val activity: SimpleActivity, val isBackCamera: Boo
AlertDialog.Builder(activity) AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, null) .setPositiveButton(R.string.ok, null)
.setOnDismissListener { callback() }
.create().apply { .create().apply {
activity.setupDialogStuff(view, this, if (isBackCamera) R.string.back_camera else R.string.front_camera) activity.setupDialogStuff(view, this, if (isBackCamera) R.string.back_camera else R.string.front_camera)
} }