Skip to content

Commit 00198b3

Browse files
committed
Add code for persistent exposure functionality
1 parent 3df2bbf commit 00198b3

2 files changed

Lines changed: 69 additions & 10 deletions

File tree

app/src/main/java/app/grapheneos/camera/CamConfig.kt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ class CamConfig(private val mActivity: MainActivity) {
105105

106106
const val REMOVE_EXIF_AFTER_CAPTURE = "remove_exif_after_capture"
107107

108+
const val PERSIST_EXPOSURE_LEVEL = "persist_exposure_level"
109+
110+
const val EXPOSURE_LEVEL = "exposure_level"
111+
108112
const val GYROSCOPE_SUGGESTIONS = "gyroscope_suggestions"
109113

110114
const val CAMERA_SOUNDS = "camera_sounds"
@@ -150,6 +154,10 @@ class CamConfig(private val mActivity: MainActivity) {
150154

151155
const val REMOVE_EXIF_AFTER_CAPTURE = true
152156

157+
const val PERSIST_EXPOSURE_LEVEL = false
158+
159+
const val EXPOSURE_LEVEL = 0
160+
153161
const val GYROSCOPE_SUGGESTIONS = false
154162

155163
const val CAMERA_SOUNDS = true
@@ -539,6 +547,50 @@ class CamConfig(private val mActivity: MainActivity) {
539547
editor.apply()
540548
}
541549

550+
var persistExposureLevel: Boolean
551+
get() {
552+
return commonPref.getBoolean(
553+
SettingValues.Key.PERSIST_EXPOSURE_LEVEL,
554+
SettingValues.Default.PERSIST_EXPOSURE_LEVEL
555+
)
556+
}
557+
set(value) {
558+
val editor = commonPref.edit()
559+
editor.putBoolean(
560+
SettingValues.Key.PERSIST_EXPOSURE_LEVEL,
561+
value
562+
)
563+
editor.apply()
564+
}
565+
566+
private val exposureLevelKey: String
567+
get() {
568+
569+
val pf = if (lensFacing == CameraSelector.LENS_FACING_FRONT) {
570+
"FRONT"
571+
} else {
572+
"BACK"
573+
}
574+
575+
return "${SettingValues.Key.EXPOSURE_LEVEL}_$pf"
576+
}
577+
578+
var exposureLevel: Int
579+
get() {
580+
return modePref.getInt(
581+
exposureLevelKey,
582+
SettingValues.Default.EXPOSURE_LEVEL,
583+
)
584+
}
585+
set(value) {
586+
val editor = modePref.edit()
587+
editor.putInt(
588+
exposureLevelKey,
589+
value
590+
)
591+
editor.apply()
592+
}
593+
542594
var gSuggestions: Boolean
543595
get() {
544596
return commonPref.getBoolean(
@@ -1262,6 +1314,10 @@ class CamConfig(private val mActivity: MainActivity) {
12621314

12631315
mActivity.zoomBar.updateThumb(false)
12641316

1317+
if (persistExposureLevel) {
1318+
camera?.cameraControl?.setExposureCompensationIndex(exposureLevel)
1319+
}
1320+
12651321
camera?.cameraInfo?.exposureState?.let { mActivity.exposureBar.setExposureConfig(it) }
12661322

12671323
mActivity.settingsDialog.torchToggle.isChecked = false

app/src/main/java/app/grapheneos/camera/ui/seekbar/ExposureBar.kt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,7 @@ class ExposureBar : AppCompatSeekBar {
4646
max = exposureState.exposureCompensationRange.upper
4747
min = exposureState.exposureCompensationRange.lower
4848

49-
incrementProgressBy(exposureState.exposureCompensationIndex)
50-
51-
Log.i("TAG", "Setting progress from setExposureConfig")
52-
progress = (exposureState.exposureCompensationStep.numerator
53-
/ exposureState.exposureCompensationStep.denominator) *
54-
exposureState.exposureCompensationIndex
49+
progress = exposureState.exposureCompensationIndex
5550

5651
onSizeChanged(width, height, 0, 0)
5752
}
@@ -109,11 +104,10 @@ class ExposureBar : AppCompatSeekBar {
109104
MotionEvent.ACTION_DOWN, MotionEvent.ACTION_MOVE, MotionEvent.ACTION_UP -> {
110105
progress = max - (max * event.y / (height / 2)).toInt()
111106

112-
Log.i("progress", progress.toString())
113-
Log.i("max", max.toString())
107+
Log.d("progress", progress.toString())
108+
Log.d("max", max.toString())
114109

115-
mainActivity.camConfig.camera?.cameraControl
116-
?.setExposureCompensationIndex(progress)
110+
updateExposureCompensationIndex(progress)
117111

118112
showPanel()
119113

@@ -124,4 +118,13 @@ class ExposureBar : AppCompatSeekBar {
124118
}
125119
return true
126120
}
121+
122+
private fun updateExposureCompensationIndex(exposureCompensationIndex: Int) {
123+
mainActivity.camConfig.camera?.cameraControl
124+
?.setExposureCompensationIndex(progress)
125+
126+
if (mainActivity.camConfig.persistExposureLevel) {
127+
mainActivity.camConfig.exposureLevel = exposureCompensationIndex
128+
}
129+
}
127130
}

0 commit comments

Comments
 (0)