User Tools

Site Tools


script_webview_with_refresh

===== About the script ====== * Purpose : WebView Widget with refresh * Author : Jappie Toutenhoofd (https://plus.google.com/+JappieToutenhoofd) * Link: https://plus.google.com/+JappieToutenhoofd/posts/KgcWsg7F9CP ====== How to use the script ====== * make sure the Internet permission is added to the launcher through the installation of the plugin found at [[http://www.pierrox.net/android/applications/lightning_launcher/permissions/|http://www.pierrox.net/android/applications/lightning_launcher/permissions/]]. * Import all three script's from here. * Set 'WV-create' script on Custom View 'created'-event. * Set 'WV-resume' script on Custom View 'resume'-event. * Set 'WV-pause' script on Custom View 'pause'-event. ====== Script code ====== ======= WV-create ======= <code> // webviews work best on first page. // After resize, reload LL // usage: check data. and enter: // zoom;url LL.bindClass("android.webkit.WebView"); var context = LL.getContext(); var mydata = data.split(";"); var myZoom = mydata[0]; var myURL = mydata[1]; var webView = new WebView(context); webView.getSettings().setJavaScriptEnabled(true); webView.setInitialScale(myZoom); // webView.loadUrl("http://forecast.io/embed/#lat=52.3&lon=4.68&name=Holland&units=ca" ); webView.loadUrl("http://"+ myURL); return webView; </code> ======= WV-resume ======= <code> var refresh_interval_minutes = 60; var myItem = LL.getEvent().getItem(); var myId = myItem.getId(); var myView = myItem.getView(); function refreshWV() { // prevent event flooding var nu = new Date(); var last = myItem.getTag(myId)||0; if ((nu - last) > (refresh_interval_minutes *60000)) { //myView.reload(); <-- seams to crash when it failed to load before. //myView.loadUrl(myView.getUrl()); <-- alternative, if everything else fails myView.loadUrl( "javascript:window.location.reload( true )" ); myItem.setTag(myId, nu); } // store the timeout id so that it can be cleared when pausing the item myItem.setTag("WV", setTimeout(refreshWV, 30000)); } refreshWV(); </code> ======= WV-pause ======= <code> // important: preserve the battery life and clear timeouts when the item is paused to avoid useless background activity var id = LL.getEvent().getItem().getTag("WV"); if(id != null) { clearTimeout(parseInt(id)); } </code>

script_webview_with_refresh.txt · Last modified: 2015/05/20 14:44 by jappie