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

Commit bb18df33 authored by Juan Sebastian Martinez's avatar Juan Sebastian Martinez Committed by Android (Google) Code Review
Browse files

Merge changes from topic "revert-32206328-MAGNETIC_REATTACH-ZWQICZGUQH" into main

* changes:
  Revert "Consolidating magnetic detachment with dismissibility."
  Revert "Implementing magnetic attachment using springs."
parents 0791a627 14ab8dc3
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.platform.test.annotations.DisableFlags;
import android.provider.Settings;
import android.testing.TestableLooper;
import android.testing.TestableLooper.RunWithLooper;
@@ -39,7 +38,6 @@ import android.view.ViewGroup;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;

import com.android.systemui.Flags;
import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder;
@@ -415,7 +413,6 @@ public class NotificationMenuRowTest extends LeakCheckedTest {
        assertTrue("when alpha is .5, menu is visible", row.isMenuVisible());
    }

    @DisableFlags(Flags.FLAG_MAGNETIC_NOTIFICATION_SWIPES)
    @Test
    public void testOnTouchMove() {
        NotificationMenuRow row = Mockito.spy(
+7 −40
Original line number Diff line number Diff line
@@ -130,9 +130,7 @@ class MagneticNotificationRowManagerImplTest : SysuiTestCase() {
        kosmos.testScope.runTest {
            // GIVEN a threshold of 100 px
            val threshold = 100f
            underTest.onDensityChange(
                threshold / MagneticNotificationRowManager.MAGNETIC_DETACH_THRESHOLD_DP
            )
            underTest.setSwipeThresholdPx(threshold)

            // GIVEN that targets are set and the rows are being pulled
            setTargets()
@@ -152,9 +150,7 @@ class MagneticNotificationRowManagerImplTest : SysuiTestCase() {
        kosmos.testScope.runTest {
            // GIVEN a threshold of 100 px
            val threshold = 100f
            underTest.onDensityChange(
                threshold / MagneticNotificationRowManager.MAGNETIC_DETACH_THRESHOLD_DP
            )
            underTest.setSwipeThresholdPx(threshold)

            // GIVEN that targets are set and the rows are being pulled
            canRowBeDismissed = false
@@ -176,9 +172,7 @@ class MagneticNotificationRowManagerImplTest : SysuiTestCase() {
        kosmos.testScope.runTest {
            // GIVEN a threshold of 100 px
            val threshold = 100f
            underTest.onDensityChange(
                threshold / MagneticNotificationRowManager.MAGNETIC_DETACH_THRESHOLD_DP
            )
            underTest.setSwipeThresholdPx(threshold)

            // GIVEN that targets are set and the rows are being pulled
            setTargets()
@@ -198,9 +192,7 @@ class MagneticNotificationRowManagerImplTest : SysuiTestCase() {
        kosmos.testScope.runTest {
            // GIVEN a threshold of 100 px
            val threshold = 100f
            underTest.onDensityChange(
                threshold / MagneticNotificationRowManager.MAGNETIC_DETACH_THRESHOLD_DP
            )
            underTest.setSwipeThresholdPx(threshold)

            // GIVEN that targets are set and the rows are being pulled
            canRowBeDismissed = false
@@ -302,29 +294,6 @@ class MagneticNotificationRowManagerImplTest : SysuiTestCase() {
            assertThat(underTest.isSwipedViewRoundableSet).isFalse()
        }

    @Test
    fun isMagneticRowDismissible_isDismissibleWhenDetached() =
        kosmos.testScope.runTest {
            setDetachedState()

            val isDismissible = underTest.isMagneticRowSwipeDetached(swipedRow)
            assertThat(isDismissible).isTrue()
        }

    @Test
    fun setMagneticRowTranslation_whenDetached_belowAttachThreshold_reattaches() =
        kosmos.testScope.runTest {
            // GIVEN that the swiped view has been detached
            setDetachedState()

            // WHEN setting a new translation above the attach threshold
            val translation = 50f
            underTest.setMagneticRowTranslation(swipedRow, translation)

            // THEN the swiped view reattaches magnetically and the state becomes PULLING
            assertThat(underTest.currentState).isEqualTo(State.PULLING)
        }

    @After
    fun tearDown() {
        // We reset the manager so that all MagneticRowListener can cancel all animations
@@ -333,9 +302,7 @@ class MagneticNotificationRowManagerImplTest : SysuiTestCase() {

    private fun setDetachedState() {
        val threshold = 100f
        underTest.onDensityChange(
            threshold / MagneticNotificationRowManager.MAGNETIC_DETACH_THRESHOLD_DP
        )
        underTest.setSwipeThresholdPx(threshold)

        // Set the pulling state
        setTargets()
@@ -360,8 +327,8 @@ class MagneticNotificationRowManagerImplTest : SysuiTestCase() {
    private fun MagneticRowListener.asTestableListener(rowIndex: Int): MagneticRowListener {
        val delegate = this
        return object : MagneticRowListener {
            override fun setMagneticTranslation(translation: Float, trackEagerly: Boolean) {
                delegate.setMagneticTranslation(translation, trackEagerly)
            override fun setMagneticTranslation(translation: Float) {
                delegate.setMagneticTranslation(translation)
            }

            override fun triggerMagneticForce(
+0 −16
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@ import android.view.ViewConfiguration;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;

import com.android.systemui.Flags;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.classifier.FalsingManagerFake;
import com.android.systemui.flags.FakeFeatureFlags;
@@ -363,7 +362,6 @@ public class NotificationSwipeHelperTest extends SysuiTestCase {
        verify(mSwipeHelper, times(1)).isFalseGesture();
    }

    @DisableFlags(Flags.FLAG_MAGNETIC_NOTIFICATION_SWIPES)
    @Test
    public void testIsDismissGesture_farEnough() {
        doReturn(false).when(mSwipeHelper).isFalseGesture();
@@ -376,20 +374,6 @@ public class NotificationSwipeHelperTest extends SysuiTestCase {
        verify(mSwipeHelper, times(1)).isFalseGesture();
    }

    @EnableFlags(Flags.FLAG_MAGNETIC_NOTIFICATION_SWIPES)
    @Test
    public void testIsDismissGesture_magneticSwipeIsDismissible() {
        doReturn(false).when(mSwipeHelper).isFalseGesture();
        doReturn(false).when(mSwipeHelper).swipedFarEnough();
        doReturn(false).when(mSwipeHelper).swipedFastEnough();
        doReturn(true).when(mCallback).isMagneticViewDetached(any());
        when(mCallback.canChildBeDismissedInDirection(any(), anyBoolean())).thenReturn(true);
        when(mEvent.getActionMasked()).thenReturn(MotionEvent.ACTION_UP);

        assertTrue("Should be a dismissal", mSwipeHelper.isDismissGesture(mEvent));
        verify(mSwipeHelper, times(1)).isFalseGesture();
    }

    @Test
    public void testIsDismissGesture_notFarOrFastEnough() {
        doReturn(false).when(mSwipeHelper).isFalseGesture();
+3 −18
Original line number Diff line number Diff line
@@ -778,26 +778,18 @@ public class SwipeHelper implements Gefingerpoken, Dumpable {

    protected boolean swipedFarEnough() {
        float translation = getTranslation(mTouchedView);
        return Math.abs(translation) > SWIPED_FAR_ENOUGH_SIZE_FRACTION * getSize(mTouchedView);
        return Math.abs(translation) > SWIPED_FAR_ENOUGH_SIZE_FRACTION * getSize(
                mTouchedView);
    }

    public boolean isDismissGesture(MotionEvent ev) {
        float translation = getTranslation(mTouchedView);
        return ev.getActionMasked() == MotionEvent.ACTION_UP
                && !mFalsingManager.isUnlockingDisabled()
                && !isFalseGesture() && isSwipeDismissible()
                && !isFalseGesture() && (swipedFastEnough() || swipedFarEnough())
                && mCallback.canChildBeDismissedInDirection(mTouchedView, translation > 0);
    }

    /** Can the swipe gesture on the touched view be considered as a dismiss intention */
    public boolean isSwipeDismissible() {
        if (magneticNotificationSwipes()) {
            return mCallback.isMagneticViewDetached(mTouchedView) || swipedFastEnough();
        } else {
            return swipedFastEnough() || swipedFarEnough();
        }
    }

    /** Returns true if the gesture should be rejected. */
    public boolean isFalseGesture() {
        boolean falsingDetected = mCallback.isAntiFalsingNeeded();
@@ -977,13 +969,6 @@ public class SwipeHelper implements Gefingerpoken, Dumpable {
         */
        void onMagneticInteractionEnd(View view, float velocity);

        /**
         * Determine if a view managed by magnetic interactions is magnetically detached
         * @param view The magnetic view
         * @return if the view is detached according to its magnetic state.
         */
        boolean isMagneticViewDetached(View view);

        /**
         * Called when the child is long pressed and available to start drag and drop.
         *
+4 −21
Original line number Diff line number Diff line
@@ -19,8 +19,6 @@ package com.android.systemui.statusbar.notification.row;
import static com.android.systemui.Flags.notificationColorUpdateLogger;
import static com.android.systemui.Flags.physicalNotificationMovement;

import static java.lang.Math.abs;

import android.animation.AnimatorListenerAdapter;
import android.content.Context;
import android.content.res.Configuration;
@@ -31,7 +29,6 @@ import android.util.FloatProperty;
import android.util.IndentingPrintWriter;
import android.util.Log;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.FrameLayout;
@@ -113,28 +110,15 @@ public abstract class ExpandableView extends FrameLayout implements Dumpable, Ro
    protected SpringAnimation mMagneticAnimator = new SpringAnimation(
            this /* object */, DynamicAnimation.TRANSLATION_X);

    private int mTouchSlop;

    protected MagneticRowListener mMagneticRowListener = new MagneticRowListener() {

        @Override
        public void setMagneticTranslation(float translation, boolean trackEagerly) {
            if (!mMagneticAnimator.isRunning()) {
                setTranslation(translation);
                return;
            }

            if (trackEagerly) {
                float delta = abs(getTranslation() - translation);
                if (delta > mTouchSlop) {
        public void setMagneticTranslation(float translation) {
            if (mMagneticAnimator.isRunning()) {
                mMagneticAnimator.animateToFinalPosition(translation);
            } else {
                    mMagneticAnimator.cancel();
                setTranslation(translation);
            }
            } else {
                mMagneticAnimator.animateToFinalPosition(translation);
            }
        }

        @Override
@@ -199,7 +183,6 @@ public abstract class ExpandableView extends FrameLayout implements Dumpable, Ro
    private void initDimens() {
        mContentShift = getResources().getDimensionPixelSize(
                R.dimen.shelf_transform_content_shift);
        mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
    }

    @Override
Loading