adding some initial camera states

This commit is contained in:
tibbi 2018-05-28 16:00:30 +02:00
parent a52716a3a5
commit e529bdd15c
3 changed files with 12 additions and 6 deletions

View File

@ -97,7 +97,7 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
mPreview?.releaseCamera()
mOrientationEventListener.disable()
if (mPreview?.isWaitingForTakePictureCallback == true) {
if (mPreview?.getCameraState() == STATE_PICTURE_TAKEN) {
toast(R.string.photo_not_saved)
}
}
@ -219,7 +219,7 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
private fun toggleCamera() {
if (checkCameraAvailable()) {
mPreview!!.toggleCamera()
mPreview!!.toggleFrontBackCamera()
}
}

View File

@ -27,3 +27,7 @@ const val PHOTO_QUALITY = "photo_quality"
const val FLASH_OFF = 0
const val FLASH_ON = 1
const val FLASH_AUTO = 2
// camera states
const val STATE_PREVIEW = 0
const val STATE_PICTURE_TAKEN = 1

View File

@ -50,6 +50,7 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback {
private var mZoomRatios = ArrayList<Int>()
private var mFlashlightState = FLASH_OFF
private var mCameraImpl: MyCameraOneImpl? = null
private var mCameraState = STATE_PREVIEW
private var mCurrVideoPath = ""
private var mCanTakePicture = false
@ -71,7 +72,6 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback {
private var autoFocusHandler = Handler()
private var mActivity: MainActivity? = null
var isWaitingForTakePictureCallback = false
var mTargetUri: Uri? = null
var isImageCaptureIntent = false
@ -195,7 +195,7 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback {
return true
}
fun toggleCamera() {
fun toggleFrontBackCamera() {
mCurrCameraId = if (mCurrCameraId == mCameraImpl!!.getBackCameraId()) {
mCameraImpl!!.getFrontCameraId()
} else {
@ -213,6 +213,8 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback {
}
}
fun getCameraState() = mCameraState
private fun refreshPreview() {
mIsSixteenToNine = getSelectedResolution().isSixteenToNine()
mSetupPreviewAfterMeasure = true
@ -332,7 +334,7 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback {
mRotationAtCapture = mActivity!!.mLastHandledOrientation
updateCameraParameters()
isWaitingForTakePictureCallback = true
mCameraState = STATE_PICTURE_TAKEN
mIsPreviewShown = true
try {
Thread {
@ -360,7 +362,7 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback {
return@PictureCallback
}
isWaitingForTakePictureCallback = false
mCameraState = STATE_PREVIEW
if (!isImageCaptureIntent) {
handlePreview()
}