[android] Tweak the online bridge to tell native when an event has happened.

This allows the native side to not send excess events.
(cherry picked from commit 1be2876635d2a788270238c4b1cfad200c488e32)


Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/257ab551
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/257ab551
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/257ab551

Branch: refs/heads/2.9.x
Commit: 257ab5519a0fbd903fdfda77c2e13d9641f1a1cd
Parents: afb4f94
Author: Andrew Grieve <[email protected]>
Authored: Thu Aug 15 15:47:27 2013 -0400
Committer: Andrew Grieve <[email protected]>
Committed: Tue Oct 22 11:38:41 2013 -0400

----------------------------------------------------------------------
 lib/android/exec.js                                | 12 ++++++++----
 lib/android/plugin/android/promptbasednativeapi.js |  4 ++--
 2 files changed, 10 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/257ab551/lib/android/exec.js
----------------------------------------------------------------------
diff --git a/lib/android/exec.js b/lib/android/exec.js
index 08d3e56..f22c46b 100644
--- a/lib/android/exec.js
+++ b/lib/android/exec.js
@@ -103,8 +103,12 @@ function androidExec(success, fail, service, action, args) 
{
     }
 }
 
-function pollOnce() {
-    var msg = nativeApiProvider.get().retrieveJsMessages();
+function pollOnceFromOnlineEvent() {
+    pollOnce(true);
+}
+
+function pollOnce(opt_fromOnlineEvent) {
+    var msg = 
nativeApiProvider.get().retrieveJsMessages(!!opt_fromOnlineEvent);
     androidExec.processMessages(msg);
 }
 
@@ -123,8 +127,8 @@ function hookOnlineApis() {
     // It currently fires them only on document though, so we bridge them
     // to window here (while first listening for exec()-releated online/offline
     // events).
-    window.addEventListener('online', pollOnce, false);
-    window.addEventListener('offline', pollOnce, false);
+    window.addEventListener('online', pollOnceFromOnlineEvent, false);
+    window.addEventListener('offline', pollOnceFromOnlineEvent, false);
     cordova.addWindowEventHandler('online');
     cordova.addWindowEventHandler('offline');
     document.addEventListener('online', proxyEvent, false);

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/257ab551/lib/android/plugin/android/promptbasednativeapi.js
----------------------------------------------------------------------
diff --git a/lib/android/plugin/android/promptbasednativeapi.js 
b/lib/android/plugin/android/promptbasednativeapi.js
index a665135..c12f46e 100644
--- a/lib/android/plugin/android/promptbasednativeapi.js
+++ b/lib/android/plugin/android/promptbasednativeapi.js
@@ -29,7 +29,7 @@ module.exports = {
     setNativeToJsBridgeMode: function(value) {
         prompt(value, 'gap_bridge_mode:');
     },
-    retrieveJsMessages: function() {
-        return prompt('', 'gap_poll:');
+    retrieveJsMessages: function(fromOnlineEvent) {
+        return prompt(+fromOnlineEvent, 'gap_poll:');
     }
 };

Reply via email to