File tree Expand file tree Collapse file tree 4 files changed +27
-11
lines changed
app/src/main/kotlin/com/simplemobiletools/flashlight Expand file tree Collapse file tree 4 files changed +27
-11
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ import com.simplemobiletools.commons.models.FAQItem
1919import com.simplemobiletools.flashlight.BuildConfig
2020import com.simplemobiletools.flashlight.R
2121import com.simplemobiletools.flashlight.extensions.config
22- import com.simplemobiletools.flashlight.helpers.DEFAULT_BRIGHTNESS_LEVEL
22+ import com.simplemobiletools.flashlight.helpers.MIN_BRIGHTNESS_LEVEL
2323import com.simplemobiletools.flashlight.helpers.MyCameraImpl
2424import com.simplemobiletools.flashlight.models.Events
2525import kotlinx.android.synthetic.main.activity_main.*
@@ -218,10 +218,10 @@ class MainActivity : SimpleActivity() {
218218 }
219219
220220 private fun setupBrightness () {
221- brightness_bar.max = mCameraImpl?.getMaximumBrightnessLevel() ? : DEFAULT_BRIGHTNESS_LEVEL
222- brightness_bar.progress = config.brightnessLevel
221+ brightness_bar.max = mCameraImpl?.getMaximumBrightnessLevel() ? : MIN_BRIGHTNESS_LEVEL
222+ brightness_bar.progress = mCameraImpl?.getCurrentBrightnessLevel() ? : MIN_BRIGHTNESS_LEVEL
223223 brightness_bar.onSeekBarChangeListener { level ->
224- val newLevel = level.coerceAtLeast(DEFAULT_BRIGHTNESS_LEVEL )
224+ val newLevel = level.coerceAtLeast(MIN_BRIGHTNESS_LEVEL )
225225 mCameraImpl?.updateBrightnessLevel(newLevel)
226226 config.brightnessLevel = newLevel
227227 }
Original file line number Diff line number Diff line change @@ -12,4 +12,5 @@ const val STROBOSCOPE_PROGRESS = "stroboscope_progress"
1212const val FORCE_PORTRAIT_MODE = " force_portrait_mode"
1313const val SOS = " sos"
1414const val BRIGHTNESS_LEVEL = " brightness_level"
15- const val DEFAULT_BRIGHTNESS_LEVEL = 1
15+ const val MIN_BRIGHTNESS_LEVEL = 1
16+ const val DEFAULT_BRIGHTNESS_LEVEL = - 1
Original file line number Diff line number Diff line change @@ -344,8 +344,14 @@ class MyCameraImpl(val context: Context) {
344344
345345 fun getMaximumBrightnessLevel (): Int {
346346 return if (isMarshmallow) {
347- marshmallowCamera?.getMaximumBrightnessLevel() ? : DEFAULT_BRIGHTNESS_LEVEL
348- } else DEFAULT_BRIGHTNESS_LEVEL
347+ marshmallowCamera?.getMaximumBrightnessLevel() ? : MIN_BRIGHTNESS_LEVEL
348+ } else MIN_BRIGHTNESS_LEVEL
349+ }
350+
351+ fun getCurrentBrightnessLevel (): Int {
352+ return if (isMarshmallow) {
353+ marshmallowCamera?.getCurrentBrightnessLevel() ? : MIN_BRIGHTNESS_LEVEL
354+ } else MIN_BRIGHTNESS_LEVEL
349355 }
350356
351357 fun supportsBrightnessControl (): Boolean {
Original file line number Diff line number Diff line change @@ -30,7 +30,8 @@ internal class PostMarshmallowCamera constructor(val context: Context) {
3030 try {
3131 manager.setTorchMode(cameraId!! , enable)
3232 if (enable) {
33- changeTorchBrightness(context.config.brightnessLevel)
33+ val brightnessLevel = getCurrentBrightnessLevel()
34+ changeTorchBrightness(brightnessLevel)
3435 }
3536 } catch (e: Exception ) {
3637 context.showErrorToast(e)
@@ -50,14 +51,22 @@ internal class PostMarshmallowCamera constructor(val context: Context) {
5051 fun getMaximumBrightnessLevel (): Int {
5152 return if (isTiramisuPlus()) {
5253 val characteristics = manager.getCameraCharacteristics(cameraId!! )
53- characteristics.get(CameraCharacteristics .FLASH_INFO_STRENGTH_MAXIMUM_LEVEL ) ? : DEFAULT_BRIGHTNESS_LEVEL
54+ characteristics.get(CameraCharacteristics .FLASH_INFO_STRENGTH_MAXIMUM_LEVEL ) ? : MIN_BRIGHTNESS_LEVEL
5455 } else {
55- DEFAULT_BRIGHTNESS_LEVEL
56+ MIN_BRIGHTNESS_LEVEL
5657 }
5758 }
5859
5960 fun supportsBrightnessControl (): Boolean {
6061 val maxBrightnessLevel = getMaximumBrightnessLevel()
61- return maxBrightnessLevel > DEFAULT_BRIGHTNESS_LEVEL
62+ return maxBrightnessLevel > MIN_BRIGHTNESS_LEVEL
63+ }
64+
65+ fun getCurrentBrightnessLevel (): Int {
66+ var brightnessLevel = context.config.brightnessLevel
67+ if (brightnessLevel == DEFAULT_BRIGHTNESS_LEVEL ) {
68+ brightnessLevel = getMaximumBrightnessLevel()
69+ }
70+ return brightnessLevel
6271 }
6372}
You can’t perform that action at this time.
0 commit comments