1

I am writing a phoneGap plugin to allow multitouch on android devices (hoping to get this included in phonegap/callback eventually)

Event delegation is taking ~200ms using the plugin success callback and ~50ms with the WebView.loadUrl('javascript:somecodehere()') call

Unfortunately loadUrl has the side-effect of flickering the soft keyboard which isn't acceptable for a general solution.

Phonegap's Plugin.success uses an internal web server and an XmlHttpRequest object to send data, this method is way too slow.

Is there any 3rd method of sending javascript to the web browser? (or even sending a poke to the javascript engine to cause an event to happen, so that event could check a custom jsInterface object)

4 Answers 4

0

Take a look at addJavascriptInterface in the WebView class. It sounds more like what you are looking for.

1
  • Unfortunately this is for using javascript to call java code. I want to use java to call javascript code.
    – Jamie Pate
    Dec 7, 2011 at 0:07
0

In you plugin try calling:

this.ctx.sendJavascript(statement);

Not quite as fast as loadUrl but it may be a bit faster than returning a PluginResult.

1
0

You could roll your own stripped down message queue with a java object that is basically an arraylist and an accessor, then use addJavascriptInterface to bind it into the javascript context and inject a javascript polling loop that uses setTimeout to call the accessor method of your queue. Whenever you have javascript to execute, just add it to your arraylist. I'm not sure how it would perform, but perhaps it's worth a try?

class JSQueue {
    private ArrayList<String> messages;

    public String getMessage() {
        String message = "";
        if(messages.size() >0) {
            message = messages.remove(0);
        }
        return message;
    }
    public void addMessage(String message) {
        messages.add(message);
    }
}
JSQueue jsq = new JSQueue();
dc.appMobiCanvas.hiddenView.addJavascriptInterface(jsq, "jsq");
dc.appMobiCanvas.hiddenView.loadUrl("javascript:(function checkJSQ(){eval(jsq.getMessage());setTimeout(checkJSQ, 50);}})();");
//add messages via jsq.addMessage();
2
  • great idea, but since i'm trying to beat the 200ms delay of the current solution it'd have to be a pretty tight interval (10ms or so?) I guess the code could be pretty tight for checking this, but i'm not sure on the boundary performance of the javascript interface to java. I'll have to run some timings to see if this solution works better than what i've got now
    – Jamie Pate
    Mar 3, 2012 at 17:12
  • I might even be able to get away with only running the queue interval during a native touch event, since the browser will detect that properly. Otherwise it'd be a cpu drain even if it's only running 2 lines of code on each poll
    – Jamie Pate
    Mar 3, 2012 at 17:28
0

It seems we have developed something similar

https://github.com/Philzen/webview-multitouch-polyfill

However, i have never experienced the issue you're describing before, but maybe you would like to test on your device or maybe contribute your expertise to the project. It has already been suggested on the Cordova (Phonegap) Roadmap, so we'll happy about every user and/or contributor to help this cause!

3
  • I'll have to take a look (and probably contribute) once I am back on track for this app (currently working solely on the website part) this sounds like exactly what I was looking for on the high level
    – Jamie Pate
    Sep 3, 2012 at 18:42
  • @JamiePate Did you get a chance to test it yet? Would really love to hear your feedback whether you expierence a soft keyboard flickering or any other issues.
    – Philzen
    Jan 23, 2013 at 23:31
  • Unfortunately, i'm no longer employed by the company that was developing this product, so I have nothing to test and no way to test it :)
    – Jamie Pate
    Jan 27, 2013 at 0:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.