merge of latest phonegap/android bs

This commit is contained in:
brianleroux
2010-09-30 13:39:10 +02:00
13 changed files with 2359 additions and 1150 deletions
+106 -51
View File
@@ -1,72 +1,127 @@
var Contact = function() {
this.name = new ContactName();
this.emails = [];
this.phones = [];
var Contact = function(id, displayName, name, nickname, phoneNumbers, emails, addresses,
ims, organizations, published, updated, birthday, anniversary, gender, note,
preferredUsername, photos, tags, relationships, urls, accounts, utcOffset, connected) {
this.id = id || null;
this.displayName = displayName || null;
this.name = name || null; // ContactName
this.nickname = nickname || null;
this.phoneNumbers = phoneNumbers || null; // ContactField[]
this.emails = emails || null; // ContactField[]
this.addresses = addresses || null; // ContactAddress[]
this.ims = ims || null; // ContactField[]
this.organizations = organizations || null; // ContactOrganization[]
this.published = published || null;
this.updated = updated || null;
this.birthday = birthday || null;
this.anniversary = anniversary || null;
this.gender = gender || null;
this.note = note || null;
this.preferredUsername = preferredUsername || null;
this.photos = photos || null; // ContactField[]
this.tags = tags || null; // ContactField[]
this.relationships = relationships || null; // ContactField[]
this.urls = urls || null; // ContactField[]
this.accounts = accounts || null; // ContactAccount[]
this.utcOffset = utcOffset || null;
this.connected = connected || null;
};
var ContactName = function() {
this.formatted = "";
this.familyName = "";
this.givenName = "";
this.additionalNames = [];
this.prefixes = [];
this.suffixes = [];
var ContactName = function(formatted, familyName, givenName, middle, prefix, suffix) {
this.formatted = formatted || null;
this.familyName = familyName || null;
this.givenName = givenName || null;
this.middleName = middle || null;
this.honorificPrefix = prefix || null;
this.honorificSuffix = suffix || null;
};
var ContactEmail = function() {
this.types = [];
this.address = "";
var ContactField = function(type, value, primary) {
this.type = type || null;
this.value = value || null;
this.primary = primary || null;
};
var ContactPhoneNumber = function() {
this.types = [];
this.number = "";
var ContactAddress = function(formatted, streetAddress, locality, region, postalCode, country) {
this.formatted = formatted || null;
this.streetAddress = streetAddress || null;
this.locality = locality || null;
this.region = region || null;
this.postalCode = postalCode || null;
this.country = country || null;
};
var ContactOrganization = function(name, dept, title, startDate, endDate, location, desc) {
this.name = name || null;
this.department = dept || null;
this.title = title || null;
this.startDate = startDate || null;
this.endDate = endDate || null;
this.location = location || null;
this.description = desc || null;
};
var ContactAccount = function(domain, username, userid) {
this.domain = domain || null;
this.username = username || null;
this.userid = userid || null;
}
var Contacts = function() {
this.records = [];
};
this.inProgress = false;
this.records = new Array();
}
Contacts.prototype.find = function(obj, win, fail) {
// Contacts.prototype.find = function(obj, win, fail) {
Contacts.prototype.find = function(fields, win, fail, options) {
this.win = win;
this.fail = fail;
if(obj.name != null) {
// Build up the search term that we'll use in SQL, based on the structure/contents of the contact object passed into find.
var searchTerm = '';
if (obj.name.givenName && obj.name.givenName.length > 0) {
searchTerm = obj.name.givenName.split(' ').join('%');
}
if (obj.name.familyName && obj.name.familyName.length > 0) {
searchTerm += obj.name.familyName.split(' ').join('%');
}
if (!obj.name.familyName && !obj.name.givenName && obj.name.formatted) {
searchTerm = obj.name.formatted;
}
PhoneGap.execAsync(null, null, "Contacts", "search", [searchTerm, "", ""]);
}
PhoneGap.execAsync(null, null, "Contacts", "search", [fields, options]);
};
Contacts.prototype.droidFoundContact = function(name, npa, email) {
var contact = new Contact();
contact.name = new ContactName();
contact.name.formatted = name;
contact.name.givenName = name;
var mail = new ContactEmail();
mail.types.push("home");
mail.address = email;
contact.emails.push(mail);
phone = new ContactPhoneNumber();
phone.types.push("home");
phone.number = npa;
contact.phones.push(phone);
this.records.push(contact);
Contacts.prototype.droidDone = function(contacts) {
this.win(eval('(' + contacts + ')'));
};
Contacts.prototype.droidDone = function() {
this.win(this.records);
Contacts.prototype.remove = function(contact) {
};
Contacts.prototype.save = function(contact) {
};
Contacts.prototype.create = function(contact) {
};
Contacts.prototype.m_foundContacts = function(win, contacts) {
this.inProgress = false;
win(contacts);
};
var ContactFindOptions = function(filter, multiple, limit, updatedSince) {
this.filter = filter || '';
this.multiple = multiple || true;
this.limit = limit || Number.MAX_VALUE;
this.updatedSince = updatedSince || '';
};
var ContactError = function() {
this.code=null;
};
ContactError.INVALID_ARGUMENT_ERROR = 0;
ContactError.IO_ERROR = 1;
ContactError.NOT_FOUND_ERROR = 2;
ContactError.NOT_SUPPORTED_ERROR = 3;
ContactError.PENDING_OPERATION_ERROR = 4;
ContactError.PERMISSION_DENIED_ERROR = 5;
ContactError.TIMEOUT_ERROR = 6;
ContactError.UNKNOWN_ERROR = 7;
PhoneGap.addConstructor(function() {
if(typeof navigator.contacts == "undefined") navigator.contacts = new Contacts();
if(typeof navigator.service == "undefined") navigator.service = new Object();
if(typeof navigator.service.contacts == "undefined") navigator.service.contacts = new Contacts();
});
+2 -2
View File
@@ -41,7 +41,7 @@ Notification.prototype.blink = function(count, colour) {
* @param {Integer} mills The number of milliseconds to vibrate for.
*/
Notification.prototype.vibrate = function(mills) {
PhoneGap.execAsync(null, null, "Device", "vibrate", [mills]);
PhoneGap.execAsync(null, null, "Notification", "vibrate", [mills]);
};
/**
@@ -51,7 +51,7 @@ Notification.prototype.vibrate = function(mills) {
* @param {Integer} count The number of beeps.
*/
Notification.prototype.beep = function(count) {
PhoneGap.execAsync(null, null, "Device", "beep", [count]);
PhoneGap.execAsync(null, null, "Notification", "beep", [count]);
};
// TODO: of course on Blackberry and Android there notifications in the UI as well
+22
View File
@@ -290,6 +290,28 @@ PhoneGap.stringify = function(args) {
if ((type == "number") || (type == "boolean")) {
s = s + args[i];
}
else if (args[i] instanceof Array) {
s = s + "[" + args[i] + "]";
}
else if (args[i] instanceof Object) {
var start = true;
s = s + '{';
for (var name in args[i]) {
if (!start) {
s = s + ',';
}
s = s + '"' + name + '":';
var nameType = typeof args[i][name];
if ((nameType == "number") || (nameType == "boolean")) {
s = s + args[i][name];
}
else {
s = s + '"' + args[i][name] + '"';
}
start=false;
}
s = s + '}';
}
else {
s = s + '"' + args[i] + '"';
}
File diff suppressed because it is too large Load Diff