mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-06-27 09:02:59 +02:00
wrap autofocusing in a try/catch block
This commit is contained in:
@ -58,7 +58,7 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
|
|||||||
private var mCurrCameraId = 0
|
private var mCurrCameraId = 0
|
||||||
private var mMaxZoom = 0
|
private var mMaxZoom = 0
|
||||||
private var mRotationAtCapture = 0
|
private var mRotationAtCapture = 0
|
||||||
private var mIsFocusing = false
|
private var mIsFocusingBeforeCapture = false
|
||||||
private var autoFocusHandler = Handler()
|
private var autoFocusHandler = Handler()
|
||||||
|
|
||||||
var isWaitingForTakePictureCallback = false
|
var isWaitingForTakePictureCallback = false
|
||||||
@ -296,7 +296,7 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
mCanTakePicture = false
|
mCanTakePicture = false
|
||||||
mIsFocusing = false
|
mIsFocusingBeforeCapture = false
|
||||||
}
|
}
|
||||||
|
|
||||||
private val takePictureCallback = Camera.PictureCallback { data, cam ->
|
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) {
|
private fun focusArea(takePictureAfter: Boolean, showFocusRect: Boolean = true) {
|
||||||
if (mCamera == null || (mIsFocusing && !takePictureAfter))
|
if (mCamera == null || (mIsFocusingBeforeCapture && !takePictureAfter))
|
||||||
return
|
return
|
||||||
|
|
||||||
if (takePictureAfter)
|
if (takePictureAfter)
|
||||||
mIsFocusing = true
|
mIsFocusingBeforeCapture = true
|
||||||
|
|
||||||
mCamera!!.cancelAutoFocus()
|
mCamera!!.cancelAutoFocus()
|
||||||
if (mParameters!!.maxNumFocusAreas > 0) {
|
if (mParameters!!.maxNumFocusAreas > 0) {
|
||||||
@ -347,22 +347,26 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
|
|||||||
}
|
}
|
||||||
|
|
||||||
mCamera!!.parameters = mParameters
|
mCamera!!.parameters = mParameters
|
||||||
mCamera!!.autoFocus { success, camera ->
|
try {
|
||||||
camera.cancelAutoFocus()
|
mCamera!!.autoFocus { success, camera ->
|
||||||
val focusModes = mParameters!!.supportedFocusModes
|
camera.cancelAutoFocus()
|
||||||
if (focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE))
|
val focusModes = mParameters!!.supportedFocusModes
|
||||||
mParameters!!.focusMode = Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE
|
if (focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE))
|
||||||
|
mParameters!!.focusMode = Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE
|
||||||
|
|
||||||
camera.parameters = mParameters
|
camera.parameters = mParameters
|
||||||
|
|
||||||
if (takePictureAfter) {
|
if (takePictureAfter) {
|
||||||
takePicture()
|
takePicture()
|
||||||
} else if (!mIsVideoMode || !mIsRecording) {
|
} else if (!mIsVideoMode || !mIsRecording) {
|
||||||
autoFocusHandler.removeCallbacksAndMessages(null)
|
autoFocusHandler.removeCallbacksAndMessages(null)
|
||||||
autoFocusHandler.postDelayed({
|
autoFocusHandler.postDelayed({
|
||||||
focusArea(false, false)
|
focusArea(false, false)
|
||||||
}, REFOCUS_PERIOD)
|
}, REFOCUS_PERIOD)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (ignored: RuntimeException) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user