catch some extra exceptions at stroboscope
This commit is contained in:
parent
fbf6e0e111
commit
dc4142e54b
|
@ -12,7 +12,6 @@ import com.simplemobiletools.flashlight.extensions.config
|
||||||
import com.simplemobiletools.flashlight.extensions.updateWidgets
|
import com.simplemobiletools.flashlight.extensions.updateWidgets
|
||||||
import com.simplemobiletools.flashlight.models.Events
|
import com.simplemobiletools.flashlight.models.Events
|
||||||
import org.greenrobot.eventbus.EventBus
|
import org.greenrobot.eventbus.EventBus
|
||||||
import java.io.IOException
|
|
||||||
|
|
||||||
class MyCameraImpl(val context: Context) {
|
class MyCameraImpl(val context: Context) {
|
||||||
var stroboFrequency = 1000L
|
var stroboFrequency = 1000L
|
||||||
|
@ -191,7 +190,11 @@ class MyCameraImpl(val context: Context) {
|
||||||
|
|
||||||
params!!.flashMode = Camera.Parameters.FLASH_MODE_TORCH
|
params!!.flashMode = Camera.Parameters.FLASH_MODE_TORCH
|
||||||
camera!!.parameters = params
|
camera!!.parameters = params
|
||||||
|
try {
|
||||||
camera!!.startPreview()
|
camera!!.startPreview()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
disableFlashlight()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val mainRunnable = Runnable { stateChanged(true) }
|
val mainRunnable = Runnable { stateChanged(true) }
|
||||||
|
@ -270,32 +273,26 @@ class MyCameraImpl(val context: Context) {
|
||||||
initCamera()
|
initCamera()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
val torchOn = camera!!.parameters ?: return@Runnable
|
val torchOn = camera!!.parameters ?: return@Runnable
|
||||||
val torchOff = camera!!.parameters
|
val torchOff = camera!!.parameters
|
||||||
torchOn.flashMode = Camera.Parameters.FLASH_MODE_TORCH
|
torchOn.flashMode = Camera.Parameters.FLASH_MODE_TORCH
|
||||||
torchOff.flashMode = Camera.Parameters.FLASH_MODE_OFF
|
torchOff.flashMode = Camera.Parameters.FLASH_MODE_OFF
|
||||||
|
|
||||||
val dummy = SurfaceTexture(1)
|
val dummy = SurfaceTexture(1)
|
||||||
try {
|
|
||||||
camera!!.setPreviewTexture(dummy)
|
camera!!.setPreviewTexture(dummy)
|
||||||
} catch (e: IOException) {
|
|
||||||
}
|
|
||||||
|
|
||||||
camera!!.startPreview()
|
camera!!.startPreview()
|
||||||
|
|
||||||
while (!shouldStroboscopeStop) {
|
while (!shouldStroboscopeStop) {
|
||||||
try {
|
|
||||||
camera!!.parameters = torchOn
|
camera!!.parameters = torchOn
|
||||||
val onDuration = if (isStroboSOS) SOS[sosIndex++ % SOS.size] else stroboFrequency
|
val onDuration = if (isStroboSOS) SOS[sosIndex++ % SOS.size] else stroboFrequency
|
||||||
Thread.sleep(onDuration)
|
Thread.sleep(onDuration)
|
||||||
camera!!.parameters = torchOff
|
camera!!.parameters = torchOff
|
||||||
val offDuration = if (isStroboSOS) SOS[sosIndex++ % SOS.size] else stroboFrequency
|
val offDuration = if (isStroboSOS) SOS[sosIndex++ % SOS.size] else stroboFrequency
|
||||||
Thread.sleep(offDuration)
|
Thread.sleep(offDuration)
|
||||||
} catch (e: Exception) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
if (camera != null) {
|
if (camera != null) {
|
||||||
camera!!.parameters = torchOff
|
camera!!.parameters = torchOff
|
||||||
if (!shouldEnableFlashlight || isMarshmallow) {
|
if (!shouldEnableFlashlight || isMarshmallow) {
|
||||||
|
@ -304,6 +301,7 @@ class MyCameraImpl(val context: Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: RuntimeException) {
|
} catch (e: RuntimeException) {
|
||||||
|
shouldStroboscopeStop = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue