Google Nexus 7 - Nasty Bug - Click Handlers Called Twice

188 views
Skip to first unread message

jogo

unread,
Feb 5, 2013, 4:53:32 AM2/5/13
to gwtm...@googlegroups.com
Yesterday I tested new app on Google Nexus 7 tablet running Android 4.2.1. Occasionally when I hit the back button, app moved back twice. I was wondering what was going on. Then I installed the GWT Mobile UI Showcase app and the same + many other things like Accordion panel that never collapses, FlipSwitch that never changes state etc...

After googling a bit I found out there is a really nasty bug in Android 4.2.1, more here:

Star the issue so it gets resolved quickly.

Zhihua (Dennis) Jiang

unread,
Feb 5, 2013, 10:41:45 PM2/5/13
to gwtm...@googlegroups.com
jogo,

I remember running into this issue on a 4.1 device. I ended up putting in a workaround on the DragControllerMobile.fireClick method to prevent the simulated click. I don't like the workaround but it seems to work. :-)

protected native void fireClick(Element theTarget) /*-{
       var isJellyBeanOrGreater = parseFloat($wnd.device.version) >= 4.1;
       if (isJellyBeanOrGreater)
        return;
       if (theTarget.nodeType == 3) theTarget = theTarget.parentNode;
       var theEvent = $doc.createEvent('MouseEvents');
       theEvent.initEvent('click', true, true);
       theTarget.dispatchEvent(theEvent);
}-*/;



--
You received this message because you are subscribed to the Google Groups "GWT Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gwtmobile+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Stanislav Tvarůžek

unread,
Feb 6, 2013, 9:03:45 AM2/6/13
to gwtm...@googlegroups.com
Great workaround ;o) Thanks for sharing it.

jogo

unread,
Apr 3, 2013, 1:26:56 PM4/3/13
to gwtm...@googlegroups.com
But DragControllerMobile.fireClick is never called in my code. Should I change something in the DragController?

jogo

unread,
Apr 4, 2013, 12:34:43 PM4/4/13
to gwtm...@googlegroups.com
Oh, I see, the class is replaced in gwtmobile_ui.gwt.xml and I tested it only on desktop Safari. On a mobile device the method is called.

At the end I used the code below, because device.version is available only when PhoneGap is used and I don't use it at all...

protected native void fireClick(Element theTarget) /*-{
   if ($wnd.lastClickTime == undefined) {
    $wnd.lastClickTime = 0;
   }
   var current = new Date().getTime();
   var delta = current - $wnd.lastClickTime;
if (delta != current && delta < 200) {
  // This happens because of a bug, so we ignore it.
} else {
$wnd.lastClickTime = current;
if (theTarget.nodeType == 3) theTarget = theTarget.parentNode;
   var theEvent = $doc.createEvent('MouseEvents');
   theEvent.initEvent('click', true, true);
   theTarget.dispatchEvent(theEvent);
}
    
}-*/;


But the problem still remains. Sometimes double click occurs, but the fireClick method is called only once, not twice, so the workaround doesn't work...

Zhihua (Dennis) Jiang

unread,
Apr 4, 2013, 10:11:45 PM4/4/13
to gwtm...@googlegroups.com
jogo, putting a check on the "delta" in the fireclick method will not fix it. Since the method only gets called once for each click, there is no "delta" for it to use to suppress the duplicate click event. One way or the other, you will need to find out what android version is used on the device and act on it accordingly.

jogo

unread,
Apr 5, 2013, 6:26:39 AM4/5/13
to gwtm...@googlegroups.com
Thank you. Now it is fixed.

protected native void fireClick(Element theTarget) /*-{

var ua = $wnd.navigator.userAgent;
if( ua.indexOf("Android") >= 0 ) {
  var androidversion = parseFloat(ua.slice(ua.indexOf("Android")+8));
   if (androidversion >= 4.1) {
            return;
  }
}
if (theTarget.nodeType == 3) theTarget = theTarget.parentNode;
var theEvent = $doc.createEvent('MouseEvents');
theEvent.initEvent('click', true, true);
theTarget.dispatchEvent(theEvent);
}-*/;

Zhihua (Dennis) Jiang

unread,
Apr 8, 2013, 12:41:23 PM4/8/13
to gwtm...@googlegroups.com
Thanks Jogo. I added the code to the fireClick method. I like the idea not to force the use of phonegap on the ui. Thanks.

Reply all
Reply to author
Forward
0 new messages