From 2023cdca50a3009efbe9c6a725ccdbe75aed3698 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 12 Jan 2018 23:47:50 +0100 Subject: [PATCH] handle picture taking on a background thread --- .../simplemobiletools/camera/views/Preview.kt | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/views/Preview.kt b/app/src/main/kotlin/com/simplemobiletools/camera/views/Preview.kt index a535cb94..7faa32a8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/views/Preview.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/views/Preview.kt @@ -296,16 +296,18 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan isWaitingForTakePictureCallback = true mIsPreviewShown = true try { - mCamera!!.takePicture(null, null, takePictureCallback) + Thread { + mCamera!!.takePicture(null, null, takePictureCallback) - if (config.isSoundEnabled) { - val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager - val volume = audioManager.getStreamVolume(AudioManager.STREAM_SYSTEM) - if (volume != 0) { - val mp = MediaPlayer.create(context, Uri.parse("file:///system/media/audio/ui/camera_click.ogg")) - mp?.start() + if (config.isSoundEnabled) { + val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager + val volume = audioManager.getStreamVolume(AudioManager.STREAM_SYSTEM) + if (volume != 0) { + val mp = MediaPlayer.create(context, Uri.parse("file:///system/media/audio/ui/camera_click.ogg")) + mp?.start() + } } - } + }.start() } catch (ignored: Exception) { } }