Skip to content

Commit 902bc26

Browse files
author
Chris Banes
committed
Fix #72. Add option to disable the filtering of Touch Events
1 parent e716d0b commit 902bc26

1 file changed

Lines changed: 33 additions & 4 deletions

File tree

library/src/com/handmark/pulltorefresh/library/PullToRefreshBase.java

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public abstract class PullToRefreshBase<T extends View> extends LinearLayout {
3737

3838
public static enum Mode {
3939
/**
40-
* Only allow the user to Pull Down from the top to refresh, this is
41-
* the default.
40+
* Only allow the user to Pull Down from the top to refresh, this is the
41+
* default.
4242
*/
4343
PULL_DOWN_TO_REFRESH(0x1),
4444

@@ -173,7 +173,7 @@ public void stop() {
173173
static final int RELEASE_TO_REFRESH = 0x1;
174174
static final int REFRESHING = 0x2;
175175
static final int MANUAL_REFRESHING = 0x3;
176-
176+
177177
static final Mode DEFAULT_MODE = Mode.PULL_DOWN_TO_REFRESH;
178178

179179
static final String STATE_STATE = "ptr_state";
@@ -202,6 +202,7 @@ public void stop() {
202202
private boolean mPullToRefreshEnabled = true;
203203
private boolean mShowViewWhileRefreshing = true;
204204
private boolean mDisableScrollingWhileRefreshing = true;
205+
private boolean mFilterTouchEvents = true;
205206

206207
private LoadingLayout mHeaderLayout;
207208
private LoadingLayout mFooterLayout;
@@ -364,6 +365,34 @@ public final void setOnRefreshListener(OnRefreshListener2 listener) {
364365
mOnRefreshListener2 = listener;
365366
}
366367

368+
/**
369+
* Returns whether the Touch Events are filtered or not. If true is
370+
* returned, then the View will only use touch events where the difference
371+
* in the Y-axis is greater than the difference in the X-axis. This means
372+
* that the View will not interfere when it is used in a horizontal
373+
* scrolling View (such as a ViewPager).
374+
*
375+
* @return boolean - true if the View is filtering Touch Events
376+
*/
377+
public final boolean getFilterTouchEvents() {
378+
return mFilterTouchEvents;
379+
}
380+
381+
/**
382+
* Set the Touch Events to be filtered or not. If set to true, then the View
383+
* will only use touch events where the difference in the Y-axis is greater
384+
* than the difference in the X-axis. This means that the View will not
385+
* interfere when it is used in a horizontal scrolling View (such as a
386+
* ViewPager), but will restrict which types of finger scrolls will trigger
387+
* the View.
388+
*
389+
* @param filterEvents
390+
* - true if you want to filter Touch Events. Default is true.
391+
*/
392+
public final void setFilterTouchEvents(boolean filterEvents) {
393+
mFilterTouchEvents = filterEvents;
394+
}
395+
367396
/**
368397
* A mutator to enable/disable Pull-to-Refresh for the current View
369398
*
@@ -615,7 +644,7 @@ public final boolean onInterceptTouchEvent(MotionEvent event) {
615644
final float yDiff = Math.abs(dy);
616645
final float xDiff = Math.abs(event.getX() - mLastMotionX);
617646

618-
if (yDiff > mTouchSlop && yDiff > xDiff) {
647+
if (yDiff > mTouchSlop && (!mFilterTouchEvents || yDiff > xDiff)) {
619648
if (mMode.canPullDown() && dy >= 1f && isReadyForPullDown()) {
620649
mLastMotionY = y;
621650
mIsBeingDragged = true;

0 commit comments

Comments
 (0)