Skip to content

Commit

Permalink
refs #64 scrolling is more stable
Browse files Browse the repository at this point in the history
  • Loading branch information
jogehring authored and jogehring committed Aug 7, 2013
1 parent 573b38a commit b581f4f
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/com/jjoe64/graphview/GraphView.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
Expand All @@ -57,6 +58,7 @@ static final private class GraphViewConfig {
private class GraphViewContentView extends View {
private float lastTouchEventX;
private float graphwidth;
private boolean scrollingStarted;

/**
* @param context
Expand Down Expand Up @@ -195,23 +197,32 @@ public boolean onTouchEvent(MotionEvent event) {
handled = scaleDetector.isInProgress();
}
if (!handled) {
Log.d("GraphView", "on touch event scale not handled+"+lastTouchEventX);
// if not scaled, scroll
if ((event.getAction() & MotionEvent.ACTION_DOWN) == MotionEvent.ACTION_DOWN) {
scrollingStarted = true;
handled = true;
}
if ((event.getAction() & MotionEvent.ACTION_UP) == MotionEvent.ACTION_UP) {
scrollingStarted = false;
lastTouchEventX = 0;
handled = true;
}
if ((event.getAction() & MotionEvent.ACTION_MOVE) == MotionEvent.ACTION_MOVE) {
if (lastTouchEventX != 0) {
onMoveGesture(event.getX() - lastTouchEventX);
if (scrollingStarted) {
if (lastTouchEventX != 0) {
onMoveGesture(event.getX() - lastTouchEventX);
}
lastTouchEventX = event.getX();
handled = true;
}
lastTouchEventX = event.getX();
handled = true;
}
if (handled)
invalidate();
} else {
// currently scaling
scrollingStarted = false;
lastTouchEventX = 0;
}
return handled;
}
Expand Down

0 comments on commit b581f4f

Please sign in to comment.