public Uri getContactUri(int partitionIndex, Cursor cursor) { long contactId = cursor.getLong(ContactQuery.CONTACT_ID); String lookupKey = cursor.getString(ContactQuery.CONTACT_LOOKUP_KEY); Uri uri = Contacts.getLookupUri(contactId, lookupKey); long directoryId = ((DirectoryPartition)getPartition(partitionIndex)).getDirectoryId(); if (uri != null && directoryId != Directory.DEFAULT) { uri = uri.buildUpon().appendQueryParameter( ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(directoryId)).build(); } return uri; }
protected Uri getContactUri(int partitionIndex, Cursor cursor, int contactIdColumn, int lookUpKeyColumn) { long contactId = cursor.getLong(contactIdColumn); String lookupKey = cursor.getString(lookUpKeyColumn); long directoryId = ((DirectoryPartition)getPartition(partitionIndex)).getDirectoryId(); Uri uri = Contacts.getLookupUri(contactId, lookupKey); if (uri != null && directoryId != Directory.DEFAULT) { uri = uri.buildUpon().appendQueryParameter( ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(directoryId)).build(); } return uri; }
/** * Loads the directory partition. */ protected void loadDirectoryPartition(int partitionIndex, DirectoryPartition partition) { Bundle args = new Bundle(); args.putLong(DIRECTORY_ID_ARG_KEY, partition.getDirectoryId()); getLoaderManager().restartLoader(partitionIndex, args, this); }
protected int getPartitionByDirectoryId(long id) { int count = getPartitionCount(); for (int i = 0; i < count; i++) { Partition partition = getPartition(i); if (partition instanceof DirectoryPartition) { if (((DirectoryPartition)partition).getDirectoryId() == id) { return i; } } } return -1; }
protected DirectoryPartition getDirectoryById(long id) { int count = getPartitionCount(); for (int i = 0; i < count; i++) { Partition partition = getPartition(i); if (partition instanceof DirectoryPartition) { final DirectoryPartition directoryPartition = (DirectoryPartition) partition; if (directoryPartition.getDirectoryId() == id) { return directoryPartition; } } } return null; }
public Uri getDataUri(int partitionIndex, Cursor cursor) { final long directoryId = ((DirectoryPartition)getPartition(partitionIndex)).getDirectoryId(); if (DirectoryCompat.isRemoteDirectoryId(directoryId)) { return null; } else if (DirectoryCompat.isEnterpriseDirectoryId(directoryId)) { /* * ContentUris.withAppendedId(Data.CONTENT_URI, phoneId), is invalid if * isEnterpriseDirectoryId returns true, because the uri itself will fail since the * ContactsProvider in Android Framework currently doesn't support it. return null until * Android framework has enterprise version of Data.CONTENT_URI */ return null; } else { final long phoneId = cursor.getLong(PhoneQuery.PHONE_ID); return ContentUris.withAppendedId(Data.CONTENT_URI, phoneId); } }
@Override protected Uri getContactUri(int partitionIndex, Cursor cursor, int contactIdColumn, int lookUpKeyColumn) { final DirectoryPartition directory = (DirectoryPartition) getPartition(partitionIndex); final long directoryId = directory.getDirectoryId(); if (!isExtendedDirectory(directoryId)) { return super.getContactUri(partitionIndex, cursor, contactIdColumn, lookUpKeyColumn); } return Contacts.CONTENT_LOOKUP_URI.buildUpon() .appendPath(Constants.LOOKUP_URI_ENCODED) .appendQueryParameter(Directory.DISPLAY_NAME, directory.getLabel()) .appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(directoryId)) .encodedFragment(cursor.getString(lookUpKeyColumn)) .build(); }
/** * Returns true if the specified contact is selected in the list. For a * contact to be shown as selected, we need both the directory and and the * lookup key to be the same. We are paying no attention to the contactId, * because it is volatile, especially in the case of directories. */ public boolean isSelectedContact(int partitionIndex, Cursor cursor) { long directoryId = ((DirectoryPartition)getPartition(partitionIndex)).getDirectoryId(); if (getSelectedContactDirectoryId() != directoryId) { return false; } String lookupKey = getSelectedContactLookupKey(); if (lookupKey != null && TextUtils.equals(lookupKey, cursor.getString(ContactQuery.CONTACT_LOOKUP_KEY))) { return true; } return directoryId != Directory.DEFAULT && directoryId != Directory.LOCAL_INVISIBLE && getSelectedContactId() == cursor.getLong(ContactQuery.CONTACT_ID); }
protected void bindWorkProfileIcon(final ContactListItemView view, int partitionId) { final Partition partition = getPartition(partitionId); if (partition instanceof DirectoryPartition) { final DirectoryPartition directoryPartition = (DirectoryPartition) partition; final long directoryId = directoryPartition.getDirectoryId(); final long userType = ContactsUtils.determineUserType(directoryId, null); view.setWorkProfileIconEnabled(userType == ContactsUtils.USER_TYPE_WORK); } }
@Override protected void bindWorkProfileIcon(final ContactListItemView view, int partition) { final DirectoryPartition directory = (DirectoryPartition) getPartition(partition); final long directoryId = directory.getDirectoryId(); final long userType = ContactsUtils.determineUserType(directoryId, null); // Work directory must not be a extended directory. An extended directory is custom // directory in the app, but not a directory provided by framework. So it can't be // USER_TYPE_WORK. view.setWorkProfileIconEnabled( !isExtendedDirectory(directoryId) && userType == ContactsUtils.USER_TYPE_WORK); }
/** * Remove all directories after the default directory. This is typically used when contacts * list screens are asked to exit the search mode and thus need to remove all remote directory * results for the search. * * This code assumes that the default directory and directories before that should not be * deleted (e.g. Join screen has "suggested contacts" directory before the default director, * and we should not remove the directory). */ public void removeDirectoriesAfterDefault() { final int partitionCount = getPartitionCount(); for (int i = partitionCount - 1; i >= 0; i--) { final Partition partition = getPartition(i); if ((partition instanceof DirectoryPartition) && ((DirectoryPartition) partition).getDirectoryId() == Directory.DEFAULT) { break; } else { removePartition(i); } } }
private void startLoadingDirectoryPartition(int partitionIndex) { DirectoryPartition partition = (DirectoryPartition)mAdapter.getPartition(partitionIndex); partition.setStatus(DirectoryPartition.STATUS_LOADING); long directoryId = partition.getDirectoryId(); if (mForceLoad) { if (directoryId == Directory.DEFAULT) { loadDirectoryPartition(partitionIndex, partition); } else { loadDirectoryPartitionDelayed(partitionIndex, partition); } } else { Bundle args = new Bundle(); args.putLong(DIRECTORY_ID_ARG_KEY, directoryId); getLoaderManager().initLoader(partitionIndex, args, this); } }
@Override protected void bindHeaderView(View view, int partitionIndex, Cursor cursor) { Partition partition = getPartition(partitionIndex); if (!(partition instanceof DirectoryPartition)) { return; } DirectoryPartition directoryPartition = (DirectoryPartition)partition; long directoryId = directoryPartition.getDirectoryId(); TextView labelTextView = (TextView)view.findViewById(R.id.label); TextView displayNameTextView = (TextView)view.findViewById(R.id.display_name); labelTextView.setText(directoryPartition.getLabel()); if (!DirectoryCompat.isRemoteDirectoryId(directoryId)) { displayNameTextView.setText(null); } else { String directoryName = directoryPartition.getDisplayName(); String displayName = !TextUtils.isEmpty(directoryName) ? directoryName : directoryPartition.getDirectoryType(); displayNameTextView.setText(displayName); } final Resources res = getContext().getResources(); final int headerPaddingTop = partitionIndex == 1 && getPartition(0).isEmpty()? 0 : res.getDimensionPixelOffset(R.dimen.directory_header_extra_top_padding); // There should be no extra padding at the top of the first directory header view.setPaddingRelative(view.getPaddingStart(), headerPaddingTop, view.getPaddingEnd(), view.getPaddingBottom()); }
for (int i = 0; i < partitionCount; i++) { DirectoryPartition partition = (DirectoryPartition) getPartition(i); if (partition.getDirectoryId() == mSelectedContactDirectoryId) { partitionIndex = i; break;
/** * Changes visibility parameters for the default directory partition. */ public void configureDefaultPartition(boolean showIfEmpty, boolean hasHeader) { int defaultPartitionIndex = -1; int count = getPartitionCount(); for (int i = 0; i < count; i++) { Partition partition = getPartition(i); if (partition instanceof DirectoryPartition && ((DirectoryPartition)partition).getDirectoryId() == Directory.DEFAULT) { defaultPartitionIndex = i; break; } } if (defaultPartitionIndex != -1) { setShowIfEmpty(defaultPartitionIndex, showIfEmpty); setHasHeader(defaultPartitionIndex, hasHeader); } }
Partition partition = getPartition(i); if (partition instanceof DirectoryPartition) { long id = ((DirectoryPartition)partition).getDirectoryId(); if (!directoryIds.contains(id)) { removePartition(i);
final DirectoryPartition partition = (DirectoryPartition) getPartition(getPartitionForPosition(position)); final long directoryId = partition.getDirectoryId(); final boolean isExtendedDirectory = isExtendedDirectory(directoryId);
for (int i = 0, n = getPartitionCount(); i < n; i++) { final DirectoryPartition partition = (DirectoryPartition) getPartition(i); final long id = partition.getDirectoryId(); if (id > maxId) { maxId = id;