use of com.android.dialer.calllog.ContactInfo in project android_packages_apps_Dialer by MoKee.
the class CallerInfoUtils method buildCachedContactInfo.
/**
* Creates a new {@link CachedContactInfo} from a {@link CallerInfo}
*
* @param lookupService the {@link CachedNumberLookupService} used to build a
* new {@link CachedContactInfo}
* @param {@link CallerInfo} object
* @return a CachedContactInfo object created from this CallerInfo
* @throws NullPointerException if lookupService or ci are null
*/
public static CachedContactInfo buildCachedContactInfo(CachedNumberLookupService lookupService, CallerInfo ci) {
ContactInfo info = new ContactInfo();
info.name = ci.name;
info.type = ci.numberType;
info.label = ci.phoneLabel;
info.number = ci.phoneNumber;
info.normalizedNumber = ci.normalizedNumber;
info.photoUri = ci.contactDisplayPhotoUri;
info.userType = ci.userType;
CachedContactInfo cacheInfo = lookupService.buildCachedContactInfo(info);
cacheInfo.setLookupKey(ci.lookupKeyOrNull);
return cacheInfo;
}
use of com.android.dialer.calllog.ContactInfo in project android_packages_apps_Dialer by MoKee.
the class ContactInfoCache method maybeInsertCnapInformationIntoCache.
public void maybeInsertCnapInformationIntoCache(Context context, final Call call, final CallerInfo info) {
if (mCachedNumberLookupService == null || TextUtils.isEmpty(info.cnapName) || mInfoMap.get(call.getId()) != null) {
return;
}
final Context applicationContext = context.getApplicationContext();
Log.i(TAG, "Found contact with CNAP name - inserting into cache");
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
ContactInfo contactInfo = new ContactInfo();
CachedContactInfo cacheInfo = mCachedNumberLookupService.buildCachedContactInfo(contactInfo);
cacheInfo.setSource(CachedContactInfo.SOURCE_TYPE_CNAP, "CNAP", 0);
contactInfo.name = info.cnapName;
contactInfo.number = call.getNumber();
contactInfo.type = ContactsContract.CommonDataKinds.Phone.TYPE_MAIN;
try {
final JSONObject contactRows = new JSONObject().put(Phone.CONTENT_ITEM_TYPE, new JSONObject().put(Phone.NUMBER, contactInfo.number).put(Phone.TYPE, Phone.TYPE_MAIN));
final String jsonString = new JSONObject().put(Contacts.DISPLAY_NAME, contactInfo.name).put(Contacts.DISPLAY_NAME_SOURCE, DisplayNameSources.STRUCTURED_NAME).put(Contacts.CONTENT_ITEM_TYPE, contactRows).toString();
cacheInfo.setLookupKey(jsonString);
} catch (JSONException e) {
Log.w(TAG, "Creation of lookup key failed when caching CNAP information");
}
mCachedNumberLookupService.addContact(applicationContext, cacheInfo);
return null;
}
}.execute();
}
use of com.android.dialer.calllog.ContactInfo in project android_packages_apps_Dialer by MoKee.
the class RegularSearchListAdapter method getContactInfo.
public CachedContactInfo getContactInfo(CachedNumberLookupService lookupService, int position) {
ContactInfo info = new ContactInfo();
CachedContactInfo cacheInfo = lookupService.buildCachedContactInfo(info);
final Cursor item = (Cursor) getItem(position);
if (item != null) {
final DirectoryPartition partition = (DirectoryPartition) getPartition(getPartitionForPosition(position));
final long directoryId = partition.getDirectoryId();
final boolean isExtendedDirectory = isExtendedDirectory(directoryId);
info.name = item.getString(PhoneQuery.DISPLAY_NAME);
info.type = item.getInt(PhoneQuery.PHONE_TYPE);
info.label = item.getString(PhoneQuery.PHONE_LABEL);
info.number = item.getString(PhoneQuery.PHONE_NUMBER);
final String photoUriStr = item.getString(PhoneQuery.PHOTO_URI);
info.photoUri = photoUriStr == null ? null : Uri.parse(photoUriStr);
/*
* An extended directory is custom directory in the app, but not a directory provided by
* framework. So it can't be USER_TYPE_WORK.
*
* When a search result is selected, RegularSearchFragment calls getContactInfo and
* cache the resulting @{link ContactInfo} into local db. Set usertype to USER_TYPE_WORK
* only if it's NOT extended directory id and is enterprise directory.
*/
info.userType = !isExtendedDirectory && DirectoryCompat.isEnterpriseDirectoryId(directoryId) ? ContactsUtils.USER_TYPE_WORK : ContactsUtils.USER_TYPE_CURRENT;
cacheInfo.setLookupKey(item.getString(PhoneQuery.LOOKUP_KEY));
final String sourceName = partition.getLabel();
if (isExtendedDirectory) {
cacheInfo.setExtendedSource(sourceName, directoryId);
} else {
cacheInfo.setDirectorySource(sourceName, directoryId);
}
}
return cacheInfo;
}
use of com.android.dialer.calllog.ContactInfo in project android_packages_apps_Dialer by MoKee.
the class LookupCache method getCachedContact.
public static ContactInfo getCachedContact(Context context, String number) {
String normalizedNumber = formatE164(context, number);
if (normalizedNumber == null) {
return null;
}
File file = getFilePath(context, normalizedNumber);
if (!file.exists()) {
// Whatever is calling this should probably check anyway
return null;
}
ContactInfo info = new ContactInfo();
FileInputStream in = null;
JsonReader reader = null;
try {
in = new FileInputStream(file);
reader = new JsonReader(new InputStreamReader(in, "UTF-8"));
reader.beginObject();
while (reader.hasNext()) {
String name = reader.nextName();
if (NAME.equals(name)) {
info.name = reader.nextString();
} else if (TYPE.equals(name)) {
info.type = reader.nextInt();
} else if (LABEL.equals(name)) {
info.label = reader.nextString();
} else if (NUMBER.equals(name)) {
info.number = reader.nextString();
} else if (FORMATTED_NUMBER.equals(name)) {
info.formattedNumber = reader.nextString();
} else if (NORMALIZED_NUMBER.equals(name)) {
info.normalizedNumber = reader.nextString();
} else if (PHOTO_ID.equals(name)) {
info.photoId = reader.nextInt();
} else if (LOOKUP_URI.equals(name)) {
Uri lookupUri = Uri.parse(reader.nextString());
if (hasCachedImage(context, normalizedNumber)) {
// Insert cached photo URI
Uri image = Uri.withAppendedPath(LookupProvider.IMAGE_CACHE_URI, Uri.encode(normalizedNumber));
String json = lookupUri.getEncodedFragment();
if (json != null) {
try {
JSONObject jsonObj = new JSONObject(json);
jsonObj.putOpt(Contacts.PHOTO_URI, image.toString());
lookupUri = lookupUri.buildUpon().encodedFragment(jsonObj.toString()).build();
} catch (JSONException e) {
Log.e(TAG, "Failed to add image URI to json", e);
}
}
info.photoUri = image;
}
info.lookupUri = lookupUri;
}
}
reader.endObject();
} catch (IOException e) {
e.printStackTrace();
} finally {
IoUtils.closeQuietly(reader);
IoUtils.closeQuietly(in);
}
return info;
}
use of com.android.dialer.calllog.ContactInfo in project android_packages_apps_Dialer by MoKee.
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;
}
Aggregations