From bced8f138f78c2b12bc57c7237ce8c64aaea8bc3 Mon Sep 17 00:00:00 2001 From: serso Date: Tue, 17 Feb 2015 12:15:14 +0100 Subject: [PATCH] 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 --- .../calculator/view/LongClickEraser.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/android-app/src/main/java/org/solovyev/android/calculator/view/LongClickEraser.java b/android-app/src/main/java/org/solovyev/android/calculator/view/LongClickEraser.java index 369fc25a..72c76d5c 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/view/LongClickEraser.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/view/LongClickEraser.java @@ -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,7 +38,9 @@ public final class LongClickEraser implements View.OnTouchListener { this.view = view; this.gestureDetector = new GestureDetector(view.getContext(), new GestureDetector.SimpleOnGestureListener() { public void onLongPress(MotionEvent e) { - eraser.start(); + 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; + } } }