Multitouch on WebView in Android 2.3.x

71 views
Skip to first unread message

Zabuza Momochi

unread,
Dec 18, 2014, 7:33:25 PM12/18/14
to phon...@googlegroups.com
Someone managed to simulate or create a virtual on-screen control with support for multi-touch?

I even managed, creating a single element with addEventListener and each key would be a position click the element.

But the button is pressed.


function init(){
    gamepad
.addEventListener("touchstart", function(e){buttonStart(e)});
    gamepad
.addEventListener("touchend", function(e){buttonEnd(e)});
}

function buttonStart(e){
   
var cX = e.touches[0].pageX;
   
if(cX > 0 || cX < 32){
       
//Active Button A
   
}
   
if(cX > 100 || cX < 132){
       
//Active Button B
   
}
}

function buttonEnd(e){
   
//Disable button
   
}.

DIV Element (HTML):
<div id="gamepad" style="position:absolute;bottom:25%;left:0px;background-color:green;height: 25%;width: 100%;">

Kerri Shotts

unread,
Dec 20, 2014, 12:38:11 AM12/20/14
to phon...@googlegroups.com
Multiple touches will be passed in as an array. So I imagine something like this:

var numberOfTouches = e.touches.length,
    buttons: { A: false, B: false, UP: false, DOWN: false, ...}

for (var i=0;i<numberOfTouches;i++) {
    var theTouch = e.touches[i];
    // check which button was pressed
    buttons.A =  (theTouch.pageX > 100 && theTouch.pageX<200 && theTouch.pageY > 100 && theTouch.pageY <200);
    ...
}
// act according to which button(s) the user touched
...

Zabuza Momochi

unread,
Dec 20, 2014, 9:13:52 PM12/20/14
to phon...@googlegroups.com
No work... But I need to work both at the same time.

Kerri Shotts

unread,
Dec 20, 2014, 9:48:35 PM12/20/14
to phon...@googlegroups.com
Took me a bit to remember, but: 

This is a known issue with Android 2.3.x and Webkit: https://code.google.com/p/android/issues/detail?id=11909

You're out of luck on anything <4.0 (since Cordova doesn't support 3.x).

Zabuza Momochi

unread,
Dec 21, 2014, 10:11:29 AM12/21/14
to phon...@googlegroups.com
The fact is that I could simulate in part, using coordinates of touches.
But the button first pressed lock on "Down".

I will try to simulate with the event "Click" rather than "TouchStart" and use a timer to stop the function triggered by the event.

Then I say the result.

:)

Zabuza Momochi

unread,
Dec 21, 2014, 10:40:51 AM12/21/14
to phon...@googlegroups.com
It's working!
The Click event does not catch why not allow two simutaneos touches.
Android can not multitouch in ViewWeb but will now prevent any bug in an app or game done in HTML5.

Thank you!
Reply all
Reply to author
Forward
0 new messages