> WebView seems to stop firing onTouch events after the builtin zoom
> controls have been used.

If anyone's interested in my fix/workaround for this, it was to extend
WebView, and override the onTouchEvent method:

    @Override
    public boolean onTouchEvent(MotionEvent evt) {
        boolean consumed = super.onTouchEvent(evt);

        if (isClickable()) {
            switch (evt.getAction()) {
            case MotionEvent.ACTION_DOWN:
                lastTouchX = evt.getX();
                lastTouchY = evt.getY();
                hasMoved = false;
                break;
            case MotionEvent.ACTION_MOVE:
                hasMoved = moved(evt);
                break;
            case MotionEvent.ACTION_UP:
                if (!moved(evt)) performClick();
                break;
            }
        }

        return consumed || isClickable();
    }

    private float lastTouchX, lastTouchY;
    private boolean hasMoved = false;

    private boolean moved(MotionEvent evt) {
        return hasMoved ||
            Math.abs(evt.getX() - lastTouchX) > 10.0 ||
            Math.abs(evt.getY() - lastTouchY) > 10.0;
    }

Hope this helps someone.

Regards,
Tom

On Thu, May 20, 2010 at 10:24 PM, Tom Coxon <[email protected]> wrote:
> Hi all,
>
> WebView seems to stop firing onTouch events after the builtin zoom
> controls have been used.
>
> I've got a WebView displaying an image from the web. I want users to
> be able to use the builtin zoom controls (+/- buttons, and pinch-zoom,
> when it's available), but I also want to be able to display a dialog
> containing some text when the user clicks the image in the WebView.
> WebView doesn't produce onClick events, so I've attached an
> onTouchListener to emulate clicks. I've got something like this:
>
>         webview = (WebView)findViewById(R.id.viewer);
>         webview.getSettings().setBuiltInZoomControls(true);
>         webview.setOnTouchListener(new OnTouchListener() {
>             public boolean onTouch(View v, MotionEvent event) {
>                // show dialog on click
>            }
>        });
>
> When the activity starts, the user can click the WebView and show the
> dialog, as expected. But if they drag or pinch-zoom the WebView, the
> WebView stops firing onTouch events, and the dialog won't show any
> more.
>
> This seems to happen on 1.6 and 2.1 (at the very least), and both on
> hardware and in the emulator. Why does it happen? I can't find it
> documented anywhere. Are there any workarounds?
>
> Regards,
> Tom
>

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

Reply via email to