diff options
| author | 2025-03-06 18:20:46 +0000 | |
|---|---|---|
| committer | 2025-03-06 18:20:46 +0000 | |
| commit | 0599480317a911405ed6bbc05569e15b4ea45dde (patch) | |
| tree | 4145871d33f89ec85092329508f6bfcf81b706c1 | |
| parent | 72d5882b76963a5bf1e72502d50252bb309ac38d (diff) | |
[MediaCarousel] Extend disablePagination to disableScrolling
This CL extends the disablePagination option in MediaHostState
to disableScrolling. When disableScrolling is enabled, all scroll events
to the MediaCarousel will be ignored.
Bug:398019996
Flag: com.android.systemui.status_bar_popup_chips
Test: Make sure the carousel can not scroll when shown in a popup
Test: Make sure the carousel scrolling is unchanged in other locations
Change-Id: Iae23b94d130cee95f54d17379bf3cf4a21f79b4f
6 files changed, 52 insertions, 16 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/media/controls/ui/view/MediaCarouselScrollHandlerTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/media/controls/ui/view/MediaCarouselScrollHandlerTest.kt index c2f0ab92b32b..13e127e0d53f 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/media/controls/ui/view/MediaCarouselScrollHandlerTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/media/controls/ui/view/MediaCarouselScrollHandlerTest.kt @@ -237,6 +237,19 @@ class MediaCarouselScrollHandlerTest : SysuiTestCase() { verify(mediaCarousel, never()).animationTargetX = anyFloat() } + @Test + fun testScrollingDisabled_noScroll_notDismissible() { + setupMediaContainer(visibleIndex = 1, showsSettingsButton = false) + + mediaCarouselScrollHandler.scrollingDisabled = true + + clock.advanceTime(DISMISS_DELAY) + executor.runAllReady() + + verify(mediaCarousel, never()).smoothScrollTo(anyInt(), anyInt()) + verify(mediaCarousel, never()).animationTargetX = anyFloat() + } + private fun setupMediaContainer(visibleIndex: Int, showsSettingsButton: Boolean = true) { whenever(contentContainer.childCount).thenReturn(2) val child1: View = mock() diff --git a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalViewModel.kt b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalViewModel.kt index d7859c985c7b..c04c04bd7baf 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalViewModel.kt @@ -247,7 +247,7 @@ constructor( showsOnlyActiveMedia = false } falsingProtectionNeeded = false - disablePagination = true + disableScrolling = true init(MediaHierarchyManager.LOCATION_COMMUNAL_HUB) } } diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/ui/controller/MediaCarouselController.kt b/packages/SystemUI/src/com/android/systemui/media/controls/ui/controller/MediaCarouselController.kt index bfd48c825424..6960f9c4e87e 100644 --- a/packages/SystemUI/src/com/android/systemui/media/controls/ui/controller/MediaCarouselController.kt +++ b/packages/SystemUI/src/com/android/systemui/media/controls/ui/controller/MediaCarouselController.kt @@ -171,8 +171,8 @@ constructor( /** Is the player currently visible (at the end of the transformation */ private var playersVisible: Boolean = false - /** Are we currently disabling pagination only allowing one media session to show */ - private var currentlyDisablePagination: Boolean = false + /** Are we currently disabling scolling, only allowing the first media session to show */ + private var currentlyDisableScrolling: Boolean = false /** * The desired location where we'll be at the end of the transformation. Usually this matches @@ -1434,21 +1434,22 @@ constructor( val endShowsActive = hostStates[currentEndLocation]?.showsOnlyActiveMedia ?: true val startShowsActive = hostStates[currentStartLocation]?.showsOnlyActiveMedia ?: endShowsActive - val startDisablePagination = hostStates[currentStartLocation]?.disablePagination ?: false - val endDisablePagination = hostStates[currentEndLocation]?.disablePagination ?: false + val startDisableScrolling = hostStates[currentStartLocation]?.disableScrolling ?: false + val endDisableScrolling = hostStates[currentEndLocation]?.disableScrolling ?: false if ( currentlyShowingOnlyActive != endShowsActive || - currentlyDisablePagination != endDisablePagination || + currentlyDisableScrolling != endDisableScrolling || ((currentTransitionProgress != 1.0f && currentTransitionProgress != 0.0f) && (startShowsActive != endShowsActive || - startDisablePagination != endDisablePagination)) + startDisableScrolling != endDisableScrolling)) ) { // Whenever we're transitioning from between differing states or the endstate differs // we reset the translation currentlyShowingOnlyActive = endShowsActive - currentlyDisablePagination = endDisablePagination + currentlyDisableScrolling = endDisableScrolling mediaCarouselScrollHandler.resetTranslation(animate = true) + mediaCarouselScrollHandler.scrollingDisabled = currentlyDisableScrolling } } diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/ui/view/MediaCarouselScrollHandler.kt b/packages/SystemUI/src/com/android/systemui/media/controls/ui/view/MediaCarouselScrollHandler.kt index 0107a5278e3e..f6440704fbdd 100644 --- a/packages/SystemUI/src/com/android/systemui/media/controls/ui/view/MediaCarouselScrollHandler.kt +++ b/packages/SystemUI/src/com/android/systemui/media/controls/ui/view/MediaCarouselScrollHandler.kt @@ -128,6 +128,9 @@ class MediaCarouselScrollHandler( scrollView.relativeScrollX = newRelativeScroll } + /** Is scrolling disabled for the carousel */ + var scrollingDisabled: Boolean = false + /** Does the dismiss currently show the setting cog? */ var showsSettingsButton: Boolean = false @@ -271,6 +274,10 @@ class MediaCarouselScrollHandler( } private fun onTouch(motionEvent: MotionEvent): Boolean { + if (scrollingDisabled) { + return false + } + val isUp = motionEvent.action == MotionEvent.ACTION_UP if (gestureDetector.onTouchEvent(motionEvent)) { if (isUp) { @@ -350,6 +357,10 @@ class MediaCarouselScrollHandler( } fun onScroll(down: MotionEvent, lastMotion: MotionEvent, distanceX: Float): Boolean { + if (scrollingDisabled) { + return false + } + val totalX = lastMotion.x - down.x val currentTranslation = scrollView.getContentTranslation() if (currentTranslation != 0.0f || !scrollView.canScrollHorizontally((-totalX).toInt())) { @@ -406,6 +417,10 @@ class MediaCarouselScrollHandler( } private fun onFling(vX: Float, vY: Float): Boolean { + if (scrollingDisabled) { + return false + } + if (vX * vX < 0.5 * vY * vY) { return false } @@ -577,6 +592,9 @@ class MediaCarouselScrollHandler( * @param destIndex destination index to indicate where the scroll should end. */ fun scrollToPlayer(sourceIndex: Int = -1, destIndex: Int) { + if (scrollingDisabled) { + return + } if (sourceIndex >= 0 && sourceIndex < mediaContent.childCount) { scrollView.relativeScrollX = sourceIndex * playerWidthPlusPadding } @@ -598,6 +616,9 @@ class MediaCarouselScrollHandler( * @param step A positive number means next, and negative means previous. */ fun scrollByStep(step: Int) { + if (scrollingDisabled) { + return + } val destIndex = visibleMediaIndex + step if (destIndex >= mediaContent.childCount || destIndex < 0) { if (!showsSettingsButton) return diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/ui/view/MediaHost.kt b/packages/SystemUI/src/com/android/systemui/media/controls/ui/view/MediaHost.kt index 11251cdb6315..07c9e0f5fdd4 100644 --- a/packages/SystemUI/src/com/android/systemui/media/controls/ui/view/MediaHost.kt +++ b/packages/SystemUI/src/com/android/systemui/media/controls/ui/view/MediaHost.kt @@ -294,7 +294,7 @@ class MediaHost( changedListener?.invoke() } - override var disablePagination: Boolean = false + override var disableScrolling: Boolean = false set(value) { if (field == value) { return @@ -319,7 +319,7 @@ class MediaHost( mediaHostState.visible = visible mediaHostState.disappearParameters = disappearParameters.deepCopy() mediaHostState.falsingProtectionNeeded = falsingProtectionNeeded - mediaHostState.disablePagination = disablePagination + mediaHostState.disableScrolling = disableScrolling return mediaHostState } @@ -348,7 +348,7 @@ class MediaHost( if (!disappearParameters.equals(other.disappearParameters)) { return false } - if (disablePagination != other.disablePagination) { + if (disableScrolling != other.disableScrolling) { return false } return true @@ -362,7 +362,7 @@ class MediaHost( result = 31 * result + showsOnlyActiveMedia.hashCode() result = 31 * result + if (visible) 1 else 2 result = 31 * result + disappearParameters.hashCode() - result = 31 * result + disablePagination.hashCode() + result = 31 * result + disableScrolling.hashCode() return result } } @@ -422,10 +422,11 @@ interface MediaHostState { var disappearParameters: DisappearParameters /** - * Whether pagination should be disabled for this host, meaning that when there are multiple - * media sessions, only the first one will appear. + * Whether scrolling should be disabled for this host, meaning that when there are multiple + * media sessions, it will not be possible to scroll between media sessions or swipe away the + * entire media carousel. The first media session will always be shown. */ - var disablePagination: Boolean + var disableScrolling: Boolean /** Get a copy of this view state, deepcopying all appropriate members */ fun copy(): MediaHostState diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/shared/ui/composable/StatusBarRoot.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/shared/ui/composable/StatusBarRoot.kt index 4189221d8a83..90d41d84e69b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/shared/ui/composable/StatusBarRoot.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/shared/ui/composable/StatusBarRoot.kt @@ -253,7 +253,7 @@ fun StatusBarRoot( expandedMatchesParentHeight = true showsOnlyActiveMedia = true falsingProtectionNeeded = false - disablePagination = true + disableScrolling = true init(MediaHierarchyManager.LOCATION_STATUS_BAR_POPUP) } |