Skip to content

Commit

Permalink
Updated Contacts API following the contacts API review meeting. Now s…
Browse files Browse the repository at this point in the history
…hould properly return new Contacts interface-based objects.
  • Loading branch information
Fil Maj committed Dec 1, 2009
1 parent 4821aae commit 15afec1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 33 deletions.
Expand Up @@ -49,7 +49,7 @@ public class ContactsCommand implements Command {
private static final int REMOVE_COMMAND = 3;
private static final int NEW_COMMAND = 4;
private static final String CODE = "PhoneGap=contacts";
private static final String CONTACT_MANAGER_JS_NAMESPACE = "navigator.AddressBook";
private static final String CONTACT_MANAGER_JS_NAMESPACE = "navigator.contacts";

private static final String ERROR_NO_CONTACTID = ";alert('[PhoneGap Error] Contact ID not specified during contact removal operation.');";

Expand Down Expand Up @@ -279,7 +279,7 @@ private static void addContactToBuffer(StringBuffer buff, BlackBerryContact cont
// TODO: Eventually extend this to return proper labels/values for differing phone/email types.
buff.append("{");
if (contact.countValues(Contact.EMAIL) > 0) {
buff.append("email:[{'label':'mobile','value':'");
buff.append("emails:[{'types':['mobile'],'address':'");
buff.append(contact.getString(Contact.EMAIL, 0));
buff.append("'}]");
}
Expand All @@ -300,38 +300,24 @@ private static void addContactToBuffer(StringBuffer buff, BlackBerryContact cont
}
if (sentinel) {
if (buff.length() > 1) buff.append(",");
buff.append("phoneNumber:[{'label':'mobile','value':'");
buff.append("phoneNumber:[{'types':['mobile'],'number':'");
buff.append(phoneMobile);
buff.append("'}]");
}
}
// See if there is a meaningful name set for the contact.
if (contact.countValues(Contact.NAME) > 0) {
if (buff.length() > 1) buff.append(",");
buff.append("firstName:'");
buff.append("name:{");
buff.append("givenName:'");
final String[] name = contact.getStringArray(Contact.NAME, 0);
final String firstName = name[Contact.NAME_GIVEN];
final String lastName = name[Contact.NAME_FAMILY];
buff.append((firstName != null ? firstName : "") + "',lastName:'");
buff.append((firstName != null ? firstName : "") + "',familyName:'");
buff.append((lastName != null ? lastName : "") + "'");
}
if (buff.length() > 1) buff.append(",");
buff.append("address:'");
// Build up a meaningful address field.
if (contact.countValues(Contact.ADDR) > 0) {
String address = "";
final String[] addr = contact.getStringArray(Contact.ADDR, 0);
final String street = addr[Contact.ADDR_STREET];
final String city = addr[Contact.ADDR_LOCALITY];
final String state = addr[Contact.ADDR_REGION];
final String country = addr[Contact.ADDR_COUNTRY];
final String postalCode = addr[Contact.ADDR_POSTALCODE];
if (street!=null) address = street.replace('\'',' ');
if (city!=null) if (address.length() > 0) address += ", " + city.replace('\'',' '); else address = city.replace('\'',' ');
if (state!=null) if (address.length() > 0) address += ", " + state.replace('\'',' '); else address = state.replace('\'',' ');
if (country!=null) if (address.length() > 0) address += ", " + country.replace('\'',' '); else address = country.replace('\'',' ');
if (postalCode!=null) if (address.length() > 0) address += ", " + postalCode.replace('\'',' '); else address = postalCode.replace('\'',' ');
buff.append(address);
String formatted = (firstName != null ? firstName : "");
formatted += (lastName != null? " " + lastName : "");
buff.append(",'formatted':'" + formatted + "'}");
}
buff.append("'}");
}
Expand Down
18 changes: 8 additions & 10 deletions blackberry/js/contacts.js
Expand Up @@ -4,18 +4,16 @@
*/

function Contact(jsonObject) {
this.firstName = "";
this.lastName = "";
this.name = "";
this.phones = {};
this.emails = {};
this.address = "";
this.name = {
formatted:''
};
this.phones = [];
this.emails = [];
this.id = "";
}

Contact.prototype.displayName = function()
{
// TODO: can be tuned according to prefs
return this.name;
Contact.prototype.displayName = function() {
return this.name.formatted;
}

function Contacts() {
Expand Down

0 comments on commit 15afec1

Please sign in to comment.