Loading packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceController.java +28 −6 Original line number Diff line number Diff line Loading @@ -30,6 +30,9 @@ import com.android.systemui.statusbar.policy.DarkIconDispatcher; import com.android.systemui.statusbar.policy.OnHeadsUpChangedListener; import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; import java.util.function.BiConsumer; import java.util.function.Consumer; /** * Controls the appearance of heads up notifications in the icon area and the header itself. */ Loading @@ -43,11 +46,19 @@ class HeadsUpAppearanceController implements OnHeadsUpChangedListener, private final HeadsUpStatusBarView mHeadsUpStatusBarView; private final View mClockView; private final DarkIconDispatcher mDarkIconDispatcher; private final NotificationPanelView mPanelView; private final Consumer<ExpandableNotificationRow> mSetTrackingHeadsUp = this::setTrackingHeadsUp; private final Runnable mUpdatePanelTranslation = this::updatePanelTranslation; private final BiConsumer<Float, Float> mSetExpandedHeight = this::setExpandedHeight; private float mExpandedHeight; private boolean mIsExpanded; private float mExpandFraction; private ExpandableNotificationRow mTrackedChild; private boolean mShown; private final View.OnLayoutChangeListener mStackScrollLayoutChangeListener = (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> updatePanelTranslation(); public HeadsUpAppearanceController( NotificationIconAreaController notificationIconAreaController, Loading Loading @@ -75,18 +86,29 @@ class HeadsUpAppearanceController implements OnHeadsUpChangedListener, headsUpStatusBarView.setOnDrawingRectChangedListener( () -> updateIsolatedIconLocation(true /* requireUpdate */)); mStackScroller = stackScroller; panelView.addTrackingHeadsUpListener(this::setTrackingHeadsUp); panelView.setVerticalTranslationListener(this::updatePanelTranslation); mPanelView = panelView; panelView.addTrackingHeadsUpListener(mSetTrackingHeadsUp); panelView.addVerticalTranslationListener(mUpdatePanelTranslation); panelView.setHeadsUpAppearanceController(this); mStackScroller.addOnExpandedHeightListener(this::setExpandedHeight); mStackScroller.addOnLayoutChangeListener( (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> updatePanelTranslation()); mStackScroller.addOnExpandedHeightListener(mSetExpandedHeight); mStackScroller.addOnLayoutChangeListener(mStackScrollLayoutChangeListener); mClockView = clockView; mDarkIconDispatcher = Dependency.get(DarkIconDispatcher.class); mDarkIconDispatcher.addDarkReceiver(this); } public void destroy() { mHeadsUpManager.removeListener(this); mHeadsUpStatusBarView.setOnDrawingRectChangedListener(null); mPanelView.removeTrackingHeadsUpListener(mSetTrackingHeadsUp); mPanelView.removeVerticalTranslationListener(mUpdatePanelTranslation); mPanelView.setHeadsUpAppearanceController(null); mStackScroller.removeOnExpandedHeightListener(mSetExpandedHeight); mStackScroller.removeOnLayoutChangeListener(mStackScrollLayoutChangeListener); mDarkIconDispatcher.removeDarkReceiver(this); } private void updateIsolatedIconLocation(boolean requireStateUpdate) { mNotificationIconAreaController.setIsolatedIconLocation( mHeadsUpStatusBarView.getIconDrawingRect(), requireStateUpdate); Loading packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java +14 −5 Original line number Diff line number Diff line Loading @@ -247,7 +247,7 @@ public class NotificationPanelView extends PanelView implements private int mStackScrollerMeasuringPass; private ArrayList<Consumer<ExpandableNotificationRow>> mTrackingHeadsUpListeners = new ArrayList<>(); private Runnable mVerticalTranslationListener; private ArrayList<Runnable> mVerticalTranslationListener = new ArrayList<>(); private HeadsUpAppearanceController mHeadsUpAppearanceController; public NotificationPanelView(Context context, AttributeSet attrs) { Loading Loading @@ -2431,8 +2431,9 @@ public class NotificationPanelView extends PanelView implements protected void setVerticalPanelTranslation(float translation) { mNotificationStackScroller.setTranslationX(translation); mQsFrame.setTranslationX(translation); if (mVerticalTranslationListener != null) { mVerticalTranslationListener.run(); int size = mVerticalTranslationListener.size(); for (int i = 0; i < size; i++) { mVerticalTranslationListener.get(i).run(); } } Loading Loading @@ -2744,8 +2745,16 @@ public class NotificationPanelView extends PanelView implements mTrackingHeadsUpListeners.add(listener); } public void setVerticalTranslationListener(Runnable verticalTranslationListener) { mVerticalTranslationListener = verticalTranslationListener; public void removeTrackingHeadsUpListener(Consumer<ExpandableNotificationRow> listener) { mTrackingHeadsUpListeners.remove(listener); } public void addVerticalTranslationListener(Runnable verticalTranslationListener) { mVerticalTranslationListener.add(verticalTranslationListener); } public void removeVerticalTranslationListener(Runnable verticalTranslationListener) { mVerticalTranslationListener.remove(verticalTranslationListener); } public void setHeadsUpAppearanceController( Loading packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +4 −0 Original line number Diff line number Diff line Loading @@ -809,6 +809,10 @@ public class StatusBar extends SystemUI implements DemoMode, mStatusBarView.setPanel(mNotificationPanel); mStatusBarView.setScrimController(mScrimController); mStatusBarView.setBouncerShowing(mBouncerShowing); if (mHeadsUpAppearanceController != null) { // This view is being recreated, let's destroy the old one mHeadsUpAppearanceController.destroy(); } mHeadsUpAppearanceController = new HeadsUpAppearanceController( mNotificationIconAreaController, mHeadsUpManager, mStatusBarWindow); setAreThereNotifications(); Loading packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java +7 −0 Original line number Diff line number Diff line Loading @@ -4531,6 +4531,13 @@ public class NotificationStackScrollLayout extends ViewGroup mExpandedHeightListeners.add(listener); } /** * Stop a listener from listening to the expandedHeight. */ public void removeOnExpandedHeightListener(BiConsumer<Float, Float> listener) { mExpandedHeightListeners.remove(listener); } /** * A listener that is notified when the empty space below the notifications is clicked on */ Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceControllerTest.java +27 −3 Original line number Diff line number Diff line Loading @@ -16,8 +16,11 @@ package com.android.systemui.statusbar.phone; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyObject; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; Loading @@ -26,6 +29,7 @@ import android.support.test.runner.AndroidJUnit4; import android.view.View; import android.widget.TextView; import com.android.systemui.Dependency; import com.android.systemui.SysuiTestCase; import com.android.systemui.TestableDependency; import com.android.systemui.statusbar.CommandQueue; Loading @@ -46,6 +50,10 @@ import java.util.HashSet; @RunWith(AndroidJUnit4.class) public class HeadsUpAppearanceControllerTest extends SysuiTestCase { private final NotificationStackScrollLayout mStackScroller = mock(NotificationStackScrollLayout.class); private final NotificationPanelView mPanelView = mock(NotificationPanelView.class); private final DarkIconDispatcher mDarkIconDispatcher = mock(DarkIconDispatcher.class); private HeadsUpAppearanceController mHeadsUpAppearanceController; private ExpandableNotificationRow mFirst; private HeadsUpStatusBarView mHeadsUpStatusBarView; Loading @@ -55,7 +63,7 @@ public class HeadsUpAppearanceControllerTest extends SysuiTestCase { public void setUp() throws Exception { NotificationTestHelper testHelper = new NotificationTestHelper(getContext()); mFirst = testHelper.createRow(); mDependency.injectMockDependency(DarkIconDispatcher.class); mDependency.injectTestDependency(DarkIconDispatcher.class, mDarkIconDispatcher); mHeadsUpStatusBarView = new HeadsUpStatusBarView(mContext, mock(View.class), mock(TextView.class)); mHeadsUpManager = mock(HeadsUpManagerPhone.class); Loading @@ -63,8 +71,8 @@ public class HeadsUpAppearanceControllerTest extends SysuiTestCase { mock(NotificationIconAreaController.class), mHeadsUpManager, mHeadsUpStatusBarView, mock(NotificationStackScrollLayout.class), mock(NotificationPanelView.class), mStackScroller, mPanelView, new View(mContext)); mHeadsUpAppearanceController.setExpandedHeight(0.0f, 0.0f); } Loading Loading @@ -110,4 +118,20 @@ public class HeadsUpAppearanceControllerTest extends SysuiTestCase { mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst); Assert.assertEquals(mFirst.getHeaderVisibleAmount(), 1.0f, 0.0f); } @Test public void testDestroy() { reset(mHeadsUpManager); reset(mDarkIconDispatcher); reset(mPanelView); reset(mStackScroller); mHeadsUpAppearanceController.destroy(); verify(mHeadsUpManager).removeListener(any()); verify(mDarkIconDispatcher).removeDarkReceiver((DarkIconDispatcher.DarkReceiver) any()); verify(mPanelView).removeVerticalTranslationListener(any()); verify(mPanelView).removeTrackingHeadsUpListener(any()); verify(mPanelView).setHeadsUpAppearanceController(any()); verify(mStackScroller).removeOnExpandedHeightListener(any()); verify(mStackScroller).removeOnLayoutChangeListener(any()); } } Loading
packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceController.java +28 −6 Original line number Diff line number Diff line Loading @@ -30,6 +30,9 @@ import com.android.systemui.statusbar.policy.DarkIconDispatcher; import com.android.systemui.statusbar.policy.OnHeadsUpChangedListener; import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; import java.util.function.BiConsumer; import java.util.function.Consumer; /** * Controls the appearance of heads up notifications in the icon area and the header itself. */ Loading @@ -43,11 +46,19 @@ class HeadsUpAppearanceController implements OnHeadsUpChangedListener, private final HeadsUpStatusBarView mHeadsUpStatusBarView; private final View mClockView; private final DarkIconDispatcher mDarkIconDispatcher; private final NotificationPanelView mPanelView; private final Consumer<ExpandableNotificationRow> mSetTrackingHeadsUp = this::setTrackingHeadsUp; private final Runnable mUpdatePanelTranslation = this::updatePanelTranslation; private final BiConsumer<Float, Float> mSetExpandedHeight = this::setExpandedHeight; private float mExpandedHeight; private boolean mIsExpanded; private float mExpandFraction; private ExpandableNotificationRow mTrackedChild; private boolean mShown; private final View.OnLayoutChangeListener mStackScrollLayoutChangeListener = (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> updatePanelTranslation(); public HeadsUpAppearanceController( NotificationIconAreaController notificationIconAreaController, Loading Loading @@ -75,18 +86,29 @@ class HeadsUpAppearanceController implements OnHeadsUpChangedListener, headsUpStatusBarView.setOnDrawingRectChangedListener( () -> updateIsolatedIconLocation(true /* requireUpdate */)); mStackScroller = stackScroller; panelView.addTrackingHeadsUpListener(this::setTrackingHeadsUp); panelView.setVerticalTranslationListener(this::updatePanelTranslation); mPanelView = panelView; panelView.addTrackingHeadsUpListener(mSetTrackingHeadsUp); panelView.addVerticalTranslationListener(mUpdatePanelTranslation); panelView.setHeadsUpAppearanceController(this); mStackScroller.addOnExpandedHeightListener(this::setExpandedHeight); mStackScroller.addOnLayoutChangeListener( (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> updatePanelTranslation()); mStackScroller.addOnExpandedHeightListener(mSetExpandedHeight); mStackScroller.addOnLayoutChangeListener(mStackScrollLayoutChangeListener); mClockView = clockView; mDarkIconDispatcher = Dependency.get(DarkIconDispatcher.class); mDarkIconDispatcher.addDarkReceiver(this); } public void destroy() { mHeadsUpManager.removeListener(this); mHeadsUpStatusBarView.setOnDrawingRectChangedListener(null); mPanelView.removeTrackingHeadsUpListener(mSetTrackingHeadsUp); mPanelView.removeVerticalTranslationListener(mUpdatePanelTranslation); mPanelView.setHeadsUpAppearanceController(null); mStackScroller.removeOnExpandedHeightListener(mSetExpandedHeight); mStackScroller.removeOnLayoutChangeListener(mStackScrollLayoutChangeListener); mDarkIconDispatcher.removeDarkReceiver(this); } private void updateIsolatedIconLocation(boolean requireStateUpdate) { mNotificationIconAreaController.setIsolatedIconLocation( mHeadsUpStatusBarView.getIconDrawingRect(), requireStateUpdate); Loading
packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java +14 −5 Original line number Diff line number Diff line Loading @@ -247,7 +247,7 @@ public class NotificationPanelView extends PanelView implements private int mStackScrollerMeasuringPass; private ArrayList<Consumer<ExpandableNotificationRow>> mTrackingHeadsUpListeners = new ArrayList<>(); private Runnable mVerticalTranslationListener; private ArrayList<Runnable> mVerticalTranslationListener = new ArrayList<>(); private HeadsUpAppearanceController mHeadsUpAppearanceController; public NotificationPanelView(Context context, AttributeSet attrs) { Loading Loading @@ -2431,8 +2431,9 @@ public class NotificationPanelView extends PanelView implements protected void setVerticalPanelTranslation(float translation) { mNotificationStackScroller.setTranslationX(translation); mQsFrame.setTranslationX(translation); if (mVerticalTranslationListener != null) { mVerticalTranslationListener.run(); int size = mVerticalTranslationListener.size(); for (int i = 0; i < size; i++) { mVerticalTranslationListener.get(i).run(); } } Loading Loading @@ -2744,8 +2745,16 @@ public class NotificationPanelView extends PanelView implements mTrackingHeadsUpListeners.add(listener); } public void setVerticalTranslationListener(Runnable verticalTranslationListener) { mVerticalTranslationListener = verticalTranslationListener; public void removeTrackingHeadsUpListener(Consumer<ExpandableNotificationRow> listener) { mTrackingHeadsUpListeners.remove(listener); } public void addVerticalTranslationListener(Runnable verticalTranslationListener) { mVerticalTranslationListener.add(verticalTranslationListener); } public void removeVerticalTranslationListener(Runnable verticalTranslationListener) { mVerticalTranslationListener.remove(verticalTranslationListener); } public void setHeadsUpAppearanceController( Loading
packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +4 −0 Original line number Diff line number Diff line Loading @@ -809,6 +809,10 @@ public class StatusBar extends SystemUI implements DemoMode, mStatusBarView.setPanel(mNotificationPanel); mStatusBarView.setScrimController(mScrimController); mStatusBarView.setBouncerShowing(mBouncerShowing); if (mHeadsUpAppearanceController != null) { // This view is being recreated, let's destroy the old one mHeadsUpAppearanceController.destroy(); } mHeadsUpAppearanceController = new HeadsUpAppearanceController( mNotificationIconAreaController, mHeadsUpManager, mStatusBarWindow); setAreThereNotifications(); Loading
packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java +7 −0 Original line number Diff line number Diff line Loading @@ -4531,6 +4531,13 @@ public class NotificationStackScrollLayout extends ViewGroup mExpandedHeightListeners.add(listener); } /** * Stop a listener from listening to the expandedHeight. */ public void removeOnExpandedHeightListener(BiConsumer<Float, Float> listener) { mExpandedHeightListeners.remove(listener); } /** * A listener that is notified when the empty space below the notifications is clicked on */ Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceControllerTest.java +27 −3 Original line number Diff line number Diff line Loading @@ -16,8 +16,11 @@ package com.android.systemui.statusbar.phone; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyObject; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; Loading @@ -26,6 +29,7 @@ import android.support.test.runner.AndroidJUnit4; import android.view.View; import android.widget.TextView; import com.android.systemui.Dependency; import com.android.systemui.SysuiTestCase; import com.android.systemui.TestableDependency; import com.android.systemui.statusbar.CommandQueue; Loading @@ -46,6 +50,10 @@ import java.util.HashSet; @RunWith(AndroidJUnit4.class) public class HeadsUpAppearanceControllerTest extends SysuiTestCase { private final NotificationStackScrollLayout mStackScroller = mock(NotificationStackScrollLayout.class); private final NotificationPanelView mPanelView = mock(NotificationPanelView.class); private final DarkIconDispatcher mDarkIconDispatcher = mock(DarkIconDispatcher.class); private HeadsUpAppearanceController mHeadsUpAppearanceController; private ExpandableNotificationRow mFirst; private HeadsUpStatusBarView mHeadsUpStatusBarView; Loading @@ -55,7 +63,7 @@ public class HeadsUpAppearanceControllerTest extends SysuiTestCase { public void setUp() throws Exception { NotificationTestHelper testHelper = new NotificationTestHelper(getContext()); mFirst = testHelper.createRow(); mDependency.injectMockDependency(DarkIconDispatcher.class); mDependency.injectTestDependency(DarkIconDispatcher.class, mDarkIconDispatcher); mHeadsUpStatusBarView = new HeadsUpStatusBarView(mContext, mock(View.class), mock(TextView.class)); mHeadsUpManager = mock(HeadsUpManagerPhone.class); Loading @@ -63,8 +71,8 @@ public class HeadsUpAppearanceControllerTest extends SysuiTestCase { mock(NotificationIconAreaController.class), mHeadsUpManager, mHeadsUpStatusBarView, mock(NotificationStackScrollLayout.class), mock(NotificationPanelView.class), mStackScroller, mPanelView, new View(mContext)); mHeadsUpAppearanceController.setExpandedHeight(0.0f, 0.0f); } Loading Loading @@ -110,4 +118,20 @@ public class HeadsUpAppearanceControllerTest extends SysuiTestCase { mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst); Assert.assertEquals(mFirst.getHeaderVisibleAmount(), 1.0f, 0.0f); } @Test public void testDestroy() { reset(mHeadsUpManager); reset(mDarkIconDispatcher); reset(mPanelView); reset(mStackScroller); mHeadsUpAppearanceController.destroy(); verify(mHeadsUpManager).removeListener(any()); verify(mDarkIconDispatcher).removeDarkReceiver((DarkIconDispatcher.DarkReceiver) any()); verify(mPanelView).removeVerticalTranslationListener(any()); verify(mPanelView).removeTrackingHeadsUpListener(any()); verify(mPanelView).setHeadsUpAppearanceController(any()); verify(mStackScroller).removeOnExpandedHeightListener(any()); verify(mStackScroller).removeOnLayoutChangeListener(any()); } }