Skip to content

Commit 2cdf4a5

Browse files
committed
implementing the actual SOS signalling
1 parent c3d00cd commit 2cdf4a5

File tree

1 file changed

+10
-4
lines changed
  • app/src/main/kotlin/com/simplemobiletools/flashlight/helpers

1 file changed

+10
-4
lines changed

app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MyCameraImpl.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class MyCameraImpl(val context: Context) {
1919

2020
companion object {
2121
var isFlashlightOn = false
22+
private val SOS = arrayListOf(250L, 250L, 250L, 250L, 250L, 250L, 500L, 250L, 500L, 250L, 500L, 250L, 250L, 250L, 250L, 250L, 250L, 1000L)
2223

2324
private var camera: Camera? = null
2425
private var params: Camera.Parameters? = null
@@ -245,13 +246,16 @@ class MyCameraImpl(val context: Context) {
245246
isStroboscopeRunning = true
246247
}
247248

249+
var sosIndex = 0
248250
if (isNougatPlus()) {
249251
while (!shouldStroboscopeStop) {
250252
try {
251253
marshmallowCamera!!.toggleMarshmallowFlashlight(bus!!, true)
252-
Thread.sleep(stroboFrequency)
254+
val onDuration = if (isStroboSOS) SOS[sosIndex++ % SOS.size] else stroboFrequency
255+
Thread.sleep(onDuration)
253256
marshmallowCamera!!.toggleMarshmallowFlashlight(bus!!, false)
254-
Thread.sleep(stroboFrequency)
257+
val offDuration = if (isStroboSOS) SOS[sosIndex++ % SOS.size] else stroboFrequency
258+
Thread.sleep(offDuration)
255259
} catch (e: Exception) {
256260
shouldStroboscopeStop = true
257261
}
@@ -277,9 +281,11 @@ class MyCameraImpl(val context: Context) {
277281
while (!shouldStroboscopeStop) {
278282
try {
279283
camera!!.parameters = torchOn
280-
Thread.sleep(stroboFrequency)
284+
val onDuration = if (isStroboSOS) SOS[sosIndex++ % SOS.size] else stroboFrequency
285+
Thread.sleep(onDuration)
281286
camera!!.parameters = torchOff
282-
Thread.sleep(stroboFrequency)
287+
val offDuration = if (isStroboSOS) SOS[sosIndex++ % SOS.size] else stroboFrequency
288+
Thread.sleep(offDuration)
283289
} catch (e: Exception) {
284290
}
285291
}

0 commit comments

Comments
 (0)