0

i'm developing an application that simulates a trackpad. I need to get an accurate value of the position at every point in time, but using events just won't do the job.

Since the motion event ACTION_MOVE "starts" sending events only when i move a bit from the position where ACTION_DOWN is called, the position will stick there until i move the finger farther away from the starting position.

Also, while reading the data, the position will eventually get stuck for a short time.

Any way to get the position of the touch imperatively, for example, similarly to how one would do on Unity? (Touches[touchIndex].Position)

Code i used which doesn't do the job:

@Override
public boolean onTouchEvent(MotionEvent event) {
    x = event.getX();
    y = event.getY();
}
  • I'm having a bit of difficulty understanding what you need. Perhaps adding the code you have tried with an explanation what the result was and how you wanted it to be would be helpful. In general, I don't know why you need to "track" the position if no movement occurred. `ACTION_DOWN` and `ACTION_UP` with no `ACTION_MOVE` seems pretty clear – Barns Jan 17 '18 at 19:51
  • have you tried something like this? https://stackoverflow.com/questions/2068007/android-how-do-i-get-raw-touch-screen-information – Tomer Shemesh Jan 17 '18 at 19:52
  • Added what i did, but it was pretty straightforward. The problem is, that events start being called after you move a bit from the first position you touch, where ACTION_DOWN is called. I need a way to directly get the touch position, or at least remove that delay. – Simone Bondi Jan 17 '18 at 19:56

1 Answers1

0

There is no way easily to get raw touch data. the touchEvent is the best way. the reason you get a delay is because of the "TOUCH_SLOP" which is what android uses to determine whether finger movement was enough to trigger an event broadcast. There is no method you can call to reduce this so your best option is to try and extend View and set mTouchSlop to zero or something small, which will trigger touch broadcasts more often. See more here:

Android ACTION_MOVE Threshold

Tomer Shemesh
  • 10,278
  • 4
  • 21
  • 44