cpp-140: Long click eraser is triggered when several buttons are clicked
It turned out that onLongPress method call might be postponed and thus ACTION_UP happens before eraser.start is called. Now with new property this case should be handled Fixes #140
This commit is contained in:
parent
6b9614b402
commit
bced8f138f
@ -1,6 +1,5 @@
|
||||
package org.solovyev.android.calculator.view;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
@ -39,8 +38,10 @@ public final class LongClickEraser implements View.OnTouchListener {
|
||||
this.view = view;
|
||||
this.gestureDetector = new GestureDetector(view.getContext(), new GestureDetector.SimpleOnGestureListener() {
|
||||
public void onLongPress(MotionEvent e) {
|
||||
if (eraser.isTracking()) {
|
||||
eraser.start();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -49,9 +50,10 @@ public final class LongClickEraser implements View.OnTouchListener {
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
case MotionEvent.ACTION_UP:
|
||||
eraser.stop();
|
||||
eraser.stopTracking();
|
||||
break;
|
||||
default:
|
||||
eraser.startTracking();
|
||||
gestureDetector.onTouchEvent(event);
|
||||
break;
|
||||
}
|
||||
@ -63,6 +65,7 @@ public final class LongClickEraser implements View.OnTouchListener {
|
||||
private long delay;
|
||||
private boolean wasCalculatingOnFly;
|
||||
private boolean erasing;
|
||||
private boolean tracking = true;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@ -100,5 +103,18 @@ public final class LongClickEraser implements View.OnTouchListener {
|
||||
calculator.setCalculateOnFly(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void stopTracking() {
|
||||
stop();
|
||||
tracking = false;
|
||||
}
|
||||
|
||||
public boolean isTracking() {
|
||||
return tracking;
|
||||
}
|
||||
|
||||
public void startTracking() {
|
||||
tracking = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user