Skip to content

Commit b581f4f

Browse files
jogehringjogehring
jogehring
authored and
jogehring
committed
refs #64 scrolling is more stable
1 parent 573b38a commit b581f4f

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/com/jjoe64/graphview/GraphView.java

+15-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import android.graphics.Rect;
3232
import android.graphics.RectF;
3333
import android.util.AttributeSet;
34+
import android.util.Log;
3435
import android.view.MotionEvent;
3536
import android.view.View;
3637
import android.widget.LinearLayout;
@@ -57,6 +58,7 @@ static final private class GraphViewConfig {
5758
private class GraphViewContentView extends View {
5859
private float lastTouchEventX;
5960
private float graphwidth;
61+
private boolean scrollingStarted;
6062

6163
/**
6264
* @param context
@@ -195,23 +197,32 @@ public boolean onTouchEvent(MotionEvent event) {
195197
handled = scaleDetector.isInProgress();
196198
}
197199
if (!handled) {
200+
Log.d("GraphView", "on touch event scale not handled+"+lastTouchEventX);
198201
// if not scaled, scroll
199202
if ((event.getAction() & MotionEvent.ACTION_DOWN) == MotionEvent.ACTION_DOWN) {
203+
scrollingStarted = true;
200204
handled = true;
201205
}
202206
if ((event.getAction() & MotionEvent.ACTION_UP) == MotionEvent.ACTION_UP) {
207+
scrollingStarted = false;
203208
lastTouchEventX = 0;
204209
handled = true;
205210
}
206211
if ((event.getAction() & MotionEvent.ACTION_MOVE) == MotionEvent.ACTION_MOVE) {
207-
if (lastTouchEventX != 0) {
208-
onMoveGesture(event.getX() - lastTouchEventX);
212+
if (scrollingStarted) {
213+
if (lastTouchEventX != 0) {
214+
onMoveGesture(event.getX() - lastTouchEventX);
215+
}
216+
lastTouchEventX = event.getX();
217+
handled = true;
209218
}
210-
lastTouchEventX = event.getX();
211-
handled = true;
212219
}
213220
if (handled)
214221
invalidate();
222+
} else {
223+
// currently scaling
224+
scrollingStarted = false;
225+
lastTouchEventX = 0;
215226
}
216227
return handled;
217228
}

0 commit comments

Comments
 (0)