Search code examples
androideventsgraphwebviewtitanium

Communication between web view and titanium Android app


I have a titanium app where I load a web view. In this web view I load a html5 with a chart.

I want to show a vertical line and get some information about the position of the line. This line will be controlled by a slider in Titanium App, so the line would change its position very fast and very often.

You can see something similar here: graph

In html file, I write the graph and I add a listener for an event. When the event is fired, it draw a line in some position with this code:

        function updateVerticalLine(posX) {
            drawSeries(c);
            c.strokeStyle = '#000000';
            c.beginPath();
            c.moveTo(getXPixel(posX), graph.height() - yPadding);
            c.lineTo(getXPixel(posX), 0);
            c.stroke();

        } 

In Titanium app, I only fire the event when I receive the change slider event and I pass the new position of the line:

slider.addEventListener('change', function(e) {

    Ti.App.fireEvent('sliderhtml5line:change', {
            value : e.value
        });
});

It works ok on ios, but on Android, it is very slow and events are disorganized.

Do you know how I can solve it? Is there any better option for this?

Thanks!!


Solution

  • it should be done the otherway.

    when the user changes the slider, you should call the method in the HTML page using the evaljs function to update the user interface directly