@@ -39,7 +39,6 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
3939 private var mPreviewSize: Camera .Size ? = null
4040 private var mParameters: Camera .Parameters ? = null
4141 private var mRecorder: MediaRecorder ? = null
42- private var mTargetUri: Uri ? = null
4342 private var mScaleGestureDetector: ScaleGestureDetector ? = null
4443 private var mZoomRatios: List <Int >? = null
4544
@@ -62,6 +61,8 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
6261 private var autoFocusHandler = Handler ()
6362
6463 var isWaitingForTakePictureCallback = false
64+ var mTargetUri: Uri ? = null
65+ var isImageCaptureIntent = false
6566
6667 constructor (context: Context ) : super (context)
6768
@@ -94,7 +95,7 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
9495 if (mIsPreviewShown) {
9596 resumePreview()
9697 } else {
97- if (! mWasZooming)
98+ if (! mWasZooming && ! mIsPreviewShown )
9899 focusArea(false )
99100
100101 mWasZooming = false
@@ -214,10 +215,6 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
214215 return null
215216 }
216217
217- fun setTargetUri (uri : Uri ) {
218- mTargetUri = uri
219- }
220-
221218 private fun initGestureDetector () {
222219 mScaleGestureDetector = ScaleGestureDetector (mActivity, object : ScaleGestureDetector .SimpleOnScaleGestureListener () {
223220 override fun onScale (detector : ScaleGestureDetector ): Boolean {
@@ -285,6 +282,7 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
285282 mRotationAtCapture = MainActivity .mLastHandledOrientation
286283 mCamera!! .parameters = mParameters
287284 isWaitingForTakePictureCallback = true
285+ mIsPreviewShown = true
288286 mCamera!! .takePicture(null , null , takePictureCallback)
289287
290288 if (config.isSoundEnabled) {
@@ -302,19 +300,37 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
302300
303301 private val takePictureCallback = Camera .PictureCallback { data, cam ->
304302 isWaitingForTakePictureCallback = false
303+ if (! isImageCaptureIntent) {
304+ handlePreview()
305+ }
306+
307+ if (isImageCaptureIntent) {
308+ if (mTargetUri != null ) {
309+ storePhoto(data)
310+ } else {
311+ mActivity.finishActivity()
312+ }
313+ } else {
314+ storePhoto(data)
315+ }
316+ }
317+
318+ private fun storePhoto (data : ByteArray ) {
319+ PhotoProcessor (mActivity, mTargetUri, mCurrCameraId, mRotationAtCapture).execute(data)
320+ }
321+
322+ private fun handlePreview () {
305323 if (config.isShowPreviewEnabled) {
306- mIsPreviewShown = true
307324 if (! config.wasPhotoPreviewHintShown) {
308325 mActivity.toast(R .string.click_to_resume_preview)
309326 config.wasPhotoPreviewHintShown = true
310327 }
311328 } else {
312329 Handler ().postDelayed({
330+ mIsPreviewShown = false
313331 resumePreview()
314332 }, PHOTO_PREVIEW_LENGTH )
315333 }
316-
317- PhotoProcessor (mActivity, mTargetUri, mCurrCameraId, mRotationAtCapture).execute(data)
318334 }
319335
320336 private fun resumePreview () {
0 commit comments