Loading packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/button/ui/composable/ButtonComponent.kt +4 −3 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ import androidx.compose.ui.semantics.clearAndSetSemantics import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.role import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.stateDescription import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.android.compose.animation.Expandable Loading @@ -64,7 +65,6 @@ class ButtonComponent( override fun VolumePanelComposeScope.Content(modifier: Modifier) { val viewModelByState by viewModelFlow.collectAsStateWithLifecycle() val viewModel = viewModelByState ?: return val label = viewModel.label.toString() val screenWidth: Float = with(LocalDensity.current) { LocalConfiguration.current.screenWidthDp.dp.toPx() } Loading @@ -81,7 +81,8 @@ class ButtonComponent( modifier = Modifier.fillMaxSize().padding(8.dp).semantics { role = Role.Button contentDescription = label contentDescription = viewModel.label viewModel.stateDescription?.let { stateDescription = it } }, color = if (viewModel.isActive) { Loading Loading @@ -118,7 +119,7 @@ class ButtonComponent( } Text( modifier = Modifier.clearAndSetSemantics {}.basicMarquee(), text = label, text = viewModel.label, style = MaterialTheme.typography.labelMedium, maxLines = 2, ) Loading packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/button/ui/composable/ToggleButtonComponent.kt +13 −9 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ import androidx.compose.ui.semantics.clearAndSetSemantics import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.role import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.stateDescription import androidx.compose.ui.semantics.toggleableState import androidx.compose.ui.state.ToggleableState import androidx.compose.ui.unit.dp Loading @@ -59,7 +60,6 @@ class ToggleButtonComponent( override fun VolumePanelComposeScope.Content(modifier: Modifier) { val viewModelByState by viewModelFlow.collectAsStateWithLifecycle() val viewModel = viewModelByState ?: return val label = viewModel.label.toString() Column( modifier = modifier, Loading Loading @@ -97,13 +97,17 @@ class ToggleButtonComponent( modifier = Modifier.fillMaxSize().padding(8.dp).semantics { role = Role.Switch if (viewModel.stateDescription == null) { toggleableState = if (viewModel.isActive) { ToggleableState.On } else { ToggleableState.Off } contentDescription = label } else { stateDescription = viewModel.stateDescription } contentDescription = viewModel.label }, onClick = { onCheckedChange(!viewModel.isActive) }, shape = RoundedCornerShape(20.dp), Loading @@ -116,7 +120,7 @@ class ToggleButtonComponent( Text( modifier = Modifier.clearAndSetSemantics {}.basicMarquee(), text = label, text = viewModel.label, style = MaterialTheme.typography.labelMedium, maxLines = 2, ) Loading packages/SystemUI/src/com/android/systemui/volume/panel/component/button/ui/viewmodel/ButtonViewModel.kt +2 −1 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import com.android.systemui.common.shared.model.Icon /** Models base buttons appearance. */ data class ButtonViewModel( val icon: Icon, val label: CharSequence, val label: String, val isActive: Boolean = true, val stateDescription: String? = null, ) packages/SystemUI/src/com/android/systemui/volume/panel/component/spatial/ui/viewmodel/SpatialAudioViewModel.kt +14 −5 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.systemui.volume.panel.component.spatial.ui.viewmodel import android.content.Context import com.android.app.tracing.coroutines.launchTraced as launch import com.android.internal.logging.UiEventLogger import com.android.systemui.common.shared.model.Icon import com.android.systemui.dagger.qualifiers.Application Loading @@ -35,7 +36,6 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import com.android.app.tracing.coroutines.launchTraced as launch @VolumePanelScope class SpatialAudioViewModel Loading @@ -58,6 +58,7 @@ constructor( isChecked = isEnabled is SpatialAudioEnabledModel.SpatialAudioEnabled, isHeadTrackingAvailable = isAvailable is SpatialAudioAvailabilityModel.HeadTracking, shouldUseLabelInStateDescription = true, ) .copy(label = context.getString(R.string.volume_panel_spatial_audio_title)) } Loading Loading @@ -94,6 +95,7 @@ constructor( isChecked = isEnabled == currentIsEnabled, isHeadTrackingAvailable = isAvailable is SpatialAudioAvailabilityModel.HeadTracking, shouldUseLabelInStateDescription = false, ) SpatialAudioButtonViewModel(button = buttonViewModel, model = isEnabled) } Loading @@ -112,7 +114,7 @@ constructor( else -> { -1 } } }, ) scope.launch { interactor.setEnabled(model) } } Loading @@ -120,10 +122,12 @@ constructor( private fun SpatialAudioEnabledModel.toViewModel( isChecked: Boolean, isHeadTrackingAvailable: Boolean, shouldUseLabelInStateDescription: Boolean, ): ButtonViewModel { // This method deliberately uses the same icon for the case when head tracking is disabled // to show a toggle button with a non-changing icon if (this is SpatialAudioEnabledModel.HeadTrackingEnabled) { val label = context.getString(R.string.volume_panel_spatial_audio_tracking) return ButtonViewModel( isActive = isChecked, icon = Loading @@ -132,11 +136,13 @@ constructor( } else { spatialSpeakerIcon }, label = context.getString(R.string.volume_panel_spatial_audio_tracking) label = label, stateDescription = label.takeIf { shouldUseLabelInStateDescription }, ) } if (this is SpatialAudioEnabledModel.SpatialAudioEnabled) { val label = context.getString(R.string.volume_panel_spatial_audio_fixed) return ButtonViewModel( isActive = isChecked, icon = Loading @@ -145,11 +151,13 @@ constructor( } else { spatialSpeakerIcon }, label = context.getString(R.string.volume_panel_spatial_audio_fixed) label = label, stateDescription = label.takeIf { shouldUseLabelInStateDescription }, ) } if (this is SpatialAudioEnabledModel.Disabled) { val label = context.getString(R.string.volume_panel_spatial_audio_off) return ButtonViewModel( isActive = isChecked, icon = Loading @@ -158,7 +166,8 @@ constructor( } else { spatialSpeakerIcon }, label = context.getString(R.string.volume_panel_spatial_audio_off) label = label, stateDescription = label.takeIf { shouldUseLabelInStateDescription }, ) } Loading Loading
packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/button/ui/composable/ButtonComponent.kt +4 −3 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ import androidx.compose.ui.semantics.clearAndSetSemantics import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.role import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.stateDescription import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.android.compose.animation.Expandable Loading @@ -64,7 +65,6 @@ class ButtonComponent( override fun VolumePanelComposeScope.Content(modifier: Modifier) { val viewModelByState by viewModelFlow.collectAsStateWithLifecycle() val viewModel = viewModelByState ?: return val label = viewModel.label.toString() val screenWidth: Float = with(LocalDensity.current) { LocalConfiguration.current.screenWidthDp.dp.toPx() } Loading @@ -81,7 +81,8 @@ class ButtonComponent( modifier = Modifier.fillMaxSize().padding(8.dp).semantics { role = Role.Button contentDescription = label contentDescription = viewModel.label viewModel.stateDescription?.let { stateDescription = it } }, color = if (viewModel.isActive) { Loading Loading @@ -118,7 +119,7 @@ class ButtonComponent( } Text( modifier = Modifier.clearAndSetSemantics {}.basicMarquee(), text = label, text = viewModel.label, style = MaterialTheme.typography.labelMedium, maxLines = 2, ) Loading
packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/button/ui/composable/ToggleButtonComponent.kt +13 −9 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ import androidx.compose.ui.semantics.clearAndSetSemantics import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.role import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.stateDescription import androidx.compose.ui.semantics.toggleableState import androidx.compose.ui.state.ToggleableState import androidx.compose.ui.unit.dp Loading @@ -59,7 +60,6 @@ class ToggleButtonComponent( override fun VolumePanelComposeScope.Content(modifier: Modifier) { val viewModelByState by viewModelFlow.collectAsStateWithLifecycle() val viewModel = viewModelByState ?: return val label = viewModel.label.toString() Column( modifier = modifier, Loading Loading @@ -97,13 +97,17 @@ class ToggleButtonComponent( modifier = Modifier.fillMaxSize().padding(8.dp).semantics { role = Role.Switch if (viewModel.stateDescription == null) { toggleableState = if (viewModel.isActive) { ToggleableState.On } else { ToggleableState.Off } contentDescription = label } else { stateDescription = viewModel.stateDescription } contentDescription = viewModel.label }, onClick = { onCheckedChange(!viewModel.isActive) }, shape = RoundedCornerShape(20.dp), Loading @@ -116,7 +120,7 @@ class ToggleButtonComponent( Text( modifier = Modifier.clearAndSetSemantics {}.basicMarquee(), text = label, text = viewModel.label, style = MaterialTheme.typography.labelMedium, maxLines = 2, ) Loading
packages/SystemUI/src/com/android/systemui/volume/panel/component/button/ui/viewmodel/ButtonViewModel.kt +2 −1 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import com.android.systemui.common.shared.model.Icon /** Models base buttons appearance. */ data class ButtonViewModel( val icon: Icon, val label: CharSequence, val label: String, val isActive: Boolean = true, val stateDescription: String? = null, )
packages/SystemUI/src/com/android/systemui/volume/panel/component/spatial/ui/viewmodel/SpatialAudioViewModel.kt +14 −5 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.systemui.volume.panel.component.spatial.ui.viewmodel import android.content.Context import com.android.app.tracing.coroutines.launchTraced as launch import com.android.internal.logging.UiEventLogger import com.android.systemui.common.shared.model.Icon import com.android.systemui.dagger.qualifiers.Application Loading @@ -35,7 +36,6 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import com.android.app.tracing.coroutines.launchTraced as launch @VolumePanelScope class SpatialAudioViewModel Loading @@ -58,6 +58,7 @@ constructor( isChecked = isEnabled is SpatialAudioEnabledModel.SpatialAudioEnabled, isHeadTrackingAvailable = isAvailable is SpatialAudioAvailabilityModel.HeadTracking, shouldUseLabelInStateDescription = true, ) .copy(label = context.getString(R.string.volume_panel_spatial_audio_title)) } Loading Loading @@ -94,6 +95,7 @@ constructor( isChecked = isEnabled == currentIsEnabled, isHeadTrackingAvailable = isAvailable is SpatialAudioAvailabilityModel.HeadTracking, shouldUseLabelInStateDescription = false, ) SpatialAudioButtonViewModel(button = buttonViewModel, model = isEnabled) } Loading @@ -112,7 +114,7 @@ constructor( else -> { -1 } } }, ) scope.launch { interactor.setEnabled(model) } } Loading @@ -120,10 +122,12 @@ constructor( private fun SpatialAudioEnabledModel.toViewModel( isChecked: Boolean, isHeadTrackingAvailable: Boolean, shouldUseLabelInStateDescription: Boolean, ): ButtonViewModel { // This method deliberately uses the same icon for the case when head tracking is disabled // to show a toggle button with a non-changing icon if (this is SpatialAudioEnabledModel.HeadTrackingEnabled) { val label = context.getString(R.string.volume_panel_spatial_audio_tracking) return ButtonViewModel( isActive = isChecked, icon = Loading @@ -132,11 +136,13 @@ constructor( } else { spatialSpeakerIcon }, label = context.getString(R.string.volume_panel_spatial_audio_tracking) label = label, stateDescription = label.takeIf { shouldUseLabelInStateDescription }, ) } if (this is SpatialAudioEnabledModel.SpatialAudioEnabled) { val label = context.getString(R.string.volume_panel_spatial_audio_fixed) return ButtonViewModel( isActive = isChecked, icon = Loading @@ -145,11 +151,13 @@ constructor( } else { spatialSpeakerIcon }, label = context.getString(R.string.volume_panel_spatial_audio_fixed) label = label, stateDescription = label.takeIf { shouldUseLabelInStateDescription }, ) } if (this is SpatialAudioEnabledModel.Disabled) { val label = context.getString(R.string.volume_panel_spatial_audio_off) return ButtonViewModel( isActive = isChecked, icon = Loading @@ -158,7 +166,8 @@ constructor( } else { spatialSpeakerIcon }, label = context.getString(R.string.volume_panel_spatial_audio_off) label = label, stateDescription = label.takeIf { shouldUseLabelInStateDescription }, ) } Loading