Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3241dea0 authored by Fabián Kozynski's avatar Fabián Kozynski
Browse files

Change color of border around BrightnessSlider

Allow providing a color for idle and another for mirroring and animate
between the two.

Also, force the slider in QSFragmentCompose to always be in dark mode.

Test: manual, in fragment and dual shade
Fixes: 394923812
Flag: com.android.systemui.qs_ui_refactor_compose_fragment
Flag: com.android.systemui.scene_container

Change-Id: I24c29d20244cffb4b2f785599fab3c9cc4ab65f0
parent 30e652fb
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import com.android.compose.animation.scene.UserActionResult
import com.android.compose.animation.scene.content.state.TransitionState
import com.android.compose.modifiers.thenIf
import com.android.systemui.brightness.ui.compose.BrightnessSliderContainer
import com.android.systemui.brightness.ui.compose.ContainerColors
import com.android.systemui.compose.modifiers.sysuiResTag
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.lifecycle.rememberViewModel
@@ -259,7 +260,7 @@ fun ContentScope.QuickSettingsLayout(

            BrightnessSliderContainer(
                viewModel = viewModel.brightnessSliderViewModel,
                containerColor = OverlayShade.Colors.PanelBackground,
                containerColors = ContainerColors.singleColor(OverlayShade.Colors.PanelBackground),
                modifier =
                    Modifier.systemGestureExclusionInShade(
                            enabled = { layoutState.transitionState is TransitionState.Idle }
+24 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.brightness.ui.compose
import android.content.Context
import android.view.MotionEvent
import androidx.annotation.VisibleForTesting
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.AnimationVector1D
import androidx.compose.animation.core.VectorConverter
@@ -40,6 +41,7 @@ import androidx.compose.material3.SliderDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
@@ -323,7 +325,7 @@ private fun Modifier.sliderBackground(color: Color) = drawWithCache {
fun BrightnessSliderContainer(
    viewModel: BrightnessSliderViewModel,
    modifier: Modifier = Modifier,
    containerColor: Color = colorResource(R.color.shade_scrim_background_dark),
    containerColors: ContainerColors,
) {
    val gamma = viewModel.currentBrightness.value
    if (gamma == BrightnessSliderViewModel.initialValue.value) { // Ignore initial negative value.
@@ -344,6 +346,16 @@ fun BrightnessSliderContainer(

    DisposableEffect(Unit) { onDispose { viewModel.setIsDragging(false) } }

    var dragging by remember { mutableStateOf(false) }

    // Use dragging instead of viewModel.showMirror so the color starts changing as soon as the
    // dragging state changes. If not, we may be waiting for the background to finish fading in
    // when stopping dragging
    val containerColor by
        animateColorAsState(
            if (dragging) containerColors.mirrorColor else containerColors.idleColor
        )

    Box(
        modifier =
            modifier
@@ -360,10 +372,12 @@ fun BrightnessSliderContainer(
            onRestrictedClick = viewModel::showPolicyRestrictionDialog,
            onDrag = {
                viewModel.setIsDragging(true)
                dragging = true
                coroutineScope.launch { viewModel.onDrag(Drag.Dragging(GammaBrightness(it))) }
            },
            onStop = {
                viewModel.setIsDragging(false)
                dragging = false
                coroutineScope.launch { viewModel.onDrag(Drag.Stopped(GammaBrightness(it))) }
            },
            modifier =
@@ -392,6 +406,15 @@ fun BrightnessSliderContainer(
    }
}

data class ContainerColors(val idleColor: Color, val mirrorColor: Color) {
    companion object {
        fun singleColor(color: Color) = ContainerColors(color, color)

        val defaultContainerColor: Color
            @Composable @ReadOnlyComposable get() = colorResource(R.color.shade_panel_fallback)
    }
}

private object Dimensions {
    val SliderBackgroundFrameSize = DpSize(10.dp, 6.dp)
    val SliderBackgroundRoundedCorner = 24.dp
+50 −12
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.qs.composefragment

import android.annotation.SuppressLint
import android.content.Context
import android.content.res.Configuration
import android.graphics.PointF
import android.graphics.Rect
import android.os.Bundle
@@ -48,6 +49,7 @@ import androidx.compose.foundation.layout.requiredHeightIn
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
@@ -58,6 +60,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.pointer.PointerEventPass
import androidx.compose.ui.input.pointer.PointerInputChange
@@ -69,6 +72,8 @@ import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.layout.positionInRoot
import androidx.compose.ui.layout.positionOnScreen
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.CustomAccessibilityAction
@@ -102,6 +107,7 @@ import com.android.mechanics.GestureContext
import com.android.systemui.Dumpable
import com.android.systemui.Flags
import com.android.systemui.brightness.ui.compose.BrightnessSliderContainer
import com.android.systemui.brightness.ui.compose.ContainerColors
import com.android.systemui.compose.modifiers.sysuiResTag
import com.android.systemui.dump.DumpManager
import com.android.systemui.keyboard.shortcut.ui.composable.InteractionsConfig
@@ -249,7 +255,7 @@ constructor(

    @Composable
    private fun Content() {
        PlatformTheme(isDarkTheme = true) {
        PlatformTheme(isDarkTheme = true /* Delete AlwaysDarkMode when removing this */) {
            ProvideShortcutHelperIndication(interactionsConfig = interactionsConfig()) {
                // TODO(b/389985793): Make sure that there is no coroutine work or recompositions
                // happening when alwaysCompose is true but isQsVisibleAndAnyShadeExpanded is false.
@@ -740,8 +746,14 @@ constructor(
                        )
                        val BrightnessSlider =
                            @Composable {
                                AlwaysDarkMode {
                                    BrightnessSliderContainer(
                                        viewModel = containerViewModel.brightnessSliderViewModel,
                                        containerColors =
                                            ContainerColors(
                                                Color.Transparent,
                                                ContainerColors.defaultContainerColor,
                                            ),
                                        modifier =
                                            Modifier.systemGestureExclusionInShade(
                                                    enabled = {
@@ -752,6 +764,7 @@ constructor(
                                                .fillMaxWidth(),
                                    )
                                }
                            }
                        val TileGrid =
                            @Composable {
                                Box {
@@ -1226,3 +1239,28 @@ private fun interactionsConfig() =

private inline val alwaysCompose
    get() = Flags.alwaysComposeQsUiFragment()

/**
 * Forces the configuration and themes to be dark theme. This is needed in order to have
 * [colorResource] retrieve the dark mode colors.
 *
 * This should be removed when we remove the force dark mode in [PlatformTheme] at the root of the
 * compose hierarchy.
 */
@Composable
private fun AlwaysDarkMode(content: @Composable () -> Unit) {
    val currentConfig = LocalConfiguration.current
    val darkConfig =
        Configuration(currentConfig).apply {
            uiMode =
                (uiMode and (Configuration.UI_MODE_NIGHT_MASK.inv())) or
                    Configuration.UI_MODE_NIGHT_YES
        }
    val newContext = LocalContext.current.createConfigurationContext(darkConfig)
    CompositionLocalProvider(
        LocalConfiguration provides darkConfig,
        LocalContext provides newContext,
    ) {
        content()
    }
}
+6 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.compose.ui.unit.dp
import com.android.compose.theme.PlatformTheme
import com.android.systemui.brightness.ui.compose.BrightnessSliderContainer
import com.android.systemui.brightness.ui.compose.ContainerColors
import com.android.systemui.brightness.ui.viewmodel.BrightnessSliderViewModel
import com.android.systemui.lifecycle.rememberViewModel

@@ -46,7 +47,11 @@ private fun BrightnessSliderForDialog(
        rememberViewModel(traceName = "BrightnessDialog.viewModel") {
            brightnessSliderViewModelFactory.create(false)
        }
    BrightnessSliderContainer(viewModel = viewModel, Modifier.fillMaxWidth().padding(8.dp))
    BrightnessSliderContainer(
        viewModel = viewModel,
        containerColors = ContainerColors.singleColor(ContainerColors.defaultContainerColor),
        modifier = Modifier.fillMaxWidth().padding(8.dp),
    )
}

class ComposableProvider(