private void unregisterObserver() { if (mObserver != null) { getContext().getContentResolver().unregisterContentObserver(mObserver); mObserver = null; } }
private void loadDirectoryMetaData(Contact result) { long directoryId = result.getDirectoryId(); Cursor cursor = getContext().getContentResolver().query( ContentUris.withAppendedId(Directory.CONTENT_URI, directoryId), DirectoryQuery.COLUMNS, null, null, null); String directoryType = null; if (!TextUtils.isEmpty(packageName)) { PackageManager pm = getContext().getPackageManager(); try { Resources resources = pm.getResourcesForApplication(packageName);
/** * 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); } } } }
/** * 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); } } } }
final Cursor cursor = getContext().getContentResolver().query(Groups.CONTENT_URI, GroupQuery.COLUMNS, selection.toString(), selectionArgs.toArray(new String[0]), null);
fd = null; } else { fd = getContext().getContentResolver().openAssetFileDescriptor(uri, "r"); inputStream = fd.createInputStream();
/** * 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()); }
@Override public void deliverResult(Contact result) { unregisterObserver(); // The creator isn't interested in any further updates if (isReset() || result == null) { return; } mContact = result; if (result.isLoaded()) { mLookupUri = result.getLookupUri(); if (!result.isDirectoryEntry()) { Log.i(TAG, "Registering content observer for " + mLookupUri); if (mObserver == null) { mObserver = new ForceLoadContentObserver(); } getContext().getContentResolver().registerContentObserver( mLookupUri, true, mObserver); } if (mPostViewNotification) { // inform the source of the data that this contact is being looked at postViewNotificationToSyncAdapter(); } } super.deliverResult(mContact); }
Log.e(TAG, "loadInBackground=" + mLookupUri); try { final ContentResolver resolver = getContext().getContentResolver(); final Uri uriCurrentFormat = ContactLoaderUtils.ensureIsContactUri( resolver, mLookupUri);