Skip to content

Commit 827d2d0

Browse files
authored
Merge pull request #84 from Andrius-B/develop
Fixed scroll input lag
2 parents 6f28526 + da31f35 commit 827d2d0

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

library/src/main/java/com/alamkanak/weekview/WeekView.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,16 @@ private enum Direction {
164164

165165
@Override
166166
public boolean onDown(MotionEvent e) {
167-
goToNearestOrigin();
167+
stopScrolling();
168168
return true;
169169
}
170170

171+
@Override
172+
public boolean onSingleTapUp(MotionEvent e){
173+
goToNearestOrigin();
174+
return false;
175+
}
176+
171177
@Override
172178
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
173179
// Check if view is zoomed.
@@ -272,6 +278,7 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve
272278

273279
@Override
274280
public boolean onSingleTapConfirmed(MotionEvent e) {
281+
goToNearestOrigin();
275282

276283
// If the tap was on an event then trigger the callback.
277284
if (mEventRects != null && mEventClickListener != null) {
@@ -371,6 +378,7 @@ top < getHeight() &&
371378
@Override
372379
public void onLongPress(MotionEvent e) {
373380
super.onLongPress(e);
381+
goToNearestOrigin();
374382

375383
if (mEventLongPressListener != null && mEventRects != null) {
376384
List<EventRect> reversedEventRects = mEventRects;
@@ -2525,6 +2533,16 @@ public boolean onTouchEvent(MotionEvent event) {
25252533
return val;
25262534
}
25272535

2536+
/**
2537+
* A lighter function to stop the current scroll animation
2538+
*/
2539+
private void stopScrolling(){
2540+
//force scroller animation stop
2541+
mScroller.forceFinished(true);
2542+
// Reset scrolling and fling direction.
2543+
mCurrentScrollDirection = mCurrentFlingDirection = Direction.NONE;
2544+
}
2545+
25282546
private void goToNearestOrigin() {
25292547
double leftDays = mCurrentOrigin.x / (mWidthPerDay + mColumnGap);
25302548

0 commit comments

Comments
 (0)