Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 15e52540 authored by Selim Cinek's avatar Selim Cinek Committed by android-build-merger
Browse files

Merge "Fixed an issue where the heads-up icon location was wrong" into pi-dev

am: 194cca21

Change-Id: I3bbf2e2eb3882a8a13e456df1bf143cc823c8eec
parents 3da0b8ef 194cca21
Loading
Loading
Loading
Loading
+28 −6
Original line number Original line Diff line number Diff line
@@ -30,6 +30,9 @@ import com.android.systemui.statusbar.policy.DarkIconDispatcher;
import com.android.systemui.statusbar.policy.OnHeadsUpChangedListener;
import com.android.systemui.statusbar.policy.OnHeadsUpChangedListener;
import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
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.
 * Controls the appearance of heads up notifications in the icon area and the header itself.
 */
 */
@@ -43,11 +46,19 @@ class HeadsUpAppearanceController implements OnHeadsUpChangedListener,
    private final HeadsUpStatusBarView mHeadsUpStatusBarView;
    private final HeadsUpStatusBarView mHeadsUpStatusBarView;
    private final View mClockView;
    private final View mClockView;
    private final DarkIconDispatcher mDarkIconDispatcher;
    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 float mExpandedHeight;
    private boolean mIsExpanded;
    private boolean mIsExpanded;
    private float mExpandFraction;
    private float mExpandFraction;
    private ExpandableNotificationRow mTrackedChild;
    private ExpandableNotificationRow mTrackedChild;
    private boolean mShown;
    private boolean mShown;
    private final View.OnLayoutChangeListener mStackScrollLayoutChangeListener =
            (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom)
                    -> updatePanelTranslation();


    public HeadsUpAppearanceController(
    public HeadsUpAppearanceController(
            NotificationIconAreaController notificationIconAreaController,
            NotificationIconAreaController notificationIconAreaController,
@@ -75,18 +86,29 @@ class HeadsUpAppearanceController implements OnHeadsUpChangedListener,
        headsUpStatusBarView.setOnDrawingRectChangedListener(
        headsUpStatusBarView.setOnDrawingRectChangedListener(
                () -> updateIsolatedIconLocation(true /* requireUpdate */));
                () -> updateIsolatedIconLocation(true /* requireUpdate */));
        mStackScroller = stackScroller;
        mStackScroller = stackScroller;
        panelView.addTrackingHeadsUpListener(this::setTrackingHeadsUp);
        mPanelView = panelView;
        panelView.setVerticalTranslationListener(this::updatePanelTranslation);
        panelView.addTrackingHeadsUpListener(mSetTrackingHeadsUp);
        panelView.addVerticalTranslationListener(mUpdatePanelTranslation);
        panelView.setHeadsUpAppearanceController(this);
        panelView.setHeadsUpAppearanceController(this);
        mStackScroller.addOnExpandedHeightListener(this::setExpandedHeight);
        mStackScroller.addOnExpandedHeightListener(mSetExpandedHeight);
        mStackScroller.addOnLayoutChangeListener(
        mStackScroller.addOnLayoutChangeListener(mStackScrollLayoutChangeListener);
                (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom)
                        -> updatePanelTranslation());
        mClockView = clockView;
        mClockView = clockView;
        mDarkIconDispatcher = Dependency.get(DarkIconDispatcher.class);
        mDarkIconDispatcher = Dependency.get(DarkIconDispatcher.class);
        mDarkIconDispatcher.addDarkReceiver(this);
        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) {
    private void updateIsolatedIconLocation(boolean requireStateUpdate) {
        mNotificationIconAreaController.setIsolatedIconLocation(
        mNotificationIconAreaController.setIsolatedIconLocation(
                mHeadsUpStatusBarView.getIconDrawingRect(), requireStateUpdate);
                mHeadsUpStatusBarView.getIconDrawingRect(), requireStateUpdate);
+14 −5
Original line number Original line Diff line number Diff line
@@ -247,7 +247,7 @@ public class NotificationPanelView extends PanelView implements
    private int mStackScrollerMeasuringPass;
    private int mStackScrollerMeasuringPass;
    private ArrayList<Consumer<ExpandableNotificationRow>> mTrackingHeadsUpListeners
    private ArrayList<Consumer<ExpandableNotificationRow>> mTrackingHeadsUpListeners
            = new ArrayList<>();
            = new ArrayList<>();
    private Runnable mVerticalTranslationListener;
    private ArrayList<Runnable> mVerticalTranslationListener = new ArrayList<>();
    private HeadsUpAppearanceController mHeadsUpAppearanceController;
    private HeadsUpAppearanceController mHeadsUpAppearanceController;


    public NotificationPanelView(Context context, AttributeSet attrs) {
    public NotificationPanelView(Context context, AttributeSet attrs) {
@@ -2431,8 +2431,9 @@ public class NotificationPanelView extends PanelView implements
    protected void setVerticalPanelTranslation(float translation) {
    protected void setVerticalPanelTranslation(float translation) {
        mNotificationStackScroller.setTranslationX(translation);
        mNotificationStackScroller.setTranslationX(translation);
        mQsFrame.setTranslationX(translation);
        mQsFrame.setTranslationX(translation);
        if (mVerticalTranslationListener != null) {
        int size = mVerticalTranslationListener.size();
            mVerticalTranslationListener.run();
        for (int i = 0; i < size; i++) {
            mVerticalTranslationListener.get(i).run();
        }
        }
    }
    }


@@ -2744,8 +2745,16 @@ public class NotificationPanelView extends PanelView implements
        mTrackingHeadsUpListeners.add(listener);
        mTrackingHeadsUpListeners.add(listener);
    }
    }


    public void setVerticalTranslationListener(Runnable verticalTranslationListener) {
    public void removeTrackingHeadsUpListener(Consumer<ExpandableNotificationRow> listener) {
        mVerticalTranslationListener = verticalTranslationListener;
        mTrackingHeadsUpListeners.remove(listener);
    }

    public void addVerticalTranslationListener(Runnable verticalTranslationListener) {
        mVerticalTranslationListener.add(verticalTranslationListener);
    }

    public void removeVerticalTranslationListener(Runnable verticalTranslationListener) {
        mVerticalTranslationListener.remove(verticalTranslationListener);
    }
    }


    public void setHeadsUpAppearanceController(
    public void setHeadsUpAppearanceController(
+4 −0
Original line number Original line Diff line number Diff line
@@ -809,6 +809,10 @@ public class StatusBar extends SystemUI implements DemoMode,
                    mStatusBarView.setPanel(mNotificationPanel);
                    mStatusBarView.setPanel(mNotificationPanel);
                    mStatusBarView.setScrimController(mScrimController);
                    mStatusBarView.setScrimController(mScrimController);
                    mStatusBarView.setBouncerShowing(mBouncerShowing);
                    mStatusBarView.setBouncerShowing(mBouncerShowing);
                    if (mHeadsUpAppearanceController != null) {
                        // This view is being recreated, let's destroy the old one
                        mHeadsUpAppearanceController.destroy();
                    }
                    mHeadsUpAppearanceController = new HeadsUpAppearanceController(
                    mHeadsUpAppearanceController = new HeadsUpAppearanceController(
                            mNotificationIconAreaController, mHeadsUpManager, mStatusBarWindow);
                            mNotificationIconAreaController, mHeadsUpManager, mStatusBarWindow);
                    setAreThereNotifications();
                    setAreThereNotifications();
+7 −0
Original line number Original line Diff line number Diff line
@@ -4531,6 +4531,13 @@ public class NotificationStackScrollLayout extends ViewGroup
        mExpandedHeightListeners.add(listener);
        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
     * A listener that is notified when the empty space below the notifications is clicked on
     */
     */
+27 −3
Original line number Original line Diff line number Diff line
@@ -16,8 +16,11 @@


package com.android.systemui.statusbar.phone;
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.atLeast;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.when;


@@ -26,6 +29,7 @@ import android.support.test.runner.AndroidJUnit4;
import android.view.View;
import android.view.View;
import android.widget.TextView;
import android.widget.TextView;


import com.android.systemui.Dependency;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.TestableDependency;
import com.android.systemui.TestableDependency;
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.CommandQueue;
@@ -46,6 +50,10 @@ import java.util.HashSet;
@RunWith(AndroidJUnit4.class)
@RunWith(AndroidJUnit4.class)
public class HeadsUpAppearanceControllerTest extends SysuiTestCase {
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 HeadsUpAppearanceController mHeadsUpAppearanceController;
    private ExpandableNotificationRow mFirst;
    private ExpandableNotificationRow mFirst;
    private HeadsUpStatusBarView mHeadsUpStatusBarView;
    private HeadsUpStatusBarView mHeadsUpStatusBarView;
@@ -55,7 +63,7 @@ public class HeadsUpAppearanceControllerTest extends SysuiTestCase {
    public void setUp() throws Exception {
    public void setUp() throws Exception {
        NotificationTestHelper testHelper = new NotificationTestHelper(getContext());
        NotificationTestHelper testHelper = new NotificationTestHelper(getContext());
        mFirst = testHelper.createRow();
        mFirst = testHelper.createRow();
        mDependency.injectMockDependency(DarkIconDispatcher.class);
        mDependency.injectTestDependency(DarkIconDispatcher.class, mDarkIconDispatcher);
        mHeadsUpStatusBarView = new HeadsUpStatusBarView(mContext, mock(View.class),
        mHeadsUpStatusBarView = new HeadsUpStatusBarView(mContext, mock(View.class),
                mock(TextView.class));
                mock(TextView.class));
        mHeadsUpManager = mock(HeadsUpManagerPhone.class);
        mHeadsUpManager = mock(HeadsUpManagerPhone.class);
@@ -63,8 +71,8 @@ public class HeadsUpAppearanceControllerTest extends SysuiTestCase {
                mock(NotificationIconAreaController.class),
                mock(NotificationIconAreaController.class),
                mHeadsUpManager,
                mHeadsUpManager,
                mHeadsUpStatusBarView,
                mHeadsUpStatusBarView,
                mock(NotificationStackScrollLayout.class),
                mStackScroller,
                mock(NotificationPanelView.class),
                mPanelView,
                new View(mContext));
                new View(mContext));
        mHeadsUpAppearanceController.setExpandedHeight(0.0f, 0.0f);
        mHeadsUpAppearanceController.setExpandedHeight(0.0f, 0.0f);
    }
    }
@@ -110,4 +118,20 @@ public class HeadsUpAppearanceControllerTest extends SysuiTestCase {
        mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst);
        mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst);
        Assert.assertEquals(mFirst.getHeaderVisibleAmount(), 1.0f, 0.0f);
        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());
    }
}
}