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

make horizontal move better #209

Open
wants to merge 3 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
19 changes: 16 additions & 3 deletions ptr-lib/src/in/srain/cube/views/ptr/PtrFrameLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.*;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.widget.Scroller;
import android.widget.TextView;

import in.srain.cube.views.ptr.indicator.PtrIndicator;
import in.srain.cube.views.ptr.util.PtrCLog;

Expand Down Expand Up @@ -107,7 +112,7 @@ public PtrFrameLayout(Context context, AttributeSet attrs, int defStyle) {
mScrollChecker = new ScrollChecker();

final ViewConfiguration conf = ViewConfiguration.get(getContext());
mPagingTouchSlop = conf.getScaledTouchSlop() * 2;
mPagingTouchSlop = conf.getScaledPagingTouchSlop();
}

@Override
Expand Down Expand Up @@ -308,7 +313,7 @@ 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 (mDisableWhenHorizontalMove && !mPreventForHorizontal && (Math.abs(mPtrIndicator.getDistanceX()) > mPagingTouchSlop && Math.abs(offsetX) > Math.abs(offsetY))) {
if (mPtrIndicator.isInStartPosition()) {
mPreventForHorizontal = true;
}
Expand All @@ -318,6 +323,11 @@ public boolean dispatchTouchEvent(MotionEvent e) {
}

boolean moveDown = offsetY > 0;
if (mDisableWhenHorizontalMove && moveDown && mPtrIndicator.isInStartPosition()) {
if (mPtrIndicator.getDistanceY() <= mPagingTouchSlop) {
moveDown = false;
}
}
boolean moveUp = !moveDown;
boolean canMoveUp = mPtrIndicator.hasLeftStartPosition();

Expand Down Expand Up @@ -979,6 +989,9 @@ public void run() {
movePos(deltaY);
post(this);
} else {
if (mPtrIndicator.getCurrentPosY() != mTo) {
movePos(mTo - mPtrIndicator.getCurrentPosY());
}
finish();
}
}
Expand Down
16 changes: 15 additions & 1 deletion ptr-lib/src/in/srain/cube/views/ptr/indicator/PtrIndicator.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class PtrIndicator {

public final static int POS_START = 0;
protected int mOffsetToRefresh = 0;
private PointF mPtLastDownPoint = new PointF();
private PointF mPtLastMove = new PointF();
private float mOffsetX;
private float mOffsetY;
Expand Down Expand Up @@ -46,7 +47,11 @@ public boolean goDownCrossFinishPosition() {
}

protected void processOnMove(float currentX, float currentY, float offsetX, float offsetY) {
setOffset(offsetX, offsetY / mResistance);
if (isOverOffsetToRefresh() && offsetY > 0 && mCurrentPos > (1.2 * getHeaderHeight())) {
setOffset(offsetX, offsetY / mResistance / (mCurrentPos / (float) (getHeaderHeight() / 8)));
} else {
setOffset(offsetX, offsetY / mResistance);
}
}

public void setRatioOfHeaderHeightToRefresh(float ratio) {
Expand All @@ -70,6 +75,7 @@ public void setOffsetToRefresh(int offset) {
public void onPressDown(float x, float y) {
mIsUnderTouch = true;
mPressedPos = mCurrentPos;
mPtLastDownPoint.set(x, y);
mPtLastMove.set(x, y);
}

Expand All @@ -93,6 +99,14 @@ public float getOffsetY() {
return mOffsetY;
}

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

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

public int getLastPosY() {
return mLastPos;
}
Expand Down