Search in sources :

Example 1 with ContactField

use of com.googlecode.gwtphonegap.client.contacts.ContactField in project gwtphonegap by dankurka.

the class ContactBrowserImpl method fromJSON.

public static Contact fromJSON(ContactsBrowserImpl controller, JSONObject jsonContact) {
    ContactBrowserImpl contact = new ContactBrowserImpl(controller);
    // simple fields
    contact.setId(getFieldAsString(jsonContact.get(FIELD_ID)));
    contact.setDisplayName(getFieldAsString(jsonContact.get(CONTACT_DISPLAY_NAME)));
    contact.setNickName(getFieldAsString(jsonContact.get(CONTACT_NICK_NAME)));
    contact.setNote(getFieldAsString(jsonContact.get(CONTACT_NOTE)));
    // birthday
    JSONValue dateValue = jsonContact.get(CONTACT_BIRTHDAY);
    if (dateValue != null && dateValue.isNumber() != null) {
        contact.setBirthDay(new Date((long) dateValue.isNumber().doubleValue()));
    }
    // contact fields
    JSONArray phoneNumberArray = jsonContact.get(CONTACT_PHONE_NUMBERS).isArray();
    LightArray<ContactField> phoneNumbers = getContactFieldsForArray(phoneNumberArray);
    contact.setPhoneNumbers(phoneNumbers);
    JSONArray emailsArray = jsonContact.get(CONTACT_EMAILS).isArray();
    LightArray<ContactField> emails = getContactFieldsForArray(emailsArray);
    contact.setEmails(emails);
    JSONArray imsArray = jsonContact.get(CONTACT_IMS).isArray();
    LightArray<ContactField> ims = getContactFieldsForArray(imsArray);
    contact.setIms(ims);
    JSONArray photosArray = jsonContact.get(CONTACT_PHOTOS).isArray();
    LightArray<ContactField> photos = getContactFieldsForArray(photosArray);
    contact.setPhotos(photos);
    JSONArray categoriesArray = jsonContact.get(CONTACT_CATEGORIES).isArray();
    LightArray<ContactField> categories = getContactFieldsForArray(categoriesArray);
    contact.setCategories(categories);
    JSONArray urlsArray = jsonContact.get(CONTACT_URLS).isArray();
    LightArray<ContactField> urls = getContactFieldsForArray(urlsArray);
    contact.setUrls(urls);
    ContactName name = getName(jsonContact.get(CONTACT_NAME).isObject());
    contact.setName(name);
    LightArray<ContactAddress> addresses = getAddressArray(jsonContact.get(CONTACT_ADDRESSES).isArray());
    contact.setContactAddresses(addresses);
    LightArray<ContactOrganisation> organisations = getContactOrganisationArray(jsonContact.get(CONTACT_ORGANISATION).isArray());
    contact.setOrganisations(organisations);
    return contact;
}
Also used : JSONValue(com.google.gwt.json.client.JSONValue) ContactAddress(com.googlecode.gwtphonegap.client.contacts.ContactAddress) JSONArray(com.google.gwt.json.client.JSONArray) ContactField(com.googlecode.gwtphonegap.client.contacts.ContactField) ContactName(com.googlecode.gwtphonegap.client.contacts.ContactName) Date(java.util.Date) ContactOrganisation(com.googlecode.gwtphonegap.client.contacts.ContactOrganisation)

Example 2 with ContactField

use of com.googlecode.gwtphonegap.client.contacts.ContactField in project gwtphonegap by dankurka.

the class ContactBrowserImpl method toJSONArray.

private JSONValue toJSONArray(LightArray<ContactField> contactField) {
    JSONArray jsonArray = new JSONArray();
    for (int i = 0; i < contactField.length(); i++) {
        ContactField field = contactField.get(i);
        JSONObject jsonField = new JSONObject();
        jsonField.put(CONTACT_FIELD_TYPE, getAsJSONString(field.getType()));
        jsonField.put(CONTACT_FIELD_VALUE, getAsJSONString(field.getValue()));
        jsonField.put(CONTACT_FIELD_PREF, JSONBoolean.getInstance(field.isPref()));
        jsonArray.set(i, jsonField);
    }
    return jsonArray;
}
Also used : JSONObject(com.google.gwt.json.client.JSONObject) JSONArray(com.google.gwt.json.client.JSONArray) ContactField(com.googlecode.gwtphonegap.client.contacts.ContactField)

Example 3 with ContactField

use of com.googlecode.gwtphonegap.client.contacts.ContactField in project gwtphonegap by dankurka.

the class ContactBrowserImpl method getContactFieldsForArray.

private static LightArray<ContactField> getContactFieldsForArray(JSONArray jsonArray) {
    LightArray<ContactField> array = CollectionFactory.constructArray();
    if (jsonArray == null) {
        return array;
    }
    for (int i = 0; i < jsonArray.size(); i++) {
        ContactFieldBrowserImpl cf = new ContactFieldBrowserImpl();
        JSONObject object = jsonArray.get(i).isObject();
        String type = getFieldAsString(object.get(CONTACT_FIELD_TYPE));
        String value = getFieldAsString(object.get(CONTACT_FIELD_VALUE));
        boolean pref = getFieldAsBoolean(object.get(CONTACT_FIELD_PREF));
        cf.setPref(pref);
        cf.setType(type);
        cf.setValue(value);
        array.push(cf);
    }
    return array;
}
Also used : JSONObject(com.google.gwt.json.client.JSONObject) ContactField(com.googlecode.gwtphonegap.client.contacts.ContactField) JSONString(com.google.gwt.json.client.JSONString)

Aggregations

ContactField (com.googlecode.gwtphonegap.client.contacts.ContactField)3 JSONArray (com.google.gwt.json.client.JSONArray)2 JSONObject (com.google.gwt.json.client.JSONObject)2 JSONString (com.google.gwt.json.client.JSONString)1 JSONValue (com.google.gwt.json.client.JSONValue)1 ContactAddress (com.googlecode.gwtphonegap.client.contacts.ContactAddress)1 ContactName (com.googlecode.gwtphonegap.client.contacts.ContactName)1 ContactOrganisation (com.googlecode.gwtphonegap.client.contacts.ContactOrganisation)1 Date (java.util.Date)1