Search in sources :

Example 46 with DataKind

use of com.android.contacts.common.model.dataitem.DataKind in project packages_apps_Contacts by AOKP.

the class QuickContactActivity method generateDataModelFromContact.

/**
 * Builds the {@link DataItem}s Map out of the Contact.
 * @param data The contact to build the data from.
 * @return A pair containing a list of data items sorted within mimetype and sorted
 *  amongst mimetype. The map goes from mimetype string to the sorted list of data items within
 *  mimetype
 */
private Cp2DataCardModel generateDataModelFromContact(Contact data) {
    Trace.beginSection("Build data items map");
    final Map<String, List<DataItem>> dataItemsMap = new HashMap<>();
    final ResolveCache cache = ResolveCache.getInstance(this);
    for (RawContact rawContact : data.getRawContacts()) {
        for (DataItem dataItem : rawContact.getDataItems()) {
            dataItem.setRawContactId(rawContact.getId());
            final String mimeType = dataItem.getMimeType();
            if (mimeType == null)
                continue;
            final AccountType accountType = rawContact.getAccountType(this);
            final DataKind dataKind = AccountTypeManager.getInstance(this).getKindOrFallback(accountType, mimeType);
            if (dataKind == null)
                continue;
            dataItem.setDataKind(dataKind);
            final boolean hasData = !TextUtils.isEmpty(dataItem.buildDataString(this, dataKind));
            if (isMimeExcluded(mimeType) || !hasData)
                continue;
            List<DataItem> dataItemListByType = dataItemsMap.get(mimeType);
            if (dataItemListByType == null) {
                dataItemListByType = new ArrayList<>();
                dataItemsMap.put(mimeType, dataItemListByType);
            }
            dataItemListByType.add(dataItem);
        }
    }
    Trace.endSection();
    Trace.beginSection("sort within mimetypes");
    /*
         * Sorting is a multi part step. The end result is to a have a sorted list of the most
         * used data items, one per mimetype. Then, within each mimetype, the list of data items
         * for that type is also sorted, based off of {super primary, primary, times used} in that
         * order.
         */
    final List<List<DataItem>> dataItemsList = new ArrayList<>();
    for (List<DataItem> mimeTypeDataItems : dataItemsMap.values()) {
        // Remove duplicate data items
        Collapser.collapseList(mimeTypeDataItems, this);
        // Sort within mimetype
        Collections.sort(mimeTypeDataItems, mWithinMimeTypeDataItemComparator);
        // Add to the list of data item lists
        dataItemsList.add(mimeTypeDataItems);
    }
    Trace.endSection();
    Trace.beginSection("sort amongst mimetypes");
    // Sort amongst mimetypes to bubble up the top data items for the contact card
    Collections.sort(dataItemsList, mAmongstMimeTypeDataItemComparator);
    Trace.endSection();
    Trace.beginSection("cp2 data items to entries");
    final List<List<Entry>> contactCardEntries = new ArrayList<>();
    final List<List<Entry>> aboutCardEntries = buildAboutCardEntries(dataItemsMap);
    final MutableString aboutCardName = new MutableString();
    for (int i = 0; i < dataItemsList.size(); ++i) {
        final List<DataItem> dataItemsByMimeType = dataItemsList.get(i);
        final DataItem topDataItem = dataItemsByMimeType.get(0);
        if (SORTED_ABOUT_CARD_MIMETYPES.contains(topDataItem.getMimeType())) {
            // About card mimetypes are built in buildAboutCardEntries, skip here
            continue;
        } else {
            List<Entry> contactEntries = dataItemsToEntries(dataItemsList.get(i), aboutCardName);
            if (contactEntries.size() > 0) {
                contactCardEntries.add(contactEntries);
            }
        }
    }
    Trace.endSection();
    final Cp2DataCardModel dataModel = new Cp2DataCardModel();
    dataModel.customAboutCardName = aboutCardName.value;
    dataModel.aboutCardEntries = aboutCardEntries;
    dataModel.contactCardEntries = contactCardEntries;
    dataModel.dataItemsMap = dataItemsMap;
    return dataModel;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) PhoneDataItem(com.android.contacts.common.model.dataitem.PhoneDataItem) EventDataItem(com.android.contacts.common.model.dataitem.EventDataItem) OrganizationDataItem(com.android.contacts.common.model.dataitem.OrganizationDataItem) RelationDataItem(com.android.contacts.common.model.dataitem.RelationDataItem) StructuredNameDataItem(com.android.contacts.common.model.dataitem.StructuredNameDataItem) NoteDataItem(com.android.contacts.common.model.dataitem.NoteDataItem) DataItem(com.android.contacts.common.model.dataitem.DataItem) SipAddressDataItem(com.android.contacts.common.model.dataitem.SipAddressDataItem) EmailDataItem(com.android.contacts.common.model.dataitem.EmailDataItem) NicknameDataItem(com.android.contacts.common.model.dataitem.NicknameDataItem) StructuredPostalDataItem(com.android.contacts.common.model.dataitem.StructuredPostalDataItem) WebsiteDataItem(com.android.contacts.common.model.dataitem.WebsiteDataItem) GroupMembershipDataItem(com.android.contacts.common.model.dataitem.GroupMembershipDataItem) ImDataItem(com.android.contacts.common.model.dataitem.ImDataItem) DataKind(com.android.contacts.common.model.dataitem.DataKind) ArrayList(java.util.ArrayList) SpannableString(android.text.SpannableString) AccountType(com.android.contacts.common.model.account.AccountType) Entry(com.android.contacts.quickcontact.ExpandingEntryCardView.Entry) RawContact(com.android.contacts.common.model.RawContact) ColorStateList(android.content.res.ColorStateList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList)

