Example usage for android.content ContentValues getAsString

List of usage examples for android.content ContentValues getAsString

Introduction

In this page you can find the example usage for android.content ContentValues getAsString.

Prototype

public String getAsString(String key) 

Source Link

Document

Gets a value and converts it to a String.

Usage

From source file:at.bitfire.davdroid.resource.LocalAddressBook.java

protected void populateIMPP(Contact c, ContentValues row) {
    String handle = row.getAsString(Im.DATA);

    Impp impp = null;/*w w  w .jav  a2s .c om*/
    switch (row.getAsInteger(Im.PROTOCOL)) {
    case Im.PROTOCOL_AIM:
        impp = Impp.aim(handle);
        break;
    case Im.PROTOCOL_MSN:
        impp = Impp.msn(handle);
        break;
    case Im.PROTOCOL_YAHOO:
        impp = Impp.yahoo(handle);
        break;
    case Im.PROTOCOL_SKYPE:
        impp = Impp.skype(handle);
        break;
    case Im.PROTOCOL_QQ:
        impp = new Impp("qq", handle);
        break;
    case Im.PROTOCOL_GOOGLE_TALK:
        impp = new Impp("google-talk", handle);
        break;
    case Im.PROTOCOL_ICQ:
        impp = Impp.icq(handle);
        break;
    case Im.PROTOCOL_JABBER:
        impp = Impp.xmpp(handle);
        break;
    case Im.PROTOCOL_NETMEETING:
        impp = new Impp("netmeeting", handle);
        break;
    case Im.PROTOCOL_CUSTOM:
        impp = new Impp(row.getAsString(Im.CUSTOM_PROTOCOL), handle);
    }

    if (impp != null) {
        if (row.containsKey(Im.TYPE))
            switch (row.getAsInteger(Im.TYPE)) {
            case Im.TYPE_HOME:
                impp.addType(ImppType.HOME);
                break;
            case Im.TYPE_WORK:
                impp.addType(ImppType.WORK);
                break;
            case Im.TYPE_CUSTOM:
                String customType = row.getAsString(Im.LABEL);
                if (StringUtils.isNotEmpty(customType))
                    impp.addType(ImppType.get(labelToXName(customType)));
            }

        c.getImpps().add(impp);
    }
}

From source file:org.kontalk.provider.UsersProvider.java

private int insertKeys(ContentValues[] values) {
    SQLiteDatabase db = dbHelper.getWritableDatabase();

    int rows = 0;
    SQLiteStatement stm = db.compileStatement("INSERT OR REPLACE INTO " + TABLE_KEYS + " (" + Keys.JID + ", "
            + Keys.FINGERPRINT + ") VALUES(?, ?)");

    for (ContentValues v : values) {
        try {//  w  w w. jav  a  2 s.c o m
            stm.bindString(1, v.getAsString(Keys.JID));
            stm.bindString(2, v.getAsString(Keys.FINGERPRINT));
            stm.executeInsert();
            rows++;
        } catch (SQLException e) {
            Log.w(SyncAdapter.TAG, "error inserting trusted key [" + v + "]", e);
        }
    }

    return rows;
}

From source file:com.granita.icloudcalsync.resource.LocalAddressBook.java

protected void populateEmailAddress(Contact c, ContentValues row) {
    ezvcard.property.Email email = new ezvcard.property.Email(row.getAsString(Email.ADDRESS));
    switch (row.getAsInteger(Email.TYPE)) {
    case Email.TYPE_HOME:
        email.addType(EmailType.HOME);// w  w w. j a va  2 s . co m
        break;
    case Email.TYPE_WORK:
        email.addType(EmailType.WORK);
        break;
    case Email.TYPE_MOBILE:
        email.addType(Contact.EMAIL_TYPE_MOBILE);
        break;
    case Email.TYPE_CUSTOM:
        String customType = row.getAsString(Email.LABEL);
        if (StringUtils.isNotEmpty(customType))
            email.addType(EmailType.get(labelToXName(customType)));
    }
    if (row.getAsInteger(Email.IS_PRIMARY) != 0)
        email.addType(EmailType.PREF);
    c.getEmails().add(email);
}

From source file:at.bitfire.davdroid.resource.LocalAddressBook.java

