You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by an...@apache.org on 2012/04/28 02:27:55 UTC
[15/17] bada-wac commit: adding connection object
adding connection object
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada-wac/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada-wac/commit/07c467f8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada-wac/tree/07c467f8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada-wac/diff/07c467f8
Branch: refs/heads/master
Commit: 07c467f89354e320cf74127c0c68e8257d972737
Parents: 628e8ea
Author: Anis Kadri <an...@gmail.com>
Authored: Wed Apr 4 16:50:23 2012 -0700
Committer: Anis Kadri <an...@gmail.com>
Committed: Wed Apr 4 16:50:23 2012 -0700
----------------------------------------------------------------------
Res/index.html | 10 ++++++++++
Res/js/connection.js | 29 ++++++++++++++++++-----------
Res/js/sample.js | 9 +++++++++
3 files changed, 37 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada-wac/blob/07c467f8/Res/index.html
----------------------------------------------------------------------
diff --git a/Res/index.html b/Res/index.html
index 750f182..c8a8d19 100644
--- a/Res/index.html
+++ b/Res/index.html
@@ -70,7 +70,17 @@ button.btn {
<span id="heading"></span>
</div>
</li>
+ <li>
+ <h3>Connection</h3>
+ <div>
+ <button type="button" class="btn" onclick="getConnection();">getConnectionType</button>
+ </div>
+ <div>
+ <span id="connection"></span>
+ </div>
+ </li>
</ul>
+<script type="text/javascript" src="./js/connection.js"></script>
<script type="text/javascript" src="./js/accelerometer.js"></script>
<script type="text/javascript" src="./js/compass.js"></script>
<script type="text/javascript" src="./js/device.js"></script>
http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada-wac/blob/07c467f8/Res/js/connection.js
----------------------------------------------------------------------
diff --git a/Res/js/connection.js b/Res/js/connection.js
index b6fed3f..f1ad5db 100644
--- a/Res/js/connection.js
+++ b/Res/js/connection.js
@@ -1,4 +1,4 @@
-Connection = {
+var Connection = {
UNKNOWN: "unknown",
ETHERNET: "ethernet",
WIFI: "wifi",
@@ -7,24 +7,31 @@ Connection = {
CELL_4G: "4g",
NONE: "none"
};
-
+// 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
function NetworkConnection() {
+ this.type = Connection.UNKNOWN;
var self = this;
- var info = deviceapis.devicestatus;
- info.getPropertyValue(function(value) {
+ var error = function(error) {
+ console.log(JSON.stringify(error));
+ };
+
+ deviceapis.devicestatus.getPropertyValue(function(value) {
console.log("Device WiFi network status: "+value);
if(value == "connected") {
self.type = Connection.WIFI;
}
}, error, {aspect: "WiFiNetwork", property: "networkStatus"});
- info.getPropertyValue(function(value) {
- console.log("Device Cellular network status: "+value);
- if(value == "connected") {
- self.type = Connection.WIFI;
- }
- }, error, {aspect: "CellularHardware", property: "status"});
+// info.getPropertyValue(function(value) {
+// console.log("Device Cellular network status: "+value);
+// if(signalStrength > 10) {
+// self.type = Connection.CELL_3G;
+// }
+// }, error, {aspect: "CellularNetwork", property: "signalStrength"});
}
-var connection = new NetworkConnection();
\ No newline at end of file
+navigator.network = {};
+navigator.network.connection = new NetworkConnection();
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada-wac/blob/07c467f8/Res/js/sample.js
----------------------------------------------------------------------
diff --git a/Res/js/sample.js b/Res/js/sample.js
index f8774dc..61b569f 100644
--- a/Res/js/sample.js
+++ b/Res/js/sample.js
@@ -165,4 +165,13 @@ function clearHeadingWatch() {
document.getElementById("heading").innerHTML = "";
console.log("clearHeadingWatch");
}
+}
+
+/*
+ * Connection
+ */
+
+function getConnection() {
+ var connectionEm = document.getElementById("connection");
+ connectionEm.innerHTML = "Connection type "+navigator.network.connection.type;
}
\ No newline at end of file