Please have a look at this code sample taken from overridden onTouchEvent
of a View
,
@Override
public boolean onTouchEvent(MotionEvent event) {
float eventX = event.getX();
float eventY = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
//code move pointer position
break;
case MotionEvent.ACTION_MOVE:
// code to draw line from x to y
break;
case MotionEvent.ACTION_UP:
//Release pointer
break;
default:
return false;
}
}
This draws line fine, But the issue is when I touch one corner with the single finger and touch next corner of the screen with another finger and hold it then release the first finger. It draws line automatically from one finger to another. But in my app, it should be mandatory for the user to draw line manually by using a single finger.
Here is whats happening
To overcome this issue I tried as far as I could. It's not either a Multitouch
event.
Is this fault of the Android framework?
In addition:
I downloaded many drawing apps from Playstore to check if they've prevented such auto drawing. But all the apps behave same as my one.
How can I resolve this?
you just add case MotionEvent.ACTION_POINTER_UP
and release your points.
when your case in case MotionEvent.ACTION_POINTER_UP
,at this time, you up your finger,the program will run in action_move,at this time ,your just break off this action.
my example like this:
boolean isRelease = false;
@Override public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
isRelease = false;
//code move pointer position
break;
case MotionEvent.ACTION_MOVE:
if (isRelease) {
return true;
}
// code to draw line from x to y
break;
case MotionEvent.ACTION_POINTER_UP:
isRelease = true;
//Release pointer
break;
case MotionEvent.ACTION_UP:
isRelease = true;
//Release pointer
break;
}
return true;
}
sorry for my poor English.