wrap autofocusing in a try/catch block

This commit is contained in:
tibbi
2017-06-22 21:55:59 +02:00
parent 3734ece6bf
commit 64aec3cf4f

View File

@ -58,7 +58,7 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
private var mCurrCameraId = 0
private var mMaxZoom = 0
private var mRotationAtCapture = 0
private var mIsFocusing = false
private var mIsFocusingBeforeCapture = false
private var autoFocusHandler = Handler()
var isWaitingForTakePictureCallback = false
@ -296,7 +296,7 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
}
}
mCanTakePicture = false
mIsFocusing = false
mIsFocusingBeforeCapture = false
}
private val takePictureCallback = Camera.PictureCallback { data, cam ->
@ -325,11 +325,11 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
}
private fun focusArea(takePictureAfter: Boolean, showFocusRect: Boolean = true) {
if (mCamera == null || (mIsFocusing && !takePictureAfter))
if (mCamera == null || (mIsFocusingBeforeCapture && !takePictureAfter))
return
if (takePictureAfter)
mIsFocusing = true
mIsFocusingBeforeCapture = true
mCamera!!.cancelAutoFocus()
if (mParameters!!.maxNumFocusAreas > 0) {
@ -347,6 +347,7 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
}
mCamera!!.parameters = mParameters
try {
mCamera!!.autoFocus { success, camera ->
camera.cancelAutoFocus()
val focusModes = mParameters!!.supportedFocusModes
@ -364,6 +365,9 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
}, REFOCUS_PERIOD)
}
}
} catch (ignored: RuntimeException) {
}
}
private fun calculateFocusArea(x: Float, y: Float): Rect {