Search in sources :

Example 6 with ContactInfo

use of com.android.dialer.calllog.ContactInfo in project android_packages_apps_Dialer by MoKee.

the class ContactInfoCache method queryContactInfo.

/**
 * Queries the appropriate content provider for the contact associated with the number.
 *
 * Upon completion it also updates the cache in the call log, if it is different from
 * {@code callLogInfo}.
 *
 * The number might be either a SIP address or a phone number.
 *
 * @param postDialString if required, append into number
 * @param isConf determine whether it is a 4g conf call log
 * It returns true if it updated the content of the cache and we should therefore tell the
 * view to update its content.
 */
private boolean queryContactInfo(String number, String postDialString, String countryIso, ContactInfo callLogInfo, boolean isConf) {
    final ContactInfo info = mContactInfoHelper.lookupNumber(number, postDialString, countryIso, isConf);
    if (info == null) {
        // The lookup failed, just return without requesting to update the view.
        return false;
    }
    // Check the existing entry in the cache: only if it has changed we should update the
    // view.
    String phoneNumber = number;
    if (!isConf && !TextUtils.isEmpty(postDialString)) {
        phoneNumber += postDialString;
    }
    NumberWithCountryIso numberCountryIso = new NumberWithCountryIso(phoneNumber, countryIso);
    ContactInfo existingInfo = null;
    if (isConf) {
        existingInfo = mCacheFor4gConfCall.getPossiblyExpired(numberCountryIso);
    } else {
        existingInfo = mCache.getPossiblyExpired(numberCountryIso);
    }
    final boolean isRemoteSource = info.sourceType != 0;
    // Don't force redraw if existing info in the cache is equal to {@link ContactInfo#EMPTY}
    // to avoid updating the data set for every new row that is scrolled into view.
    // see (https://googleplex-android-review.git.corp.google.com/#/c/166680/)
    // Exception: Photo uris for contacts from remote sources are not cached in the call log
    // cache, so we have to force a redraw for these contacts regardless.
    boolean updated = (existingInfo != ContactInfo.EMPTY || isRemoteSource) && !info.equals(existingInfo);
    // even if it has not changed so that it is marked as not expired.
    if (isConf) {
        mCacheFor4gConfCall.put(numberCountryIso, info);
    } else {
        mCache.put(numberCountryIso, info);
    }
    // contains the value from a different call log entry.
    if (isConf) {
        mContactInfoHelper.updateCallLogContactInfo(number, countryIso, info, callLogInfo);
    } else {
        mContactInfoHelper.updateCallLogContactInfo(phoneNumber, countryIso, info, callLogInfo);
    }
    return updated;
}
Also used : ContactInfo(com.android.dialer.calllog.ContactInfo)

Example 7 with ContactInfo

use of com.android.dialer.calllog.ContactInfo in project android_packages_apps_Dialer by MoKee.

the class ContactPhotoLoaderTest method testConstructor_NullContext.

public void testConstructor_NullContext() {
    try {
        ContactPhotoLoader loader = new ContactPhotoLoader(null, new ContactInfo());
        fail();
    } catch (NullPointerException e) {
    // expected
    }
}
Also used : ContactInfo(com.android.dialer.calllog.ContactInfo)

Example 8 with ContactInfo

use of com.android.dialer.calllog.ContactInfo in project android_packages_apps_Dialer by MoKee.

the class ContactPhotoLoaderTest method testGetIcon_Photo_Invalid.

public void testGetIcon_Photo_Invalid() {
    ContactInfo info = getTestContactInfo();
    info.photoUri = Uri.parse("file://invalid/uri");
    ContactPhotoLoader loader = new ContactPhotoLoader(mContext, info);
    // Should fall back to LetterTileDrawable
    assertTrue(loader.getIcon() instanceof LetterTileDrawable);
}
Also used : LetterTileDrawable(com.android.contacts.common.lettertiles.LetterTileDrawable) ContactInfo(com.android.dialer.calllog.ContactInfo)

Example 9 with ContactInfo

use of com.android.dialer.calllog.ContactInfo in project android_packages_apps_Dialer by MoKee.

