Reputation: 19278
I'm creating an aplication where I can draw on a picture. Drawing is achieved by a pictureView, canvas with a bitmap and a onTouchListener. I want to add a feature that will undo the last action when there is a two finger short press. I achieved it by doing this:
if(event.getActionMasked() == MotionEvent.ACTION_POINTER_UP ){
//undo
}
And I want to undo all the drawing actions when there is a two finger long press. I tried something like this, but it will detect only once.
if(event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN ){
numberOfDown++;
if(numberOfDown>100){
//undo
}
}
How can I achieve what I want?
Upvotes: 2
Views: 1639
Reputation: 93521
I'm not sure whether the action index starts at zero for the primary finger or the non-primary fingers, so you might need to flip these 0's to 1's.
if(event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN && event.getActionIndex()==0){
mSecondFingerTimeDown = System.currentTimeMillis();
}
if(event.getActionMasked() == MotionEvent.ACTION_POINTER_UP && event.getActionIndex()==0 ){
if ((System.currentTimeMillis()-mSecondFingerDownTime) >= LONG_PRESS_TIME_MILLIS)
//long double-press action
else
//short double-press action
}
Upvotes: 1