Search in sources :

Example 1 with ContactLoader

use of com.android.contacts.common.model.ContactLoader in project android_packages_apps_Dialer by LineageOS.

the class PhoneFavoriteTileView method sendViewNotification.

/**
 * Send a notification using a {@link ContactLoader} to inform the sync adapter that we are
 * viewing a particular contact, so that it can download the high-res photo.
 */
private void sendViewNotification(Context context, Uri contactUri) {
    if (loader != null) {
        // Cancels the current load if it's running and clears up any memory if it's using any.
        loader.reset();
    }
    loader = new ContactLoader(context, contactUri, true);
    // Immediately release anything we're holding in memory
    loader.registerListener(0, (loader1, contact) -> loader.reset());
    loader.startLoading();
}
Also used : ContactLoader(com.android.contacts.common.model.ContactLoader)

Example 2 with ContactLoader

use of com.android.contacts.common.model.ContactLoader in project android_packages_apps_Dialer by LineageOS.

the class CallerInfoUtils method sendViewNotification.

/**
 * Send a notification using a {@link ContactLoader} to inform the sync adapter that we are
 * viewing a particular contact, so that it can download the high-res photo.
 */
public static void sendViewNotification(Context context, Uri contactUri) {
    final ContactLoader loader = new ContactLoader(context, contactUri, true);
    loader.registerListener(0, new OnLoadCompleteListener<Contact>() {

        @Override
        public void onLoadComplete(Loader<Contact> loader, Contact contact) {
            try {
                loader.reset();
            } catch (RuntimeException e) {
                LogUtil.e("CallerInfoUtils.onLoadComplete", "Error resetting loader", e);
            }
        }
    });
    loader.startLoading();
}
Also used : ContactLoader(com.android.contacts.common.model.ContactLoader) Contact(com.android.contacts.common.model.Contact)

Example 3 with ContactLoader

use of com.android.contacts.common.model.ContactLoader in project packages_apps_Contacts by AOKP.

the class ViewNotificationService method onStartCommand.

@Override
public int onStartCommand(Intent intent, int flags, final int startId) {
    if (DEBUG) {
        Log.d(TAG, "onHandleIntent(). Intent: " + intent);
    }
    // We simply need to start a Loader here. When its done, it will send out the
    // View-Notification automatically.
    final ContactLoader contactLoader = new ContactLoader(this, intent.getData(), true);
    contactLoader.registerListener(0, new OnLoadCompleteListener<Contact>() {

        @Override
        public void onLoadComplete(Loader<Contact> loader, Contact data) {
            try {
                loader.reset();
            } catch (RuntimeException e) {
                Log.e(TAG, "Error reseting loader", e);
            }
            try {
                // This is not 100% accurate actually. If we get several calls quickly,
                // we might be stopping out-of-order, in which case the call with the last
                // startId will stop this service. In practice, this shouldn't be a problem,
                // as this service is supposed to be called by the Phone app which only sends
                // out the notification once per phonecall. And even if there is a problem,
                // the worst that should happen is a missing view notification
                stopSelfResult(startId);
            } catch (RuntimeException e) {
                Log.e(TAG, "Error stopping service", e);
            }
        }
    });
    contactLoader.startLoading();
    return START_REDELIVER_INTENT;
}
Also used : ContactLoader(com.android.contacts.common.model.ContactLoader) Contact(com.android.contacts.common.model.Contact)

Example 4 with ContactLoader

use of com.android.contacts.common.model.ContactLoader in project packages_apps_Contacts by AOKP.

the class AttachPhotoActivity method loadContact.

// TODO: consider moving this to ContactLoader, especially if we keep adding similar
// code elsewhere (ViewNotificationService is another case).  The only concern is that,
// although this is convenient, it isn't quite as robust as using LoaderManager... for
// instance, the loader doesn't persist across Activity restarts.
private void loadContact(Uri contactUri, final Listener listener) {
    final ContactLoader loader = new ContactLoader(this, contactUri, true);
    loader.registerListener(0, new OnLoadCompleteListener<Contact>() {

        @Override
        public void onLoadComplete(Loader<Contact> loader, Contact contact) {
            try {
                loader.reset();
            } catch (RuntimeException e) {
                Log.e(TAG, "Error resetting loader", e);
            }
            listener.onContactLoaded(contact);
        }
    });
    loader.startLoading();
}
Also used : ContactLoader(com.android.contacts.common.model.ContactLoader) Contact(com.android.contacts.common.model.Contact)

Example 5 with ContactLoader

use of com.android.contacts.common.model.ContactLoader in project packages_apps_Contacts by AOKP.

the class QuickContactActivity method processIntent.

private void processIntent(Intent intent) {
    if (intent == null) {
        finish();
        return;
    }
    Uri lookupUri = intent.getData();
    // Check to see whether it comes from the old version.
    if (lookupUri != null && LEGACY_AUTHORITY.equals(lookupUri.getAuthority())) {
        final long rawContactId = ContentUris.parseId(lookupUri);
        lookupUri = RawContacts.getContactLookupUri(getContentResolver(), ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId));
    }
    mExtraMode = getIntent().getIntExtra(QuickContact.EXTRA_MODE, QuickContact.MODE_LARGE);
    if (isMultiWindowOnPhone()) {
        mExtraMode = QuickContact.MODE_LARGE;
    }
    mExtraPrioritizedMimeType = getIntent().getStringExtra(QuickContact.EXTRA_PRIORITIZED_MIMETYPE);
    final Uri oldLookupUri = mLookupUri;
    if (lookupUri == null) {
        finish();
        return;
    }
    mLookupUri = lookupUri;
    mExcludeMimes = intent.getStringArrayExtra(QuickContact.EXTRA_EXCLUDE_MIMES);
    if (oldLookupUri == null) {
        mContactLoader = (ContactLoader) getLoaderManager().initLoader(LOADER_CONTACT_ID, null, mLoaderContactCallbacks);
    } else if (oldLookupUri != mLookupUri) {
        // After copying a directory contact, the contact URI changes. Therefore,
        // we need to reload the new contact.
        destroyInteractionLoaders();
        mContactLoader = (ContactLoader) (Loader<?>) getLoaderManager().getLoader(LOADER_CONTACT_ID);
        mContactLoader.setLookupUri(mLookupUri);
        mCachedCp2DataCardModel = null;
    }
    mContactLoader.forceLoad();
    NfcHandler.register(this, mLookupUri);
}
Also used : Uri(android.net.Uri) ContactLoader(com.android.contacts.common.model.ContactLoader)

Aggregations

ContactLoader (com.android.contacts.common.model.ContactLoader)7 Contact (com.android.contacts.common.model.Contact)4 Uri (android.net.Uri)1