show the captured photo until a click if selected so

This commit is contained in:
tibbi 2017-05-07 12:47:46 +02:00
parent 605a2a96f0
commit 1ed076a8f7
2 changed files with 15 additions and 11 deletions

View File

@ -24,10 +24,10 @@ import java.util.*
class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScanCompletedListener { class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScanCompletedListener {
companion object { companion object {
val PHOTO_PREVIEW_LENGTH = 1000L
var mCamera: Camera? = null var mCamera: Camera? = null
private val TAG = Preview::class.java.simpleName private val TAG = Preview::class.java.simpleName
private val FOCUS_AREA_SIZE = 100 private val FOCUS_AREA_SIZE = 100
private val PHOTO_PREVIEW_LENGTH = 500L
lateinit var mSurfaceHolder: SurfaceHolder lateinit var mSurfaceHolder: SurfaceHolder
lateinit var mSurfaceView: SurfaceView lateinit var mSurfaceView: SurfaceView
@ -52,6 +52,7 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
private var mSetupPreviewAfterMeasure = false private var mSetupPreviewAfterMeasure = false
private var mIsSixteenToNine = false private var mIsSixteenToNine = false
private var mWasZooming = false private var mWasZooming = false
private var mIsPreviewShown = false
private var mLastClickX = 0 private var mLastClickX = 0
private var mLastClickY = 0 private var mLastClickY = 0
private var mCurrCameraId = 0 private var mCurrCameraId = 0
@ -87,6 +88,9 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
} }
mSurfaceView.setOnClickListener { mSurfaceView.setOnClickListener {
if (mIsPreviewShown) {
resumePreview()
} else {
if (!mWasZooming) if (!mWasZooming)
focusArea(false) focusArea(false)
@ -94,6 +98,7 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
mSurfaceView.isSoundEffectsEnabled = true mSurfaceView.isSoundEffectsEnabled = true
} }
} }
}
fun trySwitchToVideo() { fun trySwitchToVideo() {
if (mIsSurfaceCreated) { if (mIsSurfaceCreated) {
@ -291,17 +296,19 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
private val takePictureCallback = Camera.PictureCallback { data, cam -> private val takePictureCallback = Camera.PictureCallback { data, cam ->
if (config.isShowPreviewEnabled) { if (config.isShowPreviewEnabled) {
mIsPreviewShown = true
} else {
Handler().postDelayed({ Handler().postDelayed({
resumePreview() resumePreview()
}, PHOTO_PREVIEW_LENGTH) }, PHOTO_PREVIEW_LENGTH)
} else {
resumePreview()
} }
PhotoProcessor(mActivity, mTargetUri, mCurrCameraId, mRotationAtCapture).execute(data) PhotoProcessor(mActivity, mTargetUri, mCurrCameraId, mRotationAtCapture).execute(data)
} }
private fun resumePreview() { private fun resumePreview() {
mIsPreviewShown = false
mActivity.toggleBottomButtons(false)
mCamera?.startPreview() mCamera?.startPreview()
mCanTakePicture = true mCanTakePicture = true
} }

View File

@ -273,9 +273,6 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
if (mIsInPhotoMode) { if (mIsInPhotoMode) {
toggleBottomButtons(true) toggleBottomButtons(true)
mPreview?.tryTakePicture() mPreview?.tryTakePicture()
Handler().postDelayed({
toggleBottomButtons(false)
}, Preview.PHOTO_PREVIEW_LENGTH)
} else { } else {
if (mPreview?.toggleRecording() == true) { if (mPreview?.toggleRecording() == true) {
shutter.setImageDrawable(mRes.getDrawable(R.drawable.ic_video_stop)) 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 val alpha = if (hide) 0f else 1f
shutter.animate().alpha(alpha).start() shutter.animate().alpha(alpha).start()
toggle_camera.animate().alpha(alpha).start() toggle_camera.animate().alpha(alpha).start()