-1

I want to use a function where I can get the x and y co-ordinates of a user (if he/she is currently touching the screen) every 20 milliseconds or similar. I know there timers and schedulers in Android. But the question is how do I get X and y co-ordinates without using OnTouch event listener.

Or how can I make sure that the OnTouch is called every 20 milliseconds either with the current point being touched by the user or empty if the user is not touching the screen at that instance.

The time is an important factor. I did check threads, but not sure if I can use timers or schedulers.

1 Answers1

0

final TextView xCoord = (TextView) findViewById(R.id.textView1); final TextView yCoord = (TextView) findViewById(R.id.textView2);

final View touchView = findViewById(R.id.textView3); touchView.setOnTouchListener(new View.OnTouchListener() {

public boolean onTouch(View v, MotionEvent event) {
    final int action = event.getAction();
    switch (action & MotionEvent.ACTION_MASK) {

       case MotionEvent.ACTION_DOWN: {
          xCoord.setText(String.valueOf((int) event.getX()));
          yCoord.setText(String.valueOf((int) event.getY()));
          break;
       }

       case MotionEvent.ACTION_MOVE:{
          xCoord.setText(String.valueOf((int) event.getX()));
      yCoord.setText(String.valueOf((int) event.getY()));
      break;
       }
    }
    return true;

}

});

Amit Prajapati
  • 13,525
  • 8
  • 62
  • 84
  • I don't think this will help me get X and Y co-ordinates every 20 milliseconds? Basically, onTouch is called when the user touches the screen. Whereas, I want to get the points every 20 ms. If the user is not touching the screen at some instance, it should just return blank. But thanks for trying. If you have some more ideas, it would be really helpful!! – Khali Singh Aug 09 '13 at 13:20