[Media] Allow a11y interactions to change seekbar position.

Note that the seekbar UI can now get a bit janky if
you have TalkBack on and you very quickly swipe up or down. We can file
a new bug for that if we decide it needs fixing.

Fixes: 216254595
Fixes: 216254099
Test: SeekBarViewModelTest
Test: manual: Turn TalkBack on, select the seekbar, and verify you can
swipe up/down to change the track position.
Test: manual: Verify seeking without TalkBack on still works.

Change-Id: I890e4f396fa704047c5593fff20c8924b890fc75
This commit is contained in:
Caitlin Cassidy
2022-04-21 17:18:37 +00:00
parent cdb2c06748
commit 6e947afdab
2 changed files with 17 additions and 5 deletions

View File

@@ -151,13 +151,21 @@ class SeekBarViewModel @Inject constructor(
}
/**
* Event indicating that the user has moved the seek bar but hasn't yet finished the gesture.
* Event indicating that the user has moved the seek bar.
*
* @param position Current location in the track.
*/
@AnyThread
fun onSeekProgress(position: Long) = bgExecutor.execute {
if (scrubbing) {
// The user hasn't yet finished their touch gesture, so only update the data for visual
// feedback and don't update [controller] yet.
_data = _data.copy(elapsedTime = position.toInt())
} else {
// The seek progress came from an a11y action and we should immediately update to the
// new position. (a11y actions to change the seekbar position don't trigger
// SeekBar.OnSeekBarChangeListener.onStartTrackingTouch or onStopTrackingTouch.)
onSeek(position)
}
}

View File

@@ -375,16 +375,20 @@ public class SeekBarViewModelTest : SysuiTestCase() {
}
@Test
fun onProgressChangedFromUserWithoutStartTrackingTouch() {
// WHEN user starts dragging the seek bar
fun onProgressChangedFromUserWithoutStartTrackingTouch_transportUpdated() {
whenever(mockController.transportControls).thenReturn(mockTransport)
viewModel.updateController(mockController)
val pos = 42
val bar = SeekBar(context)
// WHEN we get an onProgressChanged event without an onStartTrackingTouch event
with(viewModel.seekBarListener) {
onProgressChanged(bar, pos, true)
}
fakeExecutor.runAllReady()
// THEN then elapsed time should not be updated
assertThat(viewModel.progress.value!!.elapsedTime).isNull()
// THEN we immediately update the transport
verify(mockTransport).seekTo(pos.toLong())
}
@Test