mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-01-07 21:01:21 +01:00
move camera init into a standalone function
This commit is contained in:
parent
f62f5314f6
commit
fa9eb58012
@ -123,39 +123,43 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
|
||||
|
||||
releaseCamera()
|
||||
mCamera = newCamera
|
||||
if (mCamera != null) {
|
||||
mParameters = mCamera!!.parameters
|
||||
mMaxZoom = mParameters!!.maxZoom
|
||||
mZoomRatios = mParameters!!.zoomRatios
|
||||
mSupportedPreviewSizes = mParameters!!.supportedPreviewSizes.sortedByDescending { it.width * it.height }
|
||||
refreshPreview()
|
||||
|
||||
val focusModes = mParameters!!.supportedFocusModes
|
||||
if (focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE))
|
||||
mParameters!!.focusMode = Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE
|
||||
|
||||
mCamera!!.setDisplayOrientation(mActivity.getPreviewRotation(cameraId))
|
||||
mCamera!!.parameters = mParameters
|
||||
|
||||
if (mCanTakePicture) {
|
||||
try {
|
||||
mCamera!!.setPreviewDisplay(mSurfaceHolder)
|
||||
} catch (e: IOException) {
|
||||
Log.e(TAG, "setCamera setPreviewDisplay " + e.message)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
mCallback.setFlashAvailable(hasFlash(mCamera))
|
||||
}
|
||||
|
||||
if (mIsVideoMode) {
|
||||
if (initCamera() && mIsVideoMode) {
|
||||
initRecorder()
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
private fun initCamera(): Boolean {
|
||||
if (mCamera == null)
|
||||
return false
|
||||
|
||||
mParameters = mCamera!!.parameters
|
||||
mMaxZoom = mParameters!!.maxZoom
|
||||
mZoomRatios = mParameters!!.zoomRatios
|
||||
mSupportedPreviewSizes = mParameters!!.supportedPreviewSizes.sortedByDescending { it.width * it.height }
|
||||
refreshPreview()
|
||||
|
||||
val focusModes = mParameters!!.supportedFocusModes
|
||||
if (focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE))
|
||||
mParameters!!.focusMode = Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE
|
||||
|
||||
mCamera!!.setDisplayOrientation(mActivity.getPreviewRotation(mCurrCameraId))
|
||||
mCamera!!.parameters = mParameters
|
||||
|
||||
if (mCanTakePicture) {
|
||||
try {
|
||||
mCamera!!.setPreviewDisplay(mSurfaceHolder)
|
||||
} catch (e: IOException) {
|
||||
Log.e(TAG, "setCamera setPreviewDisplay " + e.message)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
mCallback.setFlashAvailable(hasFlash(mCamera))
|
||||
return true
|
||||
}
|
||||
|
||||
private fun refreshPreview() {
|
||||
mIsSixteenToNine = getSelectedResolution().isSixteenToNine()
|
||||
mSetupPreviewAfterMeasure = true
|
||||
|
Loading…
Reference in New Issue
Block a user