Example 47 with DataKind

use of com.android.contacts.common.model.dataitem.DataKind 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);
}
Also used : EventDataItem(com.android.contacts.common.model.dataitem.EventDataItem) NoteDataItem(com.android.contacts.common.model.dataitem.NoteDataItem) PhoneDataItem(com.android.contacts.common.model.dataitem.PhoneDataItem) DataKind(com.android.contacts.common.model.dataitem.DataKind) ShortcutIntentBuilder(com.android.contacts.common.list.ShortcutIntentBuilder) SpannableString(android.text.SpannableString) StructuredNameDataItem(com.android.contacts.common.model.dataitem.StructuredNameDataItem) ImDataItem(com.android.contacts.common.model.dataitem.ImDataItem) Uri(android.net.Uri) SipAddressDataItem(com.android.contacts.common.model.dataitem.SipAddressDataItem) Entry(com.android.contacts.quickcontact.ExpandingEntryCardView.Entry) StructuredPostalDataItem(com.android.contacts.common.model.dataitem.StructuredPostalDataItem) RelationDataItem(com.android.contacts.common.model.dataitem.RelationDataItem) EntryContextMenuInfo(com.android.contacts.quickcontact.ExpandingEntryCardView.EntryContextMenuInfo) Bundle(android.os.Bundle) Calendar(java.util.Calendar) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) LetterTileDrawable(com.android.contacts.common.lettertiles.LetterTileDrawable) GroupMembershipDataItem(com.android.contacts.common.model.dataitem.GroupMembershipDataItem) Intent(android.content.Intent) EmailDataItem(com.android.contacts.common.model.dataitem.EmailDataItem) WebsiteDataItem(com.android.contacts.common.model.dataitem.WebsiteDataItem) Date(java.util.Date) SpannableString(android.text.SpannableString) OrganizationDataItem(com.android.contacts.common.model.dataitem.OrganizationDataItem) NicknameDataItem(com.android.contacts.common.model.dataitem.NicknameDataItem) Resources(android.content.res.Resources) ParseException(com.android.contacts.quickcontact.WebAddress.ParseException) Spannable(android.text.Spannable)

Example 48 with DataKind

use of com.android.contacts.common.model.dataitem.DataKind in project packages_apps_Contacts by AOKP.

the class CompactRawContactsEditorView method parseRawContactDeltas.

private void parseRawContactDeltas(RawContactDeltaList rawContactDeltas) {
    // Build the kind section data list map
    vlog("parse: " + rawContactDeltas.size() + " rawContactDelta(s)");
    for (int j = 0; j < rawContactDeltas.size(); j++) {
        final RawContactDelta rawContactDelta = rawContactDeltas.get(j);
        vlog("parse: " + j + " rawContactDelta" + rawContactDelta);
        if (rawContactDelta == null || !rawContactDelta.isVisible())
            continue;
        final AccountType accountType = rawContactDelta.getAccountType(mAccountTypeManager);
        if (accountType == null)
            continue;
        final List<DataKind> dataKinds = accountType.getSortedDataKinds();
        final int dataKindSize = dataKinds == null ? 0 : dataKinds.size();
        vlog("parse: " + dataKindSize + " dataKinds(s)");
        for (int i = 0; i < dataKindSize; i++) {
            final DataKind dataKind = dataKinds.get(i);
            if (dataKind == null || !dataKind.editable) {
                vlog("parse: " + i + " " + dataKind.mimeType + " dropped read-only");
                continue;
            }
            final String mimeType = dataKind.mimeType;
            // Skip psuedo mime types
            if (DataKind.PSEUDO_MIME_TYPE_DISPLAY_NAME.equals(mimeType) || DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME.equals(mimeType)) {
                vlog("parse: " + i + " " + dataKind.mimeType + " dropped pseudo type");
                continue;
            }
            final KindSectionDataList kindSectionDataList = getOrCreateKindSectionDataList(mimeType);
            final KindSectionData kindSectionData = new KindSectionData(accountType, dataKind, rawContactDelta);
            kindSectionDataList.add(kindSectionData);
            vlog("parse: " + i + " " + dataKind.mimeType + " " + kindSectionData.getValuesDeltas().size() + " value(s) " + kindSectionData.getNonEmptyValuesDeltas().size() + " non-empty value(s) " + kindSectionData.getVisibleValuesDeltas().size() + " visible value(s)");
        }
    }
}
Also used : DataKind(com.android.contacts.common.model.dataitem.DataKind) RawContactDelta(com.android.contacts.common.model.RawContactDelta) AccountType(com.android.contacts.common.model.account.AccountType)

Example 49 with DataKind

use of com.android.contacts.common.model.dataitem.DataKind in project packages_apps_Contacts by AOKP.

the class CompactKindSectionView method updateEmptyNonNameEditors.

private void updateEmptyNonNameEditors(boolean shouldAnimate) {
    // Prune excess empty editors
    final List<View> emptyEditors = getEmptyEditors();
    if (emptyEditors.size() > 1) {
        // If there is more than 1 empty editor, then remove it from the list of editors.
        int deleted = 0;
        for (final View view : emptyEditors) {
            // there is more values delta so we must also count number of editors deleted.
            if (view.findFocus() == null) {
                deleteView(view, shouldAnimate);
                deleted++;
                if (deleted == emptyEditors.size() - 1)
                    break;
            }
        }
        return;
    }
    // Determine if we should add a new empty editor
    final DataKind dataKind = mKindSectionDataList.get(0).getDataKind();
    final RawContactDelta rawContactDelta = mKindSectionDataList.get(0).getRawContactDelta();
    if (// There is nothing we can do.
    dataKind == null || // We have already reached the maximum number of editors, don't add any more.
    !RawContactModifier.canInsert(rawContactDelta, dataKind) || // We have already reached the maximum number of empty editors, don't add any more.
    emptyEditors.size() == 1) {
        return;
    }
    // Add a new empty editor
    if (mShowOneEmptyEditor) {
        final String mimeType = mKindSectionDataList.getMimeType();
        if (Nickname.CONTENT_ITEM_TYPE.equals(mimeType) && mEditors.getChildCount() > 0) {
            return;
        }
        final ValuesDelta values = RawContactModifier.insertChild(rawContactDelta, dataKind);
        final Editor.EditorListener editorListener = Event.CONTENT_ITEM_TYPE.equals(mimeType) ? new EventEditorListener() : new NonNameEditorListener();
        final View view = addNonNameEditorView(rawContactDelta, dataKind, values, editorListener);
        showView(view, shouldAnimate);
    }
}
Also used : ValuesDelta(com.android.contacts.common.model.ValuesDelta) DataKind(com.android.contacts.common.model.dataitem.DataKind) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) RawContactDelta(com.android.contacts.common.model.RawContactDelta)

