0

I'm programming with Processing, what i need is the equivalent of pmouseX/Y but for touch, but I can't use pmouse because I use multi-touch and I need previous coordinates of each touched point. I don't know if I've made myself clear, to do an example I need to know initial and final coordinates of a swipe

I currently use to get initial coordinates:

    public boolean surfaceTouchEvent(MotionEvent me) {
    float x0=me.getX(0);
    float y0=me.getY(0);
    ....
    ....
    return super.surfaceTouchEvent(me);
    }
cifz
  • 1,078
  • 7
  • 24

1 Answers1

0

I'm not sure if I get your right here, since this seems to be very basic programming, but I'll try.

Just use an ArrayList and add each position there. For different touches, you might want to use a HashMap, like this:

HashMap<MotionEvent, ArrayList<Point2D.Float>> touches = new HashMap<MotionEvent, ArrayList<Point2D.Float>>();

public boolean surfaceTouchEvent(MotionEvent me)
{
    float x0=me.getX(0);
    float y0=me.getY(0);
    if (!touches.containsKey(me))
    {
        touches.add(me, new ArrayList<Point2D.Float>());
    }
    else
    {
        // get previous position
        Point2D.Float prevpos = touches.get(me).get(touches.get(me).size() - 1);
    }
    touches.get(me).add(new Point2D.Float(x0, y0));
    ....
}

Didn't test this, but that's basically how it would work.

jimpic
  • 5,360
  • 2
  • 28
  • 37
  • Yup, thanks, my problem was basically about understanding how Android handle those situations, that's because processing.org "hides" a lot of stuff. Thank you again, I'll try – cifz May 10 '12 at 15:59