Is it possible to disable MotionEvent.ACTION_POINTER_DOWN & UP - android

I have a problem with a second touch on screen and I would like to disable it. Primaly, object that has been touch if first finger is released is teleporing to second finger (MotionEvent.ACTION_POINTER_DOWN).
Is it possible to disable this event?

Try add touch listener and catch and cancel ACTION_POINTER_DOWN/UP:
public boolean onTouch(View v, MotionEvent event) {
switch(event.getActionMasked()) {
case MotionEvent.ACTION_POINTER_DOWN:
Log.d("ButtonCode", "ACTION_POINTER_DOWN");
return true;
break;
case MotionEvent.ACTION_POINTER_UP:
Log.d("ButtonCode", "ACTION_POINTER_UP");
return true;
break;
default:
break;
}
return false;}

Related

Android MotionEvent to detect only ACTION_MOVE

As per android MotionEvent documents: A change has happened during a press gesture (between ACTION_DOWN and ACTION_UP). The motion contains the most recent point, as well as any intermediate points since the last down or move event.
ACTION_MOVE Android doc
so when i apply a setOnTouchListene on my view is perfectly works, It give me ACTION_DOWN, ACTION_UP, and ACTION_MOVE
but my problem is i just want to ignore a ACTION_DOWN events exactly before ACTION_MOVE. Because ACTION_MOVE event occur only after the ACTION_DOWN event as per its documents.
my coding:
button.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
Log.e("Mouse: ", "Click");
break;
case MotionEvent.ACTION_MOVE:
Log.e("Mouse: ", "Move");
break;
}
return false;
}
});
So, there is any why to ignore ACTION_DOWN event. Because user only want to move not want to click, and ACTION_MOVE is also occur ACTION_DOWN before it execute it self.
Thanks...
According to your comment - you can play with counter. For example:
private static int counter = 0;
...
button.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
Log.e("Mouse: ", "Click");
break;
case MotionEvent.ACTION_MOVE:
counter++; //check how long the button is pressed
if(counter>10){
Log.e("Mouse: ", "Move");
}
break;
case MotionEvent.ACTION_UP:
if(counter<10){
//this is just onClick, handle it(10 is example, try different numbers)
}else{
//it's a move
}
counter = 0;
break;
}
return false;
}
});

Android on touch events not detecting after scrolling

I am facing problem during detecting touch events. Its working fine without scrolling. But after scroll finished when I am removing finger not able to receive motion up event.I am using following code.
linearMain.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// Do Something
Log.d("Touch", "Touch down");
// Now Set your animation
slidingDrawerMos.startAnimation(slideOutAnimation);
slidingDrawerReviews.startAnimation(slideOutAnimation);
slidingDrawerMos.setVisibility(View.GONE);
slidingDrawerReviews.setVisibility(View.GONE);
break;
case MotionEvent.ACTION_MOVE:
// Do Something
Log.d("Touch", "Touch move");
break;
case MotionEvent.ACTION_UP:
// Do Something
Log.d("Touch", "Touch up");
slidingDrawerMos.setVisibility(View.VISIBLE);
slidingDrawerReviews.setVisibility(View.VISIBLE);
// Now Set your animation
slidingDrawerMos.startAnimation(slideInAnimation);
slidingDrawerReviews.startAnimation(slideInAnimation);
break;
case MotionEvent.ACTION_CANCEL:
Log.d("Touch", "Touch cancel");
break;
default:
break;
}
return true;
}
});
your_control.setMovementMethod(new ScrollingMovementMethod());
and
findViewById(R.id.your_control).getParent()
.requestDisallowInterceptTouchEvent(false);

Android Imageview setOnTouchListener not working?

i'am using imageview on touch listener in this motion event not working why this happen any one have idea regarding this help me.
here is my code
img_View11.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
Log.i("img_View11", "img_View11 _1");
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
Log.i("img_View11", "img_View11 _2");
break;
case MotionEvent.ACTION_MOVE:
Log.i("img_View11", "img_View11 _3");
break;
case MotionEvent.ACTION_UP:
Log.i("img_View11", "img_View11 _4");
break;
}
return false;
}
});
here my out put show like this img_View11_1 and two img_View11_2
Log.i("img_View11", "img_View11 _1");
Log.i("img_View11", "img_View11 _2");
Question: Why MotionEvent.ACTION_MOVE and MotionEvent.ACTION_UP not working ?
Change "return false;" to "return true;" so that it will continue to receive calls.

Android Distinguishing Between Click and Drag dispatchTouchEvent

I am currently using dispatchTouchEvent to grab touch events, is there an easy way to distinguish between a click and a "drag" stylt gesture?
DispatchTouchEvent is called with a MotionEvent parameter. Method getAction within MotionEvent can return
ACTION_DOWN
ACTION_MOVE
ACTION_UP
ACTION_CANCEL
Then set on ACTION_DOWN flag isClick. If there is ACTION_MOVE clear isClick flag.
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
isClick = true;
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
if (isClick) {
//TODO Click action
}
break;
case MotionEvent.ACTION_MOVE:
isClick = false;
break;
default:
break;
}
return true;
}
set up a threshold limit.When you move the pointer within a small range make it recognized as a click or else a movement

Multitouch: ACTION_POINTER_DOWN & ACTION_POINTER_UP

I'm trying to use multitouch as a method to press 2 things simultaneously.
Here's my Code:
TouchHandle.setOnTouchListener(new OnTouchListener () {
public boolean onTouch(View view, MotionEvent event) {
int actions = event.getActionMasked();
switch (actions)
{
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
SendKeyCode(Server, "keydec.down");
case MotionEvent.ACTION_POINTER_UP:
SendKeyCode(Server, "keydec.up");
case MotionEvent.ACTION_UP:
}
return true;
}
});
The problem is that when I touch the screen, the server is retrieving "keydec.down" and "keydec.up" even thought I haven't removed my finger yet from the touchscreen. So the View TouchHandle is detecting an ACTION_POINTER_DOWN and ACTION_POINTER_UP when my finger touches the screen even if I haven't pulled my finger up yet. Any thoughts?
int actions = event.getAction();
switch (actions)
{
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_POINTER_DOWN:
SendKeyCode(Server, "keydec.down");
break;
case MotionEvent.ACTION_POINTER_UP:
SendKeyCode(Server, "keydec.up");
break;
case MotionEvent.ACTION_UP:
break;
}
You should use breaks between cases. And i also think that these MotionEvent constants might work with event.getAction() try that one.

Categories

Resources