Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Brighten camera screen if under 66%.
- Loading branch information
1 parent
3a060c7
commit 74b7057
Showing
3 changed files
with
64 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
app/src/main/java/org/thoughtcrime/securesms/mediasend/CameraScreenBrightnessController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.thoughtcrime.securesms.mediasend | ||
|
||
import android.view.Window | ||
import androidx.lifecycle.DefaultLifecycleObserver | ||
import androidx.lifecycle.LifecycleOwner | ||
|
||
/** | ||
* Modifies screen brightness to increase to a max of 66% if lower than that for optimal picture | ||
* taking conditions. | ||
*/ | ||
class CameraScreenBrightnessController(private val window: Window) : DefaultLifecycleObserver { | ||
|
||
companion object { | ||
private const val MIN_CAMERA_BRIGHTNESS = 0.66f | ||
} | ||
|
||
private var originalBrightness: Float = 0f | ||
|
||
override fun onResume(owner: LifecycleOwner) { | ||
val originalBrightness = window.attributes.screenBrightness | ||
if (originalBrightness < MIN_CAMERA_BRIGHTNESS) { | ||
window.attributes = window.attributes.apply { | ||
screenBrightness = MIN_CAMERA_BRIGHTNESS | ||
} | ||
} | ||
} | ||
|
||
override fun onPause(owner: LifecycleOwner) { | ||
if (originalBrightness > 0f && window.attributes.screenBrightness == MIN_CAMERA_BRIGHTNESS) { | ||
window.attributes = window.attributes.apply { | ||
screenBrightness = originalBrightness | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters