Skip to content
This repository has been archived by the owner on Apr 18, 2019. It is now read-only.

Commit

Permalink
adding beep vibrate and lighton
Browse files Browse the repository at this point in the history
  • Loading branch information
imhotep committed Apr 6, 2012
1 parent 07c467f commit fa18c75
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Res/index.html
Expand Up @@ -18,6 +18,7 @@
}
</style>
<script type="text/javascript" src="osp://webapp/js/webapp_core.js"> </script>
<script type="text/javascript" src="osp://webapp/js/webapp_ui.js"> </script>
<script>
/*
Osp.App.Application.addEventListener("initializing", function()
Expand Down Expand Up @@ -79,7 +80,26 @@ <h3>Connection</h3>
<span id="connection"></span>
</div>
</li>
<li>
<h3>Notifications</h3>
<div>
<button type="button" class="btn" onclick="notificationAlert();">Alert</button>
</div>
<div>
<button type="button" class="btn" onclick="notificationAlert();">Confirm</button>
</div>
<div>
<button type="button" class="btn" onclick="notificationVibrate();">Vibrate</button>
</div>
<div>
<button type="button" class="btn" onclick="notificationBeep();">Beep</button>
</div>
<div>
<button type="button" class="btn" onclick="notificationLightOn();">Light ON</button>
</div>
</li>
</ul>
<script type="text/javascript" src="./js/notification.js"></script>
<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>
Expand Down
48 changes: 48 additions & 0 deletions Res/js/notification.js
@@ -0,0 +1,48 @@
navigator.notification = {
alert: function(message, alertCallback, title, buttonName) {
alert(message);
},
confirm: function(message, confirmCallback, title, buttonLabels) {
alert(message);
},
beep: function(times, milliseconds) {
try {
deviceapis.deviceinteraction.stopNotify();
if(times == 0) {
return;
}
deviceapis.deviceinteraction.startNotify(function() {
console.log("Notifying");
},
function(e) {
console.log("Failed to notify: " + e);
},
milliseconds);
Osp.Core.Function.delay(this.beep, 1000+milliseconds, this, times - 1, milliseconds);
} catch(e) {
console.log("Exception thrown: " + e);
}
},
vibrate: function(milliseconds) {
try {
deviceapis.deviceinteraction.startVibrate(function() {
console.log("Vibrating...");
},
function(e) {
console.log("Failed to vibrate: " + e);
},
milliseconds);
} catch(e) {
console.log("Exception thrown: " + e);
}
},
lightOn: function(milliseconds) {
deviceapis.deviceinteraction.lightOn(function() {
console.log("Lighting for "+milliseconds+" second");
},
function() {
console.log("Failed to light");
},
milliseconds);
}
};
24 changes: 24 additions & 0 deletions Res/js/sample.js
Expand Up @@ -174,4 +174,28 @@ function clearHeadingWatch() {
function getConnection() {
var connectionEm = document.getElementById("connection");
connectionEm.innerHTML = "Connection type "+navigator.network.connection.type;
}

/*
* Notification
*/

function notificationAlert() {
var notifEm = document.getElementById('result');
var alertDismissed = function() {
console.log('alertDismissed');
};
navigator.notification.alert('You are the winner!', alertDismissed, 'Game Over', 'Done');
}

function notificationVibrate() {
navigator.notification.vibrate(2000);
}

function notificationBeep() {
navigator.notification.beep(4, 2000);
}

function notificationLightOn() {
navigator.notification.lightOn(2000);
}

0 comments on commit fa18c75

Please sign in to comment.