use of com.android.dialer.calllog.ContactInfo in project android_packages_apps_Dialer by MoKee.
the class ContactBuilder method build.
public ContactInfo build() {
if (mName == null) {
throw new IllegalStateException("Name has not been set");
}
if (mDirectoryType != FORWARD_LOOKUP && mDirectoryType != PEOPLE_LOOKUP && mDirectoryType != REVERSE_LOOKUP) {
throw new IllegalStateException("Invalid directory type");
}
// number differently (eg. without the area code).
if (mPhoneNumbers.size() == 0) {
PhoneNumber pn = new PhoneNumber();
// Use the formatted number where possible
pn.number = mFormattedNumber != null ? mFormattedNumber : mNormalizedNumber;
pn.type = Phone.TYPE_MAIN;
addPhoneNumber(pn);
}
try {
JSONObject contact = new JSONObject();
// Insert the name
contact.put(StructuredName.CONTENT_ITEM_TYPE, mName.getJsonObject());
// Insert phone numbers
JSONArray phoneNumbers = new JSONArray();
for (int i = 0; i < mPhoneNumbers.size(); i++) {
phoneNumbers.put(mPhoneNumbers.get(i).getJsonObject());
}
contact.put(Phone.CONTENT_ITEM_TYPE, phoneNumbers);
// Insert addresses if there are any
if (mAddresses.size() > 0) {
JSONArray addresses = new JSONArray();
for (int i = 0; i < mAddresses.size(); i++) {
addresses.put(mAddresses.get(i).getJsonObject());
}
contact.put(StructuredPostal.CONTENT_ITEM_TYPE, addresses);
}
// Insert websites if there are any
if (mWebsites.size() > 0) {
JSONArray websites = new JSONArray();
for (int i = 0; i < mWebsites.size(); i++) {
websites.put(mWebsites.get(i).getJsonObject());
}
contact.put(Website.CONTENT_ITEM_TYPE, websites);
}
ContactInfo info = new ContactInfo();
info.name = mName.displayName;
info.normalizedNumber = mNormalizedNumber;
info.number = mPhoneNumbers.get(0).number;
info.type = mPhoneNumbers.get(0).type;
info.label = mPhoneNumbers.get(0).label;
info.photoUri = mPhotoUri != null ? mPhotoUri : null;
String json = new JSONObject().put(Contacts.DISPLAY_NAME, mName.displayName).put(Contacts.DISPLAY_NAME_SOURCE, mDisplayNameSource).put(Directory.EXPORT_SUPPORT, Directory.EXPORT_SUPPORT_ANY_ACCOUNT).put(Contacts.CONTENT_ITEM_TYPE, contact).toString();
if (json != null) {
long directoryId = -1;
switch(mDirectoryType) {
case FORWARD_LOOKUP:
directoryId = DirectoryId.NEARBY;
break;
case PEOPLE_LOOKUP:
directoryId = DirectoryId.PEOPLE;
break;
case REVERSE_LOOKUP:
// use null directory to be backwards compatible with old code
directoryId = DirectoryId.NULL;
break;
}
info.lookupUri = Contacts.CONTENT_LOOKUP_URI.buildUpon().appendPath(Constants.LOOKUP_URI_ENCODED).appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(directoryId)).encodedFragment(json).build();
}
return info;
} catch (JSONException e) {
Log.e(TAG, "Failed to build contact", e);
return null;
}
}
use of com.android.dialer.calllog.ContactInfo in project android_packages_apps_Dialer by MoKee.
the class NumbersAdapter method updateView.
public void updateView(View view, String number, String countryIso) {
final TextView callerName = (TextView) view.findViewById(R.id.caller_name);
final TextView callerNumber = (TextView) view.findViewById(R.id.caller_number);
final QuickContactBadge quickContactBadge = (QuickContactBadge) view.findViewById(R.id.quick_contact_photo);
quickContactBadge.setOverlay(null);
if (CompatUtils.hasPrioritizedMimeType()) {
quickContactBadge.setPrioritizedMimeType(Phone.CONTENT_ITEM_TYPE);
}
ContactInfo info = mContactInfoHelper.lookupNumber(number, countryIso);
if (info == null) {
info = new ContactInfo();
info.number = number;
}
final CharSequence locationOrType = getNumberTypeOrLocation(info);
final String displayNumber = getDisplayNumber(info);
final String displayNumberStr = mBidiFormatter.unicodeWrap(displayNumber, TextDirectionHeuristics.LTR);
String nameForDefaultImage;
if (!TextUtils.isEmpty(info.name)) {
nameForDefaultImage = info.name;
callerName.setText(info.name);
callerNumber.setText(locationOrType + " " + displayNumberStr);
} else {
nameForDefaultImage = displayNumber;
callerName.setText(displayNumberStr);
if (!TextUtils.isEmpty(locationOrType)) {
callerNumber.setText(locationOrType);
callerNumber.setVisibility(View.VISIBLE);
} else {
callerNumber.setVisibility(View.GONE);
}
}
loadContactPhoto(info, nameForDefaultImage, quickContactBadge);
}
use of com.android.dialer.calllog.ContactInfo in project android_packages_apps_Dialer by MoKee.
the class RegularSearchListAdapter method getLookupContactInfo.
public ContactInfo getLookupContactInfo(int position) {
ContactInfo info = new ContactInfo();
final Cursor item = (Cursor) getItem(position);
if (item != null) {
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);
}
return info;
}
use of com.android.dialer.calllog.ContactInfo in project android_packages_apps_Dialer by MoKee.
the class CallStatsQueryHandler method mergeItemsByNumber.
private void mergeItemsByNumber(List<CallStatsDetails> calls, List<ContactInfo> infos) {
// temporarily store items marked for removal
final ArrayList<CallStatsDetails> callsToRemove = new ArrayList<CallStatsDetails>();
final ArrayList<ContactInfo> infosToRemove = new ArrayList<ContactInfo>();
for (int i = 0; i < calls.size(); i++) {
final CallStatsDetails outerItem = calls.get(i);
final String currentFormattedNumber = outerItem.number.toString();
for (int j = calls.size() - 1; j > i; j--) {
final CallStatsDetails innerItem = calls.get(j);
final String innerNumber = innerItem.number.toString();
if (phoneNumbersEqual(currentFormattedNumber, innerNumber)) {
outerItem.mergeWith(innerItem);
// make sure we're not counting twice in case we're dealing with
// multiple different formats
innerItem.reset();
callsToRemove.add(innerItem);
infosToRemove.add(infos.get(j));
}
}
}
for (CallStatsDetails call : callsToRemove) {
calls.remove(call);
}
for (ContactInfo info : infosToRemove) {
infos.remove(info);
}
}
use of com.android.dialer.calllog.ContactInfo in project android_packages_apps_Dialer by MoKee.
the class CallStatsQueryHandler method processData.
private Map<ContactInfo, CallStatsDetails> processData(Cursor cursor) {
final Map<ContactInfo, CallStatsDetails> result = new HashMap<ContactInfo, CallStatsDetails>();
final ArrayList<ContactInfo> infos = new ArrayList<ContactInfo>();
final ArrayList<CallStatsDetails> calls = new ArrayList<CallStatsDetails>();
CallStatsDetails pending = null;
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
final String number = cursor.getString(CallStatsQuery.NUMBER);
final long duration = cursor.getLong(CallStatsQuery.DURATION);
final int callType = cursor.getInt(CallStatsQuery.CALL_TYPE);
if (pending == null || !phoneNumbersEqual(pending.number.toString(), number)) {
final long date = cursor.getLong(CallStatsQuery.DATE);
final int numberPresentation = cursor.getInt(CallStatsQuery.NUMBER_PRESENTATION);
final String countryIso = cursor.getString(CallStatsQuery.COUNTRY_ISO);
final String geocode = cursor.getString(CallStatsQuery.GEOCODED_LOCATION);
final String postDialDigits = cursor.getString(CallStatsQuery.POST_DIAL_DIGITS);
final ContactInfo info = getContactInfoFromCallStats(cursor);
final PhoneAccountHandle accountHandle = PhoneAccountUtils.getAccount(cursor.getString(CallStatsQuery.ACCOUNT_COMPONENT_NAME), cursor.getString(CallStatsQuery.ACCOUNT_ID));
pending = new CallStatsDetails(number, numberPresentation, postDialDigits, accountHandle, info, countryIso, geocode, date);
infos.add(info);
calls.add(pending);
}
pending.addTimeOrMissed(callType, duration);
cursor.moveToNext();
}
cursor.close();
mergeItemsByNumber(calls, infos);
for (int i = 0; i < calls.size(); i++) {
result.put(infos.get(i), calls.get(i));
}
return result;
}
Aggregations