diff options
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 61119cce7bc8..8592c424ca02 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 @@ -235,6 +235,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 857fa5cac3e2..756edb3d048d 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 ac6343c6bb64..71b3223b77be 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 @@ -159,8 +159,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 @@ -1130,21 +1130,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 9cf4a7b3a007..68865d65139c 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 @@ -127,6 +127,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 @@ -270,6 +273,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) { @@ -349,6 +356,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())) { @@ -405,6 +416,10 @@ class MediaCarouselScrollHandler( } private fun onFling(vX: Float, vY: Float): Boolean { + if (scrollingDisabled) { + return false + } + if (vX * vX < 0.5 * vY * vY) { return false } @@ -575,6 +590,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 } @@ -596,6 +614,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 a518349ea424..37af7642b105 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 @@ -295,7 +295,7 @@ class MediaHost( changedListener?.invoke() } - override var disablePagination: Boolean = false + override var disableScrolling: Boolean = false set(value) { if (field == value) { return @@ -320,7 +320,7 @@ class MediaHost( mediaHostState.visible = visible mediaHostState.disappearParameters = disappearParameters.deepCopy() mediaHostState.falsingProtectionNeeded = falsingProtectionNeeded - mediaHostState.disablePagination = disablePagination + mediaHostState.disableScrolling = disableScrolling return mediaHostState } @@ -349,7 +349,7 @@ class MediaHost( if (!disappearParameters.equals(other.disappearParameters)) { return false } - if (disablePagination != other.disablePagination) { + if (disableScrolling != other.disableScrolling) { return false } return true @@ -363,7 +363,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 } } @@ -423,10 +423,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 c91ea9a50028..ba666512af5a 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 @@ -255,7 +255,7 @@ fun StatusBarRoot( expandedMatchesParentHeight = true showsOnlyActiveMedia = true falsingProtectionNeeded = false - disablePagination = true + disableScrolling = true init(MediaHierarchyManager.LOCATION_STATUS_BAR_POPUP) } |