Skip to content

Instantly share code, notes, and snippets.

@ktvipin27
Created June 24, 2020 10:49
Show Gist options
  • Save ktvipin27/ae03ce081fefdc2d360f9ea3e5c52ed5 to your computer and use it in GitHub Desktop.
Save ktvipin27/ae03ce081fefdc2d360f9ea3e5c52ed5 to your computer and use it in GitHub Desktop.
Code for toggling the flash mode in cameraX sample application
private fun toggleFlash() {
when (flashMode) {
FlashMode.FLASH_MODE_AUTO -> {
flashMode =
FlashMode.FLASH_MODE_OFF
ivFlash.setImageResource(R.drawable.ic_baseline_flash_off_24)
}
FlashMode.FLASH_MODE_ON -> {
flashMode =
FlashMode.FLASH_MODE_AUTO
ivFlash.setImageResource(R.drawable.ic_baseline_flash_auto_24)
}
FlashMode.FLASH_MODE_OFF -> {
flashMode =
FlashMode.FLASH_MODE_ON
ivFlash.setImageResource(R.drawable.ic_baseline_flash_on_24)
}
}
listener?.toggleFlash(flashMode)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment