incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [14/15] git commit: adding device, connection and acceleration support
Date Fri, 20 Apr 2012 00:21:40 GMT
adding device, connection and acceleration support


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/400ae71c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/400ae71c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/400ae71c

Branch: refs/heads/master
Commit: 400ae71c1f8b567f819be78fc34ba094f04bfebe
Parents: 293b8cc
Author: Anis Kadri <anis.kadri@gmail.com>
Authored: Thu Apr 19 15:50:03 2012 -0700
Committer: Anis Kadri <anis.kadri@gmail.com>
Committed: Thu Apr 19 15:50:03 2012 -0700

----------------------------------------------------------------------
 lib/bada/exec.js                      |   25 ++++----
 lib/bada/plugin/bada/Accelerometer.js |   43 ++++++++++++++
 lib/bada/plugin/bada/NetworkStatus.js |   31 ++++++++++
 lib/bada/plugin/bada/device.js        |   84 +++++++++++++++++++++++++++
 lib/bada/plugin/device.js             |   85 ----------------------------
 lib/scripts/bootstrap-bada.js         |    1 +
 6 files changed, 172 insertions(+), 97 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/400ae71c/lib/bada/exec.js
----------------------------------------------------------------------
diff --git a/lib/bada/exec.js b/lib/bada/exec.js
index a18cb6e..1c78a9c 100644
--- a/lib/bada/exec.js
+++ b/lib/bada/exec.js
@@ -1,16 +1,17 @@
 var plugins = {
-    "Device": require('bada/plugin/device'),
+    "Device": require('cordova/plugin/bada/device'),
+    "NetworkStatus": require('cordova/plugin/bada/NetworkStatus'),
+    "Accelerometer": require('cordova/plugin/bada/Accelerometer')
 };
-module.exports = {
-    exec: function(success, fail, service, action, args) {
-        try {
-            plugins[service][action](success, fail, args);
-        }
-        catch(e) {
-            console.log("missing exec: " + service + "." + action);
-            console.log(args);
-            console.log(e);
-            console.log(e.stack);
-        }
+
+module.exports = function(success, fail, service, action, args) {
+    try {
+        plugins[service][action](success, fail, args);
+    }
+    catch(e) {
+        console.log("missing exec: " + service + "." + action);
+        console.log(args);
+        console.log(e);
+        console.log(e.stack);
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/400ae71c/lib/bada/plugin/bada/Accelerometer.js
----------------------------------------------------------------------
diff --git a/lib/bada/plugin/bada/Accelerometer.js b/lib/bada/plugin/bada/Accelerometer.js
new file mode 100644
index 0000000..f1c4c87
--- /dev/null
+++ b/lib/bada/plugin/bada/Accelerometer.js
@@ -0,0 +1,43 @@
+var Acceleration = require('cordova/plugin/Acceleration');
+
+module.exports = {
+    getAcceleration: function(successCallback, errorCallback, options) {
+        var success = function(acceleration) {
+            console.log("Accelermometer:getAcceleration:success");
+            var accel = new Acceleration(acceleration.xAxis, acceleration.yAxis, acceleration.zAxis);
+            successCallback(accel);
+        };
+        var error = function(err) {
+            console.log("Accelermometer:getAcceleration:error");
+            switch(err.code) {
+                case err.TYPE_MISMATCH_ERR:
+                    console.log("TYPE MISMATCH ERROR");
+                    break;
+            }
+
+            errorCallback(err);
+        };
+        deviceapis.accelerometer.getCurrentAcceleration(success, error);
+    },
+    // XXX: unused with cordovaJS
+    watchAcceleration: function(successCallback, errorCallback, options) {
+        var success = function(acceleration) {
+            console.log("accelerometer:watchAcceleration:success");
+            var accel = new Acceleration(acceleration.xAxis, acceleration.yAxis, acceleration.zAxis);
+            successCallback(accel);
+        };
+        var error = function(err) {
+            console.log("accelerometer:watchAcceleration:error");
+            switch(err.code) {
+                case err.TYPE_MISMATCH_ERR:
+                break;
+            }
+
+            errorCallback(err);
+        };
+        return deviceapis.accelerometer.watchAcceleration(success, error);
+    },
+    clearWatch: function(watchID) {
+        deviceapis.accelerometer.clearWatch(watchID);
+    }
+};

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/400ae71c/lib/bada/plugin/bada/NetworkStatus.js
----------------------------------------------------------------------
diff --git a/lib/bada/plugin/bada/NetworkStatus.js b/lib/bada/plugin/bada/NetworkStatus.js
new file mode 100644
index 0000000..d35536c
--- /dev/null
+++ b/lib/bada/plugin/bada/NetworkStatus.js
@@ -0,0 +1,31 @@
+var channel = require('cordova/channel');
+
+// We can't tell if a cell connection is 2,3 or 4G.
+// We just know if it's connected and the signal strength
+// if it's roaming and the network name etc..so unless wifi we default to UNKNOWN
+
+module.exports = {
+    getConnectionInfo: function(success, fail) {
+       var Connection = require("cordova/plugin/Connection");
+       var connectionType = Connection.NONE
+       deviceapis.devicestatus.getPropertyValue(function(value) {
+               console.log("Device WiFi network status: "+value);
+               if(value == "connected") {
+                   connectionType = Connection.WIFI;
+               }
+               channel.onCordovaConnectionReady.fire();
+               success(connectionType);
+           }, 
+           function(error) {
+                console.log(JSON.stringify(error));
+                fail();
+           } , {aspect: "WiFiNetwork", property: "networkStatus"}
+       );
+        //info.getPropertyValue(function(value) {
+        //console.log("Device Cellular network status: "+value);
+        //if(signalStrength > 10) {
+        //self.type = Connection.CELL_3G;
+        //}
+        //}, fail, {aspect: "CellularNetwork", property: "signalStrength"});
+    }
+};

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/400ae71c/lib/bada/plugin/bada/device.js
----------------------------------------------------------------------
diff --git a/lib/bada/plugin/bada/device.js b/lib/bada/plugin/bada/device.js
new file mode 100644
index 0000000..555ef9a
--- /dev/null
+++ b/lib/bada/plugin/bada/device.js
@@ -0,0 +1,84 @@
+var channel = require('cordova/channel');
+
+function Device() {
+
+    this.platform = null;
+    this.version = null;
+    this.name = null;
+    this.uuid = null;
+    this.cordova = null
+
+    var me = this;
+    
+    channel.onCordovaReady.subscribeOnce(function() {
+       me.getInfo(function (device) {
+           me.platform = device.platform;
+           me.version  = device.version;
+           me.name     = device.name;
+           me.uuid     = device.uuid;
+           me.cordova  = device.cordova;
+
+           channel.onCordovaInfoReady.fire();
+           //console.log("CordovaInfoReady "+JSON.stringify(device));
+       },
+       function (e) {
+           me.available = false;
+           console.log("error initializing cordova: " + e);
+       });
+    });
+};
+
+
+Device.prototype.getInfo = function(success, fail, args) {
+   var info = deviceapis.devicestatus;
+   var properties = ["name", "uuid", "os_name", "os_vendor", "os_version"];
+
+   var me = this;
+    
+   var name = null,
+       platform = null,
+       uuid = null,
+       os_name = null,
+       os_version = null,
+       os_vendor = null;
+
+   var checkProperties = function() {
+       properties.pop();
+       if(properties.length == 0) {
+           me.name = name;
+           me.platform = os_vendor + " " + os_name;
+           me.version = os_version;
+           me.uuid = uuid;
+           me.cordova = "1.6.0";
+           success(me);
+       }
+   };
+
+   info.getPropertyValue(function(value) {
+           console.log("Device IMEI: "+value);
+           uuid = value;
+           checkProperties();
+           }, fail, {aspect: "Device", property: "imei"});
+   info.getPropertyValue(function(value) {
+           console.log("Device name: "+value);
+           name = value;
+           checkProperties();
+           }, fail, {aspect: "Device", property: "version"});
+   info.getPropertyValue(function(value) {
+           console.log("OperatingSystem name: "+value);
+           os_name = value;
+           checkProperties();
+           }, fail, {aspect: "OperatingSystem", property: "name"});
+   info.getPropertyValue(function(value) {
+           console.log("OperatingSystem version: "+value);
+           os_version = value;
+           checkProperties();
+           }, fail, {aspect: "OperatingSystem", property: "version"});
+   info.getPropertyValue(function(value) {
+           console.log("OperatingSystem vendor: "+value);
+           os_vendor = value;
+           checkProperties();
+           }, fail, {aspect: "OperatingSystem", property: "vendor"});
+}
+
+module.exports = new Device();

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/400ae71c/lib/bada/plugin/device.js
----------------------------------------------------------------------
diff --git a/lib/bada/plugin/device.js b/lib/bada/plugin/device.js
deleted file mode 100644
index 36fc9f9..0000000
--- a/lib/bada/plugin/device.js
+++ /dev/null
@@ -1,85 +0,0 @@
-var channel = require('cordova/channel');
-
-function Device() {
-
-    this.platform = null;
-    this.version = null;
-    this.name = null;
-    this.uuid = null;
-    this.cordova = null
-
-    var me = this;
-    
-    channel.onCordovaReady.subscribeOnce(function() {
-        me.getInfo(function (device) {
-            me.platform = device.platform;
-            me.version  = device.version;
-            me.name     = device.name;
-            me.uuid     = device.uuid;
-            me.cordova  = device.cordova;
-
-            channel.onCordovaInfoReady.fire();
-        },
-        function (e) {
-            me.available = false;
-            console.log("error initializing cordova: " + e);
-        });
-    });
-};
-
-
-Device.prototype.getInfo = function(success, fail, args) {
-    console.log("getInfo");
-   var info = deviceapis.devicestatus;
-   var properties = ["name", "uuid", "os_name", "os_vendor", "os_version"];
-
-   var device = new Device();
-    
-   var name = null,
-       platform = null,
-       uuid = null,
-       os_name = null,
-       os_version = null,
-       os_vendor = null;
-
-   var checkProperties = function() {
-       properties.pop();
-       if(properties.length == 0) {
-           device.name = name;
-           device.platform = os_vendor + " " + os_name;
-           device.version = os_version;
-           device.uuid = uuid;
-           device.cordova = "1.6.0";
-           channel.onNativeReady().fire();
-           success(device);
-       }
-   };
-
-   info.getPropertyValue(function(value) {
-           console.log("Device IMEI: "+value);
-           uuid = value;
-           checkProperties();
-           }, fail, {aspect: "Device", property: "imei"});
-   info.getPropertyValue(function(value) {
-           console.log("Device name: "+value);
-           name = value;
-           checkProperties();
-           }, fail, {aspect: "Device", property: "version"});
-   info.getPropertyValue(function(value) {
-           console.log("OperatingSystem name: "+value);
-           os_name = value;
-           checkProperties();
-           }, fail, {aspect: "OperatingSystem", property: "name"});
-   info.getPropertyValue(function(value) {
-           console.log("OperatingSystem version: "+value);
-           os_version = value;
-           checkProperties();
-           }, fail, {aspect: "OperatingSystem", property: "version"});
-   info.getPropertyValue(function(value) {
-           console.log("OperatingSystem vendor: "+value);
-           os_vendor = value;
-           checkProperties();
-           }, fail, {aspect: "OperatingSystem", property: "vendor"});
-}
-
-module.exports = new Device();

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/400ae71c/lib/scripts/bootstrap-bada.js
----------------------------------------------------------------------
diff --git a/lib/scripts/bootstrap-bada.js b/lib/scripts/bootstrap-bada.js
new file mode 100644
index 0000000..19cf867
--- /dev/null
+++ b/lib/scripts/bootstrap-bada.js
@@ -0,0 +1 @@
+require('cordova/channel').onNativeReady.fire();


Mime
View raw message