Search in sources :

Example 1 with PostalAddress

use of com.vodafone360.people.datatypes.VCardHelper.PostalAddress in project 360-Engine-for-Android by 360.

the class NativeContactsApi2 method putAddress.

/**
     * Put Address detail into the values
     * 
     * @param cc {@link ContactChange} to read values from
     */
private void putAddress(ContactChange cc) {
    final PostalAddress address = VCardHelper.getPostalAddress(cc.getValue());
    if (address == null) {
        // Nothing to do
        return;
    }
    mValues.put(StructuredPostal.STREET, address.addressLine1);
    mValues.put(StructuredPostal.POBOX, address.postOfficeBox);
    mValues.put(StructuredPostal.NEIGHBORHOOD, address.addressLine2);
    mValues.put(StructuredPostal.CITY, address.city);
    mValues.put(StructuredPostal.REGION, address.county);
    mValues.put(StructuredPostal.POSTCODE, address.postCode);
    mValues.put(StructuredPostal.COUNTRY, address.country);
    final int flags = cc.getFlags();
    mValues.put(StructuredPostal.TYPE, mapToNabAddressType(flags));
    mValues.put(StructuredPostal.IS_PRIMARY, flags & ContactChange.FLAG_PREFERRED);
    mValues.put(StructuredPostal.MIMETYPE, StructuredPostal.CONTENT_ITEM_TYPE);
}
Also used : PostalAddress(com.vodafone360.people.datatypes.VCardHelper.PostalAddress)

Example 2 with PostalAddress

use of com.vodafone360.people.datatypes.VCardHelper.PostalAddress in project 360-Engine-for-Android by 360.

the class UpdateNativeContactsTest method feedOneSyncableContact.

/**
     * Feeds the People database with a contact containing all the possible details
     * that can be synced on native side.
     * 
     * @return the created Contact
     */
