Skip to content

Commit

Permalink
proof of concept application as template, added acceleromter, and min…
Browse files Browse the repository at this point in the history
…or tweaks all around
  • Loading branch information
Ryan Willoughby authored and Joe Bowser committed Nov 4, 2009
1 parent 1b47542 commit 0f60329
Show file tree
Hide file tree
Showing 8 changed files with 256 additions and 35 deletions.
Binary file added nokia/assets/nitobi-avatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
131 changes: 104 additions & 27 deletions nokia/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,132 @@
<!-- embed type="application/x-systeminfo-widget" hidden="yes"></embed -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script language="javascript" type="text/javascript" src="javascripts/phonegap/phonegap-interface.js"></script>
<script language="javascript" type="text/javascript" src="javascripts/phonegap/nokia/device.js"></script>
<script language="javascript" type="text/javascript" src="javascripts/phonegap/nokia/geolocation.js"></script>
<script language="javascript" type="text/javascript" src="javascripts/phonegap/nokia/notification.js"></script>
<script language="javascript" type="text/javascript" src="javascripts/phonegap/nokia/contact.js"></script>
<script language="javascript" type="text/javascript" src="javascripts/phonegap/nokia/accelerometer.js"></script>
<link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title" charset="utf-8">
<META NAME="Generator" CONTENT="Nokia WRT plug-in for Aptana Studio 2.0.0" />
<script type="text/javascript">
var myLocation;
var myNotification;
var myContactManager;
var timeout = null;
var displayState = 0;

function start() {
try {
//myNotification.beep(0,0);
var options = new Object();
options.frequency = 8000;
myLocation.watchPosition(function(){
var pt = myLocation.lastPosition.coords;
myNotification.vibrate(2000);
alert(pt.latitude + ", " + pt.longitude + ", " + pt.altitude + ", " + pt.accuracy + ", " + pt.heading + ", " + pt.speed);
}, function () { }, options);
var myContacts = new ContactManager();
myContacts.getAllContacts(function () {}, function() { alert('getallcontacts fail'); }, new Object());
timeout = setInterval("animate()", 500);
myLocation.watchPosition(updateLocation, function() {}, options);

myContactManager.getAllContacts(displayContacts, function() { alert('getallcontacts fail'); }, new Object());

options.frequency = 1000;
myAccelerometer.watchAcceleration(updateAcceleration, function () { alert('watch failed'); }, options);
} catch (ex) {
alert("error: " + ex.name + " " + ex.message)
alert(ex.name + " " + ex.message);
}
}

function init() {
myNotification = new Notification();
myLocation = new Geolocation()
myLocation = new Geolocation();
myContactManager = new ContactManager();
myAccelerometer = new Accelerometer();
start();
}

function updateLocation() {
clearTimeout(timeout);
//pt.latitude, pt.longitude, pt.altitude, pt.accuracy, pt.heading, pt.speed
var pt = myLocation.lastPosition.coords;
document.getElementById('latitude').innerHTML = pt.latitude;
document.getElementById('longitude').innerHTML = pt.longitude;
document.getElementById('altitude').innerHTML = pt.altitude;
document.getElementById('heading').innerHTML = pt.heading;
document.getElementById('speed').innerHTML = pt.speed;
}

function updateAcceleration(accel) {
document.getElementById('accel_x').innerHTML = accel.x;
document.getElementById('accel_y').innerHTML = accel.y;
document.getElementById('accel_z').innerHTML = accel.z;
}

function displayContacts() {
var contacts = myContactManager.contacts;
var output = "";
for (var i=0; i<contacts.length; i++) {
output += "<div class='list-item'>" + contacts[i].firstName + " " + contacts[i].lastName +
"<span class='list-item-small'> Phone: " + contacts[i].phones["Mobile"] +
"</div>";
}
document.getElementById('contacts').innerHTML = output;
}

function vibrate() {
try {
myNotification.vibrate(2000);
myNotification.beep(2000, 100);
} catch (ex) {
alert(ex.name + ": " + ex.message);
}
}

function animate() {
switch (displayState) {
case 0:
displayStatus('finding satellites.');
displayState = 1;
break;
case 1:
displayStatus('finding satellites..');
displayState = 2;
break;
case 2:
displayStatus('finding satellites...');
displayState = 3;
break;
case 3:
displayStatus('finding satellites');
displayState = 0;
break;

}
}

function displayStatus(status) {
document.getElementById('latitude').innerHTML = status;
document.getElementById('longitude').innerHTML = status;
document.getElementById('altitude').innerHTML = status;
document.getElementById('heading').innerHTML = status;
document.getElementById('speed').innerHTML = status;
}

</script>
<style type="text/css">
a.btn.large {
border: 1px solid #555;
border-radius: 5px;
text-align: center;
display:block;
float:left;
background:#444;
width:90%;
color:#9AB;
font-size:1.1em;
text-decoration:none;
padding:1.2em 0;
margin:3px 0px 3px 5px;
}
</style>
</head>
<body onload="javascript:init();">
<a href="#" class="btn large" onclick="start();">GO</a>
<div class="header">phonegap nokia</div>
Geolocation
<div class="list">
<div class="list-item">latitude: <span id="latitude">finding satellites</span></div>
<div class="list-item">longitude: <span id="longitude">finding satellites</span></div>
<div class="list-item">altitude: <span id="altitude">finding satellites</span></div>
<div class="list-item">heading: <span id="heading">finding satellites</span></div>
<div class="list-item">speed: <span id="speed">finding satellites</span></div>
</div>
Accelerometer
<div class="list">
<div class="list-item">X-Accel: <span id="accel_x"></span></div>
<div class="list-item">Y-Accel: <span id="accel_y"></span></div>
<div class="list-item">Z-Accel: <span id="accel_z"></span></div>
</div>
Contacts
<div id="contacts" class="contacts"></div>
<div class="list-item"><a href="javascript:vibrate();">Notification (vibrate)</a></div>
<a href="javascript:widget.openURL('http://www.nitobi.com');"><img src="assets/nitobi-avatar.png" class="nitobi-logo" /></a>
</body>
</html>
74 changes: 74 additions & 0 deletions nokia/javascripts/phonegap/nokia/accelerometer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* Asynchronously aquires the current acceleration.
* @param {Function} successCallback The function to call when the acceleration
* data is available
* @param {Function} errorCallback The function to call when there is an error
* getting the acceleration data.
* @param {AccelerationOptions} options The options for getting the accelerometer data
* such as timeout.
*/

Accelerometer.prototype.getCurrentAcceleration = function(successCallback, errorCallback, options) {
// If the acceleration is available then call success
// If the acceleration is not available then call error

if (!this.serviceObj)
this.serviceObj = InitializeAccelerationServiceObject();

//get the sensor channel
var SensorParams = { SearchCriterion : "AccelerometerAxis" };
var returnvalue = this.serviceObj.ISensor.FindSensorChannel(SensorParams);

var error = returnvalue["ErrorCode"];
var errmsg = returnvalue["ErrorMessage"];
if( !(error == 0 || error == 1012) )
{
var ex = { name: "Unable to find Sensor Channel: " + error, message: errmsg };
errorCallback(ex);
}
var channelInfoMap = returnvalue["ReturnValue"][0];
var criteria = { ChannelInfoMap: channelInfoMap, ListeningType: "ChannelData" };

if (typeof(successCallback) != 'function')
successCallback = function() {};
if (typeof(errorCallback) != 'function')
errorCallback = function() {};

this.success_callback = successCallback;
this.error_callback = errorCallback;

//create a closure to persist this instance of Accelerometer into the RegisterForNofication callback
var obj = this;

this.serviceObj.ISensor.RegisterForNotification(criteria, function(transId, eventCode, result){
var criteria = { TransactionID: transId };
try {
obj.serviceObj.ISensor.Cancel(criteria);

var accel = new Acceleration(result.ReturnValue.XAxisData, result.ReturnValue.YAxisData, result.ReturnValue.ZAxisData);
Accelerometer.lastAcceleration = accel;

obj.success_callback(accel);

} catch (ex) {
obj.serviceObj.ISensor.Cancel(criteria);
alert("accel listener - " + ex.name + ": " + ex.message);
obj.error_callback(ex);
}

});

}

//gets the Acceleration Service Object from WRT
function InitializeAccelerationServiceObject() {
var so;

try {
so = device.getServiceObject("Service.Sensor", "ISensor");
} catch (ex) {
alert('Error: failed to load acceleration service: ' + ex.name + " " + ex.message);
return null;
}
return so;
}
9 changes: 9 additions & 0 deletions nokia/javascripts/phonegap/nokia/camera.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
*
* @param {Function} successCallback
* @param {Function} errorCallback
* @param {Object} options
*/
Camera.prototype.getPicture = function(successCallback, errorCallback, options) {

}
18 changes: 11 additions & 7 deletions nokia/javascripts/phonegap/nokia/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@
* @author ryan
*/

var contactsService;
//var contactsService;

ContactManager.prototype.getAllContacts = function(successCallback, errorCallback, options) {
contactsService = device.getServiceObject("Service.Contact", "IDataSource");
this.contactsService = device.getServiceObject("Service.Contact", "IDataSource");

var criteria = new Object();
criteria.Type = "Contact";

if (typeof(successCallback) != 'function')
successCallback = function() {};
if (typeof(errorCallback) != 'function')
errorCallback = function() {};

//need a closure here to bind this method to this instance of the contactmanager object
this.global_success = successCallback;
var obj = this;

try {
//WRT: result.ReturnValue is an iterator of contacts
contactsService.IDataSource.GetList(criteria, function(transId, eventCode, result){obj.success_callback(result.ReturnValue);});
this.contactsService.IDataSource.GetList(criteria, function(transId, eventCode, result){obj.success_callback(result.ReturnValue);});
} catch (e) {
errorCallback(e);
}
Expand All @@ -31,7 +36,7 @@ ContactManager.prototype.success_callback = function(contacts_iterator) {
var gapContact = new Contact();
gapContact.firstName = ContactManager.GetValue(contact, "FirstName");
gapContact.lastName = ContactManager.GetValue(contact, "LastName");
gapContact.name = gapContact.firstName + gapContact.lastName;
gapContact.name = gapContact.firstName + " " + gapContact.lastName;
gapContact.emails = ContactManager.getEmailsList(contact);
gapContact.phones = ContactManager.getPhonesList(contact);
gapContact.address = ContactManager.getAddress(contact);
Expand All @@ -40,9 +45,8 @@ ContactManager.prototype.success_callback = function(contacts_iterator) {
alert(e.name + ": " + e.message);
}
}
alert('yo: ' + gapContacts.length + " contacts found");
this.contacts = gapContacts;

this.global_success();
}

ContactManager.getEmailsList = function(contact) {
Expand All @@ -64,7 +68,7 @@ ContactManager.getPhonesList = function(contact) {
try {
list = {
"Home": ContactManager.GetValue(contact, "LandPhoneHome"),
"Mobile": ContactManager.GetValue(contact, "MobilePhoneHome"),
"Mobile": ContactManager.GetValue(contact, "MobilePhoneGen"),
"Fax": ContactManager.GetValue(contact, "FaxNumberHome"),
"Work": ContactManager.GetValue(contact, "LandPhoneWork"),
"WorkMobile": ContactManager.GetValue(contact, "MobilePhoneWork")
Expand Down
8 changes: 8 additions & 0 deletions nokia/javascripts/phonegap/nokia/device.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @author ryan
* @description hide the main menu bar
*/

PhoneGap.addConstructor(function() {
menu.hideSoftkeys();
});
6 changes: 5 additions & 1 deletion nokia/javascripts/phonegap/nokia/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ Notification.prototype.vibrate = function(mills)
//TODO: this is not beeping
Notification.prototype.beep = function(count, volume)
{
this.sysinfo.beep(220,2000);
if (!Notification.getSysinfoObject())
Notification.embedSysinfoObject();

this.sysinfo = Notification.getSysinfoObject();
this.sysinfo.beep(220,2000);
}

Notification.embedSysinfoObject = function() {
Expand Down
45 changes: 45 additions & 0 deletions nokia/master.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
body {
width: 340px;
height: 620px;
font-family: Helvetica;
margin: 0px;
padding: 0px 10px;
font-size: 16pt;
}

.header {
width: 100%;
text-align: center;
margin: 20px 0px;
font-size: 27pt;
}

.list {
width: 100%;
border: 1px solid black;
}

.list-item {
padding: 8px 2px;
}

.list-item-small {
font-size: 12pt;
padding-top: 3px;
float: right;
}

.contacts {
width: 100%;
height: 245px;
overflow: auto;
border: 1px solid black;
}

.nitobi-logo {
position: absolute;
bottom: 10px;
right: 10px;
height: 35px;
width: 35px;
}

0 comments on commit 0f60329

Please sign in to comment.