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

Commit d48b1175 authored by Ioana Alexandru's avatar Ioana Alexandru
Browse files

[Notif redesign] Fix group header motion on tap

A slightly different approach after
I2327de4dd1a14f40fae0d121de653516e3df55cb had to be reverted.

We had previously made this motion more gradual during the dragging
gesture in I21ef172ba5ad14404e1c863c209a35bada3790d4, but that didn't
fix the motion when the group was expanded via tapping, since that has
to be done in startAnimationToState instead of relying on updateState.

This allows us to remove the call fron NSSL that was directly updating
the alignment without any transition.

Fix: 402745695
Test: manual
Flag: android.app.notifications_redesign_templates
Change-Id: I55205f3d6e58858a6328aa5d54a6126e2e32232e
parent 5a136f7b
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -183,6 +183,12 @@ public class NotificationHeaderView extends RelativeLayout {

    /**
     * Center top line  and expand button vertically.
     * Note that this is primarily only used as a remotable method to ensure the correct initial
     * state of the RemoteView. For further updating the position after the RemoteView has been
     * created, we directly apply a translation obtained from
     * {@link NotificationHeaderView#getTopLineTranslation()} and
     * {@link NotificationHeaderView#getExpandButtonTranslation()} to the corresponding children, in
     * order to have a smoother transition.
     */
    @RemotableViewMethod
    public void centerTopLine(boolean center) {
+33 −10
Original line number Diff line number Diff line
@@ -964,13 +964,25 @@ public class NotificationChildrenContainer extends ViewGroup
            mHeaderViewState.setAlpha(mHeaderVisibleAmount);

            if (notificationsRedesignTemplates()) {
                // While mUserLocked, the expandFactor reflects where in the drag-to-expand gesture
                // we are so that we can calculate the intermediary translation needed for the
                // header components. Otherwise, we just set the final desired translation based
                // on whether the group is expanded or not.
                float topLineTranslation = 0, expandButtonTranslation = 0;
                if (mUserLocked) {
                    topLineTranslation = mGroupHeader.getTopLineTranslation() * expandFactor;
                    expandButtonTranslation =
                            mGroupHeader.getExpandButtonTranslation() * expandFactor;
                } else if (mChildrenExpanded) {
                    topLineTranslation = mGroupHeader.getTopLineTranslation();
                    expandButtonTranslation = mGroupHeader.getExpandButtonTranslation();
                }

                mTopLineViewState = initStateForGroupHeader(mTopLineViewState);
                mTopLineViewState.setYTranslation(
                        mGroupHeader.getTopLineTranslation() * expandFactor);
                mTopLineViewState.setYTranslation(topLineTranslation);

                mExpandButtonViewState = initStateForGroupHeader(mExpandButtonViewState);
                mExpandButtonViewState.setYTranslation(
                        mGroupHeader.getExpandButtonTranslation() * expandFactor);
                mExpandButtonViewState.setYTranslation(expandButtonTranslation);
            }
        }
    }
@@ -1183,10 +1195,10 @@ public class NotificationChildrenContainer extends ViewGroup
        int childCount = mAttachedChildren.size();
        ViewState tmpState = new ViewState();
        float expandFraction = getGroupExpandFraction();
        final boolean isExpanding = !showingAsLowPriority()
        final boolean isExpansionChanging = !showingAsLowPriority()
                && (mUserLocked || mContainingNotification.isGroupExpansionChanging());
        final boolean dividersVisible = (mChildrenExpanded && mShowDividersWhenExpanded)
                || (isExpanding && !mHideDividersDuringExpand);
                || (isExpansionChanging && !mHideDividersDuringExpand);
        for (int i = childCount - 1; i >= 0; i--) {
            ExpandableNotificationRow child = mAttachedChildren.get(i);
            ExpandableViewState viewState = child.getViewState();
@@ -1217,11 +1229,22 @@ public class NotificationChildrenContainer extends ViewGroup
            }
            mGroupOverFlowState.animateTo(mOverflowNumber, properties);
        }
        if (mGroupHeader != null && mHeaderViewState != null) {
        if (mGroupHeader != null) {
            if (mHeaderViewState != null) {
                // TODO(389839492): For Groups in Bundles mGroupHeader might be initialized
                //  but mHeaderViewState is null.
                mHeaderViewState.applyToView(mGroupHeader);
            }

            if (notificationsRedesignTemplates()) {
                if (mTopLineViewState != null) {
                    mTopLineViewState.animateTo(mGroupHeader.getTopLineView(), properties);
                }
                if (mExpandButtonViewState != null) {
                    mExpandButtonViewState.animateTo(mGroupHeader.getExpandButton(), properties);
                }
            }
        }
        updateChildrenClipping();
    }

+0 −33
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.systemui.statusbar.notification.stack;

import static android.app.Flags.notificationsRedesignTemplates;
import static android.os.Trace.TRACE_TAG_APP;
import static android.view.MotionEvent.ACTION_CANCEL;
import static android.view.MotionEvent.ACTION_UP;
@@ -63,7 +62,6 @@ import android.util.MathUtils;
import android.view.DisplayCutout;
import android.view.InputDevice;
import android.view.MotionEvent;
import android.view.NotificationHeaderView;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
@@ -6777,41 +6775,10 @@ public class NotificationStackScrollLayout

        changedRow.setChildrenExpanded(expanded);
        onChildHeightChanged(changedRow, false /* needsAnimation */);
        updateGroupHeaderAlignment(changedRow, expanded);

        runAfterAnimationFinished(changedRow::onFinishedExpansionChange);
    }

    private void updateGroupHeaderAlignment(ExpandableNotificationRow row, boolean expanded) {
        if (!notificationsRedesignTemplates()) {
            return;
        }

        NotificationChildrenContainer childrenContainer = row.getChildrenContainer();
        if (childrenContainer == null) {
            Log.wtf(TAG, "Tried to update group header alignment for something that's "
                    + "not a group; key = " + row.getKey());
            return;
        }
        NotificationHeaderView header = childrenContainer.getGroupHeader();
        if (header != null) {
            resetYTranslation(header.getTopLineView());
            resetYTranslation(header.getExpandButton());
            header.centerTopLine(expanded);
        }
    }

    /**
     * Reset the y translation of the {@code view} via the {@link ViewState}, to ensure that the
     * animation state is updated correctly.
     */
    private static void resetYTranslation(View view) {
        ViewState viewState = new ViewState();
        viewState.initFrom(view);
        viewState.setYTranslation(0);
        viewState.applyToView(view);
    }

    private final ExpandHelper.Callback mExpandHelperCallback = new ExpandHelper.Callback() {
        @Override
        public ExpandableView getChildAtPosition(float touchX, float touchY) {