Skip to content
Browse files

Merge pull request #623 from andreasgal/philikon/connection

Display operator name in title bar and display signal strength bars
  • Loading branch information...
2 parents 4144f76 + 537d3e8 commit bb36b8f02cd8320b53cca2537080dfac84e86a00 @philikon philikon committed Feb 23, 2012
Showing with 56 additions and 2 deletions.
  1. +51 −1 apps/homescreen/js/homescreen.js
  2. +5 −1 apps/homescreen/style/homescreen.css
View
52 apps/homescreen/js/homescreen.js
@@ -121,6 +121,7 @@ function changeDisplayState(state) {
// update clock and battery status (if needed)
updateClock();
updateBattery();
+ updateConnection();
// Make sure the source viewer is not visible.
if (state == 'locked')
@@ -752,7 +753,12 @@ function OnLoad() {
});
window.addEventListener('appclose', function(evt) {
- titlebar.innerHTML = '';
+ var title = '';
+ var conn = window.navigator.mozConnection;
+ if (conn && conn.operator) {
+ title = conn.operator;
+ }
+ titlebar.innerHTML = title;
});
window.addEventListener('keypress', function(evt) {
@@ -828,3 +834,47 @@ function updateBattery() {
battery.addEventListener('levelchange', updateBattery);
battery.addEventListener('statuschange', updateBattery);
}
+
+
+function updateConnection() {
+ var conn = window.navigator.mozMobileConnection;
+ if (!conn) {
+ console.log("There's no window.navigator.mozMobileConnection!");
+ return;
+ }
+
+ if (displayState == 'off') {
+ conn.removeEventListener("cardstatechange", updateConnection);
+ conn.removeEventListener("connectionchange", updateConnection);
+ return;
+ }
+
+ // Update the operator name / SIM status.
+ var title = "";
+ if (conn.cardState == "absent") {
+ title = "No SIM card";
+ } else if (!conn.connected) {
+ title = "Connecting...";
+ } else {
+ title = conn.operator || "";
+ if (conn.roaming) {
+ title += " (roaming)";
+ }
+ }
+ document.getElementById("titlebar").textContent = title;
+
+ // Update the signal strength bars.
+ var signalElements = document.querySelectorAll('#signal > span');
+ for (var i = 0; i < 4; i++) {
+ var haveSignal = (i < conn.bars);
+ var el = signalElements[i];
+ if (haveSignal) {
+ el.classList.add('haveSignal');
+ } else {
+ el.classList.remove('haveSignal');
+ }
+ }
+
+ conn.addEventListener("cardstatechange", updateConnection);
+ conn.addEventListener("connectionchange", updateConnection);
+}
View
6 apps/homescreen/style/homescreen.css
@@ -393,7 +393,11 @@ iframe.landscape-secondary {
width: 3px;
margin: 1px;
- background: #999;
+ background: #333333;
+}
+
+#signal span.haveSignal {
+ background: #999999;
}
#signal span:nth-child(1) {

0 comments on commit bb36b8f

Please sign in to comment.
Something went wrong with that request. Please try again.