@@ -25,9 +25,12 @@ import kotlinx.android.synthetic.main.activity_main.*
2525class MainActivity : SimpleActivity () {
2626 private val MAX_STROBO_DELAY = 2000
2727 private val MIN_STROBO_DELAY = 30
28+ private val FLASHLIGHT_STATE = " flashlight_state"
29+ private val STROBOSCOPE_STATE = " stroboscope_state"
2830
2931 private var mBus: Bus ? = null
3032 private var mCameraImpl: MyCameraImpl ? = null
33+ private var mIsFlashlightOn = false
3134
3235 override fun onCreate (savedInstanceState : Bundle ? ) {
3336 super .onCreate(savedInstanceState)
@@ -41,7 +44,7 @@ class MainActivity : SimpleActivity() {
4144 startActivity(Intent (applicationContext, BrightDisplayActivity ::class .java))
4245 }
4346
44- toggle_btn .setOnClickListener {
47+ flashlight_btn .setOnClickListener {
4548 mCameraImpl!! .toggleFlashlight()
4649 }
4750
@@ -100,6 +103,25 @@ class MainActivity : SimpleActivity() {
100103 return true
101104 }
102105
106+ override fun onSaveInstanceState (outState : Bundle ) {
107+ outState.putBoolean(FLASHLIGHT_STATE , mIsFlashlightOn)
108+ outState.putBoolean(STROBOSCOPE_STATE , stroboscope_bar.isVisible())
109+ super .onSaveInstanceState(outState)
110+ }
111+
112+ override fun onRestoreInstanceState (savedInstanceState : Bundle ) {
113+ super .onRestoreInstanceState(savedInstanceState)
114+ val isFlashlightOn = savedInstanceState.getBoolean(FLASHLIGHT_STATE , false )
115+ if (isFlashlightOn) {
116+ mCameraImpl!! .toggleFlashlight()
117+ }
118+
119+ val isStroboscopeOn = savedInstanceState.getBoolean(STROBOSCOPE_STATE , false )
120+ if (isStroboscopeOn) {
121+ toggleStroboscope()
122+ }
123+ }
124+
103125 private fun launchSettings () {
104126 startActivity(Intent (applicationContext, SettingsActivity ::class .java))
105127 }
@@ -185,16 +207,18 @@ class MainActivity : SimpleActivity() {
185207 }
186208
187209 private fun enableFlashlight () {
188- changeIconColor(getAdjustedPrimaryColor(), toggle_btn )
210+ changeIconColor(getAdjustedPrimaryColor(), flashlight_btn )
189211 window.addFlags(WindowManager .LayoutParams .FLAG_KEEP_SCREEN_ON )
212+ mIsFlashlightOn = true
190213
191214 changeIconColor(config.backgroundColor.getContrastColor(), stroboscope_btn)
192215 stroboscope_bar.beInvisible()
193216 }
194217
195218 private fun disableFlashlight () {
196- changeIconColor(config.backgroundColor.getContrastColor(), toggle_btn )
219+ changeIconColor(config.backgroundColor.getContrastColor(), flashlight_btn )
197220 window.clearFlags(WindowManager .LayoutParams .FLAG_KEEP_SCREEN_ON )
221+ mIsFlashlightOn = false
198222 }
199223
200224 private fun changeIconColor (color : Int , imageView : ImageView ? ) {
0 commit comments