public static RawContact createFrom(Entity entity) { final ContentValues values = entity.getEntityValues(); final ArrayList<Entity.NamedContentValues> subValues = entity.getSubValues(); RawContact rawContact = new RawContact(values); for (Entity.NamedContentValues subValue : subValues) { rawContact.addNamedDataItemValues(subValue.uri, subValue.values); } return rawContact; }
private static void processOneRecord(RawContact rawContact, JSONObject item, String mimetype) throws JSONException { final ContentValues itemValues = new ContentValues(); itemValues.put(Data.MIMETYPE, mimetype); itemValues.put(Data._ID, -1); final Iterator iterator = item.keys(); while (iterator.hasNext()) { String name = (String) iterator.next(); final Object o = item.get(name); if (o instanceof String) { itemValues.put(name, (String) o); } else if (o instanceof Integer) { itemValues.put(name, (Integer) o); } } rawContact.addDataItemValues(itemValues); }
public void addAll(Iterator<?> iterator) { // Perform background query to pull contact details while (iterator.hasNext()) { // Read all contacts into local deltas to prepare for edits Object nextObject = iterator.next(); final RawContact before = nextObject instanceof Entity ? RawContact.createFrom((Entity) nextObject) : (RawContact) nextObject; final RawContactDelta rawContactDelta = RawContactDelta.fromBefore(before); add(rawContactDelta); } }
public AccountType getAccountType(Context context) { return getAccountTypeManager(context).getAccountType(getAccountTypeString(), getDataSet()); }
final HashSet<AccountKey> accountsSeen = new HashSet<>(); for (RawContact rawContact : result.getRawContacts()) { final String accountName = rawContact.getAccountName(); final String accountType = rawContact.getAccountTypeString(); final String dataSet = rawContact.getDataSet(); final AccountKey accountKey = new AccountKey(accountName, accountType, dataSet); if (accountName != null && accountType != null &&
/** * Return the ID of the first raw-contact in the contact data that belongs to a * contact-writable account, or -1 if no such entity exists. */ public long getFirstWritableRawContactId(final Context context) { // Directory entries are non-writable if (isDirectoryEntry()) return -1; // Iterate through raw-contacts; if we find a writable on, return its ID. for (RawContact rawContact : getRawContacts()) { AccountType accountType = rawContact.getAccountType(context); if (accountType != null && accountType.areContactsWritable()) { return rawContact.getId(); } } // No writable raw-contact was found. return -1; }
/** * Build an {@link RawContactDelta} using the given {@link RawContact} as a * starting point; the "before" snapshot. */ public static RawContactDelta fromBefore(RawContact before) { final RawContactDelta rawContactDelta = new RawContactDelta(); rawContactDelta.mValues = ValuesDelta.fromBefore(before.getValues()); rawContactDelta.mValues.setIdColumn(RawContacts._ID); for (final ContentValues values : before.getContentValues()) { rawContactDelta.addEntry(ValuesDelta.fromBefore(values)); } return rawContactDelta; }
/** * Sets the "invitable" account types to {@link Contact#mInvitableAccountTypes}. */ private void loadInvitableAccountTypes(Contact contactData) { final ImmutableList.Builder<AccountType> resultListBuilder = new ImmutableList.Builder<AccountType>(); if (!contactData.isUserProfile()) { Map<AccountTypeWithDataSet, AccountType> invitables = AccountTypeManager.getInstance(getContext()).getUsableInvitableAccountTypes(); if (!invitables.isEmpty()) { final Map<AccountTypeWithDataSet, AccountType> resultMap = Maps.newHashMap(invitables); // Remove the ones that already have a raw contact in the current contact for (RawContact rawContact : contactData.getRawContacts()) { final AccountTypeWithDataSet type = AccountTypeWithDataSet.get( rawContact.getAccountTypeString(), rawContact.getDataSet()); resultMap.remove(type); } resultListBuilder.addAll(resultMap.values()); } } // Set to mInvitableAccountTypes contactData.setInvitableAccountTypes(resultListBuilder.build()); }
rawContact = new RawContact(loadRawContactValues(cursor)); rawContactsBuilder.add(rawContact); rawContact.addDataItemValues(data);
/** * Iterates over all data items that represent phone numbers are tries to calculate a formatted * number. This function can safely be called several times as no unformatted data is * overwritten */ private void computeFormattedPhoneNumbers(Contact contactData) { final String countryIso = GeoUtil.getCurrentCountryIso(getContext()); final ImmutableList<RawContact> rawContacts = contactData.getRawContacts(); final int rawContactCount = rawContacts.size(); for (int rawContactIndex = 0; rawContactIndex < rawContactCount; rawContactIndex++) { final RawContact rawContact = rawContacts.get(rawContactIndex); final List<DataItem> dataItems = rawContact.getDataItems(); final int dataCount = dataItems.size(); for (int dataIndex = 0; dataIndex < dataCount; dataIndex++) { final DataItem dataItem = dataItems.get(dataIndex); if (dataItem instanceof PhoneDataItem) { final PhoneDataItem phoneDataItem = (PhoneDataItem) dataItem; phoneDataItem.computeFormattedPhoneNumber(countryIso); } } } }
/** * Creates and inserts a DataItem object that wraps the content values, and returns it. */ public void addDataItemValues(ContentValues values) { addNamedDataItemValues(Data.CONTENT_URI, values); }
public ArrayList<ContentValues> getContentValues() { if (mRawContacts.size() != 1) { throw new IllegalStateException( "Cannot extract content values from an aggregated contact"); } RawContact rawContact = mRawContacts.get(0); ArrayList<ContentValues> result = rawContact.getContentValues(); // If the photo was loaded using the URI, create an entry for the photo // binary data. if (mPhotoId == 0 && mPhotoBinaryData != null) { ContentValues photo = new ContentValues(); photo.put(Data.MIMETYPE, Photo.CONTENT_ITEM_TYPE); photo.put(Photo.PHOTO, mPhotoBinaryData); result.add(photo); } return result; }
values.put(Data._ID, -1); values.put(Data.CONTACT_ID, -1); final RawContact rawContact = new RawContact(values);
/** * Posts a message to the contributing sync adapters that have opted-in, notifying them * that the contact has just been loaded */ private void postViewNotificationToSyncAdapter() { Context context = getContext(); for (RawContact rawContact : mContact.getRawContacts()) { final long rawContactId = rawContact.getId(); if (mNotifiedRawContactIds.contains(rawContactId)) { continue; // Already notified for this raw contact. } mNotifiedRawContactIds.add(rawContactId); final AccountType accountType = rawContact.getAccountType(context); final String serviceName = accountType.getViewContactNotifyServiceClassName(); final String servicePackageName = accountType.getViewContactNotifyServicePackageName(); if (!TextUtils.isEmpty(serviceName) && !TextUtils.isEmpty(servicePackageName)) { final Uri uri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId); final Intent intent = new Intent(); intent.setClassName(servicePackageName, serviceName); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(uri, RawContacts.CONTENT_ITEM_TYPE); try { context.startService(intent); } catch (Exception e) { Log.e(TAG, "Error sending message to source-app", e); } } } }
private void loadThumbnailBinaryData(Contact contactData) { final long photoId = contactData.getPhotoId(); if (photoId <= 0) { // No photo ID return; } for (RawContact rawContact : contactData.getRawContacts()) { for (DataItem dataItem : rawContact.getDataItems()) { if (dataItem.getId() == photoId) { if (!(dataItem instanceof PhotoDataItem)) { break; } final PhotoDataItem photo = (PhotoDataItem) dataItem; contactData.setThumbnailPhotoBinaryData(photo.getPhoto()); break; } } } }