Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#165): fix flashlight status after coming back from camera app #189

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ class MainActivity : SimpleActivity() {
brightness_bar.beVisibleIf(isEnabled)
}
}

override fun onTorchUnavailable() {
mCameraImpl!!.onCameraNotAvailable()
}
})
if (config.turnFlashlightOn) {
mCameraImpl!!.enableFlashlight()
Expand Down Expand Up @@ -300,7 +304,7 @@ class MainActivity : SimpleActivity() {
}

private fun changeIconColor(color: Int, imageView: ImageView?) {
imageView!!.background.mutate().applyColorFilter(color)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to call mutate here as applyColorFilter automatically call mutate() on the same drawable

imageView!!.background.applyColorFilter(color)
}

@SuppressLint("NewApi")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ internal class CameraFlash(
override fun onTorchModeChanged(cameraId: String, enabled: Boolean) {
cameraTorchListener?.onTorchEnabled(enabled)
}

override fun onTorchModeUnavailable(cameraId: String) {
cameraTorchListener?.onTorchUnavailable()
}
}

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ package com.simplemobiletools.flashlight.helpers

interface CameraTorchListener {
fun onTorchEnabled(isEnabled:Boolean)

fun onTorchUnavailable()
}
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,8 @@ class MyCameraImpl private constructor(val context: Context, private var cameraT
fun updateBrightnessLevel(level: Int) {
cameraFlash!!.changeTorchBrightness(level)
}

fun onCameraNotAvailable() {
disableFlashlight()
}
}