cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From na...@apache.org
Subject js commit: Upleveled amazon-fireos bridge.
Date Mon, 27 Oct 2014 21:27:56 GMT
Repository: cordova-js
Updated Branches:
  refs/heads/master 14fae3a30 -> 9da67a3ae


Upleveled amazon-fireos bridge.


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

Branch: refs/heads/master
Commit: 9da67a3ae34de1a91355f2a9f2fee8389f9dce54
Parents: 14fae3a
Author: Archana Naik <naika@lab126.com>
Authored: Mon Oct 27 14:27:15 2014 -0700
Committer: Archana Naik <naika@lab126.com>
Committed: Mon Oct 27 14:27:15 2014 -0700

----------------------------------------------------------------------
 src/amazon-fireos/exec.js               | 66 +++++++++++++++++-----------
 src/amazon-fireos/platform.js           | 11 +++++
 src/amazon-fireos/plugin/android/app.js | 15 +++++++
 3 files changed, 66 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/9da67a3a/src/amazon-fireos/exec.js
----------------------------------------------------------------------
diff --git a/src/amazon-fireos/exec.js b/src/amazon-fireos/exec.js
index eb7f862..856bd8e 100644
--- a/src/amazon-fireos/exec.js
+++ b/src/amazon-fireos/exec.js
@@ -180,6 +180,42 @@ androidExec.setNativeToJsBridgeMode = function(mode) {
     }
 };
 
+function buildPayload(payload, message) {
+    var payloadKind = message.charAt(0);
+    if (payloadKind == 's') {
+        payload.push(message.slice(1));
+    } else if (payloadKind == 't') {
+        payload.push(true);
+    } else if (payloadKind == 'f') {
+        payload.push(false);
+    } else if (payloadKind == 'N') {
+        payload.push(null);
+    } else if (payloadKind == 'n') {
+        payload.push(+message.slice(1));
+    } else if (payloadKind == 'A') {
+        var data = message.slice(1);
+        var bytes = window.atob(data);
+        var arraybuffer = new Uint8Array(bytes.length);
+        for (var i = 0; i < bytes.length; i++) {
+            arraybuffer[i] = bytes.charCodeAt(i);
+        }
+        payload.push(arraybuffer.buffer);
+    } else if (payloadKind == 'S') {
+        payload.push(window.atob(message.slice(1)));
+    } else if (payloadKind == 'M') {
+        var multipartMessages = message.slice(1);
+        while (multipartMessages !== "") {
+            var spaceIdx = multipartMessages.indexOf(' ');
+            var msgLen = +multipartMessages.slice(0, spaceIdx);
+            var multipartMessage = multipartMessages.substr(spaceIdx + 1, msgLen);
+            multipartMessages = multipartMessages.slice(spaceIdx + msgLen + 1);
+            buildPayload(payload, multipartMessage);
+        }
+    } else {
+        payload.push(JSON.parse(message));
+    }
+}
+
 // Processes a single message, as encoded by NativeToJsMessageQueue.java.
 function processMessage(message) {
     try {
@@ -193,32 +229,10 @@ function processMessage(message) {
             var status = +message.slice(2, spaceIdx);
             var nextSpaceIdx = message.indexOf(' ', spaceIdx + 1);
             var callbackId = message.slice(spaceIdx + 1, nextSpaceIdx);
-            var payloadKind = message.charAt(nextSpaceIdx + 1);
-            var payload;
-            if (payloadKind == 's') {
-                payload = message.slice(nextSpaceIdx + 2);
-            } else if (payloadKind == 't') {
-                payload = true;
-            } else if (payloadKind == 'f') {
-                payload = false;
-            } else if (payloadKind == 'N') {
-                payload = null;
-            } else if (payloadKind == 'n') {
-                payload = +message.slice(nextSpaceIdx + 2);
-            } else if (payloadKind == 'A') {
-                var data = message.slice(nextSpaceIdx + 2);
-                var bytes = window.atob(data);
-                var arraybuffer = new Uint8Array(bytes.length);
-                for (var i = 0; i < bytes.length; i++) {
-                    arraybuffer[i] = bytes.charCodeAt(i);
-                }
-                payload = arraybuffer.buffer;
-            } else if (payloadKind == 'S') {
-                payload = window.atob(message.slice(nextSpaceIdx + 2));
-            } else {
-                payload = JSON.parse(message.slice(nextSpaceIdx + 1));
-            }
-            cordova.callbackFromNative(callbackId, success, status, [payload], keepCallback);
+            var payloadMessage = message.slice(nextSpaceIdx + 1);
+            var payload = [];
+            buildPayload(payload, payloadMessage);
+            cordova.callbackFromNative(callbackId, success, status, payload, keepCallback);
         } else {
             console.log("processMessage failed: invalid message: " + JSON.stringify(message));
         }

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/9da67a3a/src/amazon-fireos/platform.js
----------------------------------------------------------------------
diff --git a/src/amazon-fireos/platform.js b/src/amazon-fireos/platform.js
index e2e08c9..e380c2e 100644
--- a/src/amazon-fireos/platform.js
+++ b/src/amazon-fireos/platform.js
@@ -45,6 +45,17 @@ module.exports = {
         cordova.addDocumentEventHandler('menubutton');
         cordova.addDocumentEventHandler('searchbutton');
 
+        function bindButtonChannel(buttonName) {
+            // generic button bind used for volumeup/volumedown buttons
+            var volumeButtonChannel = cordova.addDocumentEventHandler(buttonName + 'button');
+            volumeButtonChannel.onHasSubscribersChange = function() {
+                exec(null, null, "App", "overrideButton", [buttonName, this.numHandlers ==
1]);
+            };
+        }
+        // Inject a listener for the volume buttons on the document.
+        bindButtonChannel('volumeup');
+        bindButtonChannel('volumedown');
+
         // Let native code know we are all done on the JS side.
         // Native code will then un-hide the WebView.
         channel.onCordovaReady.subscribe(function() {

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/9da67a3a/src/amazon-fireos/plugin/android/app.js
----------------------------------------------------------------------
diff --git a/src/amazon-fireos/plugin/android/app.js b/src/amazon-fireos/plugin/android/app.js
index c2a4df5..7fccc40 100644
--- a/src/amazon-fireos/plugin/android/app.js
+++ b/src/amazon-fireos/plugin/android/app.js
@@ -84,6 +84,21 @@ module.exports = {
     },
 
     /**
+    * Override the default behavior of the Android volume button.
+    * If overridden, when the volume button is pressed, the "volume[up|down]button"
+    * JavaScript event will be fired.
+    *
+    * Note: The user should not have to call this method.  Instead, when the user
+    *       registers for the "volume[up|down]button" event, this is automatically done.
+    *
+    * @param button          volumeup, volumedown
+    * @param override        T=override, F=cancel override
+    */
+    overrideButton:function(button, override) {
+        exec(null, null, "App", "overrideButton", [button, override]);
+    },
+
+    /**
     * Exit and terminate the application.
     */
     exitApp:function() {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message