protected void populateEmailAddress(Contact c, ContentValues row) {
    ezvcard.property.Email email = new ezvcard.property.Email(row.getAsString(Email.ADDRESS));
    if (row.containsKey(Email.TYPE))
        switch (row.getAsInteger(Email.TYPE)) {
        case Email.TYPE_HOME:
            email.addType(EmailType.HOME);
            break;
        case Email.TYPE_WORK:
            email.addType(EmailType.WORK);
            break;
        case Email.TYPE_MOBILE:
            email.addType(Contact.EMAIL_TYPE_MOBILE);
            break;
        case Email.TYPE_CUSTOM:
            String customType = row.getAsString(Email.LABEL);
            if (StringUtils.isNotEmpty(customType))
                email.addType(EmailType.get(labelToXName(customType)));
        }/* w ww.  j  a v a2  s  .  c om*/
    if (row.getAsInteger(Email.IS_PRIMARY) != 0)
        email.addType(EmailType.PREF);
    c.getEmails().add(email);
}

From source file:com.granita.icloudcalsync.resource.LocalAddressBook.java

protected void populatePostalAddress(Contact c, ContentValues row) {
    Address address = new Address();
    address.setLabel(row.getAsString(StructuredPostal.FORMATTED_ADDRESS));
    switch (row.getAsInteger(StructuredPostal.TYPE)) {
    case StructuredPostal.TYPE_HOME:
        address.addType(AddressType.HOME);
        break;/*from  ww w.j  a v a2s  .  co  m*/
    case StructuredPostal.TYPE_WORK:
        address.addType(AddressType.WORK);
        break;
    case StructuredPostal.TYPE_CUSTOM:
        String customType = row.getAsString(StructuredPostal.LABEL);
        if (StringUtils.isNotEmpty(customType))
            address.addType(AddressType.get(labelToXName(customType)));
        break;
    }
    address.setStreetAddress(row.getAsString(StructuredPostal.STREET));
    address.setPoBox(row.getAsString(StructuredPostal.POBOX));
    address.setExtendedAddress(row.getAsString(StructuredPostal.NEIGHBORHOOD));
    address.setLocality(row.getAsString(StructuredPostal.CITY));
    address.setRegion(row.getAsString(StructuredPostal.REGION));
    address.setPostalCode(row.getAsString(StructuredPostal.POSTCODE));
    address.setCountry(row.getAsString(StructuredPostal.COUNTRY));
    c.getAddresses().add(address);
}

From source file:at.bitfire.davdroid.resource.LocalAddressBook.java

protected void populatePostalAddress(Contact c, ContentValues row) {
    Address address = new Address();
    address.setLabel(row.getAsString(StructuredPostal.FORMATTED_ADDRESS));
    if (row.containsKey(StructuredPostal.TYPE))
        switch (row.getAsInteger(StructuredPostal.TYPE)) {
        case StructuredPostal.TYPE_HOME:
            address.addType(AddressType.HOME);
            break;
        case StructuredPostal.TYPE_WORK:
            address.addType(AddressType.WORK);
            break;
        case StructuredPostal.TYPE_CUSTOM:
            String customType = row.getAsString(StructuredPostal.LABEL);
            if (StringUtils.isNotEmpty(customType))
                address.addType(AddressType.get(labelToXName(customType)));
            break;
        }/* w  w  w  .j a  va  2s  . c o  m*/
    address.setStreetAddress(row.getAsString(StructuredPostal.STREET));
    address.setPoBox(row.getAsString(StructuredPostal.POBOX));
    address.setExtendedAddress(row.getAsString(StructuredPostal.NEIGHBORHOOD));
    address.setLocality(row.getAsString(StructuredPostal.CITY));
    address.setRegion(row.getAsString(StructuredPostal.REGION));
    address.setPostalCode(row.getAsString(StructuredPostal.POSTCODE));
    address.setCountry(row.getAsString(StructuredPostal.COUNTRY));
    c.getAddresses().add(address);
}

From source file:at.bitfire.davdroid.resource.LocalAddressBook.java