private Contact feedOneSyncableContact() {
    final Contact contact = new Contact();
    // set it syncable to native side
    contact.synctophone = true;
    contact.aboutMe = "xxx xxyyyy";
    contact.friendOfMine = false;
    contact.gender = 1;
    // add a VCARD_NAME
    ContactDetail detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_NAME;
    detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
    detail.order = ContactDetail.ORDER_NORMAL;
    Name name = new Name();
    name.firstname = "Firstname";
    name.midname = "Midname";
    name.surname = "Surname";
    name.suffixes = "Suffixes";
    name.title = "Title";
    // a VCARD_NAME
    detail.value = VCardHelper.makeName(name);
    contact.details.add(detail);
    // add a VCARD_NICKNAME
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_NICKNAME;
    detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "My Nickname";
    contact.details.add(detail);
    // add a birthday VCARD_DATE + BIRTHDAY type 
    detail = new ContactDetail();
    detail.order = ContactDetail.ORDER_NORMAL;
    Time time = new Time();
    time.set(1, 1, 2010);
    detail.setDate(time, ContactDetail.DetailKeyTypes.BIRTHDAY);
    contact.details.add(detail);
    // add emails (Work, Home, Other)
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_EMAIL;
    detail.keyType = ContactDetail.DetailKeyTypes.HOME;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "email@home.test";
    contact.details.add(detail);
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_EMAIL;
    detail.keyType = ContactDetail.DetailKeyTypes.WORK;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "email@work.test";
    contact.details.add(detail);
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_EMAIL;
    detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "email@other.test";
    contact.details.add(detail);
    // add phones VCARD_PHONE (Home, Cell, Work, Fax, Other)
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_PHONE;
    detail.keyType = ContactDetail.DetailKeyTypes.HOME;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "+33111111";
    contact.details.add(detail);
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_PHONE;
    detail.keyType = ContactDetail.DetailKeyTypes.CELL;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "+33222222";
    contact.details.add(detail);
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_PHONE;
    detail.keyType = ContactDetail.DetailKeyTypes.WORK;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "+33333333";
    contact.details.add(detail);
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_PHONE;
    detail.keyType = ContactDetail.DetailKeyTypes.FAX;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "+33444444";
    contact.details.add(detail);
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_PHONE;
    detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "+33555555";
    contact.details.add(detail);
    // add a preferred detail since all the others are set to normal
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_PHONE;
    detail.keyType = ContactDetail.DetailKeyTypes.HOME;
    detail.order = ContactDetail.ORDER_PREFERRED;
    detail.value = "+33666666";
    contact.details.add(detail);
    // add VCARD_ADDRESS (Home, Work, Other)
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_ADDRESS;
    detail.keyType = ContactDetail.DetailKeyTypes.HOME;
    detail.order = ContactDetail.ORDER_NORMAL;
    PostalAddress address = new PostalAddress();
    address.addressLine1 = "home address line 1";
    address.addressLine2 = "home address line 2";
    address.city = "home city";
    address.country = "home country";
    address.county = "home county";
    address.postCode = "home postcode";
    address.postOfficeBox = "home po box";
    detail.value = VCardHelper.makePostalAddress(address);
    contact.details.add(detail);
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_ADDRESS;
    detail.keyType = ContactDetail.DetailKeyTypes.WORK;
    detail.order = ContactDetail.ORDER_NORMAL;
    address = new PostalAddress();
    address.addressLine1 = "work address line 1";
    address.addressLine2 = "work address line 2";
    address.city = "work city";
    address.country = "work country";
    address.county = "work county";
    address.postCode = "work postcode";
    address.postOfficeBox = "work po box";
    detail.value = VCardHelper.makePostalAddress(address);
    contact.details.add(detail);
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_ADDRESS;
    detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
    detail.order = ContactDetail.ORDER_NORMAL;
    address = new PostalAddress();
    address.addressLine1 = "other address line 1";
    address.addressLine2 = "other address line 2";
    address.city = "other city";
    address.country = "other country";
    address.county = "other county";
    address.postCode = "other postcode";
    address.postOfficeBox = "other po box";
    detail.value = VCardHelper.makePostalAddress(address);
    contact.details.add(detail);
    // add a VCARD_URL
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_URL;
    detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "http://myurl.test";
    contact.details.add(detail);
    // add a VCARD_NOTE
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_NOTE;
    detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "a note";
    contact.details.add(detail);
    // add a VCARD_ORG
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_ORG;
    detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
    detail.order = ContactDetail.ORDER_NORMAL;
    Organisation org = new Organisation();
    org.name = "company name";
    org.unitNames.add("department");
    detail.value = VCardHelper.makeOrg(org);
    contact.details.add(detail);
    // add a VCARD_TITLE
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_TITLE;
    detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "title";
    contact.details.add(detail);
    mDatabaseHelper.addContact(contact);
    return contact;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) PostalAddress(com.vodafone360.people.datatypes.VCardHelper.PostalAddress) Organisation(com.vodafone360.people.datatypes.VCardHelper.Organisation) Time(android.text.format.Time) Contact(com.vodafone360.people.datatypes.Contact) Name(com.vodafone360.people.datatypes.VCardHelper.Name)

Example 3 with PostalAddress

use of com.vodafone360.people.datatypes.VCardHelper.PostalAddress in project 360-Engine-for-Android by 360.

the class NativeContactsApi1 method parseRawAddress.

/**
     * Utility method used to parse a raw display Address into a
     * {@link VCardHelper.PostalAddress} object. The purpose of this method is
     * simply to remove '\n' separators. It does not aim to correctly map
     * address components to the right place, e.g. it is not guaranteed that
     * 'PostalAddress.Country' will really be the Country.
     */
private static PostalAddress parseRawAddress(String rawAddress) {
    final PostalAddress address = new PostalAddress();
    final String[] tokens = rawAddress.trim().split("\n");
    final int numTokens = tokens.length;
    address.addressLine1 = tokens[0];
    if (numTokens > 1) {
        address.addressLine2 = tokens[1];
    }
    if (numTokens > 2) {
        address.city = tokens[2];
    }
    if (numTokens > 3) {
        address.county = tokens[3];
    }
    if (numTokens > 4) {
        address.postCode = tokens[4];
    }
    if (numTokens > 5) {
        address.country = tokens[5];
    }
    if (numTokens > 6) {
        final StringBuilder sb = new StringBuilder();
        sb.append(tokens[6]);
        for (int i = 7; i < numTokens; i++) {
            sb.append(' ');
            sb.append(tokens[i]);
        }
        address.postOfficeBox = sb.toString();
    }
    return address;
}
Also used : PostalAddress(com.vodafone360.people.datatypes.VCardHelper.PostalAddress)

Example 4 with PostalAddress

use of com.vodafone360.people.datatypes.VCardHelper.PostalAddress in project 360-Engine-for-Android by 360.

