/** Constructor. */ public SplitAggregateView(Context context, Uri aggregateUri) { super(context); mAggregateUri = aggregateUri; mSources = Sources.getInstance(context); final List<RawContactInfo> list = loadData(); setAdapter(new SplitAggregateAdapter(context, list)); setOnItemClickListener( new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mListener.onContactSelected(list.get(position).rawContactId); } }); }
/** Handle the result from the {@link #TOKEN_DATA} query. */ private void handleData(Cursor cursor) { if (cursor == null) return; if (!isMimeExcluded(Contacts.CONTENT_ITEM_TYPE)) { // Add the profile shortcut action final Action action = new ProfileAction(mContext, mLookupUri); mActions.collect(Contacts.CONTENT_ITEM_TYPE, action); } final DataStatus status = new DataStatus(); final Sources sources = Sources.getInstance(mContext); final ImageView photoView = (ImageView) mHeader.findViewById(R.id.photo); Bitmap photoBitmap = null; while (cursor.moveToNext()) { final long dataId = cursor.getLong(DataQuery._ID); final String accountType = cursor.getString(DataQuery.ACCOUNT_TYPE); final String mimeType = cursor.getString(DataQuery.MIMETYPE); // Handle any social status updates from this row status.possibleUpdate(cursor); // Skip this data item if MIME-type excluded if (isMimeExcluded(mimeType)) continue; // Handle photos included as data row if (Photo.CONTENT_ITEM_TYPE.equals(mimeType)) { final int colPhoto = cursor.getColumnIndex(Photo.PHOTO); final byte[] photoBlob = cursor.getBlob(colPhoto); if (photoBlob != null) { photoBitmap = BitmapFactory.decodeByteArray(photoBlob, 0, photoBlob.length); } continue; } final DataKind kind = sources.getKindOrFallback( accountType, mimeType, mContext, ContactsSource.LEVEL_MIMETYPES); if (kind != null) { // Build an action for this data entry, find a mapping to a UI // element, build its summary from the cursor, and collect it // along with all others of this MIME-type. final Action action = new DataAction(mContext, mimeType, kind, dataId, cursor); considerAdd(action, mimeType); } // If phone number, also insert as text message action if (Phone.CONTENT_ITEM_TYPE.equals(mimeType) && kind != null) { final Action action = new DataAction(mContext, Constants.MIME_SMS_ADDRESS, kind, dataId, cursor); considerAdd(action, Constants.MIME_SMS_ADDRESS); } // Handle Email rows with presence data as Im entry final boolean hasPresence = !cursor.isNull(DataQuery.PRESENCE); if (hasPresence && Email.CONTENT_ITEM_TYPE.equals(mimeType)) { final DataKind imKind = sources.getKindOrFallback( accountType, Im.CONTENT_ITEM_TYPE, mContext, ContactsSource.LEVEL_MIMETYPES); if (imKind != null) { final Action action = new DataAction(mContext, Im.CONTENT_ITEM_TYPE, imKind, dataId, cursor); considerAdd(action, Im.CONTENT_ITEM_TYPE); } } } if (cursor.moveToLast()) { // Read contact information from last data row final String name = cursor.getString(DataQuery.DISPLAY_NAME); final int presence = cursor.getInt(DataQuery.CONTACT_PRESENCE); final Drawable statusIcon = getPresenceIcon(presence); setHeaderText(R.id.name, name); setHeaderImage(R.id.presence, statusIcon); } if (photoView != null) { // Place photo when discovered in data, otherwise hide photoView.setVisibility(photoBitmap != null ? View.VISIBLE : View.GONE); photoView.setImageBitmap(photoBitmap); } mHasValidSocial = status.isValid(); if (mHasValidSocial && mMode != QuickContact.MODE_SMALL) { // Update status when valid was found setHeaderText(R.id.status, status.getStatus()); setHeaderText(R.id.timestamp, status.getTimestampLabel(mContext)); } // Turn our list of actions into UI elements, starting with common types final Set<String> containedTypes = mActions.keySet(); for (String mimeType : ORDERED_MIMETYPES) { if (containedTypes.contains(mimeType)) { final int index = mTrack.getChildCount() - 1; mTrack.addView(inflateAction(mimeType), index); containedTypes.remove(mimeType); } } // Then continue with remaining MIME-types in alphabetical order final String[] remainingTypes = containedTypes.toArray(new String[containedTypes.size()]); Arrays.sort(remainingTypes); for (String mimeType : remainingTypes) { final int index = mTrack.getChildCount() - 1; mTrack.addView(inflateAction(mimeType), index); } }