Multitouch: ACTION_POINTER_DOWN & ACTION_POINTER_UP - android

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.

Related

Android - multiple finger touches for 1 button

I want a button that can detect multiple fingers. Like ı am holding with 1 finger and then 1 more finger touches that button it has to detect that.
Or
a button that when pushed, automatically release that button dont care if it actually released or not.
I use onTouchevent for multiple buttons for my drum kit project.
#Override
public boolean onTouch(View view, MotionEvent motionEvent)
{
Animation zoomIn = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.zoomin);
switch (motionEvent.getAction())
{
case MotionEvent.ACTION_DOWN:
switch(view.getId())
{
case R.id.BassL:
findViewById(R.id.bass).startAnimation(zoomIn);
sp.play(BassD,1.0f,1.0f,0,0,1.0f);
break;
case R.id.BassR:
findViewById(R.id.bass).startAnimation(zoomIn);
sp.play(BassD,1.0f,1.0f,0,0,1.0f);
break;
case R.id.SnareL:
findViewById(R.id.snare).startAnimation(zoomIn);
sp.play(SnareD,1.0f,1.0f,0,0,1.0f);
break;
case R.id.SnareR:
findViewById(R.id.snare).startAnimation(zoomIn);
sp.play(SnareD,1.0f,1.0f,0,0,1.0f);
break;
case R.id.OpenHihat:
findViewById(R.id.hihat).startAnimation(zoomIn);
sp.stop(OpenH);
sp.play(OpenH,1.0f,1.0f,0,0,1.0f);
break;
case R.id.CloseHihat:
findViewById(R.id.hihat).startAnimation(zoomIn);
sp.play(CloseH,1.0f,1.0f,0,0,1.0f);
break;
case R.id.RideSurface:
findViewById(R.id.ride).startAnimation(zoomIn);
sp.stop(RideS);
sp.play(RideS,1.0f,1.0f,0,0,1.0f);
break;
case R.id.RideTop:
findViewById(R.id.ride).startAnimation(zoomIn);
sp.play(RideT,1.0f,1.0f,0,0,1.0f);
break;
}
}
return true;
}
}
You can check the pointer id associated to the MotionEvent you've just received.
See the docs for more info:
https://developer.android.com/reference/android/view/MotionEvent.html#getPointerId(int)

Is it possible to disable MotionEvent.ACTION_POINTER_DOWN & UP

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;}

How to avoid intercepting all touch events?

There is this https://github.com/03uk/RippleDrawable
beautiful implementation to create a Ripple Effect on non L devices.
As you can see it is a Drawable that implements OnTouchListener.
The problem is that the Drawable intercepts ALL touch events, and therefore cannot be used in ListViews and similar.
How to avoid it?
I think the problem is in here https://github.com/03uk/RippleDrawable/blob/master/app/src/main/java/dreamers/graphics/RippleDrawable.java
and specifically here:
#Override
public boolean onTouch(View v, MotionEvent event) {
final int action = event.getAction();
switch (action){
case MotionEvent.ACTION_DOWN:
onFingerDown(v, event.getX(), event.getY());
v.onTouchEvent(event); // Fix for views, to handle clicks
return true; // fix for scroll, when ACTION_UP & ACTION_CANCEL not come
case MotionEvent.ACTION_MOVE:
onFingerMove(event.getX(), event.getY());
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
onFingerUp();
break;
}
return 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.

Multitouch issue: when pressing two buttons at the same time, it detects as if I touched only one with my fingers, why?

So I have two buttons and would like to press both at the same time. If I press the first it logs a "C" (as a piano note), the other logs a D.
So far:
#Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getActionMasked();
switch (event.getAction() & MotionEvent.ACTION_MASK){
case MotionEvent.ACTION_DOWN:
switch (v.getId()) {
case R.id.cnotebutton:
Log.i("C", "C1");
return true;
case R.id.c2notebutton:
Log.i("D", "D1");
return true;
default:
}
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_POINTER_DOWN:
break;
case MotionEvent.ACTION_POINTER_UP:
switch (v.getId()) {
case R.id.cnotebutton:
Log.i("C", "C2");
return true;
case R.id.c2notebutton:
Log.i("D", "D2");
return true;
default:
}
break;
case MotionEvent.ACTION_MOVE:
break;
default:
}
return true;
}
I Log C1 and C2 to distinguish the cases, but every time I press the buttons I get only C1,C2 or D1,D2 as if I touched the same buttons with both of my fingers. I should get C1,D2 or D1,C2 depending on which finger pointed first. Any suggestions?
Anyway I havent found a piano sample project yet, but that would definetly help me, if this is not going to work or my approach is totally wrong. Is there any?
Thanks in advance!
I think public boolean onInterceptTouchEvent (MotionEvent ev)is what you are looking for. Take a look at this.

Categories

Resources