Reputation: 27186
I'm trying to make a WebView app in Android using the HTML5 canvas and touch.
Here's what I think is the relevant part of my code :
In onCreate :
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
...
myWebView.loadData(content,"text/html", "UTF-8");
Where the string "content" contains a block of html / javascript which contain the following lines.
this.canvas = document.getElementById(AN_ID); // AN_ID is id of a canvas tag
...
this.canvas.addEventListener("touchstart", function(e) {
...
}, false);
this.canvas.addEventListener("touchend", function(e) {
...
}, false);
And the activity_main.xml file contains the tag
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
However my test device, a Nexus 7, seems not to respond to the touch events. If I replace "touchstart" and "touchend" with "mousedown" and "mouseup", it seems like the mousedown event is recognised. But mouseup isn't behaving properly (ie. like the same code running in the browser).
Am I obviously missing something eg. a config setting that I need to enable touch events in the javascript?
Upvotes: 3
Views: 3467
Reputation: 27186
OK. I resolved it.
I was still trying to get the Page.X & Page.Y values rather than from event.targetTouches. And I was assuming co-ordinates were available from in touchend when, in fact, they aren't. You have to track them during touchmove.
Upvotes: 1