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;
}
}
Aggregations