protected void populateRelation(Contact c, ContentValues row) {
    String name = row.getAsString(Relation.NAME);

    // don't process empty relations
    if (StringUtils.isEmpty(name))
        return;//from  w w w  .jav  a2s . c o  m

    // find relation by name or create new one
    Related related = null;
    for (Related rel : c.getRelations()) {
        if (name.equals(rel.getText())) {
            related = rel;
            break;
        }
    }
    if (related == null) {
        related = new Related();
        c.getRelations().add(related);
    }

    Set<RelatedType> types = related.getTypes();
    switch (row.getAsInteger(Relation.TYPE)) {
    case Relation.TYPE_ASSISTANT:
        types.add(RelatedType.AGENT);
        break;
    case Relation.TYPE_BROTHER:
        types.add(RelatedType.SIBLING);
        types.add(Contact.RELATED_TYPE_BROTHER);
        break;
    case Relation.TYPE_CHILD:
        types.add(RelatedType.CHILD);
        break;
    case Relation.TYPE_DOMESTIC_PARTNER:
        types.add(RelatedType.CO_RESIDENT);
        break;
    case Relation.TYPE_FATHER:
        types.add(Contact.RELATED_TYPE_FATHER);
        break;
    case Relation.TYPE_FRIEND:
        types.add(RelatedType.FRIEND);
        break;
    case Relation.TYPE_MANAGER:
        types.add(Contact.RELATED_TYPE_MANAGER);
        break;
    case Relation.TYPE_MOTHER:
        types.add(Contact.RELATED_TYPE_MOTHER);
        break;
    case Relation.TYPE_PARENT:
        types.add(RelatedType.PARENT);
        break;
    case Relation.TYPE_PARTNER:
        types.add(RelatedType.SWEETHEART);
        break;
    case Relation.TYPE_REFERRED_BY:
        types.add(Contact.RELATED_TYPE_REFERRED_BY);
    case Relation.TYPE_RELATIVE:
        types.add(RelatedType.KIN);
        break;
    case Relation.TYPE_SISTER:
        types.add(RelatedType.SIBLING);
        types.add(Contact.RELATED_TYPE_SISTER);
        break;
    case Relation.TYPE_SPOUSE:
        types.add(RelatedType.SPOUSE);
    case Relation.TYPE_CUSTOM:
        String customType = row.getAsString(Relation.LABEL);
        if (StringUtils.isNotEmpty(customType))
            types.add(RelatedType.get(customType));
    }
}

From source file:com.granita.icloudcalsync.resource.LocalAddressBook.java

protected void populateSipAddress(Contact c, ContentValues row) throws RemoteException {
    try {/*  w  w w  . j a  v  a  2 s.  c om*/
        Impp impp = new Impp("sip:" + row.getAsString(SipAddress.SIP_ADDRESS));
        switch (row.getAsInteger(SipAddress.TYPE)) {
        case SipAddress.TYPE_HOME:
            impp.addType(ImppType.HOME);
            break;
        case SipAddress.TYPE_WORK:
            impp.addType(ImppType.WORK);
            break;
        case SipAddress.TYPE_CUSTOM:
            String customType = row.getAsString(SipAddress.LABEL);
            if (StringUtils.isNotEmpty(customType))
                impp.addType(ImppType.get(labelToXName(customType)));
        }
        c.getImpps().add(impp);
    } catch (IllegalArgumentException e) {
        Log.e(TAG, "Illegal SIP URI", e);
    }
}

From source file:com.granita.icloudcalsync.resource.LocalAddressBook.java

