mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-01-08 13:21:33 +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()
|
releaseCamera()
|
||||||
mCamera = newCamera
|
mCamera = newCamera
|
||||||
if (mCamera != null) {
|
if (initCamera() && mIsVideoMode) {
|
||||||
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) {
|
|
||||||
initRecorder()
|
initRecorder()
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
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() {
|
private fun refreshPreview() {
|
||||||
mIsSixteenToNine = getSelectedResolution().isSixteenToNine()
|
mIsSixteenToNine = getSelectedResolution().isSixteenToNine()
|
||||||
mSetupPreviewAfterMeasure = true
|
mSetupPreviewAfterMeasure = true
|
||||||
|
Loading…
Reference in New Issue
Block a user