Search in sources :

Example 36 with Type

use of com.vodafone360.people.service.io.Request.Type in project 360-Engine-for-Android by 360.

the class NativeContactsApi2 method readName.

/**
     * Reads an name 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 readName(Cursor cursor, List<ContactChange> ccList, long nabContactId) {
    // Using display name only to check if there is a valid name to read
    final String displayName = CursorUtils.getString(cursor, StructuredName.DISPLAY_NAME);
    if (!TextUtils.isEmpty(displayName)) {
        final long nabDetailId = CursorUtils.getLong(cursor, StructuredName._ID);
        // VCard Helper data type (CAB)
        final Name name = new Name();
        // NAB: Given name -> CAB: First name
        name.firstname = CursorUtils.getString(cursor, StructuredName.GIVEN_NAME);
        // NAB: Family name -> CAB: Surname
        name.surname = CursorUtils.getString(cursor, StructuredName.FAMILY_NAME);
        // NAB: Prefix -> CAB: Title
        name.title = CursorUtils.getString(cursor, StructuredName.PREFIX);
        // NAB: Middle name -> CAB: Middle name
        name.midname = CursorUtils.getString(cursor, StructuredName.MIDDLE_NAME);
        // NAB: Suffix -> CAB: Suffixes
        name.suffixes = CursorUtils.getString(cursor, StructuredName.SUFFIX);
        // NOTE: Ignoring Phonetics (DATA7, DATA8 and DATA9)!
        // TODO: Need to get middle name and concatenate into value
        final ContactChange cc = new ContactChange(ContactChange.KEY_VCARD_NAME, VCardHelper.makeName(name), ContactChange.FLAG_NONE);
        cc.setNabContactId(nabContactId);
        cc.setNabDetailId(nabDetailId);
        ccList.add(cc);
    }
}
Also used : StructuredName(android.provider.ContactsContract.CommonDataKinds.StructuredName) Name(com.vodafone360.people.datatypes.VCardHelper.Name)

Example 37 with Type

use of com.vodafone360.people.service.io.Request.Type in project 360-Engine-for-Android by 360.

the class StateTable method fetchOption.

/**
     * Fetches an option from the settings table.
     *
     * @param option Specifies which option is required
     * @param readableDb Readable SQLite database for fetching the information
     * @return A PersistSettings object containing the option data if
     *         successful, null otherwise.
     */
public static PersistSettings fetchOption(final PersistSettings.Option option, final SQLiteDatabase readableDb) {
    if (Settings.ENABLED_DATABASE_TRACE) {
        DatabaseHelper.trace(false, "StateTable.fetchOption() name[" + option.tableFieldName() + "] value[" + option.defaultValue() + "] type[" + option.getType() + "]");
    }
    Cursor c = null;
    try {
        c = readableDb.rawQuery("SELECT " + option.tableFieldName() + " FROM " + TABLE_NAME + " WHERE " + Field.STATEID + " = " + PRIMARY_STATE_KEY_VALUE, null);
        if (!c.moveToFirst()) {
            LogUtils.logE("StateTable.fetchOption() Unable to find option " + "in the database, option[" + option + "]");
            return null;
        }
        final PersistSettings setting = new PersistSettings();
        Object data = null;
        if (!c.isNull(0)) {
            data = PersistSettings.fetchValueFromCursor(c, 0, c.getColumnName(0));
        }
        setting.putOptionData(option, data);
        LogUtils.logD("StateTable.fetchOption() Fetched option[" + option + "]");
        return setting;
    } catch (Exception e) {
        LogUtils.logE("StateTable.fetchOption() Exception - Unable to " + "fetch options from database", e);
        return null;
    } finally {
        CloseUtils.close(c);
        c = null;
    }
}
Also used : PersistSettings(com.vodafone360.people.service.PersistSettings) Cursor(android.database.Cursor) SQLException(android.database.SQLException) SQLiteException(android.database.sqlite.SQLiteException)

Example 38 with Type

use of com.vodafone360.people.service.io.Request.Type in project 360-Engine-for-Android by 360.

the class NativeChangeLogTable method getDeletedDetails.

/**
     * Gets the list of deleted details as a ContactChange array.
     * 
     * Note: the ContactChange object will have the type ContactChange.TYPE_DELETE_DETAIL
     * 
     * @see ContactChange
     * 
     * @param localContactId the local contact id to query
     * @param readableDb the db to query from
     * @return an array of ContactChange, null if no details where found
     */
