0

I am investigating writing an HTML version of a native-tablet app (Android) that a research facility uses to test user response time. That is: a screen is presented for a set time and then the time it takes a user to choose a response is measured.

What would be helpful is to know is whether this is as easily done via HTML as via native code — I need to know exactly the time between the presentation of a screen to a user and the time they touch for a response. Since HTML rendering is under the command of the browser, is there are way to know — very precisely — when the screen is actually rendered to the user, and hence when the timer should start? My thinking is that it might be best to do something like set a div state from 'hidden' to 'visible' — or to use an animation library such as Greensock, but I feel this could be "every problem is a nail when all you've got is a hammer" — that is, these are the tools I know, I don't know whether these are what I should use.

I'm trying to get a sense of whether this is feasible — I've not done any native code tablet development, have done a fair amount of HTML, need to convince them to switch if I'm going to do the work. Thanks for any info you can provide.

Cerulean
  • 511
  • 1
  • 7
  • 16

1 Answers1

1

Maybe you could use javascript & JQuery in your HTML page to record the exact time of loading?

$(document).ready(function(){ //notice that $(document).ready is JQuery
    // Your code here
});

I guess you call native Android methods via javascript in you WebView, but if not you can do so by first injecting your Object containing methods to be called when page is loaded:

WebView webView = (WebView) findViewById(R.id.webview);
webView.addJavascriptInterface(new WebAppInterface(this), "Android");

Then, the JQuery code above to notify a Java Object would be:

$(document).ready(function(){
    Android.documentReady(); // method to call in Java Object
});

Notice: This is highly experimental and I do not know whether it is a good idea to load JQuery into your WebApp, but as JQuery is used everywhere it should not be a problem. Anyway, $(document).ready(function...) is called when the document/html page is fully loaded - doing a similar "listener" in standard javascript is not recommended, but possible. (more info if you want to skip JQuery; https://stackoverflow.com/a/7053197/3911640 )

More info about using JavaScript to call native Android Objects: http://developer.android.com/guide/webapps/webview.html

EDIT: You could also do this with HTML5:

<body onload="Android.documentReady()">

Notice: Not my area of expertise and not tested, but practically possible. I'd advice you to research which way is the fastest most reliable, but in theory both should be invoked when everything (images etc included) is loaded and presented to the user.

W3C documentation of the HTML5 functions: http://www.w3schools.com/jsref/dom_obj_event.asp

Community
  • 1
  • 1
TriXigT
  • 51
  • 4