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; }
@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(); }
protected DirectoryPartition createDefaultDirectoryPartition() { DirectoryPartition partition = new DirectoryPartition(true, true); partition.setDirectoryId(Directory.DEFAULT); partition.setDirectoryType(getContext().getString(R.string.contactsList)); partition.setPriorityDirectory(true); partition.setPhotoSupported(true); partition.setLabel(mDefaultFilterHeaderText.toString()); return partition; }
/** * Marks all partitions as "loading" */ public void onDataReload() { boolean notify = false; int count = getPartitionCount(); for (int i = 0; i < count; i++) { Partition partition = getPartition(i); if (partition instanceof DirectoryPartition) { DirectoryPartition directoryPartition = (DirectoryPartition)partition; if (!directoryPartition.isLoading()) { notify = true; } directoryPartition.setStatus(DirectoryPartition.STATUS_NOT_LOADED); } } if (notify) { notifyDataSetChanged(); } }
directoryIds.add(id); if (getPartitionByDirectoryId(id) == -1) { DirectoryPartition partition = new DirectoryPartition(false, true); partition.setDirectoryId(id); if (DirectoryCompat.isRemoteDirectoryId(id)) { if (DirectoryCompat.isEnterpriseDirectoryId(id)) { partition.setLabel(mContext.getString(R.string.directory_search_label_work)); } else { partition.setLabel(mContext.getString(R.string.directory_search_label)); partition.setLabel(mContext.getString(R.string.list_filter_phones_work)); } else { partition.setLabel(mDefaultFilterHeaderText.toString()); partition.setDirectoryType(cursor.getString(directoryTypeColumnIndex)); partition.setDisplayName(cursor.getString(displayNameColumnIndex)); int photoSupport = cursor.getInt(photoSupportColumnIndex); partition.setPhotoSupported(photoSupport == Directory.PHOTO_SUPPORT_THUMBNAIL_ONLY || photoSupport == Directory.PHOTO_SUPPORT_FULL); addPartition(partition); Partition partition = getPartition(i); if (partition instanceof DirectoryPartition) { long id = ((DirectoryPartition)partition).getDirectoryId(); if (!directoryIds.contains(id)) { removePartition(i);
@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()); }
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); } }
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; if (getPartitionByDirectoryId(id) == -1) { addPartition(insertIndex, directory); directory.setDirectoryId(id);
protected void startLoading() { if (mAdapter == null) { // The method was called before the fragment was started return; } configureAdapter(); int partitionCount = mAdapter.getPartitionCount(); for (int i = 0; i < partitionCount; i++) { Partition partition = mAdapter.getPartition(i); if (partition instanceof DirectoryPartition) { DirectoryPartition directoryPartition = (DirectoryPartition)partition; if (directoryPartition.getStatus() == DirectoryPartition.STATUS_NOT_LOADED) { if (directoryPartition.isPriorityDirectory() || !mLoadPriorityDirectoriesOnly) { startLoadingDirectoryPartition(i); } } } else { getLoaderManager().initLoader(i, null, this); } } // Next time this method is called, we should start loading non-priority directories mLoadPriorityDirectoriesOnly = false; }
public boolean isLoading() { int count = getPartitionCount(); for (int i = 0; i < count; i++) { Partition partition = getPartition(i); if (partition instanceof DirectoryPartition && ((DirectoryPartition) partition).isLoading()) { return true; } } return false; }
public int getDirectoryResultLimit(DirectoryPartition directoryPartition) { final int limit = directoryPartition.getResultLimit(); return limit == DirectoryPartition.RESULT_LIMIT_DEFAULT ? mDirectoryResultLimit : limit; }
final String contentUri = directory.getContentUri(); if (contentUri == null) { throw new IllegalStateException("Extended directory must have a content URL: "
bindPhoneNumber(view, cursor, directory.isDisplayNumber(), position);
public Uri getFirstContactUri() { int partitionCount = getPartitionCount(); for (int i = 0; i < partitionCount; i++) { DirectoryPartition partition = (DirectoryPartition) getPartition(i); if (partition.isLoading()) { continue; } Cursor cursor = getCursor(i); if (cursor == null) { continue; } if (!cursor.moveToFirst()) { continue; } return getContactUri(i, cursor); } return null; }
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; }
final DirectoryPartition partition = (DirectoryPartition) getPartition(getPartitionForPosition(position)); final long directoryId = partition.getDirectoryId(); final boolean isExtendedDirectory = isExtendedDirectory(directoryId); final String sourceName = partition.getLabel(); if (isExtendedDirectory) { cacheInfo.setExtendedSource(sourceName, directoryId);
/** * 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); } }