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

Commit 7efbff35 authored by Ioana Alexandru's avatar Ioana Alexandru
Browse files

[Notif redesign] Fix group header motion on tap

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.

There were a few reasons why that didn't work in this case:
- the height used for the expandFactor calculation was only being
  updated when mUserLocked == true, so only while the user was directly
  interacting with the notification
- the translation (from the viewState) was only being applied in
  applyState, but that is only being called once for the tap-to-expand
  action; we have to also apply it in startAnimationToState

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: I2327de4dd1a14f40fae0d121de653516e3df55cb
parent 9d347fe0
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) {
+19 −6
Original line number Diff line number Diff line
@@ -828,7 +828,7 @@ public class NotificationChildrenContainer extends ViewGroup
        int firstOverflowIndex = lastVisibleIndex + 1;
        float expandFactor = 0;
        boolean expandingToExpandedGroup = mUserLocked && !showingAsLowPriority();
        if (mUserLocked) {
        if (notificationsRedesignTemplates() || mUserLocked) {
            expandFactor = getGroupExpandFraction();
            firstOverflowIndex = getMaxAllowedVisibleChildren(true /* likeCollapsed */);
        }
@@ -1161,11 +1161,24 @@ 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);
            }

            // Only apply the special viewState for the header's children if we're not currently
            // showing the minimized header.
            if (notificationsRedesignTemplates() && !showingAsLowPriority()) {
                if (mTopLineViewState != null) {
                    mTopLineViewState.applyToView(mGroupHeader.getTopLineView());
                }
                if (mExpandButtonViewState != null) {
                    mExpandButtonViewState.applyToView(mGroupHeader.getExpandButton());
                }
            }
        }
        updateChildrenClipping();
    }

@@ -1395,7 +1408,7 @@ public class NotificationChildrenContainer extends ViewGroup
    }

    public void setActualHeight(int actualHeight) {
        if (!mUserLocked) {
        if (!notificationsRedesignTemplates() && !mUserLocked) {
            return;
        }
        mActualHeight = actualHeight;
+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;
@@ -69,7 +68,6 @@ import android.view.DisplayCutout;
import android.view.InputDevice;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.NotificationHeaderView;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
@@ -6864,41 +6862,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) {