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

Commit 4815a874 authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge "Reset translation and fading of top-level notifs on collapse/hide/show" into udc-dev

parents 4ee1f010 f1ac8c49
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.app.PendingIntent;
import android.content.res.Resources;
import android.graphics.RectF;
import android.os.Handler;
import android.os.Trace;
import android.util.ArrayMap;
import android.util.Log;
import android.view.MotionEvent;
@@ -277,9 +278,11 @@ public class SwipeHelper implements Gefingerpoken, Dumpable {

    // invalidate the view's own bounds all the way up the view hierarchy
    public static void invalidateGlobalRegion(View view) {
        Trace.beginSection("SwipeHelper.invalidateGlobalRegion");
        invalidateGlobalRegion(
            view,
            new RectF(view.getLeft(), view.getTop(), view.getRight(), view.getBottom()));
        Trace.endSection();
    }

    // invalidate a rectangle relative to the view's coordinate system all the way up the view
@@ -492,7 +495,7 @@ public class SwipeHelper implements Gefingerpoken, Dumpable {
                }
                if (!mCancelled || wasRemoved) {
                    mCallback.onChildDismissed(animView);
                    resetSwipeOfView(animView);
                    resetViewIfSwiping(animView);
                }
                if (endAction != null) {
                    endAction.accept(mCancelled);
@@ -547,7 +550,7 @@ public class SwipeHelper implements Gefingerpoken, Dumpable {

            if (!cancelled) {
                updateSwipeProgressFromOffset(animView, canBeDismissed);
                resetSwipeOfView(animView);
                resetViewIfSwiping(animView);
                // Clear the snapped view after success, assuming it's not being swiped now
                if (animView == mTouchedView && !mIsSwiping) {
                    mTouchedView = null;
@@ -811,7 +814,7 @@ public class SwipeHelper implements Gefingerpoken, Dumpable {
        return mIsSwiping ? mTouchedView : null;
    }

    protected void resetSwipeOfView(View view) {
    protected void resetViewIfSwiping(View view) {
        if (getSwipedView() == view) {
            resetSwipeState();
        }
@@ -825,6 +828,12 @@ public class SwipeHelper implements Gefingerpoken, Dumpable {
        resetSwipeStates(/* resetAll= */ true);
    }

    public void forceResetSwipeState(@NonNull View view) {
        if (view.getTranslationX() == 0) return;
        setTranslation(view, 0);
        updateSwipeProgressFromOffset(view, /* dismissable= */ true, 0);
    }

    /** This method resets the swipe state, and if `resetAll` is true, also resets the snap state */
    private void resetSwipeStates(boolean resetAll) {
        final View touchedView = mTouchedView;
+9 −4
Original line number Diff line number Diff line
@@ -4011,7 +4011,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
            mCentralSurfaces.resetUserExpandedStates();
            clearTemporaryViews();
            clearUserLockedViews();
            cancelActiveSwipe();
            resetAllSwipeState();
        }
    }

@@ -4077,7 +4077,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
                mGroupExpansionManager.collapseGroups();
                mExpandHelper.cancelImmediately();
                if (!mIsExpansionChanging) {
                    cancelActiveSwipe();
                    resetAllSwipeState();
                }
                finalizeClearAllAnimation();
            }
@@ -4406,7 +4406,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
        boolean nowHiddenAtAll = mAmbientState.isHiddenAtAll();
        if (nowFullyHidden != wasFullyHidden) {
            updateVisibility();
            mSwipeHelper.resetTouchState();
            resetAllSwipeState();
        }
        if (!wasHiddenAtAll && nowHiddenAtAll) {
            resetExposedMenuView(true /* animate */, true /* animate */);
@@ -5866,9 +5866,14 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
        }
    }

    private void cancelActiveSwipe() {
    private void resetAllSwipeState() {
        Trace.beginSection("NSSL.resetAllSwipeState()");
        mSwipeHelper.resetTouchState();
        for (int i = 0; i < getChildCount(); i++) {
            mSwipeHelper.forceResetSwipeState(getChildAt(i));
        }
        updateContinuousShadowDrawing();
        Trace.endSection();
    }

    void updateContinuousShadowDrawing() {
+24 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyFloat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
@@ -29,6 +30,7 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

import android.animation.Animator;
@@ -669,6 +671,28 @@ public class NotificationSwipeHelperTest extends SysuiTestCase {
        verify(mNotificationRow, never()).setContentAlpha(anyFloat());
    }

    @Test
    public void testForceResetSwipeStateDoesNothingIfTranslationIsZero() {
        doReturn(FAKE_ROW_WIDTH).when(mNotificationRow).getMeasuredWidth();
        doReturn(0f).when(mNotificationRow).getTranslationX();

        mSwipeHelper.forceResetSwipeState(mNotificationRow);

        verify(mNotificationRow).getTranslationX();
        verifyNoMoreInteractions(mNotificationRow);
    }

    @Test
    public void testForceResetSwipeStateResetsTranslationAndAlpha() {
        doReturn(FAKE_ROW_WIDTH).when(mNotificationRow).getMeasuredWidth();
        doReturn(10f).when(mNotificationRow).getTranslationX();

        mSwipeHelper.forceResetSwipeState(mNotificationRow);

        verify(mNotificationRow).setTranslation(eq(0f));
        verify(mNotificationRow).setContentAlpha(eq(1f));
    }

    @Test
    public void testContentAlphaRemainsUnchangedWhenFeatureFlagIsDisabled() {