set brightness level to maximum by default

This commit is contained in:
darthpaul 2022-10-26 14:16:27 +01:00
parent cea57e9db0
commit 75eca9e3f0
4 changed files with 27 additions and 11 deletions

View File

@ -19,7 +19,7 @@ import com.simplemobiletools.commons.models.FAQItem
import com.simplemobiletools.flashlight.BuildConfig
import com.simplemobiletools.flashlight.R
import com.simplemobiletools.flashlight.extensions.config
import com.simplemobiletools.flashlight.helpers.DEFAULT_BRIGHTNESS_LEVEL
import com.simplemobiletools.flashlight.helpers.MIN_BRIGHTNESS_LEVEL
import com.simplemobiletools.flashlight.helpers.MyCameraImpl
import com.simplemobiletools.flashlight.models.Events
import kotlinx.android.synthetic.main.activity_main.*
@ -218,10 +218,10 @@ class MainActivity : SimpleActivity() {
}
private fun setupBrightness() {
brightness_bar.max = mCameraImpl?.getMaximumBrightnessLevel() ?: DEFAULT_BRIGHTNESS_LEVEL
brightness_bar.progress = config.brightnessLevel
brightness_bar.max = mCameraImpl?.getMaximumBrightnessLevel() ?: MIN_BRIGHTNESS_LEVEL
brightness_bar.progress = mCameraImpl?.getCurrentBrightnessLevel() ?: MIN_BRIGHTNESS_LEVEL
brightness_bar.onSeekBarChangeListener { level ->
val newLevel = level.coerceAtLeast(DEFAULT_BRIGHTNESS_LEVEL)
val newLevel = level.coerceAtLeast(MIN_BRIGHTNESS_LEVEL)
mCameraImpl?.updateBrightnessLevel(newLevel)
config.brightnessLevel = newLevel
}

View File

@ -12,4 +12,5 @@ const val STROBOSCOPE_PROGRESS = "stroboscope_progress"
const val FORCE_PORTRAIT_MODE = "force_portrait_mode"
const val SOS = "sos"
const val BRIGHTNESS_LEVEL = "brightness_level"
const val DEFAULT_BRIGHTNESS_LEVEL = 1
const val MIN_BRIGHTNESS_LEVEL = 1
const val DEFAULT_BRIGHTNESS_LEVEL = -1

View File

@ -344,8 +344,14 @@ class MyCameraImpl(val context: Context) {
fun getMaximumBrightnessLevel(): Int {
return if (isMarshmallow) {
marshmallowCamera?.getMaximumBrightnessLevel() ?: DEFAULT_BRIGHTNESS_LEVEL
} else DEFAULT_BRIGHTNESS_LEVEL
marshmallowCamera?.getMaximumBrightnessLevel() ?: MIN_BRIGHTNESS_LEVEL
} else MIN_BRIGHTNESS_LEVEL
}
fun getCurrentBrightnessLevel(): Int {
return if (isMarshmallow) {
marshmallowCamera?.getCurrentBrightnessLevel() ?: MIN_BRIGHTNESS_LEVEL
} else MIN_BRIGHTNESS_LEVEL
}
fun supportsBrightnessControl(): Boolean {

View File

@ -30,7 +30,8 @@ internal class PostMarshmallowCamera constructor(val context: Context) {
try {
manager.setTorchMode(cameraId!!, enable)
if (enable) {
changeTorchBrightness(context.config.brightnessLevel)
val brightnessLevel = getCurrentBrightnessLevel()
changeTorchBrightness(brightnessLevel)
}
} catch (e: Exception) {
context.showErrorToast(e)
@ -50,14 +51,22 @@ internal class PostMarshmallowCamera constructor(val context: Context) {
fun getMaximumBrightnessLevel(): Int {
return if (isTiramisuPlus()) {
val characteristics = manager.getCameraCharacteristics(cameraId!!)
characteristics.get(CameraCharacteristics.FLASH_INFO_STRENGTH_MAXIMUM_LEVEL) ?: DEFAULT_BRIGHTNESS_LEVEL
characteristics.get(CameraCharacteristics.FLASH_INFO_STRENGTH_MAXIMUM_LEVEL) ?: MIN_BRIGHTNESS_LEVEL
} else {
DEFAULT_BRIGHTNESS_LEVEL
MIN_BRIGHTNESS_LEVEL
}
}
fun supportsBrightnessControl(): Boolean {
val maxBrightnessLevel = getMaximumBrightnessLevel()
return maxBrightnessLevel > DEFAULT_BRIGHTNESS_LEVEL
return maxBrightnessLevel > MIN_BRIGHTNESS_LEVEL
}
fun getCurrentBrightnessLevel(): Int {
var brightnessLevel = context.config.brightnessLevel
if (brightnessLevel == DEFAULT_BRIGHTNESS_LEVEL) {
brightnessLevel = getMaximumBrightnessLevel()
}
return brightnessLevel
}
}