the class NativeContactsApi1 method putContactMethodValues.

/**
     * Put Contact Methods detail into the values
     * 
     * @param cc {@link ContactChange} to read values from
     * @param kind The kind of contact method (email or address)
     * @param nabContactId ID of the NAB Contact
     */
private void putContactMethodValues(ContactChange cc, int kind, long nabContactId) {
    mValues.put(ContactMethods.PERSON_ID, nabContactId);
    if (kind == CONTACT_METHODS_KIND_EMAIL) {
        mValues.put(ContactMethods.DATA, cc.getValue());
    } else {
        // Must be Address, once again need to use VCardHelper to extract
        // address
        PostalAddress address = VCardHelper.getPostalAddress(cc.getValue());
        mValues.put(ContactMethods.DATA, address.toString());
    }
    mValues.put(ContactMethods.KIND, kind);
    int flags = cc.getFlags();
    mValues.put(ContactMethods.TYPE, mapToNabContactMethodType(flags));
    mValues.put(ContactMethods.ISPRIMARY, flags & ContactChange.FLAG_PREFERRED);
}
Also used : PostalAddress(com.vodafone360.people.datatypes.VCardHelper.PostalAddress)

Example 5 with PostalAddress

use of com.vodafone360.people.datatypes.VCardHelper.PostalAddress in project 360-Engine-for-Android by 360.

the class NativeContactsApi2 method readAddress.

/**
     * Reads an address detail as a {@link ContactChange} from the provided
     * cursor. For this type of detail we need to use a VCARD (semicolon
     * separated) value.
     * 
     * @param cursor Cursor to read from
     * @param ccList List of Contact Changes to add read detail data
     * @param nabContactId ID of the NAB Contact
     */
private void readAddress(Cursor cursor, List<ContactChange> ccList, long nabContactId) {
    // Using formatted address only to check if there is a valid address to
    // read
    final String formattedAddress = CursorUtils.getString(cursor, StructuredPostal.FORMATTED_ADDRESS);
    if (!TextUtils.isEmpty(formattedAddress)) {
        final long nabDetailId = CursorUtils.getLong(cursor, StructuredPostal._ID);
        final int type = CursorUtils.getInt(cursor, StructuredPostal.TYPE);
        int flags = mapFromNabAddressType(type);
        final boolean isPrimary = CursorUtils.getInt(cursor, StructuredPostal.IS_PRIMARY) != 0;
        if (isPrimary) {
            flags |= ContactChange.FLAG_PREFERRED;
        }
        // VCard Helper data type (CAB)
        final PostalAddress address = new PostalAddress();
        // NAB: Street -> CAB: AddressLine1
        address.addressLine1 = CursorUtils.getString(cursor, StructuredPostal.STREET);
        // NAB: PO Box -> CAB: postOfficeBox
        address.postOfficeBox = CursorUtils.getString(cursor, StructuredPostal.POBOX);
        // NAB: Neighborhood -> CAB: AddressLine2
        address.addressLine2 = CursorUtils.getString(cursor, StructuredPostal.NEIGHBORHOOD);
        // NAB: City -> CAB: City
        address.city = CursorUtils.getString(cursor, StructuredPostal.CITY);
        // NAB: Region -> CAB: County
        address.county = CursorUtils.getString(cursor, StructuredPostal.REGION);
        // NAB: Post code -> CAB: Post code
        address.postCode = CursorUtils.getString(cursor, StructuredPostal.POSTCODE);
        // NAB: Country -> CAB: Country
        address.country = CursorUtils.getString(cursor, StructuredPostal.COUNTRY);
        final ContactChange cc = new ContactChange(ContactChange.KEY_VCARD_ADDRESS, VCardHelper.makePostalAddress(address), flags);
        cc.setNabContactId(nabContactId);
        cc.setNabDetailId(nabDetailId);
        ccList.add(cc);
    }
}
Also used : PostalAddress(com.vodafone360.people.datatypes.VCardHelper.PostalAddress)

Aggregations

PostalAddress (com.vodafone360.people.datatypes.VCardHelper.PostalAddress)7 Name (com.vodafone360.people.datatypes.VCardHelper.Name)2 Organisation (com.vodafone360.people.datatypes.VCardHelper.Organisation)2 Time (android.text.format.Time)1 Contact (com.vodafone360.people.datatypes.Contact)1 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)1