-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(player): add brightness manager
An attempt to resolve issue #94
- Loading branch information
Showing
8 changed files
with
70 additions
and
121 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
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
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
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
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
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
28 changes: 28 additions & 0 deletions
28
...bile/player/src/main/java/com/flixclusive/feature/mobile/player/util/BrightnessManager.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,28 @@ | ||
package com.flixclusive.feature.mobile.player.util | ||
|
||
import android.app.Activity | ||
import android.view.WindowManager | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.compositionLocalOf | ||
import androidx.compose.runtime.rememberUpdatedState | ||
|
||
|
||
internal val LocalBrightnessManager = compositionLocalOf<BrightnessManager> { | ||
error("BrightnessManager not provided") | ||
} | ||
|
||
@Composable | ||
internal fun rememberBrightnessManager() | ||
= rememberUpdatedState(LocalBrightnessManager.current).value | ||
|
||
internal class BrightnessManager(private val activity: Activity) { | ||
var currentBrightness = activity.currentBrightness | ||
val maxBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_FULL | ||
|
||
fun setBrightness(brightness: Float) { | ||
currentBrightness = brightness.coerceIn(0F, maxBrightness) | ||
val layoutParams = activity.window.attributes | ||
layoutParams.screenBrightness = currentBrightness | ||
activity.window.attributes = layoutParams | ||
} | ||
} |
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