diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt b/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt index f27b66be..0854ec14 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt @@ -24,10 +24,10 @@ import java.util.* class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScanCompletedListener { companion object { - val PHOTO_PREVIEW_LENGTH = 1000L var mCamera: Camera? = null private val TAG = Preview::class.java.simpleName private val FOCUS_AREA_SIZE = 100 + private val PHOTO_PREVIEW_LENGTH = 500L lateinit var mSurfaceHolder: SurfaceHolder lateinit var mSurfaceView: SurfaceView @@ -52,6 +52,7 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan private var mSetupPreviewAfterMeasure = false private var mIsSixteenToNine = false private var mWasZooming = false + private var mIsPreviewShown = false private var mLastClickX = 0 private var mLastClickY = 0 private var mCurrCameraId = 0 @@ -87,11 +88,15 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan } mSurfaceView.setOnClickListener { - if (!mWasZooming) - focusArea(false) + if (mIsPreviewShown) { + resumePreview() + } else { + if (!mWasZooming) + focusArea(false) - mWasZooming = false - mSurfaceView.isSoundEffectsEnabled = true + mWasZooming = false + mSurfaceView.isSoundEffectsEnabled = true + } } } @@ -291,17 +296,19 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan private val takePictureCallback = Camera.PictureCallback { data, cam -> if (config.isShowPreviewEnabled) { + mIsPreviewShown = true + } else { Handler().postDelayed({ resumePreview() }, PHOTO_PREVIEW_LENGTH) - } else { - resumePreview() } PhotoProcessor(mActivity, mTargetUri, mCurrCameraId, mRotationAtCapture).execute(data) } private fun resumePreview() { + mIsPreviewShown = false + mActivity.toggleBottomButtons(false) mCamera?.startPreview() mCanTakePicture = true } diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt index 3b070b94..ee916d8f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt @@ -273,9 +273,6 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave if (mIsInPhotoMode) { toggleBottomButtons(true) mPreview?.tryTakePicture() - Handler().postDelayed({ - toggleBottomButtons(false) - }, Preview.PHOTO_PREVIEW_LENGTH) } else { if (mPreview?.toggleRecording() == true) { shutter.setImageDrawable(mRes.getDrawable(R.drawable.ic_video_stop)) @@ -289,7 +286,7 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave } } - private fun toggleBottomButtons(hide: Boolean) { + fun toggleBottomButtons(hide: Boolean) { val alpha = if (hide) 0f else 1f shutter.animate().alpha(alpha).start() toggle_camera.animate().alpha(alpha).start()