onFling gesture in WebView

by me tun » Tue, 12 May 2009 08:57:25 GMT


Sponsored Links
 Hello all,

Is there a way to detect the onFling gesture in a WebView?  It doesn't
seem to get recognised, for example:

I'll add all the code because it's a pretty good example of how to
listen to gesture...

        gestureDetector = new GestureDetector(new mGestureDetector());
        gestureListener = new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                if (gestureDetector.onTouchEvent(event)) {
                    return true;
                }
                return false;
            }
        };


...

    class mGestureDetector extends SimpleOnGestureListener {
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float
velocityX, float velocityY) {
            try {
                if (Math.abs(e1.getY() - e2.getY()) >
SWIPE_MAX_OFF_PATH)
                    return false;
                // Right to left fling
                if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE &&
Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {

                        Log.d(TAG, "Right to left fling");

                }  else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {

                        Log.d(TAG, "Left to right fling");

                }
            } catch (Exception e) {
                // Nothing
            }
            return false;
        }
    }

...

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (gestureDetector.onTouchEvent(event))
                return true;
            else
                return false;
    }

This works for a FrameLayout, TextView, etc  I just can't seem to get
it to work in a WebView, is there some flag I need to enable to allow
the gestures to get through?
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Is anyone else getting bored of announced product releases that don't materialise ...

How does the operator matter? Buy the phone, stick in your card,
enjoy. This phone locking nonsense should die -- I will only ever buy
a phone if it is NOT LOCKED, either in OS or in operator.






--~--~---------~--~----~------------~-------~--~----~

2. Webview Question: onCreate always get called when activity comes to foreground

I did a little poking around and I think I can DEFINITELY shine some
light on this.

Basically, I think the difference lies in the way Eclipse ports the
apk to the emulator and launches it.

I just downloaded GeoWebOne from the AdvAndroid site, created an
Eclipse project out of it.  No problems compiling or anything.  I put
in a little Log.i() call in GeoWebOne's onCreate call that reads
"GeoWebOne onCreate".  I then right-clicked (I'm on Windows XP, btw)
the project and selected Run As -> Android Application.  The console
spit this out:

[2009-04-08 17:49:01 - GeoWebOne] ------------------------------
[2009-04-08 17:49:01 - GeoWebOne] Android Launch!
[2009-04-08 17:49:01 - GeoWebOne] adb is running normally.
[2009-04-08 17:49:01 - GeoWebOne] Launching:
com.commonsware.android.geoweb.GeoWebOne
[2009-04-08 17:49:01 - GeoWebOne] Automatic Target Mode: using
existing emulator: emulator-5554
[2009-04-08 17:49:01 - GeoWebOne] Uploading GeoWebOne.apk onto device
'emulator-5554'
[2009-04-08 17:49:01 - GeoWebOne] Installing GeoWebOne.apk...
[2009-04-08 17:49:03 - GeoWebOne] Success!
[2009-04-08 17:49:03 - GeoWebOne] Starting activity
com.commonsware.android.geoweb.GeoWebOne on device
[2009-04-08 17:49:05 - GeoWebOne] ActivityManager: Starting: Intent
{ comp={com.commonsware.android.geoweb/
com.commonsware.android.geoweb.GeoWebOne} }

And then the app launched in the emulator, everything seemed normal,
and in my Logs I got a "GeoWebOne onCreate".

I then hit the Home button on the emulator, went into the applications
launching screen, then re-opened the app (GeoWeb Demo #1), and got
ANOTHER "GeoWebOne onCreate".  I should not have gotten this unless I
hit the Back button before, as opposed to the Home button.
Furthermore, from this point, when I hit the Back button, it shows me
the same activity, which I'm sure has got to be the FIRST instance of
the activity that was created.

I then uninstalled the app from the emulator, and then opened up a
command prompt, and using the adb I manually installed the
GeoWebOne.apk to the emulator.  I then did the same process, opened
the app, hit the home button, went back in, and it behaved as it
should have - I only got ONE "GeoWebOne onCreate" in the logs.

It seems that eclipse ports the app to the emulator in such a way that
each successive launch that is made while the app is running pushes
another instance of the app onto the stack, unless you hit the back
button before relaunching.  Indeed, you can launch the app from
eclipse, and then hit Home and go back into it X number of times, and
after this you will have to press Back X times to actually exit the
app.

I've had this same problem in my other projects, and tried adding
numerous Android Manifest elements to my activities, the one's listed
at http://developer.android.com/guide/topics/manifest/activity-element.html
, to no avail (I thought it was something in the manifest like
android:alwaysRetainTaskState="true", for instance, but it's not).
The difference is eclipse, but I suspect that also first installing
the app on the device from the Market, or AppsInstaller, or
downloading it from the Browser may produce this behavior as well.

Any light that you guys can shine on this would help a lot, and well
done on providing very helpful examples and suggestions, Mark, you've
been quite a legend on this forum!

Thank you!

-Zack





--~--~---------~--~----~------------~-------~--~----~

3. Bug in ADP

4. build JNI C code fail ???

5. Layout question - how to replicate what the iPhone does...

6. Handler for map panning

7. Making VideoView play automatically