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

Commit 1c82804d authored by Selim Cinek's avatar Selim Cinek Committed by Automerger Merge Worker
Browse files

Merge changes from topic "notif_smooth_dismissal" into sc-dev am: 4721ef7c

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14965033

Change-Id: I7bf42cffa23eb1c92c5771e0084bf529bda6fbdb
parents f1d4d95e 4721ef7c
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -396,10 +396,6 @@
    <!-- Whether or not the notifications should always fade as they are dismissed. -->
    <bool name="config_fadeNotificationsOnDismiss">false</bool>

    <!-- Whether or not the parent of the notification row itself is being translated when swiped or
         its children views. If true, then the contents are translated and vice versa. -->
    <bool name="config_translateNotificationContentsOnSwipe">true</bool>

    <!-- Whether or not the fade on the notification is based on the amount that it has been swiped
         off-screen. -->
    <bool name="config_fadeDependingOnAmountSwiped">false</bool>
+11 −2
Original line number Diff line number Diff line
@@ -391,9 +391,9 @@ public class SwipeHelper implements Gefingerpoken {
        boolean animateLeft = (Math.abs(velocity) > getEscapeVelocity() && velocity < 0) ||
                (getTranslation(animView) < 0 && !isDismissAll);
        if (animateLeft || animateLeftForRtl || animateUpForMenu) {
            newPos = -getSize(animView);
            newPos = -getTotalTranslationLength(animView);
        } else {
            newPos = getSize(animView);
            newPos = getTotalTranslationLength(animView);
        }
        long duration;
        if (fixedDuration == 0) {
@@ -469,6 +469,15 @@ public class SwipeHelper implements Gefingerpoken {
        anim.start();
    }

    /**
     * Get the total translation length where we want to swipe to when dismissing the view. By
     * default this is the size of the view, but can also be larger.
     * @param animView the view to ask about
     */
    protected float getTotalTranslationLength(View animView) {
        return getSize(animView);
    }

    /**
     * Called to update the dismiss animation.
     */
+2 −2
Original line number Diff line number Diff line
@@ -71,11 +71,11 @@ public final class NotificationClicker implements View.OnClickListener {
        // Check if the notification is displaying the menu, if so slide notification back
        if (isMenuVisible(row)) {
            mLogger.logMenuVisible(entry);
            row.animateTranslateNotification(0);
            row.animateResetTranslation();
            return;
        } else if (row.isChildInGroup() && isMenuVisible(row.getNotificationParent())) {
            mLogger.logParentMenuVisible(entry);
            row.getNotificationParent().animateTranslateNotification(0);
            row.getNotificationParent().animateResetTranslation();
            return;
        } else if (row.isSummaryWithChildren() && row.areChildrenExpanded()) {
            // We never want to open the app directly if the user clicks in between
+43 −19
Original line number Diff line number Diff line
@@ -874,7 +874,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
    @Override
    protected boolean handleSlideBack() {
        if (mMenuRow != null && mMenuRow.isMenuVisible()) {
            animateTranslateNotification(0 /* targetLeft */);
            animateResetTranslation();
            return true;
        }
        return false;
@@ -1711,12 +1711,9 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
            mChildrenContainer.setContainingNotification(ExpandableNotificationRow.this);
            mChildrenContainer.onNotificationUpdated();

            if (mShouldTranslateContents) {
            mTranslateableViews.add(mChildrenContainer);
            }
        });

        if (mShouldTranslateContents) {
        // Add the views that we translate to reveal the menu
        mTranslateableViews = new ArrayList<>();
        for (int i = 0; i < getChildCount(); i++) {
@@ -1726,7 +1723,6 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        mTranslateableViews.remove(mChildrenContainerStub);
        mTranslateableViews.remove(mGutsStub);
    }
    }

    private void doLongClickCallback() {
        doLongClickCallback(getWidth() / 2, getHeight() / 2);
@@ -1803,7 +1799,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
            mTranslateAnim.cancel();
        }

        if (!mShouldTranslateContents) {
        if (mDismissUsingRowTranslationX) {
            setTranslationX(0);
        } else if (mTranslateableViews != null) {
            for (int i = 0; i < mTranslateableViews.size(); i++) {
@@ -1865,23 +1861,47 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        return mPrivateLayout.getActiveRemoteInputText();
    }

    public void animateTranslateNotification(final float leftTarget) {
    /**
     * Reset the translation with an animation.
     */
    public void animateResetTranslation() {
        if (mTranslateAnim != null) {
            mTranslateAnim.cancel();
        }
        mTranslateAnim = getTranslateViewAnimator(leftTarget, null /* updateListener */);
        mTranslateAnim = getTranslateViewAnimator(0, null /* updateListener */);
        if (mTranslateAnim != null) {
            mTranslateAnim.start();
        }
    }

    /**
     * Set the dismiss behavior of the view.
     * @param usingRowTranslationX {@code true} if the view should translate using regular
     *                                          translationX, otherwise the contents will be
     *                                          translated.
     */
    @Override
    public void setDismissUsingRowTranslationX(boolean usingRowTranslationX) {
        if (usingRowTranslationX != mDismissUsingRowTranslationX) {
            // In case we were already transitioning, let's switch over!
            float previousTranslation = getTranslation();
            if (previousTranslation != 0) {
                setTranslation(0);
            }
            super.setDismissUsingRowTranslationX(usingRowTranslationX);
            if (previousTranslation != 0) {
                setTranslation(previousTranslation);
            }
        }
    }

    @Override
    public void setTranslation(float translationX) {
        invalidate();
        if (isBlockingHelperShowingAndTranslationFinished()) {
            mGuts.setTranslationX(translationX);
            return;
        } else if (!mShouldTranslateContents) {
        } else if (mDismissUsingRowTranslationX) {
            setTranslationX(translationX);
        } else if (mTranslateableViews != null) {
            // Translate the group of views
@@ -1905,7 +1925,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView

    @Override
    public float getTranslation() {
        if (!mShouldTranslateContents) {
        if (mDismissUsingRowTranslationX) {
            return getTranslationX();
        }

@@ -2896,7 +2916,11 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        float y = event.getY();
        NotificationViewWrapper wrapper = getVisibleNotificationViewWrapper();
        NotificationHeaderView header = wrapper == null ? null : wrapper.getNotificationHeader();
        if (header != null && header.isInTouchRect(x - getTranslation(), y)) {
        // the extra translation only needs to be added, if we're translating the notification
        // contents, otherwise the motionEvent is already at the right place due to the
        // touch event system.
        float translation = !mDismissUsingRowTranslationX ? getTranslation() : 0;
        if (header != null && header.isInTouchRect(x - translation, y)) {
            return true;
        }
        if ((!mIsSummaryWithChildren || shouldShowPublic())
+28 −8
Original line number Diff line number Diff line
@@ -71,10 +71,10 @@ public abstract class ExpandableOutlineView extends ExpandableView {
    private int mBackgroundTop;

    /**
     * {@code true} if the children views of the {@link ExpandableOutlineView} are translated when
     * {@code false} if the children views of the {@link ExpandableOutlineView} are translated when
     * it is moved. Otherwise, the translation is set on the {@code ExpandableOutlineView} itself.
     */
    protected boolean mShouldTranslateContents;
    protected boolean mDismissUsingRowTranslationX = true;
    private float[] mTmpCornerRadii = new float[8];

    private final ViewOutlineProvider mProvider = new ViewOutlineProvider() {
@@ -82,7 +82,8 @@ public abstract class ExpandableOutlineView extends ExpandableView {
        public void getOutline(View view, Outline outline) {
            if (!mCustomOutline && getCurrentTopRoundness() == 0.0f
                    && getCurrentBottomRoundness() == 0.0f && !mAlwaysRoundBothCorners) {
                int translation = mShouldTranslateContents ? (int) getTranslation() : 0;
                // Only when translating just the contents, does the outline need to be shifted.
                int translation = !mDismissUsingRowTranslationX ? (int) getTranslation() : 0;
                int left = Math.max(translation, 0);
                int top = mClipTopAmount + mBackgroundTop;
                int right = getWidth() + Math.min(translation, 0);
@@ -107,7 +108,9 @@ public abstract class ExpandableOutlineView extends ExpandableView {
        float topRoundness = mAlwaysRoundBothCorners
                ? mOutlineRadius : getCurrentBackgroundRadiusTop();
        if (!mCustomOutline) {
            int translation = mShouldTranslateContents && !ignoreTranslation
            // The outline just needs to be shifted if we're translating the contents. Otherwise
            // it's already in the right place.
            int translation = !mDismissUsingRowTranslationX && !ignoreTranslation
                    ? (int) getTranslation() : 0;
            int halfExtraWidth = (int) (mExtraWidthForClipping / 2.0f);
            left = Math.max(translation, 0) - halfExtraWidth;
@@ -196,13 +199,14 @@ public abstract class ExpandableOutlineView extends ExpandableView {
    }

    protected boolean isClippingNeeded() {
        return mAlwaysRoundBothCorners || mCustomOutline || getTranslation() != 0 ;
        // When translating the contents instead of the overall view, we need to make sure we clip
        // rounded to the contents.
        boolean forTranslation = getTranslation() != 0 && !mDismissUsingRowTranslationX;
        return mAlwaysRoundBothCorners || mCustomOutline || forTranslation;
    }

    private void initDimens() {
        Resources res = getResources();
        mShouldTranslateContents =
                res.getBoolean(R.bool.config_translateNotificationContentsOnSwipe);
        mOutlineRadius = res.getDimension(R.dimen.notification_shadow_radius);
        mAlwaysRoundBothCorners = res.getBoolean(R.bool.config_clipNotificationsToOutline);
        if (!mAlwaysRoundBothCorners) {
@@ -342,9 +346,25 @@ public abstract class ExpandableOutlineView extends ExpandableView {
        }
    }

    /**
     * Set the dismiss behavior of the view.
     * @param usingRowTranslationX {@code true} if the view should translate using regular
     *                                          translationX, otherwise the contents will be
     *                                          translated.
     */
    public void setDismissUsingRowTranslationX(boolean usingRowTranslationX) {
        mDismissUsingRowTranslationX = usingRowTranslationX;
    }

    @Override
    public int getOutlineTranslation() {
        return mCustomOutline ? mOutlineRect.left : (int) getTranslation();
        if (mCustomOutline) {
            return mOutlineRect.left;
        }
        if (mDismissUsingRowTranslationX) {
            return 0;
        }
        return (int) getTranslation();
    }

    public void updateOutline() {
Loading