public class BaseRecipientAdapter extends BaseAdapter implements Filterable, AccountSpecifier, PhotoManager.PhotoManagerCallback
It checks whether all permissions are granted before doing
query. If not all permissions in ChipsUtil.REQUIRED_PERMISSIONS
are granted and
mShowRequestPermissionsItem
is true it will return single entry that asks user to grant
permissions to the app. Any app that uses this library should set this when it wants us to
display that entry but then it should set
RecipientEditTextView.PermissionsRequestItemClickedListener
on
RecipientEditTextView
as well.
Modifier and Type | Class and Description |
---|---|
protected class |
BaseRecipientAdapter.DirectoryFilter
An asynchronous filter that performs search in a particular directory.
|
protected static class |
BaseRecipientAdapter.DirectoryListQuery |
static class |
BaseRecipientAdapter.DirectorySearchParams
Model object for a
ContactsContract.Directory row. |
static interface |
BaseRecipientAdapter.EntriesUpdatedObserver |
protected static class |
BaseRecipientAdapter.TemporaryEntry
Used to temporarily hold results in Cursor objects.
|
Modifier and Type | Field and Description |
---|---|
protected CharSequence |
mCurrentConstraint
Used to ignore asynchronous queries with a different constraint, which may happen when
users type characters quickly.
|
protected int |
mPreferredMaxResultCount |
protected boolean |
mShowRequestPermissionsItem |
static int |
QUERY_TYPE_EMAIL |
static int |
QUERY_TYPE_PHONE |
IGNORE_ITEM_VIEW_TYPE, NO_SELECTION
Constructor and Description |
---|
BaseRecipientAdapter(Context context)
Constructor for email queries.
|
BaseRecipientAdapter(Context context,
int preferredMaxResultCount) |
BaseRecipientAdapter(Context context,
int preferredMaxResultCount,
int queryMode) |
BaseRecipientAdapter(int queryMode,
Context context) |
BaseRecipientAdapter(int queryMode,
Context context,
int preferredMaxResultCount) |
Modifier and Type | Method and Description |
---|---|
protected void |
cacheCurrentEntries() |
protected void |
cacheCurrentEntriesIfNeeded(int newEntryCount,
int paramListCount)
If there are no local results and we are searching alternate results,
in the new result set, cache off what had been shown to the user for use until
the first directory result is returned
|
protected void |
clearTempEntries() |
protected List<RecipientEntry> |
constructEntryList()
Returns the actual list to use for this Adapter.
|
protected void |
fetchPhoto(RecipientEntry entry,
PhotoManager.PhotoManagerCallback cb) |
boolean |
forceShowAddress()
If true, forces using the
SingleRecipientArrayAdapter
instead of RecipientAlternatesAdapter when
clicking on a chip. |
Account |
getAccount() |
Context |
getContext() |
int |
getCount()
How many items are in the data set represented by this Adapter.
|
DropdownChipLayouter |
getDropdownChipLayouter() |
protected List<RecipientEntry> |
getEntries() |
Filter |
getFilter()
Will be called from
AutoCompleteTextView to prepare auto-complete list. |
RecipientEntry |
getItem(int position)
Get the data item associated with the specified position in the data set.
|
long |
getItemId(int position)
Get the row id associated with the specified position in the list.
|
int |
getItemViewType(int position)
Get the type of View that will be created by
Adapter.getView(int, android.view.View, android.view.ViewGroup) for the specified item. |
void |
getMatchingRecipients(ArrayList<String> inAddresses,
RecipientAlternatesAdapter.RecipientMatchCallback callback)
Used to replace email addresses with chips.
|
Map<String,RecipientEntry> |
getMatchingRecipients(Set<String> addresses)
An extension to
RecipientAlternatesAdapter.getMatchingRecipients(android.content.Context, com.android.ex.chips.BaseRecipientAdapter, java.util.ArrayList<java.lang.String>, Account, com.android.ex.chips.RecipientAlternatesAdapter.RecipientMatchCallback, com.android.ex.chips.ChipsUtil.PermissionsCheckListener) that allows
additional sources of contacts to be considered as matching recipients. |
ChipsUtil.PermissionsCheckListener |
getPermissionsCheckListener() |
PhotoManager |
getPhotoManager() |
int |
getQueryType() |
String[] |
getRequiredPermissions()
Returns permissions that this adapter needs in order to provide results.
|
View |
getView(int position,
View convertView,
ViewGroup parent)
Get a View that displays the data at the specified position in the data set.
|
int |
getViewTypeCount()
Returns the number of types of Views that will be created by
Adapter.getView(int, android.view.View, android.view.ViewGroup) . |
boolean |
isEnabled(int position)
Returns true if the item at the specified position is not a separator.
|
void |
onPhotoBytesAsynchronouslyPopulated() |
void |
onPhotoBytesAsyncLoadFailed() |
void |
onPhotoBytesPopulated() |
protected void |
putOneEntry(BaseRecipientAdapter.TemporaryEntry entry,
boolean isAggregatedEntry)
Called whenever
BaseRecipientAdapter.DirectoryFilter
wants to add an additional entry to the results. |
void |
registerUpdateObserver(BaseRecipientAdapter.EntriesUpdatedObserver observer) |
protected List<BaseRecipientAdapter.DirectorySearchParams> |
searchOtherDirectories(Set<String> existingDestinations)
Returns the list of models for directory search (using
BaseRecipientAdapter.DirectoryFilter ) or
null when we don't need or can't search other directories. |
void |
setAccount(Account account)
Set the account when known.
|
void |
setDropdownChipLayouter(DropdownChipLayouter dropdownChipLayouter) |
void |
setPermissionsCheckListener(ChipsUtil.PermissionsCheckListener permissionsCheckListener) |
void |
setPhotoManager(PhotoManager photoManager)
Enables overriding the default photo manager that is used.
|
void |
setShowRequestPermissionsItem(boolean show)
Sets whether to ask user to grant permission if they are missing.
|
static List<BaseRecipientAdapter.DirectorySearchParams> |
setupOtherDirectories(Context context,
Cursor directoryCursor,
Account account) |
protected void |
startSearchOtherDirectories(CharSequence constraint,
List<BaseRecipientAdapter.DirectorySearchParams> paramsList,
int limit)
Starts search in other directories using
Filter . |
protected void |
updateEntries(List<RecipientEntry> newEntries)
Resets
mEntries and notify the event to its parent ListView. |
areAllItemsEnabled, getDropDownView, hasStableIds, isEmpty, notifyDataSetChanged, notifyDataSetInvalidated, registerDataSetObserver, unregisterDataSetObserver
public static final int QUERY_TYPE_EMAIL
public static final int QUERY_TYPE_PHONE
protected final int mPreferredMaxResultCount
protected CharSequence mCurrentConstraint
protected boolean mShowRequestPermissionsItem
public BaseRecipientAdapter(Context context)
public BaseRecipientAdapter(Context context, int preferredMaxResultCount)
public BaseRecipientAdapter(int queryMode, Context context)
public BaseRecipientAdapter(int queryMode, Context context, int preferredMaxResultCount)
public BaseRecipientAdapter(Context context, int preferredMaxResultCount, int queryMode)
protected List<BaseRecipientAdapter.DirectorySearchParams> searchOtherDirectories(Set<String> existingDestinations)
BaseRecipientAdapter.DirectoryFilter
) or
null
when we don't need or can't search other directories.public Context getContext()
public int getQueryType()
public void setDropdownChipLayouter(DropdownChipLayouter dropdownChipLayouter)
public DropdownChipLayouter getDropdownChipLayouter()
public void setPermissionsCheckListener(ChipsUtil.PermissionsCheckListener permissionsCheckListener)
@Nullable public ChipsUtil.PermissionsCheckListener getPermissionsCheckListener()
public void setPhotoManager(PhotoManager photoManager)
public PhotoManager getPhotoManager()
public boolean forceShowAddress()
SingleRecipientArrayAdapter
instead of RecipientAlternatesAdapter
when
clicking on a chip. Default implementation returns false
.public void getMatchingRecipients(ArrayList<String> inAddresses, RecipientAlternatesAdapter.RecipientMatchCallback callback)
inAddresses
- addresses to querycallback
- callback to return results in case of success or failurepublic void setAccount(Account account)
setAccount
in interface AccountSpecifier
public String[] getRequiredPermissions()
public void setShowRequestPermissionsItem(boolean show)
public Filter getFilter()
AutoCompleteTextView
to prepare auto-complete list.getFilter
in interface Filterable
public Map<String,RecipientEntry> getMatchingRecipients(Set<String> addresses)
RecipientAlternatesAdapter.getMatchingRecipients(android.content.Context, com.android.ex.chips.BaseRecipientAdapter, java.util.ArrayList<java.lang.String>, Account, com.android.ex.chips.RecipientAlternatesAdapter.RecipientMatchCallback, com.android.ex.chips.ChipsUtil.PermissionsCheckListener)
that allows
additional sources of contacts to be considered as matching recipients.addresses
- A set of addresses to be matchedpublic static List<BaseRecipientAdapter.DirectorySearchParams> setupOtherDirectories(Context context, Cursor directoryCursor, Account account)
protected void startSearchOtherDirectories(CharSequence constraint, List<BaseRecipientAdapter.DirectorySearchParams> paramsList, int limit)
Filter
. Results will be handled in
BaseRecipientAdapter.DirectoryFilter
.protected void putOneEntry(BaseRecipientAdapter.TemporaryEntry entry, boolean isAggregatedEntry)
BaseRecipientAdapter.DirectoryFilter
wants to add an additional entry to the results. Derived classes should override
this method if they are not using the default data structures provided by
BaseRecipientAdapter
and are instead using their
own data structures to store and collate data.entry
- the entry being addedisAggregatedEntry
- protected List<RecipientEntry> constructEntryList()
public void registerUpdateObserver(BaseRecipientAdapter.EntriesUpdatedObserver observer)
protected void updateEntries(List<RecipientEntry> newEntries)
mEntries
and notify the event to its parent ListView.protected void cacheCurrentEntriesIfNeeded(int newEntryCount, int paramListCount)
newEntryCount
- number of newly loaded entriesparamListCount
- number of alternate filters it will search (including the current one).protected void cacheCurrentEntries()
protected void clearTempEntries()
protected List<RecipientEntry> getEntries()
protected void fetchPhoto(RecipientEntry entry, PhotoManager.PhotoManagerCallback cb)
public int getCount()
Adapter
public RecipientEntry getItem(int position)
Adapter
public long getItemId(int position)
Adapter
public int getViewTypeCount()
Adapter
Returns the number of types of Views that will be created by
Adapter.getView(int, android.view.View, android.view.ViewGroup)
. Each type represents a set of views that can be
converted in Adapter.getView(int, android.view.View, android.view.ViewGroup)
. If the adapter always returns the same
type of View for all items, this method should return 1.
This method will only be called when the adapter is set on the AdapterView
.
getViewTypeCount
in interface Adapter
getViewTypeCount
in class BaseAdapter
public int getItemViewType(int position)
Adapter
Adapter.getView(int, android.view.View, android.view.ViewGroup)
for the specified item.getItemViewType
in interface Adapter
getItemViewType
in class BaseAdapter
position
- The position of the item within the adapter's data set whose view type we
want.Adapter.getView(int, android.view.View, android.view.ViewGroup)
. Note: Integers must be in the
range 0 to Adapter.getViewTypeCount()
- 1. Adapter.IGNORE_ITEM_VIEW_TYPE
can
also be returned.Adapter.IGNORE_ITEM_VIEW_TYPE
public boolean isEnabled(int position)
ListAdapter
ArrayIndexOutOfBoundsException
should be thrown in that case for fast failure.isEnabled
in interface ListAdapter
isEnabled
in class BaseAdapter
position
- Index of the itemListAdapter.areAllItemsEnabled()
public View getView(int position, View convertView, ViewGroup parent)
Adapter
LayoutInflater.inflate(int, android.view.ViewGroup, boolean)
to specify a root view and to prevent attachment to the root.getView
in interface Adapter
position
- The position of the item within the adapter's data set of the item whose view
we want.convertView
- The old view to reuse, if possible. Note: You should check that this view
is non-null and of an appropriate type before using. If it is not possible to convert
this view to display the correct data, this method can create a new view.
Heterogeneous lists can specify their number of view types, so that this View is
always of the right type (see Adapter.getViewTypeCount()
and
Adapter.getItemViewType(int)
).parent
- The parent that this view will eventually be attached topublic Account getAccount()
public void onPhotoBytesPopulated()
onPhotoBytesPopulated
in interface PhotoManager.PhotoManagerCallback
public void onPhotoBytesAsynchronouslyPopulated()
onPhotoBytesAsynchronouslyPopulated
in interface PhotoManager.PhotoManagerCallback
public void onPhotoBytesAsyncLoadFailed()
onPhotoBytesAsyncLoadFailed
in interface PhotoManager.PhotoManagerCallback