Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix bug liaohuqiu#133 HorizontalMove with a ViewPager
  • Loading branch information
pip1998 committed Dec 17, 2015
1 parent 933815f commit 83531bf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
17 changes: 11 additions & 6 deletions ptr-lib/src/in/srain/cube/views/ptr/PtrFrameLayout.java
Expand Up @@ -107,7 +107,8 @@ public PtrFrameLayout(Context context, AttributeSet attrs, int defStyle) {
mScrollChecker = new ScrollChecker();

final ViewConfiguration conf = ViewConfiguration.get(getContext());
mPagingTouchSlop = conf.getScaledTouchSlop() * 2;
// mPagingTouchSlop = conf.getScaledTouchSlop() * 2;
mPagingTouchSlop = (int) (conf.getScaledTouchSlop() * 1.f);
}

@Override
Expand Down Expand Up @@ -264,7 +265,7 @@ private void layoutChildren() {
public boolean dispatchTouchEventSupper(MotionEvent e) {
return super.dispatchTouchEvent(e);
}

private boolean mIsBeingDragged = false;
@Override
public boolean dispatchTouchEvent(MotionEvent e) {
if (!isEnabled() || mContent == null || mHeaderView == null) {
Expand All @@ -274,6 +275,7 @@ public boolean dispatchTouchEvent(MotionEvent e) {
switch (action) {
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
mIsBeingDragged = false;
mPtrIndicator.onRelease();
if (mPtrIndicator.hasLeftStartPosition()) {
if (DEBUG) {
Expand All @@ -290,6 +292,7 @@ public boolean dispatchTouchEvent(MotionEvent e) {
}

case MotionEvent.ACTION_DOWN:
mIsBeingDragged = false;
mHasSendCancelEvent = false;
mPtrIndicator.onPressDown(e.getX(), e.getY());

Expand All @@ -308,16 +311,18 @@ public boolean dispatchTouchEvent(MotionEvent e) {
float offsetX = mPtrIndicator.getOffsetX();
float offsetY = mPtrIndicator.getOffsetY();

if (mDisableWhenHorizontalMove && !mPreventForHorizontal && (Math.abs(offsetX) > mPagingTouchSlop && Math.abs(offsetX) > Math.abs(offsetY))) {
if (mPtrIndicator.isInStartPosition()) {
if (mDisableWhenHorizontalMove && !mPreventForHorizontal && (Math.abs(mPtrIndicator.getDistanceX()) > mPagingTouchSlop && Math.abs(offsetX) > Math.abs(offsetY))) {
if (Math.abs(mPtrIndicator.getDistanceY())<mPagingTouchSlop) {
mPreventForHorizontal = true;
}
}
if (mPreventForHorizontal) {
return dispatchTouchEventSupper(e);
}

boolean moveDown = offsetY > 0;

mIsBeingDragged = mIsBeingDragged || Math.abs(mPtrIndicator.getDistanceY() )>mPagingTouchSlop;
boolean moveDown = offsetY>0;
boolean moveUp = !moveDown;
boolean canMoveUp = mPtrIndicator.hasLeftStartPosition();

Expand All @@ -331,7 +336,7 @@ public boolean dispatchTouchEvent(MotionEvent e) {
return dispatchTouchEventSupper(e);
}

if ((moveUp && canMoveUp) || moveDown) {
if (((moveUp && canMoveUp) || moveDown) && mIsBeingDragged) {
movePos(offsetY);
return true;
}
Expand Down
10 changes: 10 additions & 0 deletions ptr-lib/src/in/srain/cube/views/ptr/indicator/PtrIndicator.java 100644 → 100755
Expand Up @@ -7,6 +7,7 @@ public class PtrIndicator {
public final static int POS_START = 0;
protected int mOffsetToRefresh = 0;
private PointF mPtLastMove = new PointF();
private PointF mPtPressDownPoint = new PointF();
private float mOffsetX;
private float mOffsetY;
private int mCurrentPos = 0;
Expand Down Expand Up @@ -71,6 +72,7 @@ public void onPressDown(float x, float y) {
mIsUnderTouch = true;
mPressedPos = mCurrentPos;
mPtLastMove.set(x, y);
mPtPressDownPoint.set(x, y);
}

public final void onMove(float x, float y) {
Expand All @@ -85,6 +87,14 @@ protected void setOffset(float x, float y) {
mOffsetY = y;
}

public float getDistanceX(){
return mPtLastMove.x - mPtPressDownPoint.x;
}

public float getDistanceY(){
return mPtLastMove.y - mPtPressDownPoint.y;
}

public float getOffsetX() {
return mOffsetX;
}
Expand Down

7 comments on commit 83531bf

@karashao
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

谢谢修正这个BUG!解决了大问题TAT

@120660021
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢。。

@lc2014
Copy link

@lc2014 lc2014 commented on 83531bf Mar 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compile 版本号多少?

@leftcoding
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx

@Aspsine
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@q232916067
看看这里的方案。

@shenminjie
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不错,能解决问题,Nice!

@dingbuoyi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recycleview 测过了,没有效果,VIEW PAGER还没测试

Please sign in to comment.