Created
September 7, 2017 10:55
-
-
Save seerazz/876723130e0950f5e867142b5bc8b381 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CustomSwipeToRefresh extends SwipeRefreshLayout { | |
private int mTouchSlop; | |
private float mPrevX; | |
// Indicate if we've already declined the move event | |
private boolean mDeclined; | |
public CustomSwipeToRefresh(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); | |
} | |
@Override | |
public boolean onInterceptTouchEvent(MotionEvent event) { | |
switch (event.getAction()) { | |
case MotionEvent.ACTION_DOWN: | |
mPrevX = MotionEvent.obtain(event).getX(); | |
mDeclined = false; // New action | |
break; | |
case MotionEvent.ACTION_MOVE: | |
final float eventX = event.getX(); | |
float xDiff = Math.abs(eventX - mPrevX); | |
if (mDeclined || xDiff > mTouchSlop) { | |
mDeclined = true; // Memorize | |
return false; | |
} | |
} | |
return super.onInterceptTouchEvent(event); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment