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 {
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,6 +88,9 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
}
mSurfaceView.setOnClickListener {
if (mIsPreviewShown) {
resumePreview()
} else {
if (!mWasZooming)
focusArea(false)
@ -94,6 +98,7 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
mSurfaceView.isSoundEffectsEnabled = true
}
}
}
fun trySwitchToVideo() {
if (mIsSurfaceCreated) {
@ -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
}

View File

@ -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()