use of com.android.contacts.common.model.dataitem.PhoneDataItem 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.PhoneDataItem 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.PhoneDataItem 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();
}
use of com.android.contacts.common.model.dataitem.PhoneDataItem in project packages_apps_Contacts by AOKP.
the class QuickContactActivity method copyToCard.
private void copyToCard(final int sub) {
final int MSG_COPY_DONE = 0;
final int MSG_COPY_FAILURE = 1;
final int MSG_CARD_NO_SPACE = 2;
final int MSG_NO_EMPTY_EMAIL = 3;
if (mHandler == null) {
mHandler = new Handler() {
public void handleMessage(Message msg) {
switch(msg.what) {
case MSG_COPY_DONE:
Toast.makeText(QuickContactActivity.this, R.string.copy_done, Toast.LENGTH_SHORT).show();
break;
case MSG_COPY_FAILURE:
Toast.makeText(QuickContactActivity.this, R.string.copy_failure, Toast.LENGTH_SHORT).show();
break;
case MSG_CARD_NO_SPACE:
Toast.makeText(QuickContactActivity.this, R.string.card_no_space, Toast.LENGTH_SHORT).show();
break;
case MSG_NO_EMPTY_EMAIL:
Toast.makeText(QuickContactActivity.this, R.string.no_empty_email_in_usim, Toast.LENGTH_SHORT).show();
break;
}
}
};
}
new Thread(new Runnable() {
public void run() {
synchronized (this) {
int adnCountInSimContact = 1;
int anrCountInSimContact = 0;
int emailCountInSimContact = 0;
Cursor cr = null;
// call query first, otherwise the count queries will fail
try {
int subId = MoreContactUtils.getActiveSubId(QuickContactActivity.this, sub);
if (subId >= 0 && tm.getPhoneCount() > 1) {
cr = getContentResolver().query(Uri.parse(SimContactsConstants.SIM_SUB_URI + subId), null, null, null, null);
} else {
cr = getContentResolver().query(Uri.parse(SimContactsConstants.SIM_URI), null, null, null, null);
}
} catch (NullPointerException e) {
Log.e(TAG, "Exception:" + e);
} finally {
if (cr != null) {
cr.close();
}
}
if (MoreContactUtils.canSaveAnr(QuickContactActivity.this, sub)) {
anrCountInSimContact = MoreContactUtils.getOneSimAnrCount(QuickContactActivity.this, sub);
}
if (MoreContactUtils.canSaveEmail(QuickContactActivity.this, sub)) {
emailCountInSimContact = MoreContactUtils.getOneSimEmailCount(QuickContactActivity.this, sub);
}
int totalEmptyAdn = MoreContactUtils.getSimFreeCount(QuickContactActivity.this, sub);
int totalEmptyAnr = MoreContactUtils.getSpareAnrCount(QuickContactActivity.this, sub);
int totalEmptyEmail = MoreContactUtils.getSpareEmailCount(QuickContactActivity.this, sub);
Message msg = Message.obtain();
if (totalEmptyAdn <= 0) {
msg.what = MSG_CARD_NO_SPACE;
mHandler.sendMessage(msg);
return;
}
// to indiacate how many number in one ADN can saved to SIM card,
// 1 means can only save one number,2,3 ... means can save anr
int numEntitySize = adnCountInSimContact + anrCountInSimContact;
// empty number is equals to the sum of adn and anr
int emptyNumTotal = totalEmptyAdn + totalEmptyAnr;
// Get name string
String strName = mContactData.getDisplayName();
ArrayList<String> arrayNumber = new ArrayList<String>();
ArrayList<String> arrayEmail = new ArrayList<String>();
for (RawContact rawContact : mContactData.getRawContacts()) {
for (DataItem dataItem : rawContact.getDataItems()) {
if (dataItem.getMimeType() == null) {
continue;
}
if (dataItem instanceof PhoneDataItem) {
// Get phone string
PhoneDataItem phoneNum = (PhoneDataItem) dataItem;
final String number = phoneNum.getNumber();
if (!TextUtils.isEmpty(number) && emptyNumTotal-- > 0) {
arrayNumber.add(number);
}
} else if (dataItem instanceof EmailDataItem) {
// Get email string
EmailDataItem emailData = (EmailDataItem) dataItem;
final String address = emailData.getData();
if (!TextUtils.isEmpty(address) && totalEmptyEmail-- > 0) {
arrayEmail.add(address);
}
}
}
}
// calculate how many ADN needed according to the number,name,phone,email,
// then uses the max of them
int nameCount = (strName != null && !strName.equals("")) ? 1 : 0;
int groupNumCount = (arrayNumber.size() % numEntitySize) != 0 ? (arrayNumber.size() / numEntitySize + 1) : (arrayNumber.size() / numEntitySize);
int groupEmailCount = emailCountInSimContact == 0 ? 0 : ((arrayEmail.size() % emailCountInSimContact) != 0 ? (arrayEmail.size() / emailCountInSimContact + 1) : (arrayEmail.size() / emailCountInSimContact));
int groupCount = Math.max(groupEmailCount, Math.max(nameCount, groupNumCount));
ArrayList<UsimEntity> results = new ArrayList<UsimEntity>();
for (int i = 0; i < groupCount; i++) {
results.add(new UsimEntity());
}
UsimEntity value;
// get the phone number for each ADN from arrayNumber,put them in UsimEntity
for (int i = 0; i < groupNumCount; i++) {
value = results.get(i);
ArrayList<String> numberItem = new ArrayList<String>();
for (int j = 0; j < numEntitySize; j++) {
if ((i * numEntitySize + j) < arrayNumber.size()) {
numberItem.add(arrayNumber.get(i * numEntitySize + j));
}
}
value.putNumberList(numberItem);
}
for (int i = 0; i < groupEmailCount; i++) {
value = results.get(i);
ArrayList<String> emailItem = new ArrayList<String>();
for (int j = 0; j < emailCountInSimContact; j++) {
if ((i * emailCountInSimContact + j) < arrayEmail.size()) {
emailItem.add(arrayEmail.get(i * emailCountInSimContact + j));
}
}
value.putEmailList(emailItem);
}
ArrayList<String> emptyList = new ArrayList<String>();
Uri itemUri = null;
if (totalEmptyEmail < 0 && MoreContactUtils.canSaveEmail(QuickContactActivity.this, sub)) {
Message e_msg = Message.obtain();
e_msg.what = MSG_NO_EMPTY_EMAIL;
mHandler.sendMessage(e_msg);
}
// get phone number from UsimEntity,then insert to SIM card
for (int i = 0; i < groupCount; i++) {
value = results.get(i);
if (value.containsNumber()) {
arrayNumber = (ArrayList<String>) value.getNumberList();
} else {
arrayNumber = emptyList;
}
if (value.containsEmail()) {
arrayEmail = (ArrayList<String>) value.getEmailList();
} else {
arrayEmail = emptyList;
}
String strNum = arrayNumber.size() > 0 ? arrayNumber.get(0) : null;
StringBuilder strAnrNum = new StringBuilder();
for (int j = 1; j < arrayNumber.size(); j++) {
String s = arrayNumber.get(j);
strAnrNum.append(s);
strAnrNum.append(SimContactsConstants.ANR_SEP);
}
StringBuilder strEmail = new StringBuilder();
for (int j = 0; j < arrayEmail.size(); j++) {
String s = arrayEmail.get(j);
strEmail.append(s);
strEmail.append(SimContactsConstants.EMAIL_SEP);
}
itemUri = MoreContactUtils.insertToCard(QuickContactActivity.this, strName, strNum, strEmail.toString(), strAnrNum.toString(), sub);
}
if (itemUri != null) {
msg.what = MSG_COPY_DONE;
mHandler.sendMessage(msg);
} else {
msg.what = MSG_COPY_FAILURE;
mHandler.sendMessage(msg);
}
}
}
}).start();
}
use of com.android.contacts.common.model.dataitem.PhoneDataItem in project packages_apps_Contacts by AOKP.
the class QuickContactActivity method dataItemToEntry.
/**
* Converts a {@link DataItem} into an {@link ExpandingEntryCardView.Entry} for display.
* If the {@link ExpandingEntryCardView.Entry} has no visual elements, null is returned.
*
* This runs on a background thread. This is set as static to avoid accidentally adding
* additional dependencies on unsafe things (like the Activity).
*
* @param dataItem The {@link DataItem} to convert.
* @param secondDataItem A second {@link DataItem} to help build a full entry for some
* mimetypes
* @return The {@link ExpandingEntryCardView.Entry}, or null if no visual elements are present.
*/
private static Entry dataItemToEntry(DataItem dataItem, DataItem secondDataItem, Context context, Contact contactData, final MutableString aboutCardName) {
Drawable icon = null;
String header = null;
String subHeader = null;
Drawable subHeaderIcon = null;
String text = null;
Drawable textIcon = null;
StringBuilder primaryContentDescription = new StringBuilder();
Spannable phoneContentDescription = null;
Spannable smsContentDescription = null;
Intent intent = null;
boolean shouldApplyColor = true;
Drawable alternateIcon = null;
Intent alternateIntent = null;
StringBuilder alternateContentDescription = new StringBuilder();
final boolean isEditable = false;
EntryContextMenuInfo entryContextMenuInfo = null;
Drawable thirdIcon = null;
Intent thirdIntent = null;
int thirdAction = Entry.ACTION_NONE;
String thirdContentDescription = null;
Bundle thirdExtras = null;
int iconResourceId = 0;
context = context.getApplicationContext();
final Resources res = context.getResources();
DataKind kind = dataItem.getDataKind();
if (dataItem instanceof ImDataItem) {
final ImDataItem im = (ImDataItem) dataItem;
intent = ContactsUtils.buildImIntent(context, im).first;
final boolean isEmail = im.isCreatedFromEmail();
final int protocol;
if (!im.isProtocolValid()) {
protocol = Im.PROTOCOL_CUSTOM;
} else {
protocol = isEmail ? Im.PROTOCOL_GOOGLE_TALK : im.getProtocol();
}
if (protocol == Im.PROTOCOL_CUSTOM) {
// If the protocol is custom, display the "IM" entry header as well to distinguish
// this entry from other ones
header = res.getString(R.string.header_im_entry);
subHeader = Im.getProtocolLabel(res, protocol, im.getCustomProtocol()).toString();
text = im.getData();
} else {
header = Im.getProtocolLabel(res, protocol, im.getCustomProtocol()).toString();
subHeader = im.getData();
}
entryContextMenuInfo = new EntryContextMenuInfo(im.getData(), header, dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary());
} else if (dataItem instanceof OrganizationDataItem) {
final OrganizationDataItem organization = (OrganizationDataItem) dataItem;
header = res.getString(R.string.header_organization_entry);
subHeader = organization.getCompany();
entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary());
text = organization.getTitle();
} else if (dataItem instanceof NicknameDataItem) {
final NicknameDataItem nickname = (NicknameDataItem) dataItem;
// Build nickname entries
final boolean isNameRawContact = (contactData.getNameRawContactId() == dataItem.getRawContactId());
final boolean duplicatesTitle = isNameRawContact && contactData.getDisplayNameSource() == DisplayNameSources.NICKNAME;
if (!duplicatesTitle) {
header = res.getString(R.string.header_nickname_entry);
subHeader = nickname.getName();
entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary());
}
} else if (dataItem instanceof NoteDataItem) {
final NoteDataItem note = (NoteDataItem) dataItem;
header = res.getString(R.string.header_note_entry);
subHeader = note.getNote();
entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary());
} else if (dataItem instanceof WebsiteDataItem) {
final WebsiteDataItem website = (WebsiteDataItem) dataItem;
header = res.getString(R.string.header_website_entry);
subHeader = website.getUrl();
entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary());
try {
final WebAddress webAddress = new WebAddress(website.buildDataStringForDisplay(context, kind));
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(webAddress.toString()));
} catch (final ParseException e) {
Log.e(TAG, "Couldn't parse website: " + website.buildDataStringForDisplay(context, kind));
}
} else if (dataItem instanceof EventDataItem) {
final EventDataItem event = (EventDataItem) dataItem;
final String dataString = event.buildDataStringForDisplay(context, kind);
final Calendar cal = DateUtils.parseDate(dataString, false);
if (cal != null) {
final Date nextAnniversary = DateUtils.getNextAnnualDate(cal);
final Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
builder.appendPath("time");
ContentUris.appendId(builder, nextAnniversary.getTime());
intent = new Intent(Intent.ACTION_VIEW).setData(builder.build());
}
header = res.getString(R.string.header_event_entry);
if (event.hasKindTypeColumn(kind)) {
subHeader = EventCompat.getTypeLabel(res, event.getKindTypeColumn(kind), event.getLabel()).toString();
}
text = DateUtils.formatDate(context, dataString);
entryContextMenuInfo = new EntryContextMenuInfo(text, header, dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary());
} else if (dataItem instanceof RelationDataItem) {
final RelationDataItem relation = (RelationDataItem) dataItem;
final String dataString = relation.buildDataStringForDisplay(context, kind);
if (!TextUtils.isEmpty(dataString)) {
intent = new Intent(Intent.ACTION_SEARCH);
intent.putExtra(SearchManager.QUERY, dataString);
intent.setType(Contacts.CONTENT_TYPE);
}
header = res.getString(R.string.header_relation_entry);
subHeader = relation.getName();
entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary());
if (relation.hasKindTypeColumn(kind)) {
text = Relation.getTypeLabel(res, relation.getKindTypeColumn(kind), relation.getLabel()).toString();
}
} else if (dataItem instanceof PhoneDataItem) {
final PhoneDataItem phone = (PhoneDataItem) dataItem;
String phoneLabel = null;
if (!TextUtils.isEmpty(phone.getNumber())) {
primaryContentDescription.append(res.getString(R.string.call_other)).append(" ");
header = sBidiFormatter.unicodeWrap(phone.buildDataStringForDisplay(context, kind), TextDirectionHeuristics.LTR);
entryContextMenuInfo = new EntryContextMenuInfo(header, res.getString(R.string.phoneLabelsGroup), dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary());
if (phone.hasKindTypeColumn(kind)) {
final int kindTypeColumn = phone.getKindTypeColumn(kind);
final String label = phone.getLabel();
phoneLabel = label;
if (kindTypeColumn == Phone.TYPE_CUSTOM && TextUtils.isEmpty(label)) {
text = "";
} else {
text = Phone.getTypeLabel(res, kindTypeColumn, label).toString();
phoneLabel = text;
primaryContentDescription.append(text).append(" ");
}
}
primaryContentDescription.append(header);
phoneContentDescription = com.android.contacts.common.util.ContactDisplayUtils.getTelephoneTtsSpannable(primaryContentDescription.toString(), header);
icon = res.getDrawable(R.drawable.ic_phone_24dp);
iconResourceId = R.drawable.ic_phone_24dp;
if (PhoneCapabilityTester.isPhone(context)) {
intent = CallUtil.getCallIntent(phone.getNumber());
}
alternateIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(ContactsUtils.SCHEME_SMSTO, phone.getNumber(), null));
alternateIcon = res.getDrawable(R.drawable.ic_message_24dp_mirrored);
alternateContentDescription.append(res.getString(R.string.sms_custom, header));
smsContentDescription = com.android.contacts.common.util.ContactDisplayUtils.getTelephoneTtsSpannable(alternateContentDescription.toString(), header);
int videoCapability = CallUtil.getVideoCallingAvailability(context);
boolean isPresenceEnabled = (videoCapability & CallUtil.VIDEO_CALLING_PRESENCE) != 0;
boolean isVideoEnabled = (videoCapability & CallUtil.VIDEO_CALLING_ENABLED) != 0;
if (CallUtil.isCallWithSubjectSupported(context)) {
thirdIcon = res.getDrawable(R.drawable.ic_call_note_white_24dp);
thirdAction = Entry.ACTION_CALL_WITH_SUBJECT;
thirdContentDescription = res.getString(R.string.call_with_a_note);
// Create a bundle containing the data the call subject dialog requires.
thirdExtras = new Bundle();
thirdExtras.putLong(CallSubjectDialog.ARG_PHOTO_ID, contactData.getPhotoId());
thirdExtras.putParcelable(CallSubjectDialog.ARG_PHOTO_URI, UriUtils.parseUriOrNull(contactData.getPhotoUri()));
thirdExtras.putParcelable(CallSubjectDialog.ARG_CONTACT_URI, contactData.getLookupUri());
thirdExtras.putString(CallSubjectDialog.ARG_NAME_OR_NUMBER, contactData.getDisplayName());
thirdExtras.putBoolean(CallSubjectDialog.ARG_IS_BUSINESS, false);
thirdExtras.putString(CallSubjectDialog.ARG_NUMBER, phone.getNumber());
thirdExtras.putString(CallSubjectDialog.ARG_DISPLAY_NUMBER, phone.getFormattedPhoneNumber());
thirdExtras.putString(CallSubjectDialog.ARG_NUMBER_LABEL, phoneLabel);
} else if (isVideoEnabled) {
// Check to ensure carrier presence indicates the number supports video calling.
int carrierPresence = dataItem.getCarrierPresence();
boolean isPresent = (carrierPresence & Phone.CARRIER_PRESENCE_VT_CAPABLE) != 0;
if ((isPresenceEnabled && isPresent) || !isPresenceEnabled) {
thirdIcon = res.getDrawable(R.drawable.ic_videocam);
thirdAction = Entry.ACTION_INTENT;
thirdIntent = CallUtil.getVideoCallIntent(phone.getNumber(), CALL_ORIGIN_QUICK_CONTACTS_ACTIVITY);
thirdContentDescription = res.getString(R.string.description_video_call);
}
}
}
} else if (dataItem instanceof EmailDataItem) {
final EmailDataItem email = (EmailDataItem) dataItem;
final String address = email.getData();
if (!TextUtils.isEmpty(address)) {
primaryContentDescription.append(res.getString(R.string.email_other)).append(" ");
final Uri mailUri = Uri.fromParts(ContactsUtils.SCHEME_MAILTO, address, null);
intent = new Intent(Intent.ACTION_SENDTO, mailUri);
header = email.getAddress();
entryContextMenuInfo = new EntryContextMenuInfo(header, res.getString(R.string.emailLabelsGroup), dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary());
if (email.hasKindTypeColumn(kind)) {
text = Email.getTypeLabel(res, email.getKindTypeColumn(kind), email.getLabel()).toString();
primaryContentDescription.append(text).append(" ");
}
primaryContentDescription.append(header);
icon = res.getDrawable(R.drawable.ic_email_24dp);
iconResourceId = R.drawable.ic_email_24dp;
}
} else if (dataItem instanceof StructuredPostalDataItem) {
StructuredPostalDataItem postal = (StructuredPostalDataItem) dataItem;
final String postalAddress = postal.getFormattedAddress();
if (!TextUtils.isEmpty(postalAddress)) {
primaryContentDescription.append(res.getString(R.string.map_other)).append(" ");
intent = StructuredPostalUtils.getViewPostalAddressIntent(postalAddress);
header = postal.getFormattedAddress();
entryContextMenuInfo = new EntryContextMenuInfo(header, res.getString(R.string.postalLabelsGroup), dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary());
if (postal.hasKindTypeColumn(kind)) {
text = StructuredPostal.getTypeLabel(res, postal.getKindTypeColumn(kind), postal.getLabel()).toString();
primaryContentDescription.append(text).append(" ");
}
primaryContentDescription.append(header);
alternateIntent = StructuredPostalUtils.getViewPostalAddressDirectionsIntent(postalAddress);
alternateIcon = res.getDrawable(R.drawable.ic_directions_24dp);
alternateContentDescription.append(res.getString(R.string.content_description_directions)).append(" ").append(header);
icon = res.getDrawable(R.drawable.ic_place_24dp);
iconResourceId = R.drawable.ic_place_24dp;
}
} else if (dataItem instanceof SipAddressDataItem) {
final SipAddressDataItem sip = (SipAddressDataItem) dataItem;
final String address = sip.getSipAddress();
if (!TextUtils.isEmpty(address)) {
primaryContentDescription.append(res.getString(R.string.call_other)).append(" ");
if (PhoneCapabilityTester.isSipPhone(context)) {
final Uri callUri = Uri.fromParts(PhoneAccount.SCHEME_SIP, address, null);
intent = CallUtil.getCallIntent(callUri);
}
header = address;
entryContextMenuInfo = new EntryContextMenuInfo(header, res.getString(R.string.phoneLabelsGroup), dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary());
if (sip.hasKindTypeColumn(kind)) {
text = SipAddress.getTypeLabel(res, sip.getKindTypeColumn(kind), sip.getLabel()).toString();
primaryContentDescription.append(text).append(" ");
}
primaryContentDescription.append(header);
icon = res.getDrawable(R.drawable.ic_dialer_sip_black_24dp);
iconResourceId = R.drawable.ic_dialer_sip_black_24dp;
}
} else if (dataItem instanceof StructuredNameDataItem) {
// current value. This way we show the super primary value when we are able to.
if (dataItem.isSuperPrimary() || aboutCardName.value == null || aboutCardName.value.isEmpty()) {
final String givenName = ((StructuredNameDataItem) dataItem).getGivenName();
if (!TextUtils.isEmpty(givenName)) {
aboutCardName.value = res.getString(R.string.about_card_title) + " " + givenName;
} else {
aboutCardName.value = res.getString(R.string.about_card_title);
}
}
} else if (dataItem instanceof GroupMembershipDataItem) {
GroupMembershipDataItem groupMembership = (GroupMembershipDataItem) dataItem;
Long groupId = groupMembership.getGroupRowId();
if (groupId != null) {
return new Entry(/* viewId = */
-1, /* icon = */
null, res.getString(R.string.groupsLabel), getGroupName(contactData.getGroupMetaData(), groupId), /* mSubHeaderIcon= */
null, /* text = */
null, /* mTextIcon= */
null, /* primaryContentDescription = */
null, /* intent = */
null, /* alternateIcon = */
null, /* alternateIntent = */
null, /* alternateContentDescription = */
null, /* shouldApplyColor = */
false, /* isEditable = */
false, /* EntryContextMenuInfo = */
null, /* thirdIcon = */
null, /* thirdIntent = */
null, /* thirdContentDescription = */
null, /* thirdAction = */
0, /* thirdExtras = */
null, /* iconResourceId = */
0);
}
return null;
} else {
// Custom DataItem
header = dataItem.buildDataStringForDisplay(context, kind);
text = kind.typeColumn;
intent = new Intent(Intent.ACTION_VIEW);
final Uri uri = ContentUris.withAppendedId(Data.CONTENT_URI, dataItem.getId());
intent.setDataAndType(uri, dataItem.getMimeType());
if (intent != null) {
final String mimetype = intent.getType();
// Build advanced entry for known 3p types. Otherwise default to ResolveCache icon.
switch(mimetype) {
case MIMETYPE_GPLUS_PROFILE:
// alternate actions
if (secondDataItem != null) {
icon = res.getDrawable(R.drawable.ic_google_plus_24dp);
alternateIcon = res.getDrawable(R.drawable.ic_add_to_circles_black_24);
final GPlusOrHangoutsDataItemModel itemModel = new GPlusOrHangoutsDataItemModel(intent, alternateIntent, dataItem, secondDataItem, alternateContentDescription, header, text, context);
populateGPlusOrHangoutsDataItemModel(itemModel);
intent = itemModel.intent;
alternateIntent = itemModel.alternateIntent;
alternateContentDescription = itemModel.alternateContentDescription;
header = itemModel.header;
text = itemModel.text;
} else {
if (GPLUS_PROFILE_DATA_5_ADD_TO_CIRCLE.equals(intent.getDataString())) {
icon = res.getDrawable(R.drawable.ic_add_to_circles_black_24);
} else {
icon = res.getDrawable(R.drawable.ic_google_plus_24dp);
}
}
break;
case MIMETYPE_HANGOUTS:
// alternate actions
if (secondDataItem != null) {
icon = res.getDrawable(R.drawable.ic_hangout_24dp);
alternateIcon = res.getDrawable(R.drawable.ic_hangout_video_24dp);
final GPlusOrHangoutsDataItemModel itemModel = new GPlusOrHangoutsDataItemModel(intent, alternateIntent, dataItem, secondDataItem, alternateContentDescription, header, text, context);
populateGPlusOrHangoutsDataItemModel(itemModel);
intent = itemModel.intent;
alternateIntent = itemModel.alternateIntent;
alternateContentDescription = itemModel.alternateContentDescription;
header = itemModel.header;
text = itemModel.text;
} else {
if (HANGOUTS_DATA_5_VIDEO.equals(intent.getDataString())) {
icon = res.getDrawable(R.drawable.ic_hangout_video_24dp);
} else {
icon = res.getDrawable(R.drawable.ic_hangout_24dp);
}
}
break;
default:
entryContextMenuInfo = new EntryContextMenuInfo(header, mimetype, dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary());
icon = ResolveCache.getInstance(context).getIcon(dataItem.getMimeType(), intent);
// Call mutate to create a new Drawable.ConstantState for color filtering
if (icon != null) {
icon.mutate();
}
shouldApplyColor = false;
}
}
}
if (intent != null) {
// Do not set the intent is there are no resolves
if (!PhoneCapabilityTester.isIntentRegistered(context, intent)) {
intent = null;
}
}
if (alternateIntent != null) {
// Do not set the alternate intent is there are no resolves
if (!PhoneCapabilityTester.isIntentRegistered(context, alternateIntent)) {
alternateIntent = null;
} else if (TextUtils.isEmpty(alternateContentDescription)) {
// Attempt to use package manager to find a suitable content description if needed
alternateContentDescription.append(getIntentResolveLabel(alternateIntent, context));
}
}
// If the Entry has no visual elements, return null
if (icon == null && TextUtils.isEmpty(header) && TextUtils.isEmpty(subHeader) && subHeaderIcon == null && TextUtils.isEmpty(text) && textIcon == null) {
return null;
}
// Ignore dataIds from the Me profile.
final int dataId = dataItem.getId() > Integer.MAX_VALUE ? -1 : (int) dataItem.getId();
return new Entry(dataId, icon, header, subHeader, subHeaderIcon, text, textIcon, phoneContentDescription == null ? new SpannableString(primaryContentDescription.toString()) : phoneContentDescription, intent, alternateIcon, alternateIntent, smsContentDescription == null ? new SpannableString(alternateContentDescription.toString()) : smsContentDescription, shouldApplyColor, isEditable, entryContextMenuInfo, thirdIcon, thirdIntent, thirdContentDescription, thirdAction, thirdExtras, iconResourceId);
}
Aggregations