When I press my finger on a button and then move it outside button's bounds, the onTouchListener
continues firing.
The same thing happens when I press one finger on the button and a second finger outside the button: my onTouchListener
fires for the second finger.
How do I can avoid this? I want to fire my onTouchListener
only when I press inside a button's bounds.
Here is my onTouchListener
implementation
View.OnTouchListener onTouchListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (fingerDown) {
xHistoricalFirstFinger = (int) event.getX();
yHistoricalFirstFinger = (int) event.getY();
xFirstClick = xHistoricalFirstFinger;
yFirstClick = yHistoricalFirstFinger;
//counter++;
fingerDown = false;
}
x = (int) event.getX();
y = (int) event.getY();
Log.v("Touched", client.remoteAdress.toString());
mouseMoveProvider.nextX = x - xHistoricalFirstFinger;
mouseMoveProvider.nextY = y - yHistoricalFirstFinger;
mouseMoveProvider.Ready = true;
xHistoricalFirstFinger = x;
yHistoricalFirstFinger = y;
if (event.getAction() == MotionEvent.ACTION_UP) {
if (x - xFirstClick == 0 & y - yFirstClick == 0) {
new Thread(new Runnable() {
@Override
public void run() {
try {
client.MakeMove();
} catch (IOException e) {
e.printStackTrace();
NetworkListener.HandleNetworkIsUreachableException(context);
}
}
}).start();
}
fingerDown = true;
}
return true;
}
};