shagr4th / droid48

HP48 emulator for Android
https://play.google.com/store/apps/details?id=org.ab.x48
GNU General Public License v3.0
78 stars 27 forks source link

Multitouch support added #6

Closed db47h closed 13 years ago

db47h commented 13 years ago
 - Bug fix for keycode mismatch 25 != 26 between up and down events from
   hardware keyboard
 - Multitouch support in order to allow the ability to press multiple
   keys simultaneously.
shagr4th commented 13 years ago

Thanks for the multitouch, I'm currently testing on my N1 and having some troubles (some up events are missed, so the button gray overlay stays on). Will update on my findings

db47h commented 13 years ago

I modified the code so that we keep track of the event's pointer id in the touches array (now int[] instead of boolean[]). When an UP event is received, instead of checking the event coordinates, I just look up the pointer in touches in order to find the key that originally triggered the DOWN event. As a side effect, you can now press a key and release somewhere else on the screen (really helps with fat fingers ;), the UP event for that key should not be lost (that's why I removed all the "UP rejected" stuff).

Works flawlessly on Nexus S and emulator (Gingerbread 2.3.3). I may have missed something though. May be in the way I store pointer ID + 1 in the array since the pointer IDs are zero based and I used zero as a "not pressed" value (could have missed a +/-1 somewhere).

db47h commented 13 years ago

Managed to reproduce:

  1. Press and hold down 1
  2. Press and hold down 3
  3. Release 1

Then 3 doesn't go up. It's possible that the ACTION_POINTER_UP event doesn't trigger after the primary pinter triggers ACTION_UP...

shagr4th commented 13 years ago

FWIW, it's working fine when I remove the first if block (the one with no pointerId gestion) and extend the second one with actionCode == MotionEvent.ACTION_DOWN || actionCode == MotionEvent.ACTION_UP || actionCode == MotionEvent.ACTION_POINTER_DOWN || actionCode == MotionEvent.ACTION_POINTER_UP

db47h commented 13 years ago

Well spotted, that was it.

When the primary "pointer" is released, the first secondary pointer gets promoted to primary, which then triggers ACTION_UP events instead of ACTION_POINTER_UP, but the actual pointer ID is kept. Neat.

Should be working now.