From 7b7838331e11c16c3ab53c0c21ea2fc19e3f2f74 Mon Sep 17 00:00:00 2001 From: darthpaul Date: Wed, 9 Nov 2022 10:09:47 +0000 Subject: [PATCH] persist/restore torch state for video and image capture --- .../camera/activities/MainActivity.kt | 29 +++++++------------ .../camera/implementations/CameraXPreview.kt | 1 + 2 files changed, 11 insertions(+), 19 deletions(-) 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 9b1a89fa..307f33da 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt @@ -40,11 +40,11 @@ import com.simplemobiletools.camera.views.FocusCircleView import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.models.Release +import java.util.concurrent.TimeUnit +import kotlin.math.abs import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.layout_flash.* import kotlinx.android.synthetic.main.layout_top.* -import java.util.concurrent.TimeUnit -import kotlin.math.abs class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, CameraXPreviewListener { private companion object { @@ -345,10 +345,6 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera mTimerHandler = Handler(Looper.getMainLooper()) setupPreviewImage(true) - - val initialFlashlightState = if (mIsInPhotoMode && config.flashlightState != FLASH_ALWAYS_ON) config.flashlightState else FLASH_OFF - mPreview!!.setFlashlightState(initialFlashlightState) - updateFlashlightState(initialFlashlightState) initFlashModeTransitionNames() } @@ -453,18 +449,6 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera } } - private fun updateFlashlightState(state: Int) { - config.flashlightState = state - val flashDrawable = when (state) { - FLASH_OFF -> R.drawable.ic_flash_off_vector - FLASH_ON -> R.drawable.ic_flash_on_vector - FLASH_AUTO -> R.drawable.ic_flash_auto_vector - else -> R.drawable.ic_flashlight_vector - } - toggle_flash.setShadowIcon(flashDrawable) - toggle_flash.transitionName = "${getString(R.string.toggle_flash)}$state" - } - private fun shutterPressed() { if (checkCameraAvailable()) { handleShutter() @@ -727,7 +711,14 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera } override fun onChangeFlashMode(flashMode: Int) { - updateFlashlightState(flashMode) + val flashDrawable = when (flashMode) { + FLASH_OFF -> R.drawable.ic_flash_off_vector + FLASH_ON -> R.drawable.ic_flash_on_vector + FLASH_AUTO -> R.drawable.ic_flash_auto_vector + else -> R.drawable.ic_flashlight_vector + } + toggle_flash.setShadowIcon(flashDrawable) + toggle_flash.transitionName = "${getString(R.string.toggle_flash)}$flashMode" } override fun onVideoRecordingStarted() { diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/implementations/CameraXPreview.kt b/app/src/main/kotlin/com/simplemobiletools/camera/implementations/CameraXPreview.kt index 50c40428..07497ee8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/implementations/CameraXPreview.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/implementations/CameraXPreview.kt @@ -175,6 +175,7 @@ class CameraXPreview( previewUseCase.setSurfaceProvider(previewView.surfaceProvider) preview = previewUseCase setupZoomAndFocus() + setFlashlightState(config.flashlightState) } private fun displaySelectedResolution(resolutionOption: ResolutionOption) {