protected void populateRelation(Contact c, ContentValues row) throws RemoteException {
    String name = row.getAsString(Relation.NAME);

    // find relation by name or create new one
    Related related = null;/*from   w  w w  . jav a 2 s. c  o m*/
    for (Related rel : c.getRelations()) {
        if (rel.getText().equals(name)) {
            related = rel;
            break;
        }
    }
    if (related == null) {
        related = new Related();
        c.getRelations().add(related);
    }

    Set<RelatedType> types = related.getTypes();
    switch (row.getAsInteger(Relation.TYPE)) {
    case Relation.TYPE_ASSISTANT:
        types.add(RelatedType.AGENT);
        break;
    case Relation.TYPE_BROTHER:
        types.add(RelatedType.SIBLING);
        types.add(Contact.RELATED_TYPE_BROTHER);
        break;
    case Relation.TYPE_CHILD:
        types.add(RelatedType.CHILD);
        break;
    case Relation.TYPE_DOMESTIC_PARTNER:
        types.add(RelatedType.CO_RESIDENT);
        break;
    case Relation.TYPE_FATHER:
        types.add(Contact.RELATED_TYPE_FATHER);
        break;
    case Relation.TYPE_FRIEND:
        types.add(RelatedType.FRIEND);
        break;
    case Relation.TYPE_MANAGER:
        types.add(Contact.RELATED_TYPE_MANAGER);
        break;
    case Relation.TYPE_MOTHER:
        types.add(Contact.RELATED_TYPE_MOTHER);
        break;
    case Relation.TYPE_PARENT:
        types.add(RelatedType.PARENT);
        break;
    case Relation.TYPE_PARTNER:
        types.add(RelatedType.SWEETHEART);
        break;
    case Relation.TYPE_REFERRED_BY:
        types.add(Contact.RELATED_TYPE_REFERRED_BY);
    case Relation.TYPE_RELATIVE:
        types.add(RelatedType.KIN);
        break;
    case Relation.TYPE_SISTER:
        types.add(RelatedType.SIBLING);
        types.add(Contact.RELATED_TYPE_SISTER);
        break;
    case Relation.TYPE_SPOUSE:
        types.add(RelatedType.SPOUSE);
    case Relation.TYPE_CUSTOM:
        String customType = row.getAsString(Relation.LABEL);
        if (StringUtils.isNotEmpty(customType))
            types.add(RelatedType.get(customType));
    }
}

From source file:at.bitfire.davdroid.resource.LocalAddressBook.java

@Override
public void populate(Resource res) throws LocalStorageException {
    Contact c = (Contact) res;/*from   w  w w .j  av  a2s. co m*/

    try {
        @Cleanup
        EntityIterator iter = ContactsContract.RawContacts.newEntityIterator(
                providerClient.query(syncAdapterURI(ContactsContract.RawContactsEntity.CONTENT_URI), null,
                        RawContacts._ID + "=" + c.getLocalID(), null, null));

        if (iter.hasNext()) {
            Entity e = iter.next();

            ContentValues values = e.getEntityValues();
            c.setUid(values.getAsString(entryColumnUID()));
            c.unknownProperties = values.getAsString(COLUMN_UNKNOWN_PROPERTIES);
            c.starred = values.getAsInteger(RawContacts.STARRED) != 0;

            List<Entity.NamedContentValues> subValues = e.getSubValues();
            for (Entity.NamedContentValues subValue : subValues) {
                values = subValue.values;
                String mimeType = values.getAsString(ContactsContract.RawContactsEntity.MIMETYPE);
                switch (mimeType) {
                case StructuredName.CONTENT_ITEM_TYPE:
                    populateStructuredName(c, values);
                    break;
                case Phone.CONTENT_ITEM_TYPE:
                    populatePhoneNumber(c, values);
                    break;
                case Email.CONTENT_ITEM_TYPE:
                    populateEmailAddress(c, values);
                    break;
                case Photo.CONTENT_ITEM_TYPE:
                    populatePhoto(c, values);
                    break;
                case Organization.CONTENT_ITEM_TYPE:
                    populateOrganization(c, values);
                    break;
                case Im.CONTENT_ITEM_TYPE:
                    populateIMPP(c, values);
                    break;
                case Nickname.CONTENT_ITEM_TYPE:
                    populateNickname(c, values);
                    break;
                case Note.CONTENT_ITEM_TYPE:
                    populateNote(c, values);
                    break;
                case StructuredPostal.CONTENT_ITEM_TYPE:
                    populatePostalAddress(c, values);
                    break;
                case GroupMembership.CONTENT_ITEM_TYPE:
                    populateGroupMembership(c, values);
                    break;
                case Website.CONTENT_ITEM_TYPE:
                    populateURL(c, values);
                    break;
                case CommonDataKinds.Event.CONTENT_ITEM_TYPE:
                    populateEvent(c, values);
                    break;
                case Relation.CONTENT_ITEM_TYPE:
                    populateRelation(c, values);
                    break;
                case SipAddress.CONTENT_ITEM_TYPE:
                    populateSipAddress(c, values);
                    break;
                }
            }
        } else
            throw new RecordNotFoundException();
    } catch (RemoteException ex) {
        throw new LocalStorageException(ex);
    }
}