Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public class SuperSwipeRefreshLayout extends ViewGroup {
private boolean mOriginalOffsetCalculated = false;

private float mInitialMotionY;
private float mInitialMotionX;
private boolean mIsBeingDragged;
private int mActivePointerId = INVALID_POINTER;
private boolean mScale;
Expand Down Expand Up @@ -653,10 +654,12 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
mIsBeingDragged = false;
final float initialMotionY = getMotionEventY(ev, mActivePointerId);
final float initialMotionX = getMotionEventX(ev, mActivePointerId);
if (initialMotionY == -1) {
return false;
}
mInitialMotionY = initialMotionY;// 记录按下的位置
mInitialMotionX = initialMotionX;// 记录按下的位置

case MotionEvent.ACTION_MOVE:
if (mActivePointerId == INVALID_POINTER) {
Expand All @@ -666,18 +669,20 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
}

final float y = getMotionEventY(ev, mActivePointerId);
final float x = getMotionEventX(ev, mActivePointerId);
if (y == -1) {
return false;
}
float yDiff = 0;
float xDiff = mInitialMotionX - x;
if (isChildScrollToBottom()) {
yDiff = mInitialMotionY - y;// 计算上拉距离
if (yDiff > mTouchSlop && !mIsBeingDragged) {// 判断是否下拉的距离足够
if (Math.abs(xDiff)< yDiff && yDiff > mTouchSlop && !mIsBeingDragged) {// 判断是否下拉的距离足够
mIsBeingDragged = true;// 正在上拉
}
} else {
yDiff = y - mInitialMotionY;// 计算下拉距离
if (yDiff > mTouchSlop && !mIsBeingDragged) {// 判断是否下拉的距离足够
if (Math.abs(xDiff)< yDiff && yDiff > mTouchSlop && !mIsBeingDragged) {// 判断是否下拉的距离足够
mIsBeingDragged = true;// 正在下拉
}
}
Expand Down Expand Up @@ -706,6 +711,15 @@ private float getMotionEventY(MotionEvent ev, int activePointerId) {
return MotionEventCompat.getY(ev, index);
}

private float getMotionEventX(MotionEvent ev, int activePointerId) {
final int index = MotionEventCompat.findPointerIndex(ev,
activePointerId);
if (index < 0) {
return -1;
}
return MotionEventCompat.getX(ev, index);
}

@Override
public void requestDisallowInterceptTouchEvent(boolean b) {
// Nope.
Expand Down