List of usage examples for android.content ContentValues getAsString
public String getAsString(String key)
From source file:at.bitfire.davdroid.resource.LocalAddressBook.java
protected void populateGroupMembership(Contact c, ContentValues row) throws RemoteException { List<String> categories = c.getCategories(); long rowID = row.getAsLong(GroupMembership.GROUP_ROW_ID); String sourceID = row.getAsString(GroupMembership.GROUP_SOURCE_ID); // either a row ID or a source ID must be available String where, whereArg;//w ww. ja va 2s.com if (sourceID == null) { where = Groups._ID + "=?"; whereArg = String.valueOf(rowID); } else { where = Groups.SOURCE_ID + "=?"; whereArg = sourceID; } where += " AND " + Groups.DELETED + "=0"; // ignore deleted groups Log.d(TAG, "Populating group from " + where + " " + whereArg); // fetch group @Cleanup Cursor cursorGroups = providerClient.query(Groups.CONTENT_URI, new String[] { Groups.TITLE }, where, new String[] { whereArg }, null); if (cursorGroups != null && cursorGroups.moveToNext()) { String title = cursorGroups.getString(0); if (sourceID == null) { // Group wasn't created by DAVdroid // SOURCE_ID IS NULL <=> _ID IS NOT NULL Log.d(TAG, "Setting SOURCE_ID of non-DAVdroid group to title: " + title); ContentValues v = new ContentValues(1); v.put(Groups.SOURCE_ID, title); v.put(Groups.GROUP_IS_READ_ONLY, 0); v.put(Groups.GROUP_VISIBLE, 1); providerClient.update(syncAdapterURI(Groups.CONTENT_URI), v, Groups._ID + "=?", new String[] { String.valueOf(rowID) }); sourceID = title; } // add group to CATEGORIES if (sourceID != null) categories.add(sourceID); } else Log.d(TAG, "Group not found (maybe deleted)"); }
From source file:at.bitfire.vcard4android.AndroidContact.java
protected void populateEmail(ContentValues row) { ezvcard.property.Email email = new ezvcard.property.Email(row.getAsString(Email.ADDRESS)); Integer type = row.getAsInteger(Email.TYPE); if (type != null) switch (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 (!TextUtils.isEmpty(customType)) email.addType(EmailType.get(labelToXName(customType))); }/*from w w w .j a v a 2s. com*/ if (row.getAsInteger(Email.IS_PRIMARY) != 0) email.setPref(1); contact.getEmails().add(email); }
From source file:at.bitfire.vcard4android.AndroidContact.java
protected void populateIMPP(ContentValues row) { String handle = row.getAsString(Im.DATA); if (TextUtils.isEmpty(handle)) { Constants.log.warn("Ignoring instant messenger record without handle"); return;/*from w ww . j av a2s .c om*/ } Impp impp = null; if (row.containsKey(Im.PROTOCOL)) 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: try { impp = new Impp(toURIScheme(row.getAsString(Im.CUSTOM_PROTOCOL)), handle); } catch (IllegalArgumentException e) { Constants.log.error("Messenger type/value can't be expressed as URI; ignoring"); } } if (impp != null) { Integer type = row.getAsInteger(Im.TYPE); if (type != null) switch (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 (!TextUtils.isEmpty(customType)) impp.addType(ImppType.get(labelToXName(customType))); } contact.getImpps().add(impp); } }
From source file:at.bitfire.vcard4android.AndroidContact.java
protected void populateStructuredPostal(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 (!TextUtils.isEmpty(customType)) address.addType(AddressType.get(labelToXName(customType))); break; }/*w w w .jav a 2 s .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)); contact.getAddresses().add(address); }
From source file:org.runnerup.export.SyncManager.java
public Set<String> feedSynchronizersSet(Context ctx) { Set<String> set = new HashSet<String>(); String[] from = new String[] { "_id", DB.ACCOUNT.NAME, DB.ACCOUNT.ENABLED, DB.ACCOUNT.AUTH_CONFIG, DB.ACCOUNT.FLAGS };/* w w w .j a va2 s . c o m*/ SQLiteDatabase db = DBHelper.getReadableDatabase(ctx); Cursor c = db.query(DB.ACCOUNT.TABLE, from, null, null, null, null, null); if (c.moveToFirst()) { do { final ContentValues tmp = DBHelper.get(c); final Synchronizer synchronizer = add(tmp); final String name = tmp.getAsString(DB.ACCOUNT.NAME); final long flags = tmp.getAsLong(DB.ACCOUNT.FLAGS); if (isConfigured(name) && Bitfield.test(flags, DB.ACCOUNT.FLAG_FEED) && synchronizer.checkSupport(Synchronizer.Feature.FEED)) { set.add(name); } } while (c.moveToNext()); } c.close(); DBHelper.closeDB(db); return set; }
From source file:at.bitfire.vcard4android.AndroidContact.java
protected void populatePhoneNumber(ContentValues row) { Telephone number = new Telephone(row.getAsString(Phone.NUMBER)); Integer type = row.getAsInteger(Phone.TYPE); if (type != null) switch (type) { case Phone.TYPE_HOME: number.addType(TelephoneType.HOME); break; case Phone.TYPE_MOBILE: number.addType(TelephoneType.CELL); break; case Phone.TYPE_WORK: number.addType(TelephoneType.WORK); break; case Phone.TYPE_FAX_WORK: number.addType(TelephoneType.FAX); number.addType(TelephoneType.WORK); break; case Phone.TYPE_FAX_HOME: number.addType(TelephoneType.FAX); number.addType(TelephoneType.HOME); break; case Phone.TYPE_PAGER: number.addType(TelephoneType.PAGER); break; case Phone.TYPE_CALLBACK: number.addType(Contact.PHONE_TYPE_CALLBACK); break; case Phone.TYPE_CAR: number.addType(TelephoneType.CAR); break; case Phone.TYPE_COMPANY_MAIN: number.addType(Contact.PHONE_TYPE_COMPANY_MAIN); break; case Phone.TYPE_ISDN: number.addType(TelephoneType.ISDN); break; case Phone.TYPE_MAIN: number.addType(TelephoneType.VOICE); break; case Phone.TYPE_OTHER_FAX: number.addType(TelephoneType.FAX); break; case Phone.TYPE_RADIO: number.addType(Contact.PHONE_TYPE_RADIO); break; case Phone.TYPE_TELEX: number.addType(TelephoneType.TEXTPHONE); break; case Phone.TYPE_TTY_TDD: number.addType(TelephoneType.TEXT); break; case Phone.TYPE_WORK_MOBILE: number.addType(TelephoneType.CELL); number.addType(TelephoneType.WORK); break; case Phone.TYPE_WORK_PAGER: number.addType(TelephoneType.PAGER); number.addType(TelephoneType.WORK); break; case Phone.TYPE_ASSISTANT: number.addType(Contact.PHONE_TYPE_ASSISTANT); break; case Phone.TYPE_MMS: number.addType(Contact.PHONE_TYPE_MMS); break; case Phone.TYPE_CUSTOM: String customType = row.getAsString(CommonDataKinds.Phone.LABEL); if (!TextUtils.isEmpty(customType)) number.addType(TelephoneType.get(labelToXName(customType))); }//from w w w.j av a2s . c o m if (row.getAsInteger(CommonDataKinds.Phone.IS_PRIMARY) != 0) number.setPref(1); contact.getPhoneNumbers().add(number); }
From source file:at.bitfire.vcard4android.AndroidContact.java
public Contact getContact() throws FileNotFoundException, ContactsStorageException { if (contact != null) return contact; try {//w w w . j a va 2 s . c o m @Cleanup EntityIterator iter = RawContacts.newEntityIterator(addressBook.provider.query( addressBook.syncAdapterURI(ContactsContract.RawContactsEntity.CONTENT_URI), null, ContactsContract.RawContacts._ID + "=?", new String[] { String.valueOf(id) }, null)); if (iter.hasNext()) { Entity e = iter.next(); contact = new Contact(); populateContact(e.getEntityValues()); List<Entity.NamedContentValues> subValues = e.getSubValues(); for (Entity.NamedContentValues subValue : subValues) { ContentValues values = subValue.values; String mimeType = values.getAsString(ContactsContract.RawContactsEntity.MIMETYPE); if (mimeType == null) { Constants.log.error("Ignoring raw contact data row without " + ContactsContract.RawContactsEntity.MIMETYPE); continue; } switch (mimeType) { case StructuredName.CONTENT_ITEM_TYPE: populateStructuredName(values); break; case Phone.CONTENT_ITEM_TYPE: populatePhoneNumber(values); break; case Email.CONTENT_ITEM_TYPE: populateEmail(values); break; case Photo.CONTENT_ITEM_TYPE: populatePhoto(values); break; case Organization.CONTENT_ITEM_TYPE: populateOrganization(values); break; case Im.CONTENT_ITEM_TYPE: populateIMPP(values); break; case Nickname.CONTENT_ITEM_TYPE: populateNickname(values); break; case Note.CONTENT_ITEM_TYPE: populateNote(values); break; case StructuredPostal.CONTENT_ITEM_TYPE: populateStructuredPostal(values); break; case GroupMembership.CONTENT_ITEM_TYPE: populateGroupMembership(values); break; case Website.CONTENT_ITEM_TYPE: populateWebsite(values); break; case Event.CONTENT_ITEM_TYPE: populateEvent(values); break; case Relation.CONTENT_ITEM_TYPE: populateRelation(values); break; case SipAddress.CONTENT_ITEM_TYPE: populateSipAddress(values); break; } } return contact; } else throw new FileNotFoundException(); } catch (RemoteException e) { throw new ContactsStorageException("Couldn't read local contact", e); } }
From source file:watch.oms.omswatch.actioncenter.helpers.WatchTransDBParser.java
private boolean validateRowData(ContentValues pContentValues) { String usidValue = pContentValues.getAsString(OMSDatabaseConstants.UNIQUE_ROW_ID); if (usidValue != null && usidValue.equals(OMSConstants.NULL_STRING)) { return false; }//from w ww . j av a2 s .c om /* * String isDeleteValue = pContentValues * .getAsString(DatabaseConstants.IS_DELETE); if (isDeleteValue != null * && isDeleteValue.equals(Constants.IS_DELETE_ONE)) { return false; } */ return true; }
From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java
private Uri insertSource(@NonNull final Uri uri, final ContentValues initialValues) { Context context = getContext(); if (context == null) { return null; }//w w w .j a va 2s .c o m if (!initialValues.containsKey(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME) || TextUtils.isEmpty(initialValues.getAsString(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME))) { throw new IllegalArgumentException("Initial values must contain component name " + initialValues); } ComponentName componentName = ComponentName .unflattenFromString(initialValues.getAsString(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME)); if (componentName == null) { throw new IllegalArgumentException("Invalid component name: " + initialValues.getAsString(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME)); } ApplicationInfo info; try { // Ensure the service is valid and extract the application info info = context.getPackageManager().getServiceInfo(componentName, 0).applicationInfo; } catch (PackageManager.NameNotFoundException e) { throw new IllegalArgumentException("Invalid component name " + initialValues.getAsString(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME), e); } // Make sure they are using the short string format initialValues.put(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME, componentName.flattenToShortString()); // Only Muzei can set the IS_SELECTED field if (initialValues.containsKey(MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED)) { if (!context.getPackageName().equals(getCallingPackage())) { Log.w(TAG, "Only Muzei can set the " + MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED + " column. Ignoring the value in " + initialValues); initialValues.remove(MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED); } } // Disable network access callbacks if we're running on an API 24 device and the source app // targets API 24. This is to be consistent with the Behavior Changes in Android N if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && initialValues.containsKey(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE) && initialValues.getAsBoolean(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE)) { if (info.targetSdkVersion >= Build.VERSION_CODES.N) { Log.w(TAG, "Sources targeting API 24 cannot receive network access callbacks. Changing " + componentName + " to false for " + MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE); initialValues.put(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE, false); } } final SQLiteDatabase db = databaseHelper.getWritableDatabase(); final long rowId = db.insert(MuzeiContract.Sources.TABLE_NAME, MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME, initialValues); // If the insert succeeded, the row ID exists. if (rowId > 0) { // Creates a URI with the source ID pattern and the new row ID appended to it. final Uri sourceUri = ContentUris.withAppendedId(MuzeiContract.Sources.CONTENT_URI, rowId); notifyChange(sourceUri); return sourceUri; } // If the insert didn't succeed, then the rowID is <= 0 throw new SQLException("Failed to insert row into " + uri); }
From source file:at.bitfire.vcard4android.AndroidContact.java
protected void populateEvent(ContentValues row) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.US); try {//w ww . j av a2 s .c om Date date = formatter.parse(row.getAsString(CommonDataKinds.Event.START_DATE)); if (row.containsKey(Event.TYPE)) switch (row.getAsInteger(Event.TYPE)) { case Event.TYPE_ANNIVERSARY: contact.anniversary = new Anniversary(date); break; case Event.TYPE_BIRTHDAY: contact.birthDay = new Birthday(date); break; } } catch (ParseException e) { Constants.log.warn("Couldn't parse birthday/anniversary date from database", e); } }