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

Added deadzone to pull. Fixed flickering on stacked views. #288

Open
wants to merge 1 commit 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
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ANDROID_BUILD_MIN_SDK_VERSION=8
ANDROID_BUILD_TARGET_SDK_VERSION=22
ANDROID_BUILD_SDK_VERSION=22
ANDROID_BUILD_TOOLS_VERSION=22.0.1
ANDROID_BUILD_TARGET_SDK_VERSION=25
ANDROID_BUILD_SDK_VERSION=25
ANDROID_BUILD_TOOLS_VERSION=25.0.2
20 changes: 20 additions & 0 deletions ptr-lib/src/in/srain/cube/views/ptr/PtrFrameLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.view.*;
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 @@ -310,6 +311,11 @@ public boolean dispatchTouchEvent(MotionEvent e) {

case MotionEvent.ACTION_MOVE:
mLastMoveEvent = e;

//Deadzone check
if (Math.abs(e.getY() - mPtrIndicator.getLastMove().y) < mPtrIndicator.getDeadZone() && !mPtrIndicator.isPullActivated())
return dispatchTouchEventSupper(e);

mPtrIndicator.onMove(e.getX(), e.getY());
float offsetX = mPtrIndicator.getOffsetX();
float offsetY = mPtrIndicator.getOffsetY();
Expand Down Expand Up @@ -337,6 +343,10 @@ public boolean dispatchTouchEvent(MotionEvent e) {
return dispatchTouchEventSupper(e);
}

//To stop flicker because of stacked views
if ((offsetY < 0 && offsetY < (-mPtrIndicator.getHeaderHeight() / 2)) || (offsetY > mPtrIndicator.getHeaderHeight() / 2))
return false;

if ((moveUp && canMoveUp) || moveDown) {
movePos(offsetY);
return true;
Expand Down Expand Up @@ -369,6 +379,12 @@ private void movePos(float deltaY) {
to = PtrIndicator.POS_START;
}

//TODO Düzelt
/* if (to > 0)
to = Math.max(0, to - mPtrIndicator.getDeadZone());
else if (to < 0)
to = Math.min(0, to + mPtrIndicator.getDeadZone());*/

mPtrIndicator.setCurrentPos(to);
int change = to - mPtrIndicator.getLastPosY();
updatePos(change);
Expand Down Expand Up @@ -859,6 +875,10 @@ public void setOffsetToKeepHeaderWhileLoading(int offset) {
mPtrIndicator.setOffsetToKeepHeaderWhileLoading(offset);
}

public void setDeadZone(int deadZone) {
mPtrIndicator.setDeadZone(deadZone);
}

@SuppressWarnings({"unused"})
public boolean isKeepHeaderWhenRefresh() {
return mKeepHeaderWhenRefresh;
Expand Down
21 changes: 21 additions & 0 deletions ptr-lib/src/in/srain/cube/views/ptr/indicator/PtrIndicator.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class PtrIndicator {
private int mLastPos = 0;
private int mHeaderHeight;
private int mPressedPos = 0;
private int mDeadZone = 0;
private boolean mIsPullActivated = false;

private float mRatioOfHeaderHeightToRefresh = 1.2f;
private float mResistance = 1.7f;
Expand All @@ -35,6 +37,7 @@ public void setResistance(float resistance) {

public void onRelease() {
mIsUnderTouch = false;
mIsPullActivated = false;
}

public void onUIRefreshComplete() {
Expand Down Expand Up @@ -78,6 +81,11 @@ public final void onMove(float x, float y) {
float offsetY = (y - mPtLastMove.y);
processOnMove(x, y, offsetX, offsetY);
mPtLastMove.set(x, y);
mIsPullActivated = true;
}

public PointF getLastMove(){
return mPtLastMove;
}

protected void setOffset(float x, float y) {
Expand Down Expand Up @@ -194,4 +202,17 @@ public float getCurrentPercent() {
public boolean willOverTop(int to) {
return to < POS_START;
}

public void setDeadZone(int deadZone){
mDeadZone = deadZone;
}

public int getDeadZone(){
return mDeadZone;
}

//Activated after first move after deadzone.
public boolean isPullActivated(){
return mIsPullActivated;
}
}