Swipe too sensitive on Secondary View, impossible to register a click
gregblaszczuk opened this issue · 2 comments
gregblaszczuk commented
Swipe being too sensitive has been fixed in relation to the main view but it's still a problem on the secondary view. If you place anything in the secondary view that you intent to click it will simply register the touch as a drag and not "fail" over to let the click listener capture the event.
It seems that the fix would be to apply the same logic that is being applied to main view to the secondary view.
agalamagala commented
Hello!
Here is the solution from @qihongbo, modified a bit by me to also fix the sensitivity issue for the secondary view. Hope it helps! :)
Just replace copy paste this in place of the "onInterceptTouchEvent" method.
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if(isDragLocked()){
return super.onInterceptTouchEvent(ev);
}
mGestureDetector.onTouchEvent(ev);
mDragHelper.processTouchEvent(ev);
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN: {
mX = ev.getRawX();
mY = ev.getRawY();
}
}
if(inMainView(ev)){
boolean in = isInTouchSlop(ev);
if(in){
return false;
}
} else if (inSecondaryView(ev)) {
boolean in = isInTouchSlop(ev);
if(in){
return false;
}
}
boolean settling = mDragHelper.getViewDragState() == ViewDragHelper.STATE_SETTLING;
boolean idleAfterScrolled = mDragHelper.getViewDragState() == ViewDragHelper.STATE_IDLE
&& mIsScrolling;
return settling || idleAfterScrolled;
}
private boolean inMainView(MotionEvent ev){
float x = ev.getX();
float y = ev.getY();
return x >= mMainView.getLeft() && x <= mMainView.getRight() && y >= mMainView.getTop() && y <= mMainView.getBottom();
}
private boolean inSecondaryView(MotionEvent ev){
float x = ev.getX();
float y = ev.getY();
return x >= mSecondaryView.getLeft() && x <= mSecondaryView.getRight() && y >= mSecondaryView.getTop() && y <= mSecondaryView.getBottom();
}
private boolean isInTouchSlop(MotionEvent ev){
boolean in = false;
if(getDragEdge() == DRAG_EDGE_LEFT || getDragEdge() == DRAG_EDGE_RIGHT){
float distanceX = Math.abs(ev.getRawX()-mX);
if(distanceX < mDragHelper.getTouchSlop()){
in = true;
}
}else{
float distanceY = Math.abs(ev.getRawY()-mY);
if(distanceY < mDragHelper.getTouchSlop()){
in = true;
}
}
return in;
}
FirstSpectr commented
@agalamagala how to edit lib code? Do I have to clone repo and build jar?