public static ContactChange[] getDeletedDetails(long localContactId, SQLiteDatabase readableDb) {
    final String[] SELECTION = { String.valueOf(localContactId), Integer.toString(ContactChangeType.DELETE_DETAIL.ordinal()) };
    Cursor cursor = null;
    try {
        cursor = readableDb.rawQuery(QUERY_DELETED_DETAILS, SELECTION);
        if (cursor.getCount() > 0) {
            final ContactChange[] deletedDetails = new ContactChange[cursor.getCount()];
            int index = 0;
            while (cursor.moveToNext()) {
                // fill the ContactChange class with contact detail data
                final ContactChange change = new ContactChange();
                deletedDetails[index++] = change;
                // set the ContactChange as a deleted contact detail
                change.setType(ContactChange.TYPE_DELETE_DETAIL);
                // LocalContactId=1
                change.setInternalContactId(cursor.isNull(1) ? ContactChange.INVALID_ID : cursor.getLong(1));
                // NativeContactId=2
                change.setNabContactId(cursor.isNull(2) ? ContactChange.INVALID_ID : cursor.getLong(2));
                // DetailLocalId=3
                change.setInternalDetailId(cursor.isNull(3) ? ContactChange.INVALID_ID : cursor.getInt(3));
                // NativeDetailId=4
                change.setNabDetailId(cursor.isNull(4) ? ContactChange.INVALID_ID : cursor.getLong(4));
                // DetailKey=5
                change.setKey(cursor.isNull(5) ? ContactChange.KEY_UNKNOWN : ContactDetailsTable.mapInternalKeyToContactChangeKey(cursor.getInt(5)));
                if (change.getNabContactId() == ContactChange.INVALID_ID) {
                    LogUtils.logE("NativeChangeLogTable.getDeletedDetails(): the native contact id shall not be null! cc.internalContactId=" + change.getInternalContactId() + ", cc.key=" + change.getKey());
                }
            }
            return deletedDetails;
        }
    } catch (Exception e) {
        if (Settings.ENABLED_DATABASE_TRACE) {
            DatabaseHelper.trace(false, "NativeChangeLogTable.getDeletedContactsNativeIds(): " + e);
        }
    } finally {
        CloseUtils.close(cursor);
        cursor = null;
    }
    return null;
}
Also used : Cursor(android.database.Cursor) ContactChange(com.vodafone360.people.engine.contactsync.ContactChange) SQLException(android.database.SQLException) SQLiteException(android.database.sqlite.SQLiteException)

Example 39 with Type

use of com.vodafone360.people.service.io.Request.Type in project 360-Engine-for-Android by 360.

the class PresenceList method setValue.

private void setValue(Tags key, Object value) {
    LogUtils.logI("HessianDecoder.setValue() key[" + key + "] value[" + value + "]");
    switch(key) {
        case USER_ID:
            mUserId = (Long) value;
            break;
        case TYPE:
            mType = (String) value;
            break;
        case PAYLOAD:
            LogUtils.logW("HessianDecoder.setValue() PAYLOAD mType[" + mType + "]");
            @SuppressWarnings("unchecked") Hashtable<String, Object> mPayload = (Hashtable<String, Object>) value;
            Set<Map.Entry<String, Object>> set = mPayload.entrySet();
            for (Map.Entry<String, Object> obj : set) {
                @SuppressWarnings("unchecked") User mUser = new User(obj.getKey(), (Hashtable<String, String>) obj.getValue());
                if (users == null) {
                    users = new ArrayList<User>();
                }
                users.add(mUser);
            }
            break;
        default:
            LogUtils.logE("HessianDecoder.setValue() key[" + key + "] value[" + value + "]");
    }
}
Also used : User(com.vodafone360.people.engine.presence.User) Hashtable(java.util.Hashtable) Map(java.util.Map)

Example 40 with Type

use of com.vodafone360.people.service.io.Request.Type 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)

Aggregations

ArrayList (java.util.ArrayList)14 Suppress (android.test.suitebuilder.annotation.Suppress)13 DatabaseHelper (com.vodafone360.people.database.DatabaseHelper)11 BaseDataType (com.vodafone360.people.datatypes.BaseDataType)11 IEngineEventCallback (com.vodafone360.people.engine.IEngineEventCallback)11 IContactSyncCallback (com.vodafone360.people.engine.contactsync.IContactSyncCallback)11 ProcessorFactory (com.vodafone360.people.engine.contactsync.ProcessorFactory)11 ServiceStatus (com.vodafone360.people.service.ServiceStatus)10 ServiceUiRequest (com.vodafone360.people.service.ServiceUiRequest)10 DecodedResponse (com.vodafone360.people.service.io.ResponseQueue.DecodedResponse)7 ActivityItem (com.vodafone360.people.datatypes.ActivityItem)6 Identity (com.vodafone360.people.datatypes.Identity)6 Request (com.vodafone360.people.service.io.Request)5 Cursor (android.database.Cursor)4 Contact (com.vodafone360.people.datatypes.Contact)4 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)4 ServerError (com.vodafone360.people.datatypes.ServerError)4 SQLException (android.database.SQLException)3 SQLiteException (android.database.sqlite.SQLiteException)3 Bundle (android.os.Bundle)3