use of com.android.contacts.common.model.dataitem.DataItem in project android_packages_apps_Dialer by LineageOS.
the class ContactLoader method computeFormattedPhoneNumbers.
/**
* Iterates over all data items that represent phone numbers are tries to calculate a formatted
* number. This function can safely be called several times as no unformatted data is overwritten
*/
private void computeFormattedPhoneNumbers(Contact contactData) {
final String countryIso = GeoUtil.getCurrentCountryIso(getContext());
final ImmutableList<RawContact> rawContacts = contactData.getRawContacts();
final int rawContactCount = rawContacts.size();
for (int rawContactIndex = 0; rawContactIndex < rawContactCount; rawContactIndex++) {
final RawContact rawContact = rawContacts.get(rawContactIndex);
final List<DataItem> dataItems = rawContact.getDataItems();
final int dataCount = dataItems.size();
for (int dataIndex = 0; dataIndex < dataCount; dataIndex++) {
final DataItem dataItem = dataItems.get(dataIndex);
if (dataItem instanceof PhoneDataItem) {
final PhoneDataItem phoneDataItem = (PhoneDataItem) dataItem;
phoneDataItem.computeFormattedPhoneNumber(countryIso);
}
}
}
}
use of com.android.contacts.common.model.dataitem.DataItem in project android_packages_apps_Dialer by LineageOS.
the class ContactLoader method loadThumbnailBinaryData.
private void loadThumbnailBinaryData(Contact contactData) {
final long photoId = contactData.getPhotoId();
if (photoId <= 0) {
// No photo ID
return;
}
for (RawContact rawContact : contactData.getRawContacts()) {
for (DataItem dataItem : rawContact.getDataItems()) {
if (dataItem.getId() == photoId) {
if (!(dataItem instanceof PhotoDataItem)) {
break;
}
final PhotoDataItem photo = (PhotoDataItem) dataItem;
contactData.setThumbnailPhotoBinaryData(photo.getPhoto());
break;
}
}
}
}
use of com.android.contacts.common.model.dataitem.DataItem in project packages_apps_Contacts by AOKP.
the class QuickContactActivity method startInteractionLoaders.
private void startInteractionLoaders(Cp2DataCardModel cp2DataCardModel) {
final Map<String, List<DataItem>> dataItemsMap = cp2DataCardModel.dataItemsMap;
final List<DataItem> phoneDataItems = dataItemsMap.get(Phone.CONTENT_ITEM_TYPE);
if (phoneDataItems != null && phoneDataItems.size() == 1) {
mOnlyOnePhoneNumber = true;
}
String[] phoneNumbers = null;
if (phoneDataItems != null) {
phoneNumbers = new String[phoneDataItems.size()];
for (int i = 0; i < phoneDataItems.size(); ++i) {
phoneNumbers[i] = ((PhoneDataItem) phoneDataItems.get(i)).getNumber();
}
}
final Bundle phonesExtraBundle = new Bundle();
phonesExtraBundle.putStringArray(KEY_LOADER_EXTRA_PHONES, phoneNumbers);
Trace.beginSection("start sms loader");
getLoaderManager().initLoader(LOADER_SMS_ID, phonesExtraBundle, mLoaderInteractionsCallbacks);
Trace.endSection();
Trace.beginSection("start call log loader");
getLoaderManager().initLoader(LOADER_CALL_LOG_ID, phonesExtraBundle, mLoaderInteractionsCallbacks);
Trace.endSection();
Trace.beginSection("start calendar loader");
final List<DataItem> emailDataItems = dataItemsMap.get(Email.CONTENT_ITEM_TYPE);
if (emailDataItems != null && emailDataItems.size() == 1) {
mOnlyOneEmail = true;
}
String[] emailAddresses = null;
if (emailDataItems != null) {
emailAddresses = new String[emailDataItems.size()];
for (int i = 0; i < emailDataItems.size(); ++i) {
emailAddresses[i] = ((EmailDataItem) emailDataItems.get(i)).getAddress();
}
}
final Bundle emailsExtraBundle = new Bundle();
emailsExtraBundle.putStringArray(KEY_LOADER_EXTRA_EMAILS, emailAddresses);
getLoaderManager().initLoader(LOADER_CALENDAR_ID, emailsExtraBundle, mLoaderInteractionsCallbacks);
Trace.endSection();
}
use of com.android.contacts.common.model.dataitem.DataItem in project packages_apps_Contacts by AOKP.
the class QuickContactActivity method buildAboutCardEntries.
private List<List<Entry>> buildAboutCardEntries(Map<String, List<DataItem>> dataItemsMap) {
final List<List<Entry>> aboutCardEntries = new ArrayList<>();
for (String mimetype : SORTED_ABOUT_CARD_MIMETYPES) {
final List<DataItem> mimeTypeItems = dataItemsMap.get(mimetype);
if (mimeTypeItems == null) {
continue;
}
// Set aboutCardTitleOut = null, since SORTED_ABOUT_CARD_MIMETYPES doesn't contain
// the name mimetype.
final List<Entry> aboutEntries = dataItemsToEntries(mimeTypeItems, /* aboutCardTitleOut = */
null);
if (aboutEntries.size() > 0) {
aboutCardEntries.add(aboutEntries);
}
}
return aboutCardEntries;
}
use of com.android.contacts.common.model.dataitem.DataItem in project packages_apps_Contacts by AOKP.
the class QuickContactActivity method copyToPhone.
private void copyToPhone() {
String name = mContactData.getDisplayName();
if (TextUtils.isEmpty(name)) {
name = "";
}
String phoneNumber = "";
StringBuilder anrNumber = new StringBuilder();
StringBuilder email = new StringBuilder();
// get phonenumber,email,anr from SIM contacts,then insert them to phone
for (RawContact rawContact : mContactData.getRawContacts()) {
for (DataItem dataItem : rawContact.getDataItems()) {
if (dataItem.getMimeType() == null) {
continue;
}
if (dataItem instanceof PhoneDataItem) {
PhoneDataItem phoneNum = (PhoneDataItem) dataItem;
final String number = phoneNum.getNumber();
if (!TextUtils.isEmpty(number)) {
if (Phone.TYPE_MOBILE == phoneNum.getContentValues().getAsInteger(Phone.TYPE)) {
phoneNumber = number;
} else {
if (!TextUtils.isEmpty(anrNumber.toString())) {
anrNumber.append(",");
}
anrNumber.append(number);
}
}
} else if (dataItem instanceof EmailDataItem) {
EmailDataItem emailData = (EmailDataItem) dataItem;
final String address = emailData.getData();
if (!TextUtils.isEmpty(address)) {
if (!TextUtils.isEmpty(email.toString())) {
email.append(",");
}
email.append(address);
}
}
}
}
String[] value = new String[] { name, phoneNumber, email.toString(), anrNumber.toString() };
boolean success = MoreContactUtils.insertToPhone(value, QuickContactActivity.this, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Toast.makeText(this, success ? R.string.copy_done : R.string.copy_failure, Toast.LENGTH_SHORT).show();
}
Aggregations