Search in sources :

Example 16 with ContactInfo

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

the class CallStatsQueryHandler method getContactInfoFromCallStats.

private ContactInfo getContactInfoFromCallStats(Cursor c) {
    ContactInfo info = new ContactInfo();
    info.lookupUri = UriUtils.parseUriOrNull(c.getString(CallStatsQuery.CACHED_LOOKUP_URI));
    info.name = c.getString(CallStatsQuery.CACHED_NAME);
    info.type = c.getInt(CallStatsQuery.CACHED_NUMBER_TYPE);
    info.label = c.getString(CallStatsQuery.CACHED_NUMBER_LABEL);
    final String matchedNumber = c.getString(CallStatsQuery.CACHED_MATCHED_NUMBER);
    info.number = matchedNumber == null ? c.getString(CallStatsQuery.NUMBER) : matchedNumber;
    info.normalizedNumber = c.getString(CallStatsQuery.CACHED_NORMALIZED_NUMBER);
    info.formattedNumber = c.getString(CallStatsQuery.CACHED_FORMATTED_NUMBER);
    info.photoId = c.getLong(CallStatsQuery.CACHED_PHOTO_ID);
    // We do not cache the photo URI.
    info.photoUri = null;
    return info;
}
Also used : ContactInfo(com.android.dialer.calllog.ContactInfo)

Example 17 with ContactInfo

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

the class ContactInfoCache method getValue.

public ContactInfo getValue(String number, String postDialString, String countryIso, ContactInfo cachedContactInfo, boolean isConf) {
    String phoneNumber = number;
    if (!isConf && !TextUtils.isEmpty(postDialString)) {
        phoneNumber += postDialString;
    }
    NumberWithCountryIso numberCountryIso = new NumberWithCountryIso(phoneNumber, countryIso);
    ExpirableCache.CachedValue<ContactInfo> cachedInfo = null;
    if (isConf) {
        cachedInfo = mCacheFor4gConfCall.getCachedValue(numberCountryIso);
    } else {
        cachedInfo = mCache.getCachedValue(numberCountryIso);
    }
    ContactInfo info = cachedInfo == null ? null : cachedInfo.getValue();
    if (cachedInfo == null) {
        if (isConf) {
            mCacheFor4gConfCall.put(numberCountryIso, ContactInfo.EMPTY);
        } else {
            mCache.put(numberCountryIso, ContactInfo.EMPTY);
        }
        // Use the cached contact info from the call log.
        info = cachedContactInfo;
        // The db request should happen on a non-UI thread.
        // Request the contact details immediately since they are currently missing.
        enqueueRequest(number, postDialString, countryIso, cachedContactInfo, true, isConf);
    // We will format the phone number when we make the background request.
    } else {
        if (cachedInfo.isExpired()) {
            // The contact info is no longer up to date, we should request it. However, we
            // do not need to request them immediately.
            enqueueRequest(number, postDialString, countryIso, cachedContactInfo, false, isConf);
        } else if (!callLogInfoMatches(cachedContactInfo, info)) {
            // The call log information does not match the one we have, look it up again.
            // We could simply update the call log directly, but that needs to be done in a
            // background thread, so it is easier to simply request a new lookup, which will, as
            // a side-effect, update the call log.
            enqueueRequest(number, postDialString, countryIso, cachedContactInfo, false, isConf);
        }
        if (info == ContactInfo.EMPTY) {
            // Use the cached contact info from the call log.
            info = cachedContactInfo;
        }
    }
    return info;
}
Also used : ExpirableCache(com.android.dialer.util.ExpirableCache) ContactInfo(com.android.dialer.calllog.ContactInfo)

Example 18 with ContactInfo

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

the class ContactPhotoLoaderTest method testGetIcon_LetterTile.

public void testGetIcon_LetterTile() {
    ContactInfo info = getTestContactInfo();
    ContactPhotoLoader loader = new ContactPhotoLoader(mContext, info);
    assertTrue(loader.getIcon() instanceof LetterTileDrawable);
}
Also used : LetterTileDrawable(com.android.contacts.common.lettertiles.LetterTileDrawable) ContactInfo(com.android.dialer.calllog.ContactInfo)

Example 19 with ContactInfo

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

the class ContactPhotoLoaderTest method testGetIcon_Photo.

public void testGetIcon_Photo() {
    ContactInfo info = getTestContactInfo();
    info.photoUri = getResourceUri(R.drawable.phone_icon);
    ContactPhotoLoader loader = new ContactPhotoLoader(mContext, info);
    assertTrue(loader.getIcon() instanceof RoundedBitmapDrawable);
}
Also used : RoundedBitmapDrawable(android.support.v4.graphics.drawable.RoundedBitmapDrawable) ContactInfo(com.android.dialer.calllog.ContactInfo)

Example 20 with ContactInfo

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

the class GoogleForwardLookup method getEntries.

/**
 * Parse JSON results and return them as an array of ContactInfo
 *
 * @param results The JSON results returned from the server
 * @return Array of ContactInfo containing the result information
 */
private ContactInfo[] getEntries(JSONArray results) throws JSONException {
    ArrayList<ContactInfo> details = new ArrayList<ContactInfo>();
    JSONArray entries = results.getJSONArray(1);
    for (int i = 0; i < entries.length(); i++) {
        try {
            JSONArray entry = entries.getJSONArray(i);
            String displayName = decodeHtml(entry.getString(0));
            JSONObject params = entry.getJSONObject(3);
            String phoneNumber = decodeHtml(params.getString(RESULT_NUMBER));
            String address = decodeHtml(params.getString(RESULT_ADDRESS));
            String city = decodeHtml(params.getString(RESULT_CITY));
            String profileUrl = params.optString(RESULT_WEBSITE, null);
            String photoUri = params.optString(RESULT_PHOTO_URI, null);
            ContactBuilder builder = new ContactBuilder(ContactBuilder.FORWARD_LOOKUP, null, phoneNumber);
            builder.setName(ContactBuilder.Name.createDisplayName(displayName));
            builder.addPhoneNumber(ContactBuilder.PhoneNumber.createMainNumber(phoneNumber));
            builder.addWebsite(ContactBuilder.WebsiteUrl.createProfile(profileUrl));
            ContactBuilder.Address a = new ContactBuilder.Address();
            a.formattedAddress = address;
            a.city = city;
            a.type = StructuredPostal.TYPE_WORK;
            builder.addAddress(a);
            if (photoUri != null) {
                builder.setPhotoUri(photoUri);
            } else {
                builder.setPhotoUri(ContactBuilder.PHOTO_URI_BUSINESS);
            }
            details.add(builder.build());
        } catch (JSONException e) {
            Log.e(TAG, "Skipping the suggestions at index " + i, e);
        }
    }
    if (details.size() > 0) {
        return details.toArray(new ContactInfo[details.size()]);
    } else {
        return null;
    }
}
Also used : JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) ContactInfo(com.android.dialer.calllog.ContactInfo) ContactBuilder(com.android.dialer.lookup.ContactBuilder)

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