incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [11/11] js commit: accel, device-ready, network shim
Date Fri, 20 Jul 2012 22:56:18 GMT
accel, device-ready, network shim


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

Branch: refs/heads/master
Commit: 539ea478bc5abf6f10b4b8b01ca5579a4c4802fc
Parents: 1dabf24
Author: Jesse <purplecabbage@gmail.com>
Authored: Sun Jul 15 03:42:47 2012 -0700
Committer: Jesse <purplecabbage@gmail.com>
Committed: Sun Jul 15 03:42:47 2012 -0700

----------------------------------------------------------------------
 Jakefile                                  |    2 +
 lib/scripts/bootstrap-win8metro.js        |    1 +
 lib/win8metro/exec.js                     |  148 ++++++++++++++++++++++++
 lib/win8metro/platform.js                 |   52 ++++++++
 lib/win8metro/plugin/win8metro/console.js |   35 ++++++
 lib/win8metro/plugin/win8metro/device.js  |   36 ++++++
 6 files changed, 274 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/539ea478/Jakefile
----------------------------------------------------------------------
diff --git a/Jakefile b/Jakefile
index e83c0db..fb97f8a 100644
--- a/Jakefile
+++ b/Jakefile
@@ -67,6 +67,8 @@ task('build', ['clean', 'hint'], function () {
         }
         
         console.log("building " + commitId);
+
+        packager.generate("win8metro",commitId);
         packager.generate("blackberry",commitId);
         packager.generate("playbook",commitId);
         packager.generate("ios",commitId);

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/539ea478/lib/scripts/bootstrap-win8metro.js
----------------------------------------------------------------------
diff --git a/lib/scripts/bootstrap-win8metro.js b/lib/scripts/bootstrap-win8metro.js
new file mode 100644
index 0000000..a994abf
--- /dev/null
+++ b/lib/scripts/bootstrap-win8metro.js
@@ -0,0 +1 @@
+require('cordova/channel').onNativeReady.fire();
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/539ea478/lib/win8metro/exec.js
----------------------------------------------------------------------
diff --git a/lib/win8metro/exec.js b/lib/win8metro/exec.js
new file mode 100644
index 0000000..cc05a72
--- /dev/null
+++ b/lib/win8metro/exec.js
@@ -0,0 +1,148 @@
+var cordova = require('cordova');
+
+
+ /* definition of named properties expected by the native side,
+    all arrays are stored in order of how they are received from common js code.
+    When other platforms evolve to using named args this will be removed.
+ */
+
+
+/**
+ * Execute a cordova command.  It is up to the native side whether this action
+ * is synchronous or asynchronous.  The native side can return:
+ *      Synchronous: PluginResult object as a JSON string
+ *      Asynchrounous: Empty string ""
+ * If async, the native side will cordova.callbackSuccess or cordova.callbackError,
+ * depending upon the result of the action.
+ *
+ * @param {Function} success    The success callback
+ * @param {Function} fail       The fail callback
+ * @param {String} service      The name of the service to use
+ * @param {String} action       Action to be run in cordova
+ * @param {String[]} [args]     Zero or more arguments to pass to the method
+
+ */
+
+
+
+var NativeProxy = {
+    "Accelerometer": { 
+        onDataChanged:function(e){
+            var reading = e.reading;
+            // reading.accelerationX.toFixed(2);
+            // reading.accelerationY.toFixed(2);
+            // reading.accelerationZ.toFixed(2);
+        },       
+        start:function(win,lose){
+            console.log("Accelerometer.start");
+            var accel = Windows.Devices.Sensors.Accelerometer.getDefault();
+            if(!accel) {
+                lose("No accelerometer found");
+            }
+            else {
+                var self = this;
+                // store our bound function
+                this.onDataChanged.bound = function(e) {
+                    self.onDataChanged(e);
+                }
+                accel.addEventListener("readingchanged",this.onDataChanged.bound);
+            }
+        },
+        stop:function(win,lose){
+            console.log("Accelerometer.stop");
+            var accel = Windows.Devices.Sensors.Accelerometer.getDefault();
+            if(!accel) {
+                lose("No accelerometer found");
+            }
+            else {
+                if(this.onDataChanged.bound) {
+                    accel.removeEventListener("readingchanged",this.onDataChanged.bound);
+                }
+                this.onDataChanged.bound = null;
+            }
+        }
+    },
+    "Device": {
+        getDeviceInfo:function(win,fail,args){
+            console.log("NativeProxy::getDeviceInfo");
+            setTimeout(function(){
+                win({platform:"win8metro", version:"0.1", name:"hmm", uuid:"42", cordova:"12"});
+            },0);
+        }
+    },
+    "NetworkStatus": { 
+        getConnectionInfo:function(win,fail,args)
+        {
+            console.log("getConnectionInfo");
+            
+
+            var winNetConn = Windows.Networking.Connectivity;
+            var networkInfo = winNetConn.NetworkInformation;
+            var networkCostInfo = winNetConn.NetworkCostType;
+            var networkConnectivityInfo = winNetConn.NetworkConnectivityLevel;
+            var networkAuthenticationInfo = winNetConn.NetworkAuthenticationType;
+            var networkEncryptionInfo = winNetConn.NetworkEncryptionType;
+
+            var profile = Windows.Networking.Connectivity.NetworkInformation.getInternetConnectionProfile();
+            var conLevel = profile.getNetworkConnectivityLevel();
+
+            switch (conLevel) {
+                case Windows.Networking.Connectivity.NetworkConnectivityLevel.none:
+                    break;
+                case Windows.Networking.Connectivity.NetworkConnectivityLevel.localAccess:
+                    break;
+                case Windows.Networking.Connectivity.NetworkConnectivityLevel.internetAccess:
+                    break;
+                case Windows.Networking.Connectivity.NetworkConnectivityLevel.constrainedInternetAccess:
+                    break;
+            }
+
+
+            // FYI
+            //Connection.UNKNOWN  'Unknown connection';
+            //Connection.ETHERNET 'Ethernet connection';
+            //Connection.WIFI     'WiFi connection';
+            //Connection.CELL_2G  'Cell 2G connection';
+            //Connection.CELL_3G  'Cell 3G connection';
+            //Connection.CELL_4G  'Cell 4G connection';
+            //Connection.NONE     'No network connection';
+
+            setTimeout(function(){
+                win("wifi");
+            },0);
+        }
+
+    } 
+};
+    // ,
+    // "Accelerometer": require('cordova/plugin/bada/Accelerometer'),
+    // "Notification": require('cordova/plugin/bada/Notification'),
+    // "Compass": require('cordova/plugin/bada/Compass'),
+    // "Capture": require('cordova/plugin/bada/Capture'),
+    // "Camera": require('cordova/plugin/bada/Camera'),
+    // "Contacts": require('cordova/plugin/bada/Contacts')
+
+
+module.exports = function(success, fail, service, action, args) {
+
+    var callbackId = service + cordova.callbackId++;
+    console.log("EXEC:" + service + " : " + action);
+
+    if (typeof success == "function" || typeof fail == "function")
+    {
+        cordova.callbacks[callbackId] = {success:success, fail:fail};
+    }
+
+    if(NativeProxy[service] && NativeProxy[service][action]) {
+
+        // pass it on to Notify
+        try {
+            NativeProxy[service][action](success, fail, args);
+        }
+        catch(e) {
+            console.log("Exception calling native with command :: " + service + " :: " +
action  + " ::exception=" + e);
+        }
+    }
+
+};
+

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/539ea478/lib/win8metro/platform.js
----------------------------------------------------------------------
diff --git a/lib/win8metro/platform.js b/lib/win8metro/platform.js
new file mode 100644
index 0000000..0516801
--- /dev/null
+++ b/lib/win8metro/platform.js
@@ -0,0 +1,52 @@
+var cordova = require('cordova'),
+    exec = require('cordova/exec'),
+    channel = cordova.require("cordova/channel");
+  
+module.exports = {
+    id: "win8metro",
+    initialize:function() {
+
+    console.log("win8metro initialize");
+    //window.alert = require("cordova/plugin/notification").alert;
+
+    // INject a lsitener for the backbutton, and tell native to override the flag (true/false)
when we have 1 or more, or 0, listeners
+    // var backButtonChannel = cordova.addDocumentEventHandler('backbutton', {
+    //   onSubscribe:function() {
+    //     if (this.numHandlers === 1) {
+    //         exec(null, null, "CoreEvents", "overridebackbutton", [true]);
+    //     }
+    //   },
+    //   onUnsubscribe:function() {
+    //     if (this.numHandlers === 0) {
+    //       exec(null, null, "CoreEvents", "overridebackbutton", [false]);
+    //     }
+    //   }
+    // });
+
+    },
+    objects: {
+        navigator: {
+            children: {
+                device: {
+                    path: "cordova/plugin/device",
+                    children:{
+                        capture:{
+                            path:"cordova/plugin/capture"
+                        }
+                    }
+                },
+                console: {
+                    path: "cordova/plugin/win8metro/console"
+
+                }
+            }
+        },
+        device:{
+          path:"cordova/plugin/win8metro/device"
+        }
+        // ,
+        // console:{
+        //   path: "cordova/plugin/win8metro/console"
+        // }
+    }
+};
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/539ea478/lib/win8metro/plugin/win8metro/console.js
----------------------------------------------------------------------
diff --git a/lib/win8metro/plugin/win8metro/console.js b/lib/win8metro/plugin/win8metro/console.js
new file mode 100644
index 0000000..89cc56c
--- /dev/null
+++ b/lib/win8metro/plugin/win8metro/console.js
@@ -0,0 +1,35 @@
+
+
+if(!console || !console.log)
+{
+    var exec = require('cordova/exec'),
+        channel = require('cordova/channel');
+    var cordova = require("cordova");
+
+
+    var debugConsole = {
+        log:function(msg){
+        exec(null,null,"DebugConsole","log",msg);
+        },
+        warn:function(msg){
+            exec(null,null,"DebugConsole","warn",msg);
+        },
+        error:function(msg){
+            exec(null,null,"DebugConsole","error",msg);
+        }
+    };
+
+
+    module.exports = debugConsole;
+}
+else
+{
+
+    if(console && console.log)
+    {
+        console.log("console.log exists already!");
+        console.warn = console.warn || function(msg){console.log("warn:"+msg);};
+        console.error = console.error || function(msg){console.log("error:"+msg);};
+
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/539ea478/lib/win8metro/plugin/win8metro/device.js
----------------------------------------------------------------------
diff --git a/lib/win8metro/plugin/win8metro/device.js b/lib/win8metro/plugin/win8metro/device.js
new file mode 100644
index 0000000..4889cb9
--- /dev/null
+++ b/lib/win8metro/plugin/win8metro/device.js
@@ -0,0 +1,36 @@
+
+
+if(!console || !console.log)
+{
+    var exec = require('cordova/exec'),
+        channel = require('cordova/channel');
+    var cordova = require("cordova");
+
+
+    var debugConsole = {
+        log:function(msg){
+        exec(null,null,"DebugConsole","log",msg);
+        },
+        warn:function(msg){
+            exec(null,null,"DebugConsole","warn",msg);
+        },
+        error:function(msg){
+            exec(null,null,"DebugConsole","error",msg);
+        }
+    };
+
+
+    module.exports = debugConsole;
+}
+else
+{
+
+    if(console && console.log)
+    {
+        console.log("console.log exists already!");
+        console.warn = console.warn || function(msg){console.log("warn:"+msg);};
+        console.error = console.error || function(msg){console.log("error:"+msg);};
+
+    }
+}
+


Mime
View raw message