Skip to content

Commit a00d34b

Browse files
author
Issac
committed
Add setSensitivity method.
1 parent 79aea32 commit a00d34b

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

library/src/main/java/me/imid/swipebacklayout/lib/SwipeBackLayout.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,17 @@ public SwipeBackLayout(Context context, AttributeSet attrs, int defStyle) {
154154
final float density = getResources().getDisplayMetrics().density;
155155
final float minVel = MIN_FLING_VELOCITY * density;
156156
mDragHelper.setMinVelocity(minVel);
157+
}
157158

159+
/**
160+
* Sets the sensitivity of the NavigationLayout.
161+
*
162+
* @param context The application context.
163+
* @param sensitivity value between 0 and 1, the final value for touchSlop =
164+
* ViewConfiguration.getScaledTouchSlop * (1 / s);
165+
*/
166+
public void setSensitivity(Context context, float sensitivity) {
167+
mDragHelper.setSensitivity(context, sensitivity);
158168
}
159169

160170
/**

library/src/main/java/me/imid/swipebacklayout/lib/ViewDragHelper.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,19 @@ private ViewDragHelper(Context context, ViewGroup forParent, Callback cb) {
425425
mScroller = ScrollerCompat.create(context, sInterpolator);
426426
}
427427

428+
/**
429+
* Sets the sensitivity of the dragger.
430+
*
431+
* @param context The application context.
432+
* @param sensitivity value between 0 and 1, the final value for touchSlop =
433+
* ViewConfiguration.getScaledTouchSlop * (1 / s);
434+
*/
435+
public void setSensitivity(Context context, float sensitivity) {
436+
float s = Math.max(0f, Math.min(1.0f, sensitivity));
437+
ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
438+
mTouchSlop = (int) (viewConfiguration.getScaledTouchSlop() * (1 / s));
439+
}
440+
428441
/**
429442
* Set the minimum velocity that will be detected as having a magnitude
430443
* greater than zero in pixels per second. Callback methods accepting a

0 commit comments

Comments
 (0)