diff options
| author | 2024-04-03 11:45:45 +0100 | |
|---|---|---|
| committer | 2024-04-10 17:09:56 +0100 | |
| commit | f5e1da7febf36eba8130f062f7f5a488172888e7 (patch) | |
| tree | 369e0edb12bb8d0a03609d6842c501fcd2c66198 | |
| parent | b828afedc94a45c76f086b4fcc7626d278b18597 (diff) | |
Update volume slider dragging animation
This CL removes showing percentage and adds label fading in and out when dragging
Flag: aconfig new_volume_panel TRUNKFOOD
Test: manual on the phone. Change volume using volume slider
Fixes: 330808530
Change-Id: I51dcfc06125a3ea51d1f49dafbcd960373b7d6a0
7 files changed, 25 insertions, 131 deletions
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/volume/ui/composable/VolumeSlider.kt b/packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/volume/ui/composable/VolumeSlider.kt index 19d3f599ef31..28cd37ea9327 100644 --- a/packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/volume/ui/composable/VolumeSlider.kt +++ b/packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/volume/ui/composable/VolumeSlider.kt @@ -16,13 +16,15 @@ package com.android.systemui.volume.panel.component.volume.ui.composable +import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.core.animateFloatAsState +import androidx.compose.animation.core.tween +import androidx.compose.animation.fadeIn +import androidx.compose.animation.fadeOut import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.size -import androidx.compose.material3.LocalContentColor -import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.State import androidx.compose.runtime.getValue @@ -84,27 +86,29 @@ fun VolumeSlider( valueRange = state.valueRange, onValueChange = onValueChange, enabled = state.isEnabled, - icon = { isDragging -> - if (isDragging) { - Text(text = state.valueText, color = LocalContentColor.current) - } else { - state.icon?.let { - SliderIcon( - icon = it, - onIconTapped = onIconTapped, - isTappable = state.isMutable, - ) - } + icon = { + state.icon?.let { + SliderIcon( + icon = it, + onIconTapped = onIconTapped, + isTappable = state.isMutable, + ) } }, colors = sliderColors, - label = { - VolumeSliderContent( - modifier = Modifier, - label = state.label, - isEnabled = state.isEnabled, - disabledMessage = state.disabledMessage, - ) + label = { isDragging -> + AnimatedVisibility( + visible = !isDragging, + enter = fadeIn(tween(150)), + exit = fadeOut(tween(150)), + ) { + VolumeSliderContent( + modifier = Modifier, + label = state.label, + isEnabled = state.isEnabled, + disabledMessage = state.disabledMessage, + ) + } } ) } diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/volume/domain/interactor/VolumeSliderInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/volume/domain/interactor/VolumeSliderInteractorTest.kt deleted file mode 100644 index 79d3fe9063b7..000000000000 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/volume/domain/interactor/VolumeSliderInteractorTest.kt +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.systemui.volume.panel.component.volume.domain.interactor - -import androidx.test.ext.junit.runners.AndroidJUnit4 -import androidx.test.filters.SmallTest -import com.android.systemui.SysuiTestCase -import com.google.common.truth.Truth.assertThat -import org.junit.Test -import org.junit.runner.RunWith - -@RunWith(AndroidJUnit4::class) -@SmallTest -class VolumeSliderInteractorTest : SysuiTestCase() { - - private val underTest = VolumeSliderInteractor() - - @Test - fun processVolumeToValue_returnsTranslatedVolume() { - assertThat(underTest.processVolumeToValue(2, volumeRange)).isEqualTo(20f) - } - - private companion object { - val volumeRange = 0..10 - } -} diff --git a/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/domain/interactor/VolumeSliderInteractor.kt b/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/domain/interactor/VolumeSliderInteractor.kt deleted file mode 100644 index ecd89eab1d4b..000000000000 --- a/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/domain/interactor/VolumeSliderInteractor.kt +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.systemui.volume.panel.component.volume.domain.interactor - -import com.android.systemui.volume.panel.dagger.scope.VolumePanelScope -import javax.inject.Inject - -/** Converts from slider value to volume and back. */ -@VolumePanelScope -class VolumeSliderInteractor @Inject constructor() { - - /** mimic percentage volume setting */ - private val displayValueRange: ClosedFloatingPointRange<Float> = 0f..100f - - /** - * Translates [volume], that belongs to [volumeRange] to the value that belongs to - * [displayValueRange]. - */ - fun processVolumeToValue( - volume: Int, - volumeRange: ClosedRange<Int>, - ): Float { - val currentRangeStart: Float = volumeRange.start.toFloat() - val targetRangeStart: Float = displayValueRange.start - val currentRangeLength: Float = (volumeRange.endInclusive.toFloat() - currentRangeStart) - val targetRangeLength: Float = displayValueRange.endInclusive - targetRangeStart - if (currentRangeLength == 0f || targetRangeLength == 0f) { - return 0f - } - val volumeFraction: Float = (volume.toFloat() - currentRangeStart) / currentRangeLength - return targetRangeStart + volumeFraction * targetRangeLength - } -} diff --git a/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModel.kt b/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModel.kt index 57b5d570fbbd..1ae1ebb99f8b 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModel.kt @@ -24,7 +24,6 @@ import com.android.settingslib.volume.shared.model.AudioStreamModel import com.android.settingslib.volume.shared.model.RingerMode import com.android.systemui.common.shared.model.Icon import com.android.systemui.res.R -import com.android.systemui.volume.panel.component.volume.domain.interactor.VolumeSliderInteractor import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject @@ -44,7 +43,6 @@ constructor( @Assisted private val coroutineScope: CoroutineScope, private val context: Context, private val audioVolumeInteractor: AudioVolumeInteractor, - private val volumeSliderInteractor: VolumeSliderInteractor, ) : SliderViewModel { private val audioStream = audioStreamWrapper.audioStream @@ -105,10 +103,6 @@ constructor( return State( value = volume.toFloat(), valueRange = volumeRange.first.toFloat()..volumeRange.last.toFloat(), - valueText = - SliderViewModel.formatValue( - volumeSliderInteractor.processVolumeToValue(volume, volumeRange) - ), icon = getIcon(ringerMode), label = labelsByStream[audioStream]?.let(context::getString) ?: error("No label for the stream: $audioStream"), @@ -157,7 +151,6 @@ constructor( override val valueRange: ClosedFloatingPointRange<Float>, override val icon: Icon, override val label: String, - override val valueText: String, override val disabledMessage: String?, override val isEnabled: Boolean, override val a11yStep: Int, diff --git a/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/CastVolumeSliderViewModel.kt b/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/CastVolumeSliderViewModel.kt index 8d8fa17bf986..3689303ab28d 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/CastVolumeSliderViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/CastVolumeSliderViewModel.kt @@ -22,7 +22,6 @@ import com.android.systemui.common.shared.model.Icon import com.android.systemui.res.R import com.android.systemui.volume.panel.component.mediaoutput.domain.interactor.MediaDeviceSessionInteractor import com.android.systemui.volume.panel.component.mediaoutput.shared.model.MediaDeviceSession -import com.android.systemui.volume.panel.component.volume.domain.interactor.VolumeSliderInteractor import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject @@ -41,7 +40,6 @@ constructor( @Assisted private val coroutineScope: CoroutineScope, private val context: Context, private val mediaDeviceSessionInteractor: MediaDeviceSessionInteractor, - private val volumeSliderInteractor: VolumeSliderInteractor, ) : SliderViewModel { override val slider: StateFlow<SliderState> = @@ -66,13 +64,6 @@ constructor( value = currentVolume.toFloat(), valueRange = volumeRange.first.toFloat()..volumeRange.last.toFloat(), icon = Icon.Resource(R.drawable.ic_cast, null), - valueText = - SliderViewModel.formatValue( - volumeSliderInteractor.processVolumeToValue( - volume = currentVolume, - volumeRange = volumeRange, - ) - ), label = context.getString(R.string.media_device_cast), isEnabled = true, a11yStep = 1 @@ -83,13 +74,13 @@ constructor( override val value: Float, override val valueRange: ClosedFloatingPointRange<Float>, override val icon: Icon, - override val valueText: String, override val label: String, override val isEnabled: Boolean, override val a11yStep: Int, ) : SliderState { override val disabledMessage: String? get() = null + override val isMutable: Boolean get() = false } diff --git a/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/SliderState.kt b/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/SliderState.kt index 8eb0b8947c37..d71a9d8dae94 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/SliderState.kt +++ b/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/SliderState.kt @@ -28,7 +28,6 @@ sealed interface SliderState { val valueRange: ClosedFloatingPointRange<Float> val icon: Icon? val isEnabled: Boolean - val valueText: String val label: String /** * A11y slider controls works by adjusting one step up or down. The default slider step isn't @@ -42,7 +41,6 @@ sealed interface SliderState { override val value: Float = 0f override val valueRange: ClosedFloatingPointRange<Float> = 0f..1f override val icon: Icon? = null - override val valueText: String = "" override val label: String = "" override val disabledMessage: String? = null override val a11yStep: Int = 0 diff --git a/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/SliderViewModel.kt b/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/SliderViewModel.kt index e78f833086f8..74aee559194b 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/SliderViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/SliderViewModel.kt @@ -26,9 +26,4 @@ interface SliderViewModel { fun onValueChanged(state: SliderState, newValue: Float) fun toggleMuted(state: SliderState) - - companion object { - - fun formatValue(value: Float): String = "%.0f".format(value) - } } |