Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 425E811D73 for ; Fri, 4 Jul 2014 03:02:45 +0000 (UTC) Received: (qmail 3272 invoked by uid 500); 4 Jul 2014 03:02:45 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 3160 invoked by uid 500); 4 Jul 2014 03:02:45 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 3137 invoked by uid 99); 4 Jul 2014 03:02:44 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Jul 2014 03:02:44 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 699C1999E41; Fri, 4 Jul 2014 03:02:44 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: agrieve@apache.org To: commits@cordova.apache.org Date: Fri, 04 Jul 2014 03:02:45 -0000 Message-Id: <037121fe6baa47e4a50b560d40c7e45d@git.apache.org> In-Reply-To: <0af1897f56fb4a878380a28bd8fb54bb@git.apache.org> References: <0af1897f56fb4a878380a28bd8fb54bb@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [4/8] android commit: CB-6761 Fix native->JS bridge ceasing to fire when page changes and online is set to false and the JS loads quickly CB-6761 Fix native->JS bridge ceasing to fire when page changes and online is set to false and the JS loads quickly Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/445ddd89 Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/445ddd89 Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/445ddd89 Branch: refs/heads/4.0.x Commit: 445ddd89fb3269a772978a9860247065e5886249 Parents: 6f21a96 Author: Andrew Grieve Authored: Thu Jul 3 13:27:30 2014 -0400 Committer: Andrew Grieve Committed: Thu Jul 3 13:27:30 2014 -0400 ---------------------------------------------------------------------- .../src/org/apache/cordova/NativeToJsMessageQueue.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-android/blob/445ddd89/framework/src/org/apache/cordova/NativeToJsMessageQueue.java ---------------------------------------------------------------------- diff --git a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java index 5d0c061..9f6f96e 100755 --- a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java +++ b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java @@ -308,23 +308,28 @@ public class NativeToJsMessageQueue { /** Uses online/offline events to tell the JS when to poll for messages. */ private class OnlineEventsBridgeMode extends BridgeMode { private boolean online; - final Runnable runnable = new Runnable() { + private boolean ignoreNextFlush; + + final Runnable toggleNetworkRunnable = new Runnable() { public void run() { if (!queue.isEmpty()) { + ignoreNextFlush = false; webView.setNetworkAvailable(online); } - } + } }; @Override void reset() { online = false; + // If the following call triggers a notifyOfFlush, then ignore it. + ignoreNextFlush = true; webView.setNetworkAvailable(true); } @Override void onNativeToJsMessageAvailable() { - cordova.getActivity().runOnUiThread(runnable); + cordova.getActivity().runOnUiThread(toggleNetworkRunnable); } // Track when online/offline events are fired so that we don't fire excess events. @Override void notifyOfFlush(boolean fromOnlineEvent) { - if (fromOnlineEvent) { + if (fromOnlineEvent && !ignoreNextFlush) { online = !online; } }