mirror of
https://github.com/SimpleMobileTools/Simple-Flashlight.git
synced 2025-02-17 04:10:46 +01:00
save last used stroboscope frequency
This commit is contained in:
parent
687dbe5e56
commit
8c7cbd7f3a
@ -23,8 +23,8 @@ import com.squareup.otto.Subscribe
|
|||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
|
|
||||||
class MainActivity : SimpleActivity() {
|
class MainActivity : SimpleActivity() {
|
||||||
private val MAX_STROBO_DELAY = 2000
|
private val MAX_STROBO_DELAY = 2000L
|
||||||
private val MIN_STROBO_DELAY = 30
|
private val MIN_STROBO_DELAY = 30L
|
||||||
private val FLASHLIGHT_STATE = "flashlight_state"
|
private val FLASHLIGHT_STATE = "flashlight_state"
|
||||||
private val STROBOSCOPE_STATE = "stroboscope_state"
|
private val STROBOSCOPE_STATE = "stroboscope_state"
|
||||||
|
|
||||||
@ -148,12 +148,14 @@ class MainActivity : SimpleActivity() {
|
|||||||
toggleStroboscope()
|
toggleStroboscope()
|
||||||
}
|
}
|
||||||
|
|
||||||
stroboscope_bar.max = MAX_STROBO_DELAY - MIN_STROBO_DELAY
|
stroboscope_bar.max = (MAX_STROBO_DELAY - MIN_STROBO_DELAY).toInt()
|
||||||
stroboscope_bar.progress = stroboscope_bar.max / 2
|
stroboscope_bar.progress = config.stroboscopeProgress
|
||||||
stroboscope_bar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
stroboscope_bar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
||||||
override fun onProgressChanged(seekBar: SeekBar, progress: Int, b: Boolean) {
|
override fun onProgressChanged(seekBar: SeekBar, progress: Int, b: Boolean) {
|
||||||
val frequency = stroboscope_bar.max - progress + MIN_STROBO_DELAY
|
val frequency = stroboscope_bar.max - progress + MIN_STROBO_DELAY
|
||||||
mCameraImpl?.stroboFrequency = frequency
|
mCameraImpl?.stroboFrequency = frequency
|
||||||
|
config.stroboscopeFrequency = frequency
|
||||||
|
config.stroboscopeProgress = progress
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStartTrackingTouch(seekBar: SeekBar) {
|
override fun onStartTrackingTouch(seekBar: SeekBar) {
|
||||||
|
@ -19,4 +19,12 @@ class Config(context: Context) : BaseConfig(context) {
|
|||||||
var turnFlashlightOn: Boolean
|
var turnFlashlightOn: Boolean
|
||||||
get() = prefs.getBoolean(TURN_FLASHLIGHT_ON, false)
|
get() = prefs.getBoolean(TURN_FLASHLIGHT_ON, false)
|
||||||
set(turnFlashlightOn) = prefs.edit().putBoolean(TURN_FLASHLIGHT_ON, turnFlashlightOn).apply()
|
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()
|
||||||
}
|
}
|
||||||
|
@ -6,3 +6,5 @@ const val TURN_FLASHLIGHT_ON = "turn_flashlight_on"
|
|||||||
const val IS_ENABLED = "is_enabled"
|
const val IS_ENABLED = "is_enabled"
|
||||||
const val TOGGLE = "toggle"
|
const val TOGGLE = "toggle"
|
||||||
const val TOGGLE_WIDGET_UI = "toggle_widget_ui"
|
const val TOGGLE_WIDGET_UI = "toggle_widget_ui"
|
||||||
|
const val STROBOSCOPE_FREQUENCY = "stroboscope_frequency"
|
||||||
|
const val STROBOSCOPE_PROGRESS = "stroboscope_progress"
|
||||||
|
@ -8,13 +8,14 @@ import com.simplemobiletools.commons.extensions.toast
|
|||||||
import com.simplemobiletools.commons.helpers.isMarshmallowPlus
|
import com.simplemobiletools.commons.helpers.isMarshmallowPlus
|
||||||
import com.simplemobiletools.commons.helpers.isNougatPlus
|
import com.simplemobiletools.commons.helpers.isNougatPlus
|
||||||
import com.simplemobiletools.flashlight.R
|
import com.simplemobiletools.flashlight.R
|
||||||
|
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 com.squareup.otto.Bus
|
import com.squareup.otto.Bus
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
class MyCameraImpl(val context: Context) {
|
class MyCameraImpl(val context: Context) {
|
||||||
var stroboFrequency = 1000
|
var stroboFrequency = 1000L
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
var isFlashlightOn = false
|
var isFlashlightOn = false
|
||||||
@ -43,6 +44,7 @@ class MyCameraImpl(val context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleCameraSetup()
|
handleCameraSetup()
|
||||||
|
stroboFrequency = context.config.stroboscopeFrequency
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toggleFlashlight() {
|
fun toggleFlashlight() {
|
||||||
@ -202,9 +204,9 @@ class MyCameraImpl(val context: Context) {
|
|||||||
while (!shouldStroboscopeStop) {
|
while (!shouldStroboscopeStop) {
|
||||||
try {
|
try {
|
||||||
marshmallowCamera!!.toggleMarshmallowFlashlight(bus!!, true)
|
marshmallowCamera!!.toggleMarshmallowFlashlight(bus!!, true)
|
||||||
Thread.sleep(stroboFrequency.toLong())
|
Thread.sleep(stroboFrequency)
|
||||||
marshmallowCamera!!.toggleMarshmallowFlashlight(bus!!, false)
|
marshmallowCamera!!.toggleMarshmallowFlashlight(bus!!, false)
|
||||||
Thread.sleep(stroboFrequency.toLong())
|
Thread.sleep(stroboFrequency)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
shouldStroboscopeStop = true
|
shouldStroboscopeStop = true
|
||||||
}
|
}
|
||||||
@ -231,9 +233,9 @@ class MyCameraImpl(val context: Context) {
|
|||||||
while (!shouldStroboscopeStop) {
|
while (!shouldStroboscopeStop) {
|
||||||
try {
|
try {
|
||||||
camera!!.parameters = torchOn
|
camera!!.parameters = torchOn
|
||||||
Thread.sleep(stroboFrequency.toLong())
|
Thread.sleep(stroboFrequency)
|
||||||
camera!!.parameters = torchOff
|
camera!!.parameters = torchOff
|
||||||
Thread.sleep(stroboFrequency.toLong())
|
Thread.sleep(stroboFrequency)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user