Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master #178

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
17 changes: 11 additions & 6 deletions ptr-lib/src/in/srain/cube/views/ptr/PtrFrameLayout.java
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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