the class ContactPhotoLoaderTest method getTestContactInfo.

private ContactInfo getTestContactInfo() {
    ContactInfo info = new ContactInfo();
    info.name = "foo";
    info.lookupKey = "bar";
    return info;
}
Also used : ContactInfo(com.android.dialer.calllog.ContactInfo)

Example 10 with ContactInfo

use of com.android.dialer.calllog.ContactInfo in project android_packages_apps_Dialer by MoKee.

the class AuskunftApi method query.

public static List<ContactInfo> query(String filter, int lookupType, String normalizedNumber, String formattedNumber) throws IOException {
    // build URI
    Uri uri = Uri.parse(PEOPLE_LOOKUP_URL).buildUpon().appendQueryParameter("query", filter).build();
    // get all search entry sections
    List<String> entries = LookupUtils.allRegexResults(LookupUtils.httpGet(uri.toString(), null), SEARCH_RESULTS_REGEX, true);
    // abort lookup if nothing found
    if (entries == null || entries.isEmpty()) {
        Log.w(TAG, "nothing found");
        return null;
    }
    // build response by iterating through the search entries and parsing their HTML data
    List<ContactInfo> infos = new ArrayList<ContactInfo>();
    for (String entry : entries) {
        // parse wanted data and replace null values
        String name = replaceNullResult(LookupUtils.firstRegexResult(entry, NAME_REGEX, true));
        String address = replaceNullResult(LookupUtils.firstRegexResult(entry, ADDRESS_REGEX, true));
        String number = replaceNullResult(LookupUtils.firstRegexResult(entry, NUMBER_REGEX, true));
        // missing addresses won't be a problem (but do occur)
        if (name.isEmpty() || number.isEmpty()) {
            continue;
        }
        // figure out if we have a business contact
        boolean isBusiness = name.contains(BUSINESS_IDENTIFIER);
        // cleanup results
        name = cleanupResult(name);
        number = cleanupResult(number);
        address = cleanupResult(address);
        // set normalized and formatted number if we're not doing a reverse lookup
        if (lookupType != ContactBuilder.REVERSE_LOOKUP) {
            normalizedNumber = formattedNumber = number;
        }
        // build contact and add to list
        ContactBuilder builder = new ContactBuilder(lookupType, normalizedNumber, formattedNumber);
        builder.setName(ContactBuilder.Name.createDisplayName(name));
        builder.addPhoneNumber(ContactBuilder.PhoneNumber.createMainNumber(number));
        builder.addWebsite(ContactBuilder.WebsiteUrl.createProfile(uri.toString()));
        builder.addAddress(ContactBuilder.Address.createFormattedHome(address));
        builder.setIsBusiness(isBusiness);
        infos.add(builder.build());
    }
    return infos;
}
Also used : ArrayList(java.util.ArrayList) ContactInfo(com.android.dialer.calllog.ContactInfo) ContactBuilder(com.android.dialer.lookup.ContactBuilder) Uri(android.net.Uri)

Aggregations

ContactInfo (com.android.dialer.calllog.ContactInfo)21 JSONException (org.json.JSONException)6 ArrayList (java.util.ArrayList)5 JSONObject (org.json.JSONObject)5 CachedContactInfo (com.android.dialer.service.CachedNumberLookupService.CachedContactInfo)4 Cursor (android.database.Cursor)3 ContactBuilder (com.android.dialer.lookup.ContactBuilder)3 JSONArray (org.json.JSONArray)3 Uri (android.net.Uri)2 LetterTileDrawable (com.android.contacts.common.lettertiles.LetterTileDrawable)2 Context (android.content.Context)1 MatrixCursor (android.database.MatrixCursor)1 RoundedBitmapDrawable (android.support.v4.graphics.drawable.RoundedBitmapDrawable)1 PhoneAccountHandle (android.telecom.PhoneAccountHandle)1 JsonReader (android.util.JsonReader)1 QuickContactBadge (android.widget.QuickContactBadge)1 TextView (android.widget.TextView)1 DirectoryPartition (com.android.contacts.common.list.DirectoryPartition)1 ExpirableCache (com.android.dialer.util.ExpirableCache)1 File (java.io.File)1