ElectronAnt
ElectronAnt

Reputation: 2195

Android: Multitouch issue

Here is the scenario of my problem:

-I press down on the screen. I can keep track of this touch event with the ACTION_DOWN variable of the MotionEvent class. My problem comes when I keep this initial finger pressed on the screen. I want to be able to track any other touch events on the screen.

I think my question is essentially, how can I keep track of subsequent touch events even while one is going on?

Best, Aneem

EDIT:

public boolean onTouchEvent(final MotionEvent ev) {

    if(ev.getAction()==ev.ACTION_DOWN||ev.getActionMasked()==ev.ACTION_POINTER_DOWN){                   
        AudioManager mgr = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
        int streamVolume = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
        PointF[] touchPoints = new PointF[ev.getPointerCount()];
        for(int i = 0; i < ev.getPointerCount(); i++){
            touchPoints[i] = new PointF(ev.getX(i),ev.getY(i));
        }
        for(final PointF point : touchPoints){
            x = ev.getX(ev.getActionIndex());
            y = ev.getY(ev.getActionIndex());
            int ptx = (int) (x - x%widthIncrement);
            int pty = (int) (y - y%heightIncrement);
            playSound(pointMap.get(new Point(ptx,pty)));
        }
        return true;
    }
    return true;
}

Upvotes: 2

Views: 1261

Answers (2)

GreenAsJade
GreenAsJade

Reputation: 14685

Something to be aware of: many Android phones are bugged for multitouch.

Google for android multi touch problem and watch videos.

Basically, if you hold one finger down, then move another one, as the second finger gets close in either x or y to the first one, then the first finger coords will appear to move even though the finger isn't moving.

This is a complete PITA ... just thought you might like to know...

GaJ

Upvotes: 0

Noel
Noel

Reputation: 7410

Well, you can determine if a non-primary pointer (another finger likely) has gone down the same way except instead of looking for the ACTION_DOWN, look for the ACTION_POINTER_DOWN.

Upvotes: 2

Related Questions