Loading packages/SystemUI/multivalentTests/src/com/android/systemui/media/controls/ui/view/MediaCarouselScrollHandlerTest.kt +13 −0 Original line number Diff line number Diff line Loading @@ -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() Loading packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalViewModel.kt +1 −1 Original line number Diff line number Diff line Loading @@ -247,7 +247,7 @@ constructor( showsOnlyActiveMedia = false } falsingProtectionNeeded = false disablePagination = true disableScrolling = true init(MediaHierarchyManager.LOCATION_COMMUNAL_HUB) } } Loading packages/SystemUI/src/com/android/systemui/media/controls/ui/controller/MediaCarouselController.kt +8 −7 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 } } Loading packages/SystemUI/src/com/android/systemui/media/controls/ui/view/MediaCarouselScrollHandler.kt +21 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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) { Loading Loading @@ -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())) { Loading Loading @@ -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 } Loading Loading @@ -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 } Loading @@ -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 Loading packages/SystemUI/src/com/android/systemui/media/controls/ui/view/MediaHost.kt +8 −7 Original line number Diff line number Diff line Loading @@ -295,7 +295,7 @@ class MediaHost( changedListener?.invoke() } override var disablePagination: Boolean = false override var disableScrolling: Boolean = false set(value) { if (field == value) { return Loading @@ -320,7 +320,7 @@ class MediaHost( mediaHostState.visible = visible mediaHostState.disappearParameters = disappearParameters.deepCopy() mediaHostState.falsingProtectionNeeded = falsingProtectionNeeded mediaHostState.disablePagination = disablePagination mediaHostState.disableScrolling = disableScrolling return mediaHostState } Loading Loading @@ -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 Loading @@ -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 } } Loading Loading @@ -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 Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/media/controls/ui/view/MediaCarouselScrollHandlerTest.kt +13 −0 Original line number Diff line number Diff line Loading @@ -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() Loading
packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalViewModel.kt +1 −1 Original line number Diff line number Diff line Loading @@ -247,7 +247,7 @@ constructor( showsOnlyActiveMedia = false } falsingProtectionNeeded = false disablePagination = true disableScrolling = true init(MediaHierarchyManager.LOCATION_COMMUNAL_HUB) } } Loading
packages/SystemUI/src/com/android/systemui/media/controls/ui/controller/MediaCarouselController.kt +8 −7 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 } } Loading
packages/SystemUI/src/com/android/systemui/media/controls/ui/view/MediaCarouselScrollHandler.kt +21 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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) { Loading Loading @@ -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())) { Loading Loading @@ -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 } Loading Loading @@ -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 } Loading @@ -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 Loading
packages/SystemUI/src/com/android/systemui/media/controls/ui/view/MediaHost.kt +8 −7 Original line number Diff line number Diff line Loading @@ -295,7 +295,7 @@ class MediaHost( changedListener?.invoke() } override var disablePagination: Boolean = false override var disableScrolling: Boolean = false set(value) { if (field == value) { return Loading @@ -320,7 +320,7 @@ class MediaHost( mediaHostState.visible = visible mediaHostState.disappearParameters = disappearParameters.deepCopy() mediaHostState.falsingProtectionNeeded = falsingProtectionNeeded mediaHostState.disablePagination = disablePagination mediaHostState.disableScrolling = disableScrolling return mediaHostState } Loading Loading @@ -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 Loading @@ -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 } } Loading Loading @@ -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 Loading