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

Commit 098e210a authored by Caitlin Cassidy's avatar Caitlin Cassidy
Browse files

[Status Bar Refactor] 2/3: Remove

HeadsUpAppearanceController#readFrom(oldController).

Instead, the old values are read from the parent controllers. This CL
plus the next CL will allow us to not keep track of old
HeadsUpAppearanceController instances; instead, each
HeadsUpAppearanceController knows how to correctly set itself up and
tear itself down without needing the old controller.

Bug: 205609837
Test: atest SystemUITests
Test: manual (verified via logging that new controller gets old values)
Change-Id: I15adc79982b5b7ca264e2bb45e92ba48b9844c1a
parent 7f4af891
Loading
Loading
Loading
Loading
+8 −0
Original line number Original line Diff line number Diff line
@@ -6092,6 +6092,14 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
        return mExpandHelperCallback;
        return mExpandHelperCallback;
    }
    }


    float getAppearFraction() {
        return mLastSentAppear;
    }

    float getExpandedHeight() {
        return mLastSentExpandedHeight;
    }

    /** Enum for selecting some or all notification rows (does not included non-notif views). */
    /** Enum for selecting some or all notification rows (does not included non-notif views). */
    @Retention(SOURCE)
    @Retention(SOURCE)
    @IntDef({ROWS_ALL, ROWS_HIGH_PRIORITY, ROWS_GENTLE})
    @IntDef({ROWS_ALL, ROWS_HIGH_PRIORITY, ROWS_GENTLE})
+8 −0
Original line number Original line Diff line number Diff line
@@ -858,6 +858,14 @@ public class NotificationStackScrollLayoutController {
        mView.setHeadsUpAppearanceController(controller);
        mView.setHeadsUpAppearanceController(controller);
    }
    }


    public float getAppearFraction() {
        return mView.getAppearFraction();
    }

    public float getExpandedHeight() {
        return mView.getExpandedHeight();
    }

    public void requestLayout() {
    public void requestLayout() {
        mView.requestLayout();
        mView.requestLayout();
    }
    }
+19 −17
Original line number Original line Diff line number Diff line
@@ -72,8 +72,6 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener,
    @VisibleForTesting
    @VisibleForTesting
    float mExpandedHeight;
    float mExpandedHeight;
    @VisibleForTesting
    @VisibleForTesting
    boolean mIsExpanded;
    @VisibleForTesting
    float mAppearFraction;
    float mAppearFraction;
    private ExpandableNotificationRow mTrackedChild;
    private ExpandableNotificationRow mTrackedChild;
    private boolean mShown;
    private boolean mShown;
@@ -134,6 +132,15 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener,
        mCenteredIconView = centeredIconView;
        mCenteredIconView = centeredIconView;
        headsUpStatusBarView.setOnDrawingRectChangedListener(
        headsUpStatusBarView.setOnDrawingRectChangedListener(
                () -> updateIsolatedIconLocation(true /* requireUpdate */));
                () -> updateIsolatedIconLocation(true /* requireUpdate */));

        // We may be mid-HUN-expansion when this controller is re-created (for example, if the user
        // has started pulling down the notification shade from the HUN and then the font size
        // changes). We need to re-fetch these values since they're used to correctly display the
        // HUN during this shade expansion.
        mTrackedChild = notificationPanelViewController.getTrackedHeadsUpNotification();
        mAppearFraction = stackScrollerController.getAppearFraction();
        mExpandedHeight = stackScrollerController.getExpandedHeight();

        mStackScrollerController = stackScrollerController;
        mStackScrollerController = stackScrollerController;
        mNotificationPanelViewController = notificationPanelViewController;
        mNotificationPanelViewController = notificationPanelViewController;
        notificationPanelViewController.addTrackingHeadsUpListener(mSetTrackingHeadsUp);
        notificationPanelViewController.addTrackingHeadsUpListener(mSetTrackingHeadsUp);
@@ -201,12 +208,12 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener,
                // no heads up anymore, lets start the disappear animation
                // no heads up anymore, lets start the disappear animation


                setShown(false);
                setShown(false);
                animateIsolation = !mIsExpanded;
                animateIsolation = !isExpanded();
            } else if (previousEntry == null) {
            } else if (previousEntry == null) {
                // We now have a headsUp and didn't have one before. Let's start the disappear
                // We now have a headsUp and didn't have one before. Let's start the disappear
                // animation
                // animation
                setShown(true);
                setShown(true);
                animateIsolation = !mIsExpanded;
                animateIsolation = !isExpanded();
            }
            }
            updateIsolatedIconLocation(false /* requireUpdate */);
            updateIsolatedIconLocation(false /* requireUpdate */);
            mNotificationIconAreaController.showIconIsolated(newEntry == null ? null
            mNotificationIconAreaController.showIconIsolated(newEntry == null ? null
@@ -319,7 +326,7 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener,
     */
     */
    public boolean shouldBeVisible() {
    public boolean shouldBeVisible() {
        boolean notificationsShown = !mWakeUpCoordinator.getNotificationsFullyHidden();
        boolean notificationsShown = !mWakeUpCoordinator.getNotificationsFullyHidden();
        boolean canShow = !mIsExpanded && notificationsShown;
        boolean canShow = !isExpanded() && notificationsShown;
        if (mBypassController.getBypassEnabled() &&
        if (mBypassController.getBypassEnabled() &&
                (mStatusBarStateController.getState() == StatusBarState.KEYGUARD
                (mStatusBarStateController.getState() == StatusBarState.KEYGUARD
                        || mKeyguardStateController.isKeyguardGoingAway())
                        || mKeyguardStateController.isKeyguardGoingAway())
@@ -337,17 +344,17 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener,


    public void setAppearFraction(float expandedHeight, float appearFraction) {
    public void setAppearFraction(float expandedHeight, float appearFraction) {
        boolean changed = expandedHeight != mExpandedHeight;
        boolean changed = expandedHeight != mExpandedHeight;
        boolean oldIsExpanded = isExpanded();

        mExpandedHeight = expandedHeight;
        mExpandedHeight = expandedHeight;
        mAppearFraction = appearFraction;
        mAppearFraction = appearFraction;
        boolean isExpanded = expandedHeight > 0;
        // We only notify if the expandedHeight changed and not on the appearFraction, since
        // We only notify if the expandedHeight changed and not on the appearFraction, since
        // otherwise we may run into an infinite loop where the panel and this are constantly
        // otherwise we may run into an infinite loop where the panel and this are constantly
        // updating themselves over just a small fraction
        // updating themselves over just a small fraction
        if (changed) {
        if (changed) {
            updateHeadsUpHeaders();
            updateHeadsUpHeaders();
        }
        }
        if (isExpanded != mIsExpanded) {
        if (isExpanded() != oldIsExpanded) {
            mIsExpanded = isExpanded;
            updateTopEntry();
            updateTopEntry();
        }
        }
    }
    }
@@ -367,6 +374,10 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener,
        }
        }
    }
    }


    private boolean isExpanded() {
        return mExpandedHeight > 0;
    }

    private void updateHeadsUpHeaders() {
    private void updateHeadsUpHeaders() {
        mHeadsUpManager.getAllEntries().forEach(entry -> {
        mHeadsUpManager.getAllEntries().forEach(entry -> {
            updateHeader(entry);
            updateHeader(entry);
@@ -392,15 +403,6 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener,
        updateTopEntry();
        updateTopEntry();
    }
    }


    void readFrom(HeadsUpAppearanceController oldController) {
        if (oldController != null) {
            mTrackedChild = oldController.mTrackedChild;
            mExpandedHeight = oldController.mExpandedHeight;
            mIsExpanded = oldController.mIsExpanded;
            mAppearFraction = oldController.mAppearFraction;
        }
    }

    @Override
    @Override
    public void onFullyHiddenChanged(boolean isFullyHidden) {
    public void onFullyHiddenChanged(boolean isFullyHidden) {
        updateTopEntry();
        updateTopEntry();
+17 −6
Original line number Original line Diff line number Diff line
@@ -88,6 +88,7 @@ import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.FrameLayout;
import android.widget.FrameLayout;


import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintSet;
import androidx.constraintlayout.widget.ConstraintSet;


import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
@@ -451,9 +452,13 @@ public class NotificationPanelViewController extends PanelViewController {
    private boolean mUserSetupComplete;
    private boolean mUserSetupComplete;
    private boolean mHideIconsDuringLaunchAnimation = true;
    private boolean mHideIconsDuringLaunchAnimation = true;
    private int mStackScrollerMeasuringPass;
    private int mStackScrollerMeasuringPass;
    private ArrayList<Consumer<ExpandableNotificationRow>>
    /**
            mTrackingHeadsUpListeners =
     * Non-null if there's a heads-up notification that we're currently tracking the position of.
            new ArrayList<>();
     */
    @Nullable
    private ExpandableNotificationRow mTrackedHeadsUpNotification;
    private final ArrayList<Consumer<ExpandableNotificationRow>>
            mTrackingHeadsUpListeners = new ArrayList<>();
    private HeadsUpAppearanceController mHeadsUpAppearanceController;
    private HeadsUpAppearanceController mHeadsUpAppearanceController;


    private int mPanelAlpha;
    private int mPanelAlpha;
@@ -3050,18 +3055,24 @@ public class NotificationPanelViewController extends PanelViewController {
        mQsExpandImmediate = false;
        mQsExpandImmediate = false;
        mNotificationStackScrollLayoutController.setShouldShowShelfOnly(false);
        mNotificationStackScrollLayoutController.setShouldShowShelfOnly(false);
        mTwoFingerQsExpandPossible = false;
        mTwoFingerQsExpandPossible = false;
        notifyListenersTrackingHeadsUp(null);
        updateTrackingHeadsUp(null);
        mExpandingFromHeadsUp = false;
        mExpandingFromHeadsUp = false;
        setPanelScrimMinFraction(0.0f);
        setPanelScrimMinFraction(0.0f);
    }
    }


    private void notifyListenersTrackingHeadsUp(ExpandableNotificationRow pickedChild) {
    private void updateTrackingHeadsUp(@Nullable ExpandableNotificationRow pickedChild) {
        mTrackedHeadsUpNotification = pickedChild;
        for (int i = 0; i < mTrackingHeadsUpListeners.size(); i++) {
        for (int i = 0; i < mTrackingHeadsUpListeners.size(); i++) {
            Consumer<ExpandableNotificationRow> listener = mTrackingHeadsUpListeners.get(i);
            Consumer<ExpandableNotificationRow> listener = mTrackingHeadsUpListeners.get(i);
            listener.accept(pickedChild);
            listener.accept(pickedChild);
        }
        }
    }
    }


    @Nullable
    public ExpandableNotificationRow getTrackedHeadsUpNotification() {
        return mTrackedHeadsUpNotification;
    }

    private void setListening(boolean listening) {
    private void setListening(boolean listening) {
        mKeyguardStatusBarViewController.setBatteryListening(listening);
        mKeyguardStatusBarViewController.setBatteryListening(listening);
        if (mQs == null) return;
        if (mQs == null) return;
@@ -3298,7 +3309,7 @@ public class NotificationPanelViewController extends PanelViewController {


    public void setTrackedHeadsUp(ExpandableNotificationRow pickedChild) {
    public void setTrackedHeadsUp(ExpandableNotificationRow pickedChild) {
        if (pickedChild != null) {
        if (pickedChild != null) {
            notifyListenersTrackingHeadsUp(pickedChild);
            updateTrackingHeadsUp(pickedChild);
            mExpandingFromHeadsUp = true;
            mExpandingFromHeadsUp = true;
        }
        }
        // otherwise we update the state when the expansion is finished
        // otherwise we update the state when the expansion is finished
+0 −4
Original line number Original line Diff line number Diff line
@@ -1164,7 +1164,6 @@ public class StatusBar extends SystemUI implements
                    mNotificationPanelViewController.updatePanelExpansionAndVisibility();
                    mNotificationPanelViewController.updatePanelExpansionAndVisibility();
                    setBouncerShowingForStatusBarComponents(mBouncerShowing);
                    setBouncerShowingForStatusBarComponents(mBouncerShowing);


                    HeadsUpAppearanceController oldController = mHeadsUpAppearanceController;
                    if (mHeadsUpAppearanceController != null) {
                    if (mHeadsUpAppearanceController != null) {
                        // This view is being recreated, let's destroy the old one
                        // This view is being recreated, let's destroy the old one
                        // TODO(b/205609837): Automatically destroy the old controller so that this
                        // TODO(b/205609837): Automatically destroy the old controller so that this
@@ -1175,9 +1174,6 @@ public class StatusBar extends SystemUI implements
                    // TODO(b/205609837): Migrate this to StatusBarFragmentComponent.
                    // TODO(b/205609837): Migrate this to StatusBarFragmentComponent.
                    mHeadsUpAppearanceController =
                    mHeadsUpAppearanceController =
                            statusBarFragmentComponent.getHeadsUpAppearanceController();
                            statusBarFragmentComponent.getHeadsUpAppearanceController();
                    // TODO(b/205609837): Delete this readFrom method so that this class doesn't
                    //  need to hold a reference to the old controller.
                    mHeadsUpAppearanceController.readFrom(oldController);


                    mLightsOutNotifController.setLightsOutNotifView(
                    mLightsOutNotifController.setLightsOutNotifView(
                            mStatusBarView.findViewById(R.id.notification_lights_out));
                            mStatusBarView.findViewById(R.id.notification_lights_out));
Loading