Re: [android-developers] why is onDoubleTap being called before second tup's up action?

2012-01-20 Thread Kostya Vasilyev
( will try responding at the bottom for a change )

21 января 2012 г. 2:38 пользователь skink  написал:

>
>
> Kostya Vasilyev wrote:
> > Have you tried using MotionEvent.ACTION_CANCEL in the double-tap
> listener?
> >
> > GestureDetector has code to reset its internal state in response to this:
> >
> >
> https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/GestureDetector.java#L594
> >
> > I'm thinking you'd need post a handler message to self to get out of the
> > current stack state when onDoubleTap is called, and then in response to
> > that message, use ACTION_CANCEL to reset the gesture listener and then
> > start the activity.
> >
> > -- Kostya
> >
>
> Kostya,
>
> do you mean that in onDoubleTap (MotionEvent e) listener I should
> modify "e" by:
>
> e.setAction(MotionEvent.ACTION_CANCEL)
>
> and then "feed" gesture detector with that modified event?
>

No, that won't get you out of the call chain that exists when your
onDoubleTap is called:

https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/GestureDetector.java#L488

There is code in GestureDetector's onTouchEvent after the call to
onDoubleTap, and replacing the event's action will do nothing to skip it.
The switch at line 468 won't go back to be re-evaluated, etc.



>
> but if it cancels internal state of detector why to use a Handler?
>

To return from your onDoubleTap listener to the gesture detector's
onTouchEvent, let it execute the rest of its code, and only then send the
cancel event to reset its state.


>
> btw I already tried in  onDoubleTap to post Runnable that starts
> activity and it worked well but I decided it's dirty workaround -
> that's why I used onDoubleTapEvent
>

That's pretty similar to what I was suggesting, and also unwinds the call
chain from the double-tap listener call.

Perhaps the framework sends a cancel event in this case -- or perhaps your
letting go after the double tap has time to register.

I'd do a test to find out, keeping the finger down after the double-tap's
second touch.

If the gesture detector still works Ok after returning back to this
activity (like your original email mentioned), good.

If it doesn't, it would mean that you were just getting lucky with the
timing of the second up event, and that sending a cancel is still necessary.

Hope this makes sense.

-- Kostya


>
> pskink
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] why is onDoubleTap being called before second tup's up action?

2012-01-20 Thread skink


Kostya Vasilyev wrote:
> Have you tried using MotionEvent.ACTION_CANCEL in the double-tap listener?
>
> GestureDetector has code to reset its internal state in response to this:
>
> https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/GestureDetector.java#L594
>
> I'm thinking you'd need post a handler message to self to get out of the
> current stack state when onDoubleTap is called, and then in response to
> that message, use ACTION_CANCEL to reset the gesture listener and then
> start the activity.
>
> -- Kostya
>

Kostya,

do you mean that in onDoubleTap (MotionEvent e) listener I should
modify "e" by:

e.setAction(MotionEvent.ACTION_CANCEL)

and then "feed" gesture detector with that modified event?

but if it cancels internal state of detector why to use a Handler?

btw I already tried in  onDoubleTap to post Runnable that starts
activity and it worked well but I decided it's dirty workaround -
that's why I used onDoubleTapEvent

pskink

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] why is onDoubleTap being called before second tup's up action?

2012-01-20 Thread Kostya Vasilyev
Have you tried using MotionEvent.ACTION_CANCEL in the double-tap listener?

GestureDetector has code to reset its internal state in response to this:

https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/GestureDetector.java#L594

I'm thinking you'd need post a handler message to self to get out of the
current stack state when onDoubleTap is called, and then in response to
that message, use ACTION_CANCEL to reset the gesture listener and then
start the activity.

-- Kostya

20 января 2012 г. 17:37 пользователь skink  написал:

> hi,
>
> i'm using GestureDetector to detect double tup actions and having a
> little problem when trying to startActivity() inside onDoubleTap
> listener.
>
> namely i have observed when onDoubleTap is empty i see the following:
>
> D/GestureActivity(  987): onTouchEvent action=0
> D/GestureActivity(  987): onTouchEvent action=1
> D/GestureActivity(  987): onTouchEvent action=0
> D/GestureActivity(  987): onDoubleTap
> D/GestureActivity(  987): onTouchEvent action=1
>
> here action == 0 for ACTION_DOWN, while action == 1 for ACTION_UP
>
> as you can see onDoubleTap is being called after second tups's
> ACTION_DOWN and before its ACTION_UP, strange but OK
>
> but when i call startActivity() in onDoubleTap listener i see:
>
> D/GestureActivity( 1019): onTouchEvent action=0
> D/GestureActivity( 1019): onTouchEvent action=1
> D/GestureActivity( 1019): onTouchEvent action=0
> D/GestureActivity( 1019): onDoubleTap
> D/GestureActivity( 1019): onPause
>
> as you can see there is missing second ACTION_UP (i think it's because
> my main activity is paused and doesn't handle touch events) and when i
> return back to my main activity GestureDetector is somehow mislead and
> behaves a bit strange
>
> in the end i used onDoubleTapEvent (instead of onDoubleTap) like this:
> public boolean onDoubleTapEvent(MotionEvent e) {
>if (e.getAction() == MotionEvent.ACTION_UP) {
>// start activity here
>}
> }
>
> and it works OK but i'm still not sure if it's a good solution
>
> any ideas how to use onDoubleTap in my scenario?
>
> pskink
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] why is onDoubleTap being called before second tup's up action?

2012-01-20 Thread skink
hi,

i'm using GestureDetector to detect double tup actions and having a
little problem when trying to startActivity() inside onDoubleTap
listener.

namely i have observed when onDoubleTap is empty i see the following:

D/GestureActivity(  987): onTouchEvent action=0
D/GestureActivity(  987): onTouchEvent action=1
D/GestureActivity(  987): onTouchEvent action=0
D/GestureActivity(  987): onDoubleTap
D/GestureActivity(  987): onTouchEvent action=1

here action == 0 for ACTION_DOWN, while action == 1 for ACTION_UP

as you can see onDoubleTap is being called after second tups's
ACTION_DOWN and before its ACTION_UP, strange but OK

but when i call startActivity() in onDoubleTap listener i see:

D/GestureActivity( 1019): onTouchEvent action=0
D/GestureActivity( 1019): onTouchEvent action=1
D/GestureActivity( 1019): onTouchEvent action=0
D/GestureActivity( 1019): onDoubleTap
D/GestureActivity( 1019): onPause

as you can see there is missing second ACTION_UP (i think it's because
my main activity is paused and doesn't handle touch events) and when i
return back to my main activity GestureDetector is somehow mislead and
behaves a bit strange

in the end i used onDoubleTapEvent (instead of onDoubleTap) like this:
public boolean onDoubleTapEvent(MotionEvent e) {
if (e.getAction() == MotionEvent.ACTION_UP) {
// start activity here
}
}

and it works OK but i'm still not sure if it's a good solution

any ideas how to use onDoubleTap in my scenario?

pskink

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en