incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [15/17] bada-wac commit: adding connection object
Date Sat, 28 Apr 2012 00:27:55 GMT
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 <anis.kadri@gmail.com>
Authored: Wed Apr 4 16:50:23 2012 -0700
Committer: Anis Kadri <anis.kadri@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


Mime
View raw message