Wednesday, 15 June 2011

android - Why is MotionEvent.ACTION_POINTER_UP not recorded consistently? -



android - Why is MotionEvent.ACTION_POINTER_UP not recorded consistently? -

i thought pinch trigger motionevent.action_pointer_up, happens 50% of time (it varies lot) app on @ to the lowest degree 2 tested tablet devices. appears random. not know how pinch create happen consistently.

the code straightforward next overridden method of activity in question:

@override public boolean ontouchevent(motionevent event) { switch (event.getaction()) { ... case motionevent.action_pointer_up: log.d("debug", "action_pointer_up triggered"); default: break; } ... }

could shed lite on this?

you may alter code utilize getactionmasked().

@override public boolean ontouchevent(motionevent event) { switch (event.getactionmasked()) { //... case motionevent.action_pointer_up: log.d("debug", "action_pointer_up triggered"); default: break; } //... }

motioneven getaction() reports integer consists of both action_whatever , pointer index left-shifted action_pointer_index_shift (8) bits.

return kind of action beingness performed. consider using getactionmasked() , getactionindex() retrieve separate masked action , pointer index.

returns action, such action_down or combination of action_pointer_down shifted pointer index.

getaction() can quite confusing work in multi-touch situations. if want kind of action (action_down, action_pointer_down, , on), case is, may utilize getactionmasked() instead of getaction().

getactionmasked() returns action_whatever, without pointer index bits.

getaction() returns (getactionindex() << 8 | action_whatever). (pointer indexes counter-intuitive, android trying re-use lowest indices available giving unusual behavior if utilize them directly, that's story, here improve utilize getactionmasked() , not worry indices). numerically equal getactionmasked() when pointer has index=0, hence see "random" behavior: finish each pinch "naturally",

sometimes may have released pointer 0 first, pointer 1 last, 2 events getaction() returns action_pointer_up followed 1<<8 | action_up respectively, , hits case action_pointer_up label on first event. the other time may have released pointer 1 first, pointer 0 last, 2 events getaction() homecoming 1<<8 | action_pointer_up followed action_up. there no case label these, downwards default.

if utilize getactionmasked(), action_pointer_up followed action_up, in both cases consistently.

android multi-touch motionevent

No comments:

Post a Comment