diff options
| author | 2019-01-31 04:08:03 +0000 | |
|---|---|---|
| committer | 2019-01-31 04:08:03 +0000 | |
| commit | 8330d070e8d36f1c77eccb1d056465d58cc3f85c (patch) | |
| tree | e7039f898e169c0fa3e22e303ce9234b262b42de | |
| parent | 930321a0c6800fd866bd5738964bebeed5e7279c (diff) | |
| parent | acb12153ff083cb07b67e370b7479115e31f541d (diff) | |
Merge "Properly notify expand / collapse state and add better tests"
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java | 10 | ||||
| -rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleControllerTest.java | 114 |
2 files changed, 115 insertions, 9 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java index 8731bd52e0dd..cbca2fce6b35 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java @@ -237,6 +237,10 @@ public class BubbleStackView extends FrameLayout implements BubbleTouchHandler.F * Sets the bubble that should be expanded and expands if needed. */ public void setExpandedBubble(BubbleView bubbleToExpand) { + if (mIsExpanded && !bubbleToExpand.equals(mExpandedBubble)) { + // Previously expanded, notify that this bubble is no longer expanded + notifyExpansionChanged(mExpandedBubble, false /* expanded */); + } mExpandedBubble = bubbleToExpand; if (!mIsExpanded) { // If we weren't previously expanded we should animate open. @@ -291,12 +295,12 @@ public class BubbleStackView extends FrameLayout implements BubbleTouchHandler.F int nextIndex = bubbleCount > removedIndex ? removedIndex : bubbleCount - 1; BubbleView expandedBubble = (BubbleView) mBubbleContainer.getChildAt(nextIndex); setExpandedBubble(expandedBubble); + requestUpdate(); } mIsExpanded = wasExpanded && mBubbleContainer.getChildCount() > 0; if (wasExpanded != mIsExpanded) { notifyExpansionChanged(mExpandedBubble, mIsExpanded); } - requestUpdate(); } /** @@ -373,9 +377,7 @@ public class BubbleStackView extends FrameLayout implements BubbleTouchHandler.F public void expandStack() { if (!mIsExpanded) { mExpandedBubble = getTopBubble(); - mExpandedBubble.getEntry().setShowInShadeWhenBubble(false); - animateExpansion(true /* shouldExpand */); - notifyExpansionChanged(mExpandedBubble, true /* expanded */); + setExpandedBubble(mExpandedBubble); } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleControllerTest.java index 6a3bd735fc61..5be8826f92b7 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleControllerTest.java @@ -77,6 +77,10 @@ public class BubbleControllerTest extends SysuiTestCase { @Mock private NotificationData mNotificationData; + @Mock + private BubbleController.BubbleStateChangeListener mBubbleStateChangeListener; + @Mock + private BubbleController.BubbleExpandListener mBubbleExpandListener; @Before public void setUp() throws Exception { @@ -101,6 +105,8 @@ public class BubbleControllerTest extends SysuiTestCase { when(mNotificationData.getChannel(mNoChannelRow.getEntry().key)).thenReturn(null); mBubbleController = new TestableBubbleController(mContext, mStatusBarWindowController); + mBubbleController.setBubbleStateChangeListener(mBubbleStateChangeListener); + mBubbleController.setExpandListener(mBubbleExpandListener); // Get a reference to the BubbleController's entry listener verify(mNotificationEntryManager, atLeastOnce()) @@ -112,6 +118,8 @@ public class BubbleControllerTest extends SysuiTestCase { public void testAddBubble() { mBubbleController.updateBubble(mRow.getEntry(), true /* updatePosition */); assertTrue(mBubbleController.hasBubbles()); + + verify(mBubbleStateChangeListener).onHasBubblesChanged(true); } @Test @@ -126,10 +134,14 @@ public class BubbleControllerTest extends SysuiTestCase { mBubbleController.updateBubble(mRow.getEntry(), true /* updatePosition */); assertTrue(mBubbleController.hasBubbles()); + verify(mBubbleStateChangeListener).onHasBubblesChanged(true); + mBubbleController.removeBubble(mRow.getEntry().key); assertFalse(mStatusBarWindowController.getBubblesShowing()); assertTrue(mRow.getEntry().isBubbleDismissed()); verify(mNotificationEntryManager).updateNotifications(); + + verify(mBubbleStateChangeListener).onHasBubblesChanged(false); } @Test @@ -141,41 +153,133 @@ public class BubbleControllerTest extends SysuiTestCase { mBubbleController.dismissStack(); assertFalse(mStatusBarWindowController.getBubblesShowing()); verify(mNotificationEntryManager).updateNotifications(); + assertTrue(mRow.getEntry().isBubbleDismissed()); + assertTrue(mRow2.getEntry().isBubbleDismissed()); } @Test - public void testIsStackExpanded() { + public void testExpandCollapseStack() { assertFalse(mBubbleController.isStackExpanded()); + + // Mark it as a bubble and add it explicitly + mEntryListener.onPendingEntryAdded(mRow.getEntry()); mBubbleController.updateBubble(mRow.getEntry(), true /* updatePosition */); + // We should have bubbles & their notifs should show in the shade + assertTrue(mBubbleController.hasBubbles()); + assertTrue(mRow.getEntry().showInShadeWhenBubble()); + + // Expand the stack BubbleStackView stackView = mBubbleController.getStackView(); stackView.expandStack(); assertTrue(mBubbleController.isStackExpanded()); + verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().key); + + // Make sure it's no longer in the shade + assertFalse(mRow.getEntry().showInShadeWhenBubble()); + // Collapse stackView.collapseStack(); + verify(mBubbleExpandListener).onBubbleExpandChanged(false, mRow.getEntry().key); assertFalse(mBubbleController.isStackExpanded()); } @Test - public void testCollapseStack() { + public void testCollapseAfterChangingExpandedBubble() { + // Mark it as a bubble and add it explicitly + mEntryListener.onPendingEntryAdded(mRow.getEntry()); + mEntryListener.onPendingEntryAdded(mRow2.getEntry()); mBubbleController.updateBubble(mRow.getEntry(), true /* updatePosition */); mBubbleController.updateBubble(mRow2.getEntry(), true /* updatePosition */); + // We should have bubbles & their notifs should show in the shade + assertTrue(mBubbleController.hasBubbles()); + assertTrue(mRow.getEntry().showInShadeWhenBubble()); + assertTrue(mRow2.getEntry().showInShadeWhenBubble()); + + // Expand BubbleStackView stackView = mBubbleController.getStackView(); stackView.expandStack(); assertTrue(mBubbleController.isStackExpanded()); + verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow2.getEntry().key); + + // Last added is the one that is expanded + assertEquals(mRow2.getEntry(), stackView.getExpandedBubble().getEntry()); + assertFalse(mRow2.getEntry().showInShadeWhenBubble()); + // Switch which bubble is expanded stackView.setExpandedBubble(mRow.getEntry()); - assertEquals(stackView.getExpandedBubble().getEntry(), mRow.getEntry()); + assertEquals(mRow.getEntry(), stackView.getExpandedBubble().getEntry()); + assertFalse(mRow.getEntry().showInShadeWhenBubble()); - stackView.setExpandedBubble(mRow2.getEntry()); - assertEquals(stackView.getExpandedBubble().getEntry(), mRow2.getEntry()); + // collapse for previous bubble + verify(mBubbleExpandListener).onBubbleExpandChanged(false, mRow2.getEntry().key); + // expand for selected bubble + verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().key); + // Collapse mBubbleController.collapseStack(); assertFalse(mBubbleController.isStackExpanded()); } @Test + public void testExpansionRemovesShowInShade() { + // Mark it as a bubble and add it explicitly + mEntryListener.onPendingEntryAdded(mRow.getEntry()); + mBubbleController.updateBubble(mRow.getEntry(), true /* updatePosition */); + + // We should have bubbles & their notifs should show in the shade + assertTrue(mBubbleController.hasBubbles()); + assertTrue(mRow.getEntry().showInShadeWhenBubble()); + + // Expand + BubbleStackView stackView = mBubbleController.getStackView(); + stackView.expandStack(); + assertTrue(mBubbleController.isStackExpanded()); + verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().key); + + // No longer show shade in notif after expansion + assertFalse(mRow.getEntry().showInShadeWhenBubble()); + } + + @Test + public void testRemoveLastExpandedCollapses() { + // Mark it as a bubble and add it explicitly + mEntryListener.onPendingEntryAdded(mRow.getEntry()); + mEntryListener.onPendingEntryAdded(mRow2.getEntry()); + mBubbleController.updateBubble(mRow.getEntry(), true /* updatePosition */); + mBubbleController.updateBubble(mRow2.getEntry(), true /* updatePosition */); + verify(mBubbleStateChangeListener).onHasBubblesChanged(true); + + // Expand + BubbleStackView stackView = mBubbleController.getStackView(); + stackView.expandStack(); + + assertTrue(mBubbleController.isStackExpanded()); + verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow2.getEntry().key); + + // Last added is the one that is expanded + assertEquals(mRow2.getEntry(), stackView.getExpandedBubble().getEntry()); + assertFalse(mRow2.getEntry().showInShadeWhenBubble()); + + // Dismiss currently expanded + mBubbleController.removeBubble(stackView.getExpandedBubble().getKey()); + verify(mBubbleExpandListener).onBubbleExpandChanged(false, mRow2.getEntry().key); + + // Make sure next bubble is selected + assertEquals(mRow.getEntry(), stackView.getExpandedBubble().getEntry()); + verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().key); + + // Dismiss that one + mBubbleController.removeBubble(stackView.getExpandedBubble().getKey()); + + // Make sure state changes and collapse happens + verify(mBubbleExpandListener).onBubbleExpandChanged(false, mRow.getEntry().key); + verify(mBubbleStateChangeListener).onHasBubblesChanged(false); + assertFalse(mBubbleController.hasBubbles()); + } + + @Test public void testMarkNewNotificationAsBubble() { mEntryListener.onPendingEntryAdded(mRow.getEntry()); assertTrue(mRow.getEntry().isBubble()); |