Merge pull request #368 from KryptKode/feat/persist-torch-state

persist torch state for video and image capture
This commit is contained in:
Tibor Kaputa 2022-11-09 14:42:15 +01:00 committed by GitHub
commit 25b7521b46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 19 deletions

View File

@ -40,11 +40,11 @@ import com.simplemobiletools.camera.views.FocusCircleView
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.Release
import java.util.concurrent.TimeUnit
import kotlin.math.abs
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.layout_flash.*
import kotlinx.android.synthetic.main.layout_top.*
import java.util.concurrent.TimeUnit
import kotlin.math.abs
class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, CameraXPreviewListener {
private companion object {
@ -345,10 +345,6 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
mTimerHandler = Handler(Looper.getMainLooper())
setupPreviewImage(true)
val initialFlashlightState = if (mIsInPhotoMode && config.flashlightState != FLASH_ALWAYS_ON) config.flashlightState else FLASH_OFF
mPreview!!.setFlashlightState(initialFlashlightState)
updateFlashlightState(initialFlashlightState)
initFlashModeTransitionNames()
}
@ -453,18 +449,6 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
}
}
private fun updateFlashlightState(state: Int) {
config.flashlightState = state
val flashDrawable = when (state) {
FLASH_OFF -> R.drawable.ic_flash_off_vector
FLASH_ON -> R.drawable.ic_flash_on_vector
FLASH_AUTO -> R.drawable.ic_flash_auto_vector
else -> R.drawable.ic_flashlight_vector
}
toggle_flash.setShadowIcon(flashDrawable)
toggle_flash.transitionName = "${getString(R.string.toggle_flash)}$state"
}
private fun shutterPressed() {
if (checkCameraAvailable()) {
handleShutter()
@ -727,7 +711,14 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
}
override fun onChangeFlashMode(flashMode: Int) {
updateFlashlightState(flashMode)
val flashDrawable = when (flashMode) {
FLASH_OFF -> R.drawable.ic_flash_off_vector
FLASH_ON -> R.drawable.ic_flash_on_vector
FLASH_AUTO -> R.drawable.ic_flash_auto_vector
else -> R.drawable.ic_flashlight_vector
}
toggle_flash.setShadowIcon(flashDrawable)
toggle_flash.transitionName = "${getString(R.string.toggle_flash)}$flashMode"
}
override fun onVideoRecordingStarted() {

View File

@ -175,6 +175,7 @@ class CameraXPreview(
previewUseCase.setSurfaceProvider(previewView.surfaceProvider)
preview = previewUseCase
setupZoomAndFocus()
setFlashlightState(config.flashlightState)
}
private fun displaySelectedResolution(resolutionOption: ResolutionOption) {