use of com.android.dialer.phonenumbercache.ContactInfo in project android_packages_apps_Dialer by LineageOS.
the class LookupProvider method handleFilter.
/**
* Process filter/query and perform the lookup.
*
* @param projection Columns to include in query
* @param filter String to lookup
* @param maxResults Maximum number of results
* @param lastLocation Coordinates of last location query
* @return Cursor for the results
*/
private Cursor handleFilter(int type, String[] projection, String filter, int maxResults, Location lastLocation) {
if (DEBUG)
Log.v(TAG, "handleFilter(" + filter + ")");
if (filter != null) {
try {
filter = URLDecoder.decode(filter, "UTF-8");
} catch (UnsupportedEncodingException e) {
}
ContactInfo[] results = null;
if (type == NEARBY) {
ForwardLookup fl = ForwardLookup.getInstance(getContext());
results = fl.lookup(getContext(), filter, lastLocation);
} else if (type == PEOPLE) {
PeopleLookup pl = PeopleLookup.getInstance(getContext());
results = pl.lookup(getContext(), filter);
}
if (results == null || results.length == 0) {
if (DEBUG)
Log.v(TAG, "handleFilter(" + filter + "): No results");
return null;
}
Cursor cur = null;
try {
cur = buildResultCursor(projection, results, maxResults);
if (DEBUG)
Log.v(TAG, "handleFilter(" + filter + "): " + cur.getCount() + " matches");
} catch (JSONException e) {
Log.e(TAG, "JSON failure", e);
}
return cur;
}
return null;
}
use of com.android.dialer.phonenumbercache.ContactInfo in project android_packages_apps_Dialer by LineageOS.
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;
}
use of com.android.dialer.phonenumbercache.ContactInfo in project android_packages_apps_Dialer by LineageOS.
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;
}
}
use of com.android.dialer.phonenumbercache.ContactInfo in project android_packages_apps_Dialer by LineageOS.
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;
}
}
use of com.android.dialer.phonenumbercache.ContactInfo in project android_packages_apps_Dialer by LineageOS.
the class CallLogAdapter method loadData.
/**
* Load data for call log. Any expensive operation should be put here to avoid blocking main
* thread. Do NOT put any cursor operation here since it's not thread safe.
*/
@WorkerThread
private boolean loadData(CallLogListItemViewHolder views, long rowId, PhoneCallDetails details) {
Assert.isWorkerThread();
if (rowId != views.rowId) {
LogUtil.i("CallLogAdapter.loadData", "rowId of viewHolder changed after load task is issued, aborting load");
return false;
}
final PhoneAccountHandle accountHandle = PhoneAccountUtils.getAccount(details.accountComponentName, details.accountId);
final boolean isVoicemailNumber = mCallLogCache.isVoicemailNumber(accountHandle, details.number);
// Note: Binding of the action buttons is done as required in configureActionViews when the
// user expands the actions ViewStub.
ContactInfo info = ContactInfo.EMPTY;
if (PhoneNumberHelper.canPlaceCallsTo(details.number, details.numberPresentation) && !isVoicemailNumber) {
// Lookup contacts with this number
// Only do remote lookup in first 5 rows.
int position = views.getAdapterPosition();
info = mContactInfoCache.getValue(details.number + details.postDialDigits, details.countryIso, details.cachedContactInfo, position < ConfigProviderBindings.get(mActivity).getLong("number_of_call_to_do_remote_lookup", 5L));
}
CharSequence formattedNumber = info.formattedNumber == null ? null : PhoneNumberUtilsCompat.createTtsSpannable(info.formattedNumber);
details.updateDisplayNumber(mActivity, formattedNumber, isVoicemailNumber);
views.displayNumber = details.displayNumber;
views.accountHandle = accountHandle;
details.accountHandle = accountHandle;
if (!TextUtils.isEmpty(info.name) || !TextUtils.isEmpty(info.nameAlternative)) {
details.contactUri = info.lookupUri;
details.namePrimary = info.name;
details.nameAlternative = info.nameAlternative;
details.nameDisplayOrder = mContactsPreferences.getDisplayOrder();
details.numberType = info.type;
details.numberLabel = info.label;
details.photoUri = info.photoUri;
details.sourceType = info.sourceType;
details.objectId = info.objectId;
details.contactUserType = info.userType;
}
LogUtil.d("CallLogAdapter.loadData", "position:%d, update geo info: %s, cequint caller id geo: %s, photo uri: %s <- %s", views.getAdapterPosition(), details.geocode, info.geoDescription, details.photoUri, info.photoUri);
if (!TextUtils.isEmpty(info.geoDescription)) {
details.geocode = info.geoDescription;
}
views.info = info;
views.numberType = getNumberType(mActivity.getResources(), details);
mCallLogListItemHelper.updatePhoneCallDetails(details);
return true;
}
Aggregations