save last used stroboscope frequency

This commit is contained in:
tibbi 2018-04-05 13:31:33 +02:00
parent 687dbe5e56
commit 8c7cbd7f3a
4 changed files with 23 additions and 9 deletions

View File

@ -23,8 +23,8 @@ import com.squareup.otto.Subscribe
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : SimpleActivity() {
private val MAX_STROBO_DELAY = 2000
private val MIN_STROBO_DELAY = 30
private val MAX_STROBO_DELAY = 2000L
private val MIN_STROBO_DELAY = 30L
private val FLASHLIGHT_STATE = "flashlight_state"
private val STROBOSCOPE_STATE = "stroboscope_state"
@ -148,12 +148,14 @@ class MainActivity : SimpleActivity() {
toggleStroboscope()
}
stroboscope_bar.max = MAX_STROBO_DELAY - MIN_STROBO_DELAY
stroboscope_bar.progress = stroboscope_bar.max / 2
stroboscope_bar.max = (MAX_STROBO_DELAY - MIN_STROBO_DELAY).toInt()
stroboscope_bar.progress = config.stroboscopeProgress
stroboscope_bar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar, progress: Int, b: Boolean) {
val frequency = stroboscope_bar.max - progress + MIN_STROBO_DELAY
mCameraImpl?.stroboFrequency = frequency
config.stroboscopeFrequency = frequency
config.stroboscopeProgress = progress
}
override fun onStartTrackingTouch(seekBar: SeekBar) {

View File

@ -19,4 +19,12 @@ class Config(context: Context) : BaseConfig(context) {
var turnFlashlightOn: Boolean
get() = prefs.getBoolean(TURN_FLASHLIGHT_ON, false)
set(turnFlashlightOn) = prefs.edit().putBoolean(TURN_FLASHLIGHT_ON, turnFlashlightOn).apply()
var stroboscopeProgress: Int
get() = prefs.getInt(STROBOSCOPE_PROGRESS, 1000)
set(stroboscopeProgress) = prefs.edit().putInt(STROBOSCOPE_PROGRESS, stroboscopeProgress).apply()
var stroboscopeFrequency: Long
get() = prefs.getLong(STROBOSCOPE_FREQUENCY, 1000L)
set(stroboscopeFrequency) = prefs.edit().putLong(STROBOSCOPE_FREQUENCY, stroboscopeFrequency).apply()
}

View File

@ -6,3 +6,5 @@ const val TURN_FLASHLIGHT_ON = "turn_flashlight_on"
const val IS_ENABLED = "is_enabled"
const val TOGGLE = "toggle"
const val TOGGLE_WIDGET_UI = "toggle_widget_ui"
const val STROBOSCOPE_FREQUENCY = "stroboscope_frequency"
const val STROBOSCOPE_PROGRESS = "stroboscope_progress"

View File

@ -8,13 +8,14 @@ import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.helpers.isMarshmallowPlus
import com.simplemobiletools.commons.helpers.isNougatPlus
import com.simplemobiletools.flashlight.R
import com.simplemobiletools.flashlight.extensions.config
import com.simplemobiletools.flashlight.extensions.updateWidgets
import com.simplemobiletools.flashlight.models.Events
import com.squareup.otto.Bus
import java.io.IOException
class MyCameraImpl(val context: Context) {
var stroboFrequency = 1000
var stroboFrequency = 1000L
companion object {
var isFlashlightOn = false
@ -43,6 +44,7 @@ class MyCameraImpl(val context: Context) {
}
handleCameraSetup()
stroboFrequency = context.config.stroboscopeFrequency
}
fun toggleFlashlight() {
@ -202,9 +204,9 @@ class MyCameraImpl(val context: Context) {
while (!shouldStroboscopeStop) {
try {
marshmallowCamera!!.toggleMarshmallowFlashlight(bus!!, true)
Thread.sleep(stroboFrequency.toLong())
Thread.sleep(stroboFrequency)
marshmallowCamera!!.toggleMarshmallowFlashlight(bus!!, false)
Thread.sleep(stroboFrequency.toLong())
Thread.sleep(stroboFrequency)
} catch (e: Exception) {
shouldStroboscopeStop = true
}
@ -231,9 +233,9 @@ class MyCameraImpl(val context: Context) {
while (!shouldStroboscopeStop) {
try {
camera!!.parameters = torchOn
Thread.sleep(stroboFrequency.toLong())
Thread.sleep(stroboFrequency)
camera!!.parameters = torchOff
Thread.sleep(stroboFrequency.toLong())
Thread.sleep(stroboFrequency)
} catch (e: Exception) {
}
}