mirror of
https://github.com/SimpleMobileTools/Simple-Flashlight.git
synced 2025-04-26 07:58:42 +02:00
adding some initial SOS button related code
This commit is contained in:
parent
08156c4cd5
commit
af58c36d67
@ -49,7 +49,13 @@ class MainActivity : SimpleActivity() {
|
|||||||
mCameraImpl!!.toggleFlashlight()
|
mCameraImpl!!.toggleFlashlight()
|
||||||
}
|
}
|
||||||
|
|
||||||
sos_btn.setOnClickListener {}
|
sos_btn.setOnClickListener {
|
||||||
|
toggleStroboscope(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
stroboscope_btn.setOnClickListener {
|
||||||
|
toggleStroboscope(false)
|
||||||
|
}
|
||||||
|
|
||||||
setupStroboscope()
|
setupStroboscope()
|
||||||
checkAppOnSDCard()
|
checkAppOnSDCard()
|
||||||
@ -130,7 +136,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
|
|
||||||
val isStroboscopeOn = savedInstanceState.getBoolean(STROBOSCOPE_STATE, false)
|
val isStroboscopeOn = savedInstanceState.getBoolean(STROBOSCOPE_STATE, false)
|
||||||
if (isStroboscopeOn) {
|
if (isStroboscopeOn) {
|
||||||
toggleStroboscope()
|
toggleStroboscope(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,10 +165,6 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setupStroboscope() {
|
private fun setupStroboscope() {
|
||||||
stroboscope_btn.setOnClickListener {
|
|
||||||
toggleStroboscope()
|
|
||||||
}
|
|
||||||
|
|
||||||
stroboscope_bar.max = (MAX_STROBO_DELAY - MIN_STROBO_DELAY).toInt()
|
stroboscope_bar.max = (MAX_STROBO_DELAY - MIN_STROBO_DELAY).toInt()
|
||||||
stroboscope_bar.progress = config.stroboscopeProgress
|
stroboscope_bar.progress = config.stroboscopeProgress
|
||||||
stroboscope_bar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
stroboscope_bar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
||||||
@ -183,14 +185,14 @@ class MainActivity : SimpleActivity() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleStroboscope() {
|
private fun toggleStroboscope(isSOS: Boolean) {
|
||||||
// use the old Camera API for stroboscope, the new Camera Manager is way too slow
|
// use the old Camera API for stroboscope, the new Camera Manager is way too slow
|
||||||
if (isNougatPlus()) {
|
if (isNougatPlus()) {
|
||||||
cameraPermissionGranted()
|
cameraPermissionGranted(isSOS)
|
||||||
} else {
|
} else {
|
||||||
handlePermission(PERMISSION_CAMERA) {
|
handlePermission(PERMISSION_CAMERA) {
|
||||||
if (it) {
|
if (it) {
|
||||||
cameraPermissionGranted()
|
cameraPermissionGranted(isSOS)
|
||||||
} else {
|
} else {
|
||||||
toast(R.string.camera_permission)
|
toast(R.string.camera_permission)
|
||||||
}
|
}
|
||||||
@ -198,12 +200,15 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun cameraPermissionGranted() {
|
private fun cameraPermissionGranted(isSOS: Boolean) {
|
||||||
|
if (isSOS) {
|
||||||
|
} else {
|
||||||
if (mCameraImpl!!.toggleStroboscope()) {
|
if (mCameraImpl!!.toggleStroboscope()) {
|
||||||
stroboscope_bar.beInvisibleIf(stroboscope_bar.isVisible())
|
stroboscope_bar.beInvisibleIf(stroboscope_bar.isVisible())
|
||||||
changeIconColor(if (stroboscope_bar.isVisible()) getAdjustedPrimaryColor() else config.backgroundColor.getContrastColor(), stroboscope_btn)
|
changeIconColor(if (stroboscope_bar.isVisible()) getAdjustedPrimaryColor() else config.backgroundColor.getContrastColor(), stroboscope_btn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun releaseCamera() {
|
private fun releaseCamera() {
|
||||||
mCameraImpl?.releaseCamera()
|
mCameraImpl?.releaseCamera()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user