Example 50 with DataKind

use of com.android.contacts.common.model.dataitem.DataKind in project packages_apps_Contacts by AOKP.

the class EventFieldEditorView method onLabelRebuilt.

@Override
protected void onLabelRebuilt() {
    // if we changed to a type that requires a year, ensure that it is actually set
    final String column = getKind().fieldList.get(0).column;
    final String oldValue = getEntry().getAsString(column);
    final DataKind kind = getKind();
    final Calendar calendar = Calendar.getInstance(DateUtils.UTC_TIMEZONE, Locale.US);
    final int defaultYear = calendar.get(Calendar.YEAR);
    // Check whether the year is optional
    final boolean isYearOptional = getType() != null && getType().isYearOptional();
    if (!isYearOptional && !TextUtils.isEmpty(oldValue)) {
        final ParsePosition position = new ParsePosition(0);
        final Date date2 = kind.dateFormatWithoutYear.parse(oldValue, position);
        // Don't understand the date, lets not change it
        if (date2 == null)
            return;
        // This value is missing the year. Add it now
        calendar.setTime(date2);
        calendar.set(defaultYear, calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), CommonDateUtils.DEFAULT_HOUR, 0, 0);
        onFieldChanged(column, kind.dateFormatWithYear.format(calendar.getTime()));
        rebuildDateView();
    }
}
Also used : DataKind(com.android.contacts.common.model.dataitem.DataKind) Calendar(java.util.Calendar) Date(java.util.Date) ParsePosition(java.text.ParsePosition)

Aggregations

DataKind (com.android.contacts.common.model.dataitem.DataKind)50 ContentValues (android.content.ContentValues)8 ValuesDelta (com.android.contacts.common.model.ValuesDelta)5 RawContactDelta (com.android.contacts.common.model.RawContactDelta)3 AccountType (com.android.contacts.common.model.account.AccountType)3 Calendar (java.util.Calendar)3 Intent (android.content.Intent)2 Resources (android.content.res.Resources)2 Drawable (android.graphics.drawable.Drawable)2 SpannableString (android.text.SpannableString)2 EmailDataItem (com.android.contacts.common.model.dataitem.EmailDataItem)2 EventDataItem (com.android.contacts.common.model.dataitem.EventDataItem)2 GroupMembershipDataItem (com.android.contacts.common.model.dataitem.GroupMembershipDataItem)2 ImDataItem (com.android.contacts.common.model.dataitem.ImDataItem)2 NicknameDataItem (com.android.contacts.common.model.dataitem.NicknameDataItem)2 NoteDataItem (com.android.contacts.common.model.dataitem.NoteDataItem)2 OrganizationDataItem (com.android.contacts.common.model.dataitem.OrganizationDataItem)2 PhoneDataItem (com.android.contacts.common.model.dataitem.PhoneDataItem)2 RelationDataItem (com.android.contacts.common.model.dataitem.RelationDataItem)2 SipAddressDataItem (com.android.contacts.common.model.dataitem.SipAddressDataItem)2