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

Commit 37d67e20 authored by Gus Prevas's avatar Gus Prevas
Browse files

Disables dismissing notification on leftward swipe.

This change modifies SwipeHelper to pass the direction of a swipe to the
provided callback when determining whether the swipe represents a valid
dismiss gesture, and modifies the callback defined by
NotificationStackScrollLayout to allow dismiss gestures only to the
right.

Test: manually
Change-Id: I7ff1e8f92e7da9ed36520195d823f9a62f9a64ba
parent c5cee1e4
Loading
Loading
Loading
Loading
+18 −4
Original line number Diff line number Diff line
@@ -33,10 +33,11 @@ import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.accessibility.AccessibilityEvent;

import com.android.systemui.classifier.FalsingManager;
import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.FlingAnimationUtils;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;

public class SwipeHelper implements Gefingerpoken {
    static final String TAG = "com.android.systemui.SwipeHelper";
@@ -604,13 +605,15 @@ public class SwipeHelper implements Gefingerpoken {
                    }
                    // don't let items that can't be dismissed be dragged more than
                    // maxScrollDistance
                    if (CONSTRAIN_SWIPE && !mCallback.canChildBeDismissed(mCurrView)) {
                    if (CONSTRAIN_SWIPE && !mCallback.canChildBeDismissedInDirection(mCurrView,
                            delta > 0)) {
                        float size = getSize(mCurrView);
                        float maxScrollDistance = MAX_SCROLL_SIZE_FRACTION * size;
                        if (absDelta >= size) {
                            delta = delta > 0 ? maxScrollDistance : -maxScrollDistance;
                        } else {
                            delta = maxScrollDistance * (float) Math.sin((delta/size)*(Math.PI/2));
                            delta = maxScrollDistance * (float) Math.sin(
                                    (delta / size) * (Math.PI / 2));
                        }
                    }

@@ -674,9 +677,10 @@ public class SwipeHelper implements Gefingerpoken {
    }

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

    public boolean isFalseGesture(MotionEvent ev) {
@@ -707,6 +711,16 @@ public class SwipeHelper implements Gefingerpoken {

        boolean canChildBeDismissed(View v);

        /**
         * Returns true if the provided child can be dismissed by a swipe in the given direction.
         *
         * @param isRightOrDown {@code true} if the swipe direction is right or down,
         *                      {@code false} if it is left or up.
         */
        default boolean canChildBeDismissedInDirection(View v, boolean isRightOrDown) {
            return canChildBeDismissed(v);
        }

        boolean isAntiFalsingNeeded();

        void onBeginDrag(View v);
+5 −0
Original line number Diff line number Diff line
@@ -5643,6 +5643,11 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd
        public boolean canChildBeDismissed(View v) {
            return NotificationStackScrollLayout.this.canChildBeDismissed(v);
        }

        @Override
        public boolean canChildBeDismissedInDirection(View v, boolean isRightOrDown) {
            return (isLayoutRtl() ? !isRightOrDown : isRightOrDown) && canChildBeDismissed(v);
        }
    };

    // ---------------------- DragDownHelper.OnDragDownListener ------------------------------------