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

Commit 072c6033 authored by Mindy Pereira's avatar Mindy Pereira
Browse files

Make distance count when dismissing swipedismisslayout

verify the user's gesture took up at least 40% of the screen
before dismissing
Part of b/14319825 Cliff guard against accidental card dismissals

Works in conjunction with GridViewPager change:
https://googleplex-android-review.git.corp.google.com/#/c/461036/
Change-Id: Id8ff02d0a2d727b54c9950ad14ddef7a110f4eef
parent 17c5e990
Loading
Loading
Loading
Loading
+8 −9
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ import android.widget.FrameLayout;
public class SwipeDismissLayout extends FrameLayout {
    private static final String TAG = "SwipeDismissLayout";

    private static final float DISMISS_MIN_PROGRESS = 0.6f;
    private static final float DISMISS_MIN_DRAG_WIDTH_RATIO = .4f;

    public interface OnDismissedListener {
        void onDismissed(SwipeDismissLayout layout);
@@ -244,7 +244,11 @@ public class SwipeDismissLayout extends FrameLayout {
        if (!mSwiping) {
            float deltaX = ev.getRawX() - mDownX;
            float deltaY = ev.getRawY() - mDownY;
            if ((deltaX * deltaX) + (deltaY * deltaY) > mSlop * mSlop) {
                mSwiping = deltaX > mSlop * 2 && Math.abs(deltaY) < mSlop * 2;
            } else {
                mSwiping = false;
            }
        }
    }

@@ -254,12 +258,7 @@ public class SwipeDismissLayout extends FrameLayout {
            mVelocityTracker.addMovement(ev);
            mVelocityTracker.computeCurrentVelocity(1000);

            float velocityX = mVelocityTracker.getXVelocity();
            float absVelocityX = Math.abs(velocityX);
            float absVelocityY = Math.abs(mVelocityTracker.getYVelocity());

            if (deltaX > (getWidth() * DISMISS_MIN_PROGRESS) &&
                    absVelocityX < mMinFlingVelocity && 
            if (deltaX > (getWidth() * DISMISS_MIN_DRAG_WIDTH_RATIO) &&
                    ev.getRawX() >= mLastX) {
                mDismissed = true;
            }
@@ -267,7 +266,7 @@ public class SwipeDismissLayout extends FrameLayout {
        // Check if the user tried to undo this.
        if (mDismissed && mSwiping) {
            // Check if the user's finger is actually back
            if (deltaX < (getWidth() * DISMISS_MIN_PROGRESS)) {
            if (deltaX < (getWidth() * DISMISS_MIN_DRAG_WIDTH_RATIO)) {
                mDismissed = false;
            }
        }