Search in sources :

Example 21 with ContactInfo

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

the class OpenStreetMapForwardLookup method getEntries.

private ContactInfo[] getEntries(JSONObject results) throws JSONException {
    ArrayList<ContactInfo> details = new ArrayList<ContactInfo>();
    JSONArray elements = results.getJSONArray(RESULT_ELEMENTS);
    for (int i = 0; i < elements.length(); i++) {
        try {
            JSONObject element = elements.getJSONObject(i);
            JSONObject tags = element.getJSONObject(RESULT_TAGS);
            String displayName = tags.getString(TAG_NAME);
            String phoneNumber = tags.getString(TAG_PHONE);
            // Take the first number if there are multiple
            if (phoneNumber.contains(";")) {
                phoneNumber = phoneNumber.split(";")[0];
                phoneNumber = phoneNumber.trim();
            }
            // The address is split
            String addressHouseNumber = tags.optString(TAG_HOUSENUMBER, null);
            String addressStreet = tags.optString(TAG_STREET, null);
            String addressCity = tags.optString(TAG_CITY, null);
            String addressPostCode = tags.optString(TAG_POSTCODE, null);
            String address = String.format("%s %s, %s %s", addressHouseNumber != null ? addressHouseNumber : "", addressStreet != null ? addressStreet : "", addressCity != null ? addressCity : "", addressPostCode != null ? addressPostCode : "");
            address = address.trim().replaceAll("\\s+", " ");
            if (address.length() == 0) {
                address = null;
            }
            String website = tags.optString(TAG_WEBSITE, null);
            ContactBuilder builder = new ContactBuilder(ContactBuilder.FORWARD_LOOKUP, null, phoneNumber);
            builder.setName(ContactBuilder.Name.createDisplayName(displayName));
            builder.addPhoneNumber(ContactBuilder.PhoneNumber.createMainNumber(phoneNumber));
            ContactBuilder.Address a = new ContactBuilder.Address();
            a.formattedAddress = address;
            a.city = addressCity;
            a.street = addressStreet;
            a.postCode = addressPostCode;
            a.type = StructuredPostal.TYPE_WORK;
            builder.addAddress(a);
            ContactBuilder.WebsiteUrl w = new ContactBuilder.WebsiteUrl();
            w.url = website;
            w.type = Website.TYPE_HOMEPAGE;
            builder.addWebsite(w);
            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 : ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) 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