Search in sources :

Example 11 with ContactBuilder

use of com.android.dialer.lookup.ContactBuilder 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)

Example 12 with ContactBuilder

use of com.android.dialer.lookup.ContactBuilder in project android_packages_apps_Dialer by LineageOS.

the class YellowPagesReverseLookup method lookupNumber.

/**
 * Perform phone number lookup.
 *
 * @param context The application context
 * @param normalizedNumber The normalized phone number
 * @param formattedNumber The formatted phone number
 * @return The phone number info object
 */
public ContactInfo lookupNumber(Context context, String normalizedNumber, String formattedNumber) throws IOException {
    YellowPagesApi ypa = new YellowPagesApi(context, normalizedNumber);
    YellowPagesApi.ContactInfo info = ypa.getContactInfo();
    if (info.name == null) {
        return null;
    }
    ContactBuilder builder = new ContactBuilder(ContactBuilder.REVERSE_LOOKUP, normalizedNumber, formattedNumber);
    builder.setName(ContactBuilder.Name.createDisplayName(info.name));
    builder.addPhoneNumber(ContactBuilder.PhoneNumber.createMainNumber(info.formattedNumber));
    builder.addWebsite(ContactBuilder.WebsiteUrl.createProfile(info.website));
    if (info.address != null) {
        ContactBuilder.Address a = new ContactBuilder.Address();
        a.formattedAddress = info.address;
        a.type = StructuredPostal.TYPE_WORK;
        builder.addAddress(a);
    }
    if (info.photoUrl != null) {
        builder.setPhotoUri(info.photoUrl);
    } else {
        builder.setPhotoUri(ContactBuilder.PHOTO_URI_BUSINESS);
    }
    return builder.build();
}
Also used : ContactBuilder(com.android.dialer.lookup.ContactBuilder)

Example 13 with ContactBuilder

use of com.android.dialer.lookup.ContactBuilder 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)

Example 14 with ContactBuilder

use of com.android.dialer.lookup.ContactBuilder 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)

Example 15 with ContactBuilder

use of com.android.dialer.lookup.ContactBuilder in project android_packages_apps_Dialer by MoKee.

the class ZabaSearchReverseLookup method lookupNumber.

/**
 * Perform phone number lookup.
 *
 * @param context The application context
 * @param normalizedNumber The normalized phone number
 * @param formattedNumber The formatted phone number
 * @return The phone number info object
 */
public ContactInfo lookupNumber(Context context, String normalizedNumber, String formattedNumber) throws IOException {
    ZabaSearchApi zsa = new ZabaSearchApi(normalizedNumber);
    ZabaSearchApi.ContactInfo info = zsa.getContactInfo();
    if (info.name == null) {
        return null;
    }
    ContactBuilder builder = new ContactBuilder(ContactBuilder.REVERSE_LOOKUP, normalizedNumber, formattedNumber);
    builder.setName(ContactBuilder.Name.createDisplayName(info.name));
    builder.addPhoneNumber(ContactBuilder.PhoneNumber.createMainNumber(info.formattedNumber));
    builder.addWebsite(ContactBuilder.WebsiteUrl.createProfile(info.website));
    if (info.address != null) {
        builder.addAddress(ContactBuilder.Address.createFormattedHome(info.address));
    }
    return builder.build();
}
Also used : ContactBuilder(com.android.dialer.lookup.ContactBuilder)

Aggregations

ContactBuilder (com.android.dialer.lookup.ContactBuilder)15 ArrayList (java.util.ArrayList)6 JSONArray (org.json.JSONArray)4 JSONException (org.json.JSONException)4 JSONObject (org.json.JSONObject)4 ContactInfo (com.android.dialer.calllog.ContactInfo)3 ContactInfo (com.android.dialer.phonenumbercache.ContactInfo)3 Uri (android.net.Uri)2