From 2cdf4a55a1d5be8ccedec019174289e15f5b74d5 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 24 Aug 2019 16:31:19 +0200 Subject: [PATCH] implementing the actual SOS signalling --- .../flashlight/helpers/MyCameraImpl.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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 8aa8475..ef5f860 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MyCameraImpl.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MyCameraImpl.kt @@ -19,6 +19,7 @@ class MyCameraImpl(val context: Context) { companion object { var isFlashlightOn = false + private val SOS = arrayListOf(250L, 250L, 250L, 250L, 250L, 250L, 500L, 250L, 500L, 250L, 500L, 250L, 250L, 250L, 250L, 250L, 250L, 1000L) private var camera: Camera? = null private var params: Camera.Parameters? = null @@ -245,13 +246,16 @@ class MyCameraImpl(val context: Context) { isStroboscopeRunning = true } + var sosIndex = 0 if (isNougatPlus()) { while (!shouldStroboscopeStop) { try { marshmallowCamera!!.toggleMarshmallowFlashlight(bus!!, true) - Thread.sleep(stroboFrequency) + val onDuration = if (isStroboSOS) SOS[sosIndex++ % SOS.size] else stroboFrequency + Thread.sleep(onDuration) marshmallowCamera!!.toggleMarshmallowFlashlight(bus!!, false) - Thread.sleep(stroboFrequency) + val offDuration = if (isStroboSOS) SOS[sosIndex++ % SOS.size] else stroboFrequency + Thread.sleep(offDuration) } catch (e: Exception) { shouldStroboscopeStop = true } @@ -277,9 +281,11 @@ class MyCameraImpl(val context: Context) { while (!shouldStroboscopeStop) { try { camera!!.parameters = torchOn - Thread.sleep(stroboFrequency) + val onDuration = if (isStroboSOS) SOS[sosIndex++ % SOS.size] else stroboFrequency + Thread.sleep(onDuration) camera!!.parameters = torchOff - Thread.sleep(stroboFrequency) + val offDuration = if (isStroboSOS) SOS[sosIndex++ % SOS.size] else stroboFrequency + Thread.sleep(offDuration) } catch (e: Exception) { } }