make brightnes change work
This commit is contained in:
parent
cb39937594
commit
1fde8569ce
|
@ -42,7 +42,7 @@ data class VideoPlayerUIState(
|
||||||
val soundVolume: Float,
|
val soundVolume: Float,
|
||||||
|
|
||||||
// when null use system value
|
// when null use system value
|
||||||
val brightnes: Float?
|
val brightness: Float?
|
||||||
) : Parcelable {
|
) : Parcelable {
|
||||||
companion object {
|
companion object {
|
||||||
val DEFAULT = VideoPlayerUIState(
|
val DEFAULT = VideoPlayerUIState(
|
||||||
|
@ -60,7 +60,7 @@ data class VideoPlayerUIState(
|
||||||
playbackPositionInMs = 0,
|
playbackPositionInMs = 0,
|
||||||
fastseekSeconds = 0,
|
fastseekSeconds = 0,
|
||||||
soundVolume = 0f,
|
soundVolume = 0f,
|
||||||
brightnes = null
|
brightness = null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -50,7 +50,7 @@ interface VideoPlayerViewModel {
|
||||||
fun embeddedDraggedDown(offset: Float)
|
fun embeddedDraggedDown(offset: Float)
|
||||||
fun fastSeek(count: Int)
|
fun fastSeek(count: Int)
|
||||||
fun finishFastSeek()
|
fun finishFastSeek()
|
||||||
fun brightnesChange(changeRate: Float, currentValue: Float)
|
fun brightnessChange(changeRate: Float, systemBrightness: Float)
|
||||||
fun volumeChange(changeRate: Float)
|
fun volumeChange(changeRate: Float)
|
||||||
|
|
||||||
interface Listener {
|
interface Listener {
|
||||||
|
|
|
@ -21,13 +21,11 @@
|
||||||
package net.newpipe.newplayer.model
|
package net.newpipe.newplayer.model
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.Context.AUDIO_SERVICE
|
|
||||||
import android.media.AudioManager
|
import android.media.AudioManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import androidx.core.content.ContextCompat.getSystemService
|
import androidx.core.content.ContextCompat.getSystemService
|
||||||
import androidx.lifecycle.AndroidViewModel
|
import androidx.lifecycle.AndroidViewModel
|
||||||
import androidx.lifecycle.SavedStateHandle
|
import androidx.lifecycle.SavedStateHandle
|
||||||
|
@ -44,7 +42,6 @@ import kotlinx.coroutines.launch
|
||||||
import net.newpipe.newplayer.utils.VideoSize
|
import net.newpipe.newplayer.utils.VideoSize
|
||||||
import net.newpipe.newplayer.NewPlayer
|
import net.newpipe.newplayer.NewPlayer
|
||||||
import net.newpipe.newplayer.ui.ContentScale
|
import net.newpipe.newplayer.ui.ContentScale
|
||||||
import kotlin.math.max
|
|
||||||
|
|
||||||
val VIDEOPLAYER_UI_STATE = "video_player_ui_state"
|
val VIDEOPLAYER_UI_STATE = "video_player_ui_state"
|
||||||
|
|
||||||
|
@ -303,8 +300,20 @@ class VideoPlayerViewModelImpl @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun brightnesChange(changeRate: Float, currentValue: Float) {
|
override fun brightnessChange(changeRate: Float, systemBrightness: Float) {
|
||||||
TODO("Not yet implemented")
|
if (mutableUiState.value.fullscreen) {
|
||||||
|
val currentBrightness = mutableUiState.value.brightness
|
||||||
|
?: if (systemBrightness < 0f) 0.5f else systemBrightness
|
||||||
|
Log.d(
|
||||||
|
TAG,
|
||||||
|
"currentBrightnes: $currentBrightness, sytemBrightness: $systemBrightness, changeRate: $changeRate"
|
||||||
|
)
|
||||||
|
|
||||||
|
val newBrightness = (currentBrightness + changeRate).coerceIn(0f, 1f)
|
||||||
|
mutableUiState.update {
|
||||||
|
it.copy(brightness = newBrightness)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun volumeChange(changeRate: Float) {
|
override fun volumeChange(changeRate: Float) {
|
||||||
|
@ -406,7 +415,7 @@ class VideoPlayerViewModelImpl @Inject constructor(
|
||||||
println("dummy impl")
|
println("dummy impl")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun brightnesChange(changeRate: Float, currentValue: Float) {
|
override fun brightnessChange(changeRate: Float, currentValue: Float) {
|
||||||
println("dummy impl")
|
println("dummy impl")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
package net.newpipe.newplayer.ui
|
package net.newpipe.newplayer.ui
|
||||||
|
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
import androidx.activity.compose.BackHandler
|
import androidx.activity.compose.BackHandler
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
|
@ -44,6 +45,7 @@ import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
|
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
|
||||||
|
@ -51,6 +53,7 @@ import net.newpipe.newplayer.ui.videoplayer.BottomUI
|
||||||
import net.newpipe.newplayer.ui.videoplayer.CenterUI
|
import net.newpipe.newplayer.ui.videoplayer.CenterUI
|
||||||
import net.newpipe.newplayer.ui.videoplayer.TopUI
|
import net.newpipe.newplayer.ui.videoplayer.TopUI
|
||||||
import net.newpipe.newplayer.ui.videoplayer.GestureUI
|
import net.newpipe.newplayer.ui.videoplayer.GestureUI
|
||||||
|
import net.newpipe.newplayer.utils.getScreenBrightnes
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun VideoPlayerControllerUI(
|
fun VideoPlayerControllerUI(
|
||||||
|
@ -78,18 +81,21 @@ fun VideoPlayerControllerUI(
|
||||||
embeddedDraggedDownBy: (Float) -> Unit,
|
embeddedDraggedDownBy: (Float) -> Unit,
|
||||||
fastSeek: (Int) -> Unit,
|
fastSeek: (Int) -> Unit,
|
||||||
finishFastSeek: () -> Unit,
|
finishFastSeek: () -> Unit,
|
||||||
brightnesChange: (Float, Float) -> Unit,
|
brightnessChange: (Float, Float) -> Unit,
|
||||||
volumeChange: (Float) -> Unit
|
volumeChange: (Float) -> Unit
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
if (fullscreen) {
|
if (fullscreen) {
|
||||||
BackHandler {
|
BackHandler {
|
||||||
switchToEmbeddedView()
|
switchToEmbeddedView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val internalBrightnesChange = { rateChange: Float ->
|
val internalBrightnessChange = { rateChange: Float ->
|
||||||
|
val systemBrightness = getScreenBrightnes(context as Activity)
|
||||||
|
brightnessChange(rateChange, systemBrightness)
|
||||||
}
|
}
|
||||||
|
|
||||||
val insets =
|
val insets =
|
||||||
|
@ -114,7 +120,7 @@ fun VideoPlayerControllerUI(
|
||||||
embeddedDraggedDownBy = embeddedDraggedDownBy,
|
embeddedDraggedDownBy = embeddedDraggedDownBy,
|
||||||
fastSeek = fastSeek,
|
fastSeek = fastSeek,
|
||||||
fastSeekFinished = finishFastSeek,
|
fastSeekFinished = finishFastSeek,
|
||||||
brightnesChange = internalBrightnesChange,
|
brightnessChange = internalBrightnessChange,
|
||||||
volumeChange = volumeChange
|
volumeChange = volumeChange
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -155,7 +161,7 @@ fun VideoPlayerControllerUI(
|
||||||
fastSeek = fastSeek,
|
fastSeek = fastSeek,
|
||||||
fastSeekFinished = finishFastSeek,
|
fastSeekFinished = finishFastSeek,
|
||||||
volumeChange = volumeChange,
|
volumeChange = volumeChange,
|
||||||
brightnesChange = internalBrightnesChange
|
brightnessChange = internalBrightnessChange
|
||||||
)
|
)
|
||||||
|
|
||||||
Box(modifier = Modifier.fillMaxSize()) {
|
Box(modifier = Modifier.fillMaxSize()) {
|
||||||
|
@ -254,7 +260,7 @@ fun VideoPlayerControllerUIPreviewEmbedded() {
|
||||||
embeddedDraggedDownBy = {},
|
embeddedDraggedDownBy = {},
|
||||||
fastSeek = {},
|
fastSeek = {},
|
||||||
finishFastSeek = {},
|
finishFastSeek = {},
|
||||||
internalBrightnesChange = { a, b ->},
|
brightnessChange = { a, b ->},
|
||||||
volumeChange = {})
|
volumeChange = {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -289,7 +295,7 @@ fun VideoPlayerControllerUIPreviewLandscape() {
|
||||||
embeddedDraggedDownBy = {},
|
embeddedDraggedDownBy = {},
|
||||||
fastSeek = {},
|
fastSeek = {},
|
||||||
finishFastSeek = {},
|
finishFastSeek = {},
|
||||||
internalBrightnesChange = { a, b -> },
|
brightnessChange = { a, b -> },
|
||||||
volumeChange = {})
|
volumeChange = {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -325,7 +331,7 @@ fun VideoPlayerControllerUIPreviewPortrait() {
|
||||||
embeddedDraggedDownBy = {},
|
embeddedDraggedDownBy = {},
|
||||||
fastSeek = {},
|
fastSeek = {},
|
||||||
finishFastSeek = {},
|
finishFastSeek = {},
|
||||||
internalBrightnesChange = { a, b -> },
|
brightnessChange = { a, b -> },
|
||||||
volumeChange = {})
|
volumeChange = {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ package net.newpipe.newplayer.ui
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.pm.ActivityInfo
|
import android.content.pm.ActivityInfo
|
||||||
|
import android.util.Log
|
||||||
import android.view.SurfaceView
|
import android.view.SurfaceView
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.aspectRatio
|
import androidx.compose.foundation.layout.aspectRatio
|
||||||
|
@ -55,6 +56,10 @@ import net.newpipe.newplayer.model.VideoPlayerViewModel
|
||||||
import net.newpipe.newplayer.model.VideoPlayerViewModelImpl
|
import net.newpipe.newplayer.model.VideoPlayerViewModelImpl
|
||||||
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
|
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
|
||||||
import net.newpipe.newplayer.utils.LockScreenOrientation
|
import net.newpipe.newplayer.utils.LockScreenOrientation
|
||||||
|
import net.newpipe.newplayer.utils.getScreenBrightnes
|
||||||
|
import net.newpipe.newplayer.utils.setScreenBrightnes
|
||||||
|
|
||||||
|
private const val TAG = "VideoPlayerUI"
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun VideoPlayerUI(
|
fun VideoPlayerUI(
|
||||||
|
@ -90,7 +95,7 @@ fun VideoPlayerUI(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup immersive mode
|
// Setup immersive mode
|
||||||
if (uiState.fullscreen && ! uiState.uiVissible) {
|
if (uiState.fullscreen && !uiState.uiVissible) {
|
||||||
LaunchedEffect(key1 = true) {
|
LaunchedEffect(key1 = true) {
|
||||||
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
|
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
|
||||||
}
|
}
|
||||||
|
@ -125,6 +130,16 @@ fun VideoPlayerUI(
|
||||||
val screenRatio =
|
val screenRatio =
|
||||||
displayMetrics.widthPixels.toFloat() / displayMetrics.heightPixels.toFloat()
|
displayMetrics.widthPixels.toFloat() / displayMetrics.heightPixels.toFloat()
|
||||||
|
|
||||||
|
val systemScreenBrightnes = getScreenBrightnes(activity)
|
||||||
|
|
||||||
|
LaunchedEffect(key1 = uiState.brightness) {
|
||||||
|
Log.d(TAG, "New Brightnes: ${uiState.brightness}")
|
||||||
|
setScreenBrightnes(
|
||||||
|
uiState.brightness
|
||||||
|
?: if (systemScreenBrightnes < 0f) 0.5f else systemScreenBrightnes, activity
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// Set UI
|
// Set UI
|
||||||
Surface(
|
Surface(
|
||||||
modifier = Modifier.then(
|
modifier = Modifier.then(
|
||||||
|
@ -143,6 +158,7 @@ fun VideoPlayerUI(
|
||||||
contentRatio = uiState.contentRatio
|
contentRatio = uiState.contentRatio
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
VideoPlayerControllerUI(
|
VideoPlayerControllerUI(
|
||||||
isPlaying = uiState.playing,
|
isPlaying = uiState.playing,
|
||||||
fullscreen = uiState.fullscreen,
|
fullscreen = uiState.fullscreen,
|
||||||
|
@ -153,7 +169,8 @@ fun VideoPlayerUI(
|
||||||
playbackPositionInMs = uiState.playbackPositionInMs,
|
playbackPositionInMs = uiState.playbackPositionInMs,
|
||||||
bufferedPercentage = uiState.bufferedPercentage,
|
bufferedPercentage = uiState.bufferedPercentage,
|
||||||
fastSeekSeconds = uiState.fastseekSeconds,
|
fastSeekSeconds = uiState.fastseekSeconds,
|
||||||
brightnes = uiState.brightnes,
|
brightnes = uiState.brightness
|
||||||
|
?: if (systemScreenBrightnes < 0f) 0.5f else systemScreenBrightnes,
|
||||||
soundVolume = uiState.soundVolume,
|
soundVolume = uiState.soundVolume,
|
||||||
play = viewModel::play,
|
play = viewModel::play,
|
||||||
pause = viewModel::pause,
|
pause = viewModel::pause,
|
||||||
|
@ -169,7 +186,7 @@ fun VideoPlayerUI(
|
||||||
fastSeek = viewModel::fastSeek,
|
fastSeek = viewModel::fastSeek,
|
||||||
finishFastSeek = viewModel::finishFastSeek,
|
finishFastSeek = viewModel::finishFastSeek,
|
||||||
volumeChange = viewModel::volumeChange,
|
volumeChange = viewModel::volumeChange,
|
||||||
internalBrightnesChange = viewModel::brightnesChange
|
brightnessChange = viewModel::brightnessChange
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ fun VideoPlayerControllerUIPreviewEmbeddedColorPreview() {
|
||||||
embeddedDraggedDownBy = {},
|
embeddedDraggedDownBy = {},
|
||||||
fastSeek = {},
|
fastSeek = {},
|
||||||
finishFastSeek = {},
|
finishFastSeek = {},
|
||||||
internalBrightnesChange = {},
|
brightnessChange = {a, b ->},
|
||||||
volumeChange = {})
|
volumeChange = {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,32 +20,10 @@
|
||||||
|
|
||||||
package net.newpipe.newplayer.ui.videoplayer
|
package net.newpipe.newplayer.ui.videoplayer
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
|
||||||
import androidx.compose.animation.core.tween
|
|
||||||
import androidx.compose.animation.fadeIn
|
|
||||||
import androidx.compose.animation.fadeOut
|
|
||||||
import androidx.compose.foundation.layout.Box
|
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
|
||||||
import androidx.compose.foundation.layout.wrapContentSize
|
|
||||||
import androidx.compose.material3.Surface
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.runtime.setValue
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
|
||||||
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
|
|
||||||
import net.newpipe.newplayer.ui.videoplayer.gesture_ui.EmbeddedGestureUI
|
import net.newpipe.newplayer.ui.videoplayer.gesture_ui.EmbeddedGestureUI
|
||||||
import net.newpipe.newplayer.ui.videoplayer.gesture_ui.FastSeekVisualFeedback
|
|
||||||
import net.newpipe.newplayer.ui.videoplayer.gesture_ui.FullscreenGestureUI
|
import net.newpipe.newplayer.ui.videoplayer.gesture_ui.FullscreenGestureUI
|
||||||
import net.newpipe.newplayer.ui.videoplayer.gesture_ui.FullscreenGestureUIPreview
|
|
||||||
import net.newpipe.newplayer.ui.videoplayer.gesture_ui.TouchSurface
|
|
||||||
import net.newpipe.newplayer.ui.videoplayer.gesture_ui.TouchedPosition
|
|
||||||
|
|
||||||
private const val TAG = "TouchUi"
|
private const val TAG = "TouchUi"
|
||||||
|
|
||||||
|
@ -72,7 +50,7 @@ fun GestureUI(
|
||||||
fastSeek: (Int) -> Unit,
|
fastSeek: (Int) -> Unit,
|
||||||
fastSeekFinished: () -> Unit,
|
fastSeekFinished: () -> Unit,
|
||||||
volumeChange: (Float) -> Unit,
|
volumeChange: (Float) -> Unit,
|
||||||
brightnesChange: (Float) -> Unit,
|
brightnessChange: (Float) -> Unit,
|
||||||
) {
|
) {
|
||||||
val defaultOnRegularTap = {
|
val defaultOnRegularTap = {
|
||||||
if (uiVissible) {
|
if (uiVissible) {
|
||||||
|
@ -94,7 +72,7 @@ fun GestureUI(
|
||||||
switchToEmbeddedView = switchToEmbeddedView,
|
switchToEmbeddedView = switchToEmbeddedView,
|
||||||
fastSeekFinished = fastSeekFinished,
|
fastSeekFinished = fastSeekFinished,
|
||||||
volumeChange = volumeChange,
|
volumeChange = volumeChange,
|
||||||
brightnesChange = brightnesChange)
|
brightnesChange = brightnessChange)
|
||||||
} else {
|
} else {
|
||||||
EmbeddedGestureUI(
|
EmbeddedGestureUI(
|
||||||
fastSeekSeconds = fastSeekSeconds,
|
fastSeekSeconds = fastSeekSeconds,
|
||||||
|
|
|
@ -23,8 +23,6 @@ package net.newpipe.newplayer.ui.videoplayer.gesture_ui
|
||||||
|
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
import androidx.compose.animation.core.tween
|
import androidx.compose.animation.core.tween
|
||||||
import androidx.compose.animation.fadeIn
|
|
||||||
import androidx.compose.animation.fadeOut
|
|
||||||
import androidx.compose.animation.scaleIn
|
import androidx.compose.animation.scaleIn
|
||||||
import androidx.compose.animation.scaleOut
|
import androidx.compose.animation.scaleOut
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
|
@ -170,7 +168,7 @@ fun FullscreenGestureUI(
|
||||||
VolumeCircle(
|
VolumeCircle(
|
||||||
volumeFraction = brightnes,
|
volumeFraction = brightnes,
|
||||||
modifier = Modifier.align(Alignment.Center),
|
modifier = Modifier.align(Alignment.Center),
|
||||||
isBrightnes = true
|
isBrightness = true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,7 @@ package net.newpipe.newplayer.ui.videoplayer.gesture_ui
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.compose.foundation.Canvas
|
import androidx.compose.foundation.Canvas
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.automirrored.filled.VolumeDown
|
import androidx.compose.material.icons.automirrored.filled.VolumeDown
|
||||||
import androidx.compose.material.icons.automirrored.filled.VolumeMute
|
import androidx.compose.material.icons.automirrored.filled.VolumeMute
|
||||||
|
@ -40,7 +38,6 @@ import androidx.compose.ui.graphics.drawscope.Stroke
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.shadow
|
|
||||||
import androidx.compose.ui.geometry.Offset
|
import androidx.compose.ui.geometry.Offset
|
||||||
import androidx.compose.ui.geometry.Size
|
import androidx.compose.ui.geometry.Size
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
@ -60,7 +57,7 @@ private const val CIRCLE_SIZE = 100
|
||||||
fun VolumeCircle(
|
fun VolumeCircle(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
volumeFraction: Float,
|
volumeFraction: Float,
|
||||||
isBrightnes: Boolean = false
|
isBrightness: Boolean = false
|
||||||
) {
|
) {
|
||||||
assert(0f <= volumeFraction && volumeFraction <= 1f) {
|
assert(0f <= volumeFraction && volumeFraction <= 1f) {
|
||||||
Log.e(TAG, "Volume fraction must be in ragne [0;1]. It was $volumeFraction")
|
Log.e(TAG, "Volume fraction must be in ragne [0;1]. It was $volumeFraction")
|
||||||
|
@ -87,10 +84,10 @@ fun VolumeCircle(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.align(Alignment.Center)
|
.align(Alignment.Center)
|
||||||
.size(60.dp),
|
.size(60.dp),
|
||||||
imageVector = (if (isBrightnes) getBrightnesIcon(volumeFraction = volumeFraction)
|
imageVector = (if (isBrightness) getBrightnesIcon(volumeFraction = volumeFraction)
|
||||||
else getVolumeIcon(volumeFraction = volumeFraction)),
|
else getVolumeIcon(volumeFraction = volumeFraction)),
|
||||||
contentDescription = stringResource(
|
contentDescription = stringResource(
|
||||||
id = if (isBrightnes) R.string.brightness_indicator
|
id = if (isBrightness) R.string.brightness_indicator
|
||||||
else R.string.volume_indicator
|
else R.string.volume_indicator
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -115,7 +112,7 @@ private fun getBrightnesIcon(volumeFraction: Float) =
|
||||||
fun VolumeCirclePreview() {
|
fun VolumeCirclePreview() {
|
||||||
VideoPlayerTheme {
|
VideoPlayerTheme {
|
||||||
Surface(color = Color.White) {
|
Surface(color = Color.White) {
|
||||||
VolumeCircle(volumeFraction = 0.3f, isBrightnes = false)
|
VolumeCircle(volumeFraction = 0.3f, isBrightness = false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -24,6 +24,7 @@ import android.annotation.SuppressLint
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.ContextWrapper
|
import android.content.ContextWrapper
|
||||||
|
import android.view.Window
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.DisposableEffect
|
import androidx.compose.runtime.DisposableEffect
|
||||||
|
@ -44,18 +45,14 @@ fun LockScreenOrientation(orientation: Int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
@Composable
|
fun getScreenBrightnes(activity: Activity) : Float {
|
||||||
fun getScreenBrightnes() : Float {
|
|
||||||
val activity = LocalContext.current.findActivity()!!
|
|
||||||
val window = activity.window
|
val window = activity.window
|
||||||
val layout = window.attributes as WindowManager.LayoutParams
|
val layout = window.attributes as WindowManager.LayoutParams
|
||||||
return layout.screenBrightness
|
return layout.screenBrightness
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
@Composable
|
fun setScreenBrightnes(value:Float, activity: Activity) {
|
||||||
fun SetScreenBrightnes(value:Float) {
|
|
||||||
val activity = LocalContext.current.findActivity()!!
|
|
||||||
val window = activity.window
|
val window = activity.window
|
||||||
val layout = window.attributes as WindowManager.LayoutParams
|
val layout = window.attributes as WindowManager.LayoutParams
|
||||||
layout.screenBrightness = value
|
layout.screenBrightness = value
|
||||||
|
|
Loading…
Reference in New Issue