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

Commit 362c4441 authored by Hongwei Wang's avatar Hongwei Wang
Browse files

Tone down the sensitivity of swipe for square contact tiles

Bug: 10510033
Change-Id: I57961e3f7dcc8c65dfb814afd808d01b68803f14
parent 13a58c38
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -715,6 +715,9 @@ public class PhoneFavoritesTileAdapter extends BaseAdapter implements
                        .getScaledPagingTouchSlop();
                mSwipeHelper = new SwipeHelper(context, SwipeHelper.X, this, densityScale,
                        pagingTouchSlop);
                // Increase swipe thresholds for square tiles since they are relatively small.
                mSwipeHelper.setChildSwipedFarEnoughFactor(0.9f);
                mSwipeHelper.setChildSwipedFastEnoughFactor(0.1f);
                mOnItemSwipeListener = PhoneFavoritesTileAdapter.this;
            }
        }
+17 −6
Original line number Diff line number Diff line
@@ -89,6 +89,9 @@ public class SwipeHelper {
    private float mStartAlpha;
    private boolean mProtected = false;

    private float mChildSwipedFarEnoughFactor = 0.4f;
    private float mChildSwipedFastEnoughFactor = 0.05f;

    public SwipeHelper(Context context, int swipeDirection, SwipeHelperCallback callback, float densityScale,
            float pagingTouchSlop) {
        mCallback = callback;
@@ -118,6 +121,14 @@ public class SwipeHelper {
        mPagingTouchSlop = pagingTouchSlop;
    }

    public void setChildSwipedFarEnoughFactor(float factor) {
        mChildSwipedFarEnoughFactor = factor;
    }

    public void setChildSwipedFastEnoughFactor(float factor) {
        mChildSwipedFastEnoughFactor = factor;
    }

    private float getVelocity(VelocityTracker vt) {
        return mSwipeDirection == X ? vt.getXVelocity() :
                vt.getYVelocity();
@@ -407,15 +418,15 @@ public class SwipeHelper {
                    // swipe/dismiss
                    float translation = Math.abs(mCurrAnimView.getTranslationX());
                    float currAnimViewSize = getSize(mCurrAnimView);
                    // Long swipe = translation of .4 * width
                    // Long swipe = translation of {@link #mChildSwipedFarEnoughFactor} * width
                    boolean childSwipedFarEnough = DISMISS_IF_SWIPED_FAR_ENOUGH
                            && translation > 0.4 * currAnimViewSize;
                    // Fast swipe = > escapeVelocity and translation of .1 *
                    // width
                            && translation > mChildSwipedFarEnoughFactor * currAnimViewSize;
                    // Fast swipe = > escapeVelocity and translation of
                    // {@link #mChildSwipedFastEnoughFactor} * width
                    boolean childSwipedFastEnough = (Math.abs(velocity) > escapeVelocity)
                            && (Math.abs(velocity) > Math.abs(perpendicularVelocity))
                            && (velocity > 0) == (mCurrAnimView.getTranslationX() > 0)
                            && translation > 0.05 * currAnimViewSize;
                            && translation > mChildSwipedFastEnoughFactor * currAnimViewSize;
                    if (LOG_SWIPE_DISMISS_VELOCITY) {
                        Log.v(TAG, "Swipe/Dismiss: " + velocity + "/" + escapeVelocity + "/"
                                + perpendicularVelocity + ", x: " + translation + "/"