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

Commit 9f32d37a authored by Yining Liu's avatar Yining Liu
Browse files

Fix wrong notification content alpha

Fix the wrong notification content alpha values when swiping animation
is interrupted.
This change ensures:
When the notification row's swiping progress is reset, the alpha is also
reset to 1.
When the Shade closes/opens, all the notification rows in the list is
reset.

Fix: 355132257
Bug: 292024656
Test: atest SystemUITests
Flag: com.android.systemui.notification_content_alpha_optimization
Change-Id: I4bd2bc4c7944221c78b34a4c3206eac67bbab4a2
parent 94b3e86d
Loading
Loading
Loading
Loading
+11 −2
Original line number Original line Diff line number Diff line
@@ -53,6 +53,7 @@ import com.android.systemui.plugins.FalsingManager;
import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
import com.android.systemui.res.R;
import com.android.systemui.res.R;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.notification.shared.NotificationContentAlphaOptimization;
import com.android.wm.shell.animation.FlingAnimationUtils;
import com.android.wm.shell.animation.FlingAnimationUtils;
import com.android.wm.shell.shared.animation.PhysicsAnimator;
import com.android.wm.shell.shared.animation.PhysicsAnimator;
import com.android.wm.shell.shared.animation.PhysicsAnimator.SpringConfig;
import com.android.wm.shell.shared.animation.PhysicsAnimator.SpringConfig;
@@ -242,7 +243,10 @@ public class SwipeHelper implements Gefingerpoken, Dumpable {
            float translation) {
            float translation) {
        float swipeProgress = getSwipeProgressForOffset(animView, translation);
        float swipeProgress = getSwipeProgressForOffset(animView, translation);
        if (!mCallback.updateSwipeProgress(animView, dismissable, swipeProgress)) {
        if (!mCallback.updateSwipeProgress(animView, dismissable, swipeProgress)) {
            if (dismissable) {
            if (dismissable
                    || (NotificationContentAlphaOptimization.isEnabled() && translation == 0)) {
                // We need to reset the content alpha even when the view is not dismissible (eg.
                //  when Guts is visible)
                if (swipeProgress != 0f && swipeProgress != 1f) {
                if (swipeProgress != 0f && swipeProgress != 1f) {
                    animView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
                    animView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
                } else {
                } else {
@@ -808,7 +812,12 @@ public class SwipeHelper implements Gefingerpoken, Dumpable {
    }
    }


    public void forceResetSwipeState(@NonNull View view) {
    public void forceResetSwipeState(@NonNull View view) {
        if (view.getTranslationX() == 0) return;
        if (view.getTranslationX() == 0
                && (!NotificationContentAlphaOptimization.isEnabled() || view.getAlpha() == 1f)
        ) {
            // Don't do anything when translation is 0 and alpha is 1
            return;
        }
        setTranslation(view, 0);
        setTranslation(view, 0);
        updateSwipeProgressFromOffset(
        updateSwipeProgressFromOffset(
                view,
                view,
+17 −1
Original line number Original line Diff line number Diff line
@@ -36,6 +36,7 @@ import static org.mockito.Mockito.when;
import android.animation.Animator;
import android.animation.Animator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.os.Handler;
import android.os.Handler;
import android.platform.test.annotations.EnableFlags;
import android.service.notification.StatusBarNotification;
import android.service.notification.StatusBarNotification;
import android.testing.TestableLooper;
import android.testing.TestableLooper;
import android.view.MotionEvent;
import android.view.MotionEvent;
@@ -52,6 +53,7 @@ import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
import com.android.systemui.plugins.statusbar.NotificationSwipeActionHelper.SnoozeOption;
import com.android.systemui.plugins.statusbar.NotificationSwipeActionHelper.SnoozeOption;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.notification.shared.NotificationContentAlphaOptimization;


import org.junit.Before;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Rule;
@@ -672,16 +674,30 @@ public class NotificationSwipeHelperTest extends SysuiTestCase {
    }
    }


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


        mSwipeHelper.forceResetSwipeState(mNotificationRow);
        mSwipeHelper.forceResetSwipeState(mNotificationRow);


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


    @Test
    @EnableFlags(NotificationContentAlphaOptimization.FLAG_NAME)
    public void testForceResetSwipeStateResetsAlphaIfTranslationIsZeroAndAlphaNotOne() {
        doReturn(FAKE_ROW_WIDTH).when(mNotificationRow).getMeasuredWidth();
        doReturn(0f).when(mNotificationRow).getTranslationX();
        doReturn(0.5f).when(mNotificationRow).getAlpha();

        mSwipeHelper.forceResetSwipeState(mNotificationRow);

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

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