From a84c22ebf8ca27f439283a5b71616709be4ef817 Mon Sep 17 00:00:00 2001 From: Federico Palmieri Date: Tue, 14 Feb 2023 18:45:15 +0100 Subject: [PATCH] fix(#165): fix flashlight status after coming back from camera app --- .../simplemobiletools/flashlight/activities/MainActivity.kt | 6 +++++- .../com/simplemobiletools/flashlight/helpers/CameraFlash.kt | 4 ++++ .../flashlight/helpers/CameraTorchListener.kt | 2 ++ .../simplemobiletools/flashlight/helpers/MyCameraImpl.kt | 4 ++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/MainActivity.kt index 1313ed1..3894651 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/MainActivity.kt @@ -198,6 +198,10 @@ class MainActivity : SimpleActivity() { brightness_bar.beVisibleIf(isEnabled) } } + + override fun onTorchUnavailable() { + mCameraImpl!!.onCameraNotAvailable() + } }) if (config.turnFlashlightOn) { mCameraImpl!!.enableFlashlight() @@ -300,7 +304,7 @@ class MainActivity : SimpleActivity() { } private fun changeIconColor(color: Int, imageView: ImageView?) { - imageView!!.background.mutate().applyColorFilter(color) + imageView!!.background.applyColorFilter(color) } @SuppressLint("NewApi") diff --git a/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/CameraFlash.kt b/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/CameraFlash.kt index 530200e..3d78c59 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/CameraFlash.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/CameraFlash.kt @@ -21,6 +21,10 @@ internal class CameraFlash( override fun onTorchModeChanged(cameraId: String, enabled: Boolean) { cameraTorchListener?.onTorchEnabled(enabled) } + + override fun onTorchModeUnavailable(cameraId: String) { + cameraTorchListener?.onTorchUnavailable() + } } init { diff --git a/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/CameraTorchListener.kt b/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/CameraTorchListener.kt index 481db07..c0d9dae 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/CameraTorchListener.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/CameraTorchListener.kt @@ -2,4 +2,6 @@ package com.simplemobiletools.flashlight.helpers interface CameraTorchListener { fun onTorchEnabled(isEnabled:Boolean) + + fun onTorchUnavailable() } diff --git a/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MyCameraImpl.kt b/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MyCameraImpl.kt index e6f2184..f544cdb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MyCameraImpl.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MyCameraImpl.kt @@ -276,4 +276,8 @@ class MyCameraImpl private constructor(val context: Context, private var cameraT fun updateBrightnessLevel(level: Int) { cameraFlash!!.changeTorchBrightness(level) } + + fun onCameraNotAvailable() { + disableFlashlight() + } }