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

Commit b3f164de authored by Anton Potapov's avatar Anton Potapov Committed by Android (Google) Code Review
Browse files

Merge changes from topic "volume_panel_sliders_improvements" into main

* changes:
  Add a11y descriptions for the new panel
  Improve volume sliders behaviour:
parents 6de35cc4 ddd434c6
Loading
Loading
Loading
Loading
+5 −5
Original line number Original line Diff line number Diff line
@@ -161,11 +161,11 @@ class AudioRepositoryImpl(


    override suspend fun setMuted(audioStream: AudioStream, isMuted: Boolean) =
    override suspend fun setMuted(audioStream: AudioStream, isMuted: Boolean) =
        withContext(backgroundCoroutineContext) {
        withContext(backgroundCoroutineContext) {
            if (isMuted) {
            audioManager.adjustStreamVolume(
                audioManager.adjustStreamVolume(audioStream.value, 0, AudioManager.ADJUST_MUTE)
                audioStream.value,
            } else {
                if (isMuted) AudioManager.ADJUST_MUTE else AudioManager.ADJUST_UNMUTE,
                audioManager.adjustStreamVolume(audioStream.value, 0, AudioManager.ADJUST_UNMUTE)
                0,
            }
            )
        }
        }


    private fun getMinVolume(stream: AudioStream): Int =
    private fun getMinVolume(stream: AudioStream): Int =
+2 −2
Original line number Original line Diff line number Diff line
@@ -84,10 +84,10 @@ class AudioVolumeInteractor(
                    (audioStreamModel.audioStream.value == AudioManager.STREAM_NOTIFICATION &&
                    (audioStreamModel.audioStream.value == AudioManager.STREAM_NOTIFICATION &&
                        audioStreamModel.isMuted)
                        audioStreamModel.isMuted)
            ) {
            ) {
                return 0
                return audioStreamModel.minVolume
            }
            }
        } else if (audioStreamModel.isMuted) {
        } else if (audioStreamModel.isMuted) {
            return 0
            return audioStreamModel.minVolume
        }
        }
        return audioStreamModel.volume
        return audioStreamModel.volume
    }
    }
+3 −3
Original line number Original line Diff line number Diff line
@@ -77,13 +77,13 @@ class AudioRepositoryTest {
        `when`(audioManager.getStreamMaxVolume(anyInt())).thenReturn(MAX_VOLUME)
        `when`(audioManager.getStreamMaxVolume(anyInt())).thenReturn(MAX_VOLUME)
        `when`(audioManager.ringerModeInternal).thenReturn(AudioManager.RINGER_MODE_NORMAL)
        `when`(audioManager.ringerModeInternal).thenReturn(AudioManager.RINGER_MODE_NORMAL)
        `when`(audioManager.setStreamVolume(anyInt(), anyInt(), anyInt())).then {
        `when`(audioManager.setStreamVolume(anyInt(), anyInt(), anyInt())).then {
            val streamType = it.arguments[1] as Int
            val streamType = it.arguments[0] as Int
            volumeByStream[it.arguments[0] as Int] = streamType
            volumeByStream[it.arguments[0] as Int] = it.arguments[1] as Int
            triggerEvent(AudioManagerEvent.StreamVolumeChanged(AudioStream(streamType)))
            triggerEvent(AudioManagerEvent.StreamVolumeChanged(AudioStream(streamType)))
        }
        }
        `when`(audioManager.adjustStreamVolume(anyInt(), anyInt(), anyInt())).then {
        `when`(audioManager.adjustStreamVolume(anyInt(), anyInt(), anyInt())).then {
            val streamType = it.arguments[0] as Int
            val streamType = it.arguments[0] as Int
            isMuteByStream[streamType] = it.arguments[2] == AudioManager.ADJUST_MUTE
            isMuteByStream[streamType] = it.arguments[1] == AudioManager.ADJUST_MUTE
            triggerEvent(AudioManagerEvent.StreamMuteChanged(AudioStream(streamType)))
            triggerEvent(AudioManagerEvent.StreamMuteChanged(AudioStream(streamType)))
        }
        }
        `when`(audioManager.getStreamVolume(anyInt())).thenAnswer {
        `when`(audioManager.getStreamVolume(anyInt())).thenAnswer {
+1 −1
Original line number Original line Diff line number Diff line
@@ -911,7 +911,7 @@


        <activity
        <activity
            android:name=".volume.panel.ui.activity.VolumePanelActivity"
            android:name=".volume.panel.ui.activity.VolumePanelActivity"
            android:label="@string/sound_settings"
            android:label="@string/accessibility_volume_settings"
            android:excludeFromRecents="true"
            android:excludeFromRecents="true"
            android:exported="false"
            android:exported="false"
            android:launchMode="singleInstance"
            android:launchMode="singleInstance"
+13 −2
Original line number Original line Diff line number Diff line
@@ -32,6 +32,11 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.Role
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.text.style.TextOverflow
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.dp
import com.android.compose.animation.Expandable
import com.android.compose.animation.Expandable
@@ -52,6 +57,7 @@ class ButtonComponent(
    override fun VolumePanelComposeScope.Content(modifier: Modifier) {
    override fun VolumePanelComposeScope.Content(modifier: Modifier) {
        val viewModelByState by viewModelFlow.collectAsState()
        val viewModelByState by viewModelFlow.collectAsState()
        val viewModel = viewModelByState ?: return
        val viewModel = viewModelByState ?: return
        val label = viewModel.label.toString()


        Column(
        Column(
            modifier = modifier,
            modifier = modifier,
@@ -59,7 +65,11 @@ class ButtonComponent(
            horizontalAlignment = Alignment.CenterHorizontally,
            horizontalAlignment = Alignment.CenterHorizontally,
        ) {
        ) {
            Expandable(
            Expandable(
                modifier = Modifier.height(64.dp).fillMaxWidth(),
                modifier =
                    Modifier.height(64.dp).fillMaxWidth().semantics {
                        role = Role.Button
                        contentDescription = label
                    },
                color = MaterialTheme.colorScheme.primaryContainer,
                color = MaterialTheme.colorScheme.primaryContainer,
                shape = RoundedCornerShape(28.dp),
                shape = RoundedCornerShape(28.dp),
                contentColor = MaterialTheme.colorScheme.onPrimaryContainer,
                contentColor = MaterialTheme.colorScheme.onPrimaryContainer,
@@ -71,7 +81,8 @@ class ButtonComponent(
                }
                }
            }
            }
            Text(
            Text(
                text = viewModel.label.toString(),
                modifier = Modifier.clearAndSetSemantics {},
                text = label,
                style = MaterialTheme.typography.labelMedium,
                style = MaterialTheme.typography.labelMedium,
                maxLines = 1,
                maxLines = 1,
                overflow = TextOverflow.Ellipsis,
                overflow = TextOverflow.Ellipsis,
Loading