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

Commit ed48c8aa authored by Selim Cinek's avatar Selim Cinek
Browse files

Fixed the calculation of how many views to show on the lockscreen

The gapHeight wasn't taken into account as well as any potentially
visible headers neither. The media view was simply ignored, so
when then calculating the content height we had one view too few.
This also improves some bordercases of the measurement which
could be wrong. We can't use the shelf to do the gap calculations
but need to use the actual views.

Fixes: 156914265
Fixes: 157233336
Test: Add notifications and media, observe notification visible.
Change-Id: I92ef47153b5566c713004aed729c8761618ddf5e
parent 54ef7be3
Loading
Loading
Loading
Loading
+25 −5
Original line number Diff line number Diff line
@@ -2460,9 +2460,12 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd
                    && !expandableView.hasNoContentHeight() && !footerViewOnLockScreen) {
                boolean limitReached = maxDisplayedNotifications != -1
                        && numShownItems >= maxDisplayedNotifications;
                final float viewHeight;
                if (limitReached) {
                    expandableView = mShelf;
                    viewHeight = mShelf.getIntrinsicHeight();
                    finish = true;
                } else {
                    viewHeight = expandableView.getIntrinsicHeight();
                }
                float increasedPaddingAmount = expandableView.getIncreasedPaddingAmount();
                float padding;
@@ -2493,11 +2496,9 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd
                if (height != 0) {
                    height += padding;
                }
                height += mStackScrollAlgorithm.getGapHeightForChild(mSectionsManager,
                        mAmbientState.getAnchorViewIndex(), numShownItems, expandableView,
                        previousView);
                height += calculateGapHeight(previousView, expandableView, numShownItems);
                previousPaddingAmount = increasedPaddingAmount;
                height += expandableView.getIntrinsicHeight();
                height += viewHeight;
                numShownItems++;
                previousView = expandableView;
                if (finish) {
@@ -2515,6 +2516,25 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd
        mAmbientState.setLayoutMaxHeight(mContentHeight);
    }

    /**
     * Calculate the gap height between two different views
     *
     * @param previous the previousView
     * @param current the currentView
     * @param visibleIndex the visible index in the list
     *
     * @return the gap height needed before the current view
     */
    public float calculateGapHeight(
            ExpandableView previous,
            ExpandableView current,
            int visibleIndex
    ) {
       return mStackScrollAlgorithm.getGapHeightForChild(mSectionsManager,
                mAmbientState.getAnchorViewIndex(), visibleIndex, current,
                previous);
    }

    @Override
    @ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
    public boolean hasPulsingNotifications() {
+58 −19
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.systemui.statusbar.phone;

import static android.view.View.GONE;

import static com.android.systemui.statusbar.notification.ActivityLaunchAnimator.ExpandAnimationParameters;
import static com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout.ROWS_ALL;

@@ -102,6 +104,7 @@ import com.android.systemui.statusbar.notification.row.ActivatableNotificationVi
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.notification.row.ExpandableView;
import com.android.systemui.statusbar.notification.stack.AnimationProperties;
import com.android.systemui.statusbar.notification.stack.MediaHeaderView;
import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout;
import com.android.systemui.statusbar.notification.stack.StackStateAnimator;
import com.android.systemui.statusbar.phone.dagger.StatusBarComponent;
@@ -848,34 +851,25 @@ public class NotificationPanelViewController extends PanelViewController {
                        mIndicationBottomPadding, mAmbientIndicationBottomPadding)
                        - mKeyguardStatusView.getLogoutButtonHeight();
        int count = 0;
        ExpandableView previousView = null;
        for (int i = 0; i < mNotificationStackScroller.getChildCount(); i++) {
            ExpandableView child = (ExpandableView) mNotificationStackScroller.getChildAt(i);
            if (!(child instanceof ExpandableNotificationRow)) {
            if (!canShowViewOnLockscreen(child)) {
                continue;
            }
            ExpandableNotificationRow row = (ExpandableNotificationRow) child;
            boolean
                    suppressedSummary =
                    mGroupManager != null && mGroupManager.isSummaryOfSuppressedGroup(
                            row.getEntry().getSbn());
            if (suppressedSummary) {
                continue;
            }
            if (!mLockscreenUserManager.shouldShowOnKeyguard(row.getEntry())) {
                continue;
            }
            if (row.isRemoved()) {
                continue;
            }
            availableSpace -= child.getMinHeight(true /* ignoreTemporaryStates */)
                    + notificationPadding;
            availableSpace -= child.getMinHeight(true /* ignoreTemporaryStates */);
            availableSpace -= count == 0 ? 0 : notificationPadding;
            availableSpace -= mNotificationStackScroller.calculateGapHeight(previousView, child,
                    count);
            previousView = child;
            if (availableSpace >= 0 && count < maximum) {
                count++;
            } else if (availableSpace > -shelfSize) {
                // if we are exactly the last view, then we can show us still!
                for (int j = i + 1; j < mNotificationStackScroller.getChildCount(); j++) {
                    if (mNotificationStackScroller.getChildAt(
                            j) instanceof ExpandableNotificationRow) {
                    ExpandableView view = (ExpandableView) mNotificationStackScroller.getChildAt(j);
                    if (view instanceof ExpandableNotificationRow &&
                            canShowViewOnLockscreen(view)) {
                        return count;
                    }
                }
@@ -888,6 +882,51 @@ public class NotificationPanelViewController extends PanelViewController {
        return count;
    }

    /**
     * Can a view be shown on the lockscreen when calculating the number of allowed notifications
     * to show?
     *
     * @param child the view in question
     * @return true if it can be shown
     */
    private boolean canShowViewOnLockscreen(ExpandableView child) {
        if (child.hasNoContentHeight()) {
            return false;
        }
        if (child instanceof ExpandableNotificationRow &&
                !canShowRowOnLockscreen((ExpandableNotificationRow) child)) {
            return false;
        } else if (child.getVisibility() == GONE) {
            // ENRs can be gone and count because their visibility is only set after
            // this calculation, but all other views should be up to date
            return false;
        }
        return true;
    }

    /**
     * Can a row be shown on the lockscreen when calculating the number of allowed notifications
     * to show?
     *
     * @param row the row in question
     * @return true if it can be shown
     */
    private boolean canShowRowOnLockscreen(ExpandableNotificationRow row) {
        boolean suppressedSummary =
                mGroupManager != null && mGroupManager.isSummaryOfSuppressedGroup(
                        row.getEntry().getSbn());
        if (suppressedSummary) {
            return false;
        }
        if (!mLockscreenUserManager.shouldShowOnKeyguard(row.getEntry())) {
            return false;
        }
        if (row.isRemoved()) {
            return false;
        }
        return true;
    }

    private void updateClock() {
        if (!mKeyguardStatusViewAnimating) {
            mKeyguardStatusView.setAlpha(mClockPositionResult.clockAlpha);