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

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

Improved the pulsing experience when swiping away a notification

Previously the shelf would briefly become visible, which is now fixed.
Additionally is the background disappearing when swiping.

Test: swipe away notification while pulsing
Bug: 125942236
Change-Id: I2bbf47db220aa3b078e11d9c5978342ad1355631
parent 459aee3d
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -237,7 +237,8 @@ public abstract class AlertingNotificationManager implements NotificationLifetim
     */
    protected boolean canRemoveImmediately(String key) {
        AlertEntry alertEntry = mAlertEntries.get(key);
        return alertEntry == null || alertEntry.wasShownLongEnough();
        return alertEntry == null || alertEntry.wasShownLongEnough()
                || alertEntry.mEntry.isRowDismissed();
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////
+14 −5
Original line number Diff line number Diff line
@@ -183,13 +183,22 @@ class NotificationWakeUpCoordinator @Inject constructor(
    }

    override fun onAmbientStateChanged(entry: NotificationEntry, isPulsing: Boolean) {
        if (!isPulsing && mLinearDozeAmount != 0.0f) {
        var animate = true
        if (!isPulsing) {
            if (mLinearDozeAmount != 0.0f) {
                if (entry.isRowDismissed) {
                    // if we animate, we see the shelf briefly visible. Instead we fully animate
                    // the notification and its background out
                    animate = false
                } else {
                    entry.setAmbientGoingAway(true)
                    mEntrySetToClearWhenFinished.add(entry)
        } else if (isPulsing && mEntrySetToClearWhenFinished.contains(entry)) {
                }
            }
        } else if (mEntrySetToClearWhenFinished.contains(entry)) {
            mEntrySetToClearWhenFinished.remove(entry)
            entry.setAmbientGoingAway(false)
        }
        updateNotificationVisibility(animate = true, increaseSpeed = false)
        updateNotificationVisibility(animate, increaseSpeed = false)
    }
}
 No newline at end of file
+8 −0
Original line number Diff line number Diff line
@@ -518,4 +518,12 @@ public class AmbientState {
            }
        }
    }

    /**
     * Is the device fully awake, which is different from not tark at all when there are pulsing
     * notifications.
     */
    public boolean isFullyAwake() {
        return mDozeAmount == 0.0f;
    }
}
+5 −1
Original line number Diff line number Diff line
@@ -236,7 +236,8 @@ class NotificationSection {
     * @param minBottomPosition the minimum position that the bottom needs to have
     * @return the position of the new bottom
     */
    public int updateVerticalBounds(int minTopPosition, int minBottomPosition) {
    public int updateBounds(int minTopPosition, int minBottomPosition,
            boolean shiftBackgroundWithFirst) {
        int top = minTopPosition;
        int bottom = minTopPosition;
        ActivatableNotificationView firstView = getFirstVisibleChild();
@@ -257,6 +258,9 @@ class NotificationSection {
                // If we're pulsing, the notification can actually go below!
                bottom = Math.max(bottom, finalTranslationY
                        + ExpandableViewState.getFinalActualHeight(firstView));
                if (shiftBackgroundWithFirst) {
                    mBounds.left += Math.max(firstView.getTranslation(), 0);
                }
            }
        }
        top = Math.max(minTopPosition, top);
+36 −6
Original line number Diff line number Diff line
@@ -365,6 +365,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd
    };
    protected ViewGroup mQsContainer;
    private boolean mContinuousShadowUpdate;
    private boolean mContinuousBackgroundUpdate;
    private ViewTreeObserver.OnPreDrawListener mShadowUpdater
            = new ViewTreeObserver.OnPreDrawListener() {

@@ -374,6 +375,10 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd
            return true;
        }
    };
    private ViewTreeObserver.OnPreDrawListener mBackgroundUpdater = () -> {
                updateBackground();
                return true;
            };
    private Comparator<ExpandableView> mViewPositionComparator = new Comparator<ExpandableView>() {
        @Override
        public int compare(ExpandableView view, ExpandableView otherView) {
@@ -813,26 +818,32 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd
        int backgroundRectTop = top;
        int lastSectionBottom =
                mSections[0].getCurrentBounds().bottom + animationYOffset;
        int previousLeft = left;
        boolean first = true;
        for (NotificationSection section : mSections) {
            if (section.getFirstVisibleChild() == null) {
                continue;
            }
            int sectionTop = section.getCurrentBounds().top + animationYOffset;
            int ownLeft = Math.min(Math.max(left, section.getCurrentBounds().left), right);
            // If sections are directly adjacent to each other, we don't want to draw them
            // as separate roundrects, as the rounded corners right next to each other look
            // bad.
            if (sectionTop - lastSectionBottom > DISTANCE_BETWEEN_ADJACENT_SECTIONS_PX) {
                canvas.drawRoundRect(left,
            if (sectionTop - lastSectionBottom > DISTANCE_BETWEEN_ADJACENT_SECTIONS_PX
                    || (previousLeft != ownLeft && !first)) {
                canvas.drawRoundRect(ownLeft,
                        backgroundRectTop,
                        right,
                        lastSectionBottom,
                        mCornerRadius, mCornerRadius, mBackgroundPaint);
                backgroundRectTop = sectionTop;
            }
            previousLeft = ownLeft;
            lastSectionBottom =
                    section.getCurrentBounds().bottom + animationYOffset;
            first = false;
        }
        canvas.drawRoundRect(left,
        canvas.drawRoundRect(previousLeft,
                backgroundRectTop,
                right,
                lastSectionBottom,
@@ -2463,13 +2474,16 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd
        } else if (lastSection == null) {
            minTopPosition = mTopPadding;
        }
        boolean shiftPulsingWithFirst = mAmbientPulseManager.getAllEntries().count() <= 1;
        for (NotificationSection section : mSections) {
            int minBottomPosition = minTopPosition;
            if (section == lastSection) {
                // We need to make sure the section goes all the way to the shelf
                minBottomPosition = (int) (mShelf.getTranslationY() + mShelf.getIntrinsicHeight());
            }
            minTopPosition = section.updateVerticalBounds(minTopPosition, minBottomPosition);
            minTopPosition = section.updateBounds(minTopPosition, minBottomPosition,
                    shiftPulsingWithFirst);
            shiftPulsingWithFirst = false;
        }
    }

@@ -5632,6 +5646,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd
     */
    public void setDozeAmount(float dozeAmount) {
        mAmbientState.setDozeAmount(dozeAmount);
        updateContinuousBackgroundDrawing();
        requestChildrenUpdate();
    }

@@ -5755,6 +5770,19 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd
        mAmbientState.setSectionBoundaryIndex(0, gapIndex);
    }

    private void updateContinuousBackgroundDrawing() {
        boolean continuousBackground = !mAmbientState.isFullyAwake()
                && !mAmbientState.getDraggedViews().isEmpty();
        if (continuousBackground != mContinuousBackgroundUpdate) {
            mContinuousBackgroundUpdate = continuousBackground;
            if (continuousBackground) {
                getViewTreeObserver().addOnPreDrawListener(mBackgroundUpdater);
            } else {
                getViewTreeObserver().removeOnPreDrawListener(mBackgroundUpdater);
            }
        }
    }

    @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER)
    private void updateContinuousShadowDrawing() {
        boolean continuousShadowUpdate = mAnimationRunning
@@ -6108,8 +6136,8 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd
        }

        @Override
        public boolean isExpanded() {
            return NotificationStackScrollLayout.this.isExpanded();
        public boolean shouldDismissQuickly() {
            return NotificationStackScrollLayout.this.isExpanded() && mAmbientState.isFullyAwake();
        }

        @Override
@@ -6209,6 +6237,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd
            setSwipingInProgress(true);
            mAmbientState.onBeginDrag((ExpandableView) v);
            updateContinuousShadowDrawing();
            updateContinuousBackgroundDrawing();
            requestChildrenUpdate();
        }

@@ -6216,6 +6245,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd
        public void onChildSnappedBack(View animView, float targetLeft) {
            mAmbientState.onDragFinished(animView);
            updateContinuousShadowDrawing();
            updateContinuousBackgroundDrawing();
            NotificationMenuRowPlugin menuRow = mSwipeHelper.getCurrentMenuRow();
            if (menuRow != null && targetLeft == 0) {
                menuRow.resetMenu();
Loading