From a1d03ec69b9860e3b53e393e5e17748acdae4277 Mon Sep 17 00:00:00 2001 From: fkloft Date: Fri, 3 Jan 2014 18:49:47 +0100 Subject: [PATCH] mobile: show loading progress in title bar --- code/map_data_request.js | 10 +++++----- code/status_bar.js | 14 ++++++++++---- .../cradle/iitc_mobile/IITC_JSInterface.java | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/code/map_data_request.js b/code/map_data_request.js index 1326d852..00b8682b 100644 --- a/code/map_data_request.js +++ b/code/map_data_request.js @@ -59,7 +59,7 @@ window.MapDataRequest = function() { this.FETCH_TO_REFRESH_FACTOR = 2; //refresh time is based on the time to complete a data fetch, times this value // ensure we have some initial map status - this.setStatus ('startup'); + this.setStatus ('startup', undefined, -1); } @@ -76,7 +76,7 @@ window.MapDataRequest.prototype.start = function() { // then set a timeout to start the first refresh this.refreshOnTimeout (this.STARTUP_REFRESH); - this.setStatus ('refreshing'); + this.setStatus ('refreshing', undefined, -1); this.cache && this.cache.startExpireInterval (15); } @@ -110,7 +110,7 @@ window.MapDataRequest.prototype.mapMoveEnd = function() { } } - this.setStatus('refreshing'); + this.setStatus('refreshing', undefined, -1); this.refreshOnTimeout(this.MOVE_REFRESH); } @@ -120,7 +120,7 @@ window.MapDataRequest.prototype.idleResume = function() { if (this.idle) { console.log('refresh map idle resume'); this.idle = false; - this.setStatus('idle restart'); + this.setStatus('idle restart', undefined, -1); this.refreshOnTimeout(this.IDLE_RESUME_REFRESH); } } @@ -262,7 +262,7 @@ window.MapDataRequest.prototype.refresh = function() { } } - this.setStatus ('loading'); + this.setStatus ('loading', undefined, -1); // technically a request hasn't actually finished - however, displayed portal data has been refreshed // so as far as plugins are concerned, it should be treated as a finished request diff --git a/code/status_bar.js b/code/status_bar.js index df3b2a0f..aa27c407 100644 --- a/code/status_bar.js +++ b/code/status_bar.js @@ -3,6 +3,7 @@ // gives user feedback about pending operations. Draws current status // to website. Updates info in layer chooser. window.renderUpdateStatus = function() { + var progress = 1; // portal level display var t = ''; @@ -20,19 +21,21 @@ window.renderUpdateStatus = function() { t += ' map: '; if (window.mapDataRequest) { - var status = window.mapDataRequest.getStatus(); // status.short - short description of status // status.long - longer description, for tooltip (optional) - // status.progress - fractional progress (from 0 to 1) of current state (optional) + // status.progress - fractional progress (from 0 to 1; -1 for indeterminate) of current state (optional) if (status.long) t += ''+status.short+''; else t += ''+status.short+''; - if (status.progress !== undefined) - t += ' '+Math.floor(status.progress*100)+'%'; + if (status.progress !== undefined) { + if(status.progress !== -1) + t += ' '+Math.floor(status.progress*100)+'%'; + progress = status.progress; + } } else { // no mapDataRequest object - no status known t += '...unknown...'; @@ -82,4 +85,7 @@ window.renderUpdateStatus = function() { $('#innerstatus').html(t); //$('#updatestatus').click(function() { startRefreshTimeout(10); }); //. '; + + if (typeof android !== 'undefined' && android && android.setProgress) + android.setProgress(progress); } diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java b/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java index fbfcc177..1fd5353e 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java @@ -206,4 +206,22 @@ public class IITC_JSInterface { } }); } + + @JavascriptInterface + public void setProgress(final double progress) { + mIitc.runOnUiThread(new Runnable() { + @Override + public void run() { + if (progress != -1) { + // maximum for setProgress is 10,000 + mIitc.setProgressBarIndeterminate(false); + mIitc.setProgress((int) Math.round(progress * 10000)); + } + else { + mIitc.setProgressBarIndeterminate(true); + mIitc.setProgress(1); + } + } + }); + } }