Skip to content

feat: Add light level percentage #193

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

Closed
wants to merge 7 commits into from
Closed
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 @@ -88,6 +88,10 @@ class MainActivity : SimpleActivity() {
sos_btn.setTextColor(contrastColor)
}

if (brightness_value.currentTextColor != getProperPrimaryColor()) {
brightness_value.setTextColor(contrastColor)
}

stroboscope_btn.beVisibleIf(config.stroboscope)

if (!config.stroboscope) {
Expand Down Expand Up @@ -196,6 +200,9 @@ class MainActivity : SimpleActivity() {
override fun onTorchEnabled(isEnabled: Boolean) {
if (mCameraImpl!!.supportsBrightnessControl()) {
brightness_bar.beVisibleIf(isEnabled)

brightness_value.beVisibleIf(isEnabled)
brightness_value.text = "${mCameraImpl?.getPercentageBrightnessLevel()}%"
}
}

Expand Down Expand Up @@ -242,6 +249,7 @@ class MainActivity : SimpleActivity() {
val newLevel = level.coerceAtLeast(MIN_BRIGHTNESS_LEVEL)
mCameraImpl?.updateBrightnessLevel(newLevel)
config.brightnessLevel = newLevel
brightness_value.text = "${mCameraImpl?.getPercentageBrightnessLevel()}%"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ class MyCameraImpl private constructor(val context: Context, private var cameraT
cameraFlash!!.changeTorchBrightness(level)
}

fun getPercentageBrightnessLevel(): Int {
return (getCurrentBrightnessLevel() * 100) / getMaximumBrightnessLevel()
}

fun onCameraNotAvailable() {
disableFlashlight()
}
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/stroboscope_btn" />

<TextView
android:id="@+id/brightness_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-1%"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@+id/brightness_bar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>