summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chips/res/layout/chips_recipient_dropdown_item.xml33
-rw-r--r--chips/src/com/android/ex/chips/BaseRecipientAdapter.java88
-rw-r--r--chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java14
-rw-r--r--chips/src/com/android/ex/chips/RecipientEntry.java65
4 files changed, 141 insertions, 59 deletions
diff --git a/chips/res/layout/chips_recipient_dropdown_item.xml b/chips/res/layout/chips_recipient_dropdown_item.xml
index a8d2113..2fb16c2 100644
--- a/chips/res/layout/chips_recipient_dropdown_item.xml
+++ b/chips/res/layout/chips_recipient_dropdown_item.xml
@@ -26,16 +26,16 @@
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1">
- <TextView android:id="@android:id/text1"
+ <TextView android:id="@android:id/title"
android:textColor="@drawable/list_item_font_primary"
android:textSize="18sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dip"
android:singleLine="true"
- android:ellipsize="end"
+ android:ellipsize="end"
/>
- <TextView android:id="@android:id/text2"
+ <TextView android:id="@android:id/text1"
android:textColor="@drawable/list_item_font_secondary"
android:textSize="14sp"
android:layout_width="wrap_content"
@@ -44,11 +44,24 @@
android:singleLine="true"
android:ellipsize="end" />
</LinearLayout>
- <ImageView
- android:id="@android:id/icon"
- android:layout_width="48dip"
- android:layout_height="48dip"
- android:src="@drawable/ic_contact_picture"
- android:cropToPadding="true"
- android:scaleType="centerCrop" />
+ <LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:gravity="center_vertical|right">
+ <TextView
+ android:id="@android:id/text2"
+ android:textColor="@drawable/list_item_font_secondary"
+ android:textSize="12sp"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginRight="8dip" />
+ <ImageView
+ android:id="@android:id/icon"
+ android:layout_width="48dip"
+ android:layout_height="48dip"
+ android:src="@drawable/ic_contact_picture"
+ android:cropToPadding="true"
+ android:scaleType="centerCrop" />
+ </LinearLayout>
</LinearLayout>
diff --git a/chips/src/com/android/ex/chips/BaseRecipientAdapter.java b/chips/src/com/android/ex/chips/BaseRecipientAdapter.java
index f47666d..6e1f821 100644
--- a/chips/src/com/android/ex/chips/BaseRecipientAdapter.java
+++ b/chips/src/com/android/ex/chips/BaseRecipientAdapter.java
@@ -115,16 +115,21 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter
public static final String[] PROJECTION = {
Contacts.DISPLAY_NAME, // 0
Email.DATA, // 1
- Email.CONTACT_ID, // 2
- Email._ID, // 3
- Contacts.PHOTO_THUMBNAIL_URI // 4
+ Email.TYPE, // 2
+ Email.LABEL, // 3
+ Email.CONTACT_ID, // 4
+ Email._ID, // 5
+ Contacts.PHOTO_THUMBNAIL_URI // 6
+
};
public static final int NAME = 0;
public static final int ADDRESS = 1;
- public static final int CONTACT_ID = 2;
- public static final int DATA_ID = 3;
- public static final int PHOTO_THUMBNAIL_URI = 4;
+ public static final int ADDRESS_TYPE = 2;
+ public static final int ADDRESS_LABEL = 3;
+ public static final int CONTACT_ID = 4;
+ public static final int DATA_ID = 5;
+ public static final int PHOTO_THUMBNAIL_URI = 6;
}
private static class PhotoQuery {
@@ -160,14 +165,19 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter
private static class TemporaryEntry {
public final String displayName;
public final String destination;
+ public final int destinationType;
+ public final String destinationLabel;
public final long contactId;
public final long dataId;
public final String thumbnailUriString;
- public TemporaryEntry(String displayName, String destination,
+ public TemporaryEntry(String displayName,
+ String destination, int destinationType, String destinationLabel,
long contactId, long dataId, String thumbnailUriString) {
this.displayName = displayName;
this.destination = destination;
+ this.destinationType = destinationType;
+ this.destinationLabel = destinationLabel;
this.contactId = contactId;
this.dataId = dataId;
this.thumbnailUriString = thumbnailUriString;
@@ -603,6 +613,8 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter
private TemporaryEntry constructTemporaryEntryFromCursor(Cursor cursor) {
return new TemporaryEntry(cursor.getString(EmailQuery.NAME),
cursor.getString(EmailQuery.ADDRESS),
+ cursor.getInt(EmailQuery.ADDRESS_TYPE),
+ cursor.getString(EmailQuery.ADDRESS_LABEL),
cursor.getLong(EmailQuery.CONTACT_ID),
cursor.getLong(EmailQuery.DATA_ID),
cursor.getString(EmailQuery.PHOTO_THUMBNAIL_URI));
@@ -620,19 +632,22 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter
if (!isAggregatedEntry) {
nonAggregatedEntries.add(RecipientEntry.constructTopLevelEntry(
- entry.displayName, entry.destination, entry.contactId, entry.dataId,
- entry.thumbnailUriString));
+ entry.displayName,
+ entry.destination, entry.destinationType, entry.destinationLabel,
+ entry.contactId, entry.dataId, entry.thumbnailUriString));
} else if (entryMap.containsKey(entry.contactId)) {
// We already have a section for the person.
final List<RecipientEntry> entryList = entryMap.get(entry.contactId);
entryList.add(RecipientEntry.constructSecondLevelEntry(
- entry.displayName, entry.destination, entry.contactId, entry.dataId,
- entry.thumbnailUriString));
+ entry.displayName,
+ entry.destination, entry.destinationType, entry.destinationLabel,
+ entry.contactId, entry.dataId, entry.thumbnailUriString));
} else {
final List<RecipientEntry> entryList = new ArrayList<RecipientEntry>();
entryList.add(RecipientEntry.constructTopLevelEntry(
- entry.displayName, entry.destination, entry.contactId, entry.dataId,
- entry.thumbnailUriString));
+ entry.displayName,
+ entry.destination, entry.destinationType, entry.destinationLabel,
+ entry.contactId, entry.dataId, entry.thumbnailUriString));
entryMap.put(entry.contactId, entryList);
}
}
@@ -845,26 +860,33 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter
}
default: {
String displayName = entry.getDisplayName();
- String emailAddress = entry.getDestination();
+ String destination = entry.getDestination();
if (TextUtils.isEmpty(displayName)
- || TextUtils.equals(displayName, emailAddress)) {
- displayName = emailAddress;
- emailAddress = null;
+ || TextUtils.equals(displayName, destination)) {
+ displayName = destination;
+ destination = null;
}
+ final CharSequence destinationType = Email.getTypeLabel(mContext.getResources(),
+ entry.getDestinationType(), entry.getDestinationLabel());
+
final View itemView = convertView != null ? convertView
: mInflater.inflate(getItemLayout(), parent, false);
final TextView displayNameView =
- (TextView)itemView.findViewById(getDisplayNameId());
- final TextView emailAddressView =
- (TextView)itemView.findViewById(getDestinationId());
+ (TextView) itemView.findViewById(getDisplayNameId());
+ final TextView destinationView =
+ (TextView) itemView.findViewById(getDestinationId());
+ final TextView destinationTypeView =
+ (TextView) itemView.findViewById(getDestinationTypeId());
final ImageView imageView = (ImageView)itemView.findViewById(getPhotoId());
displayNameView.setText(displayName);
- if (!TextUtils.isEmpty(emailAddress)) {
- emailAddressView.setText(emailAddress);
+ if (!TextUtils.isEmpty(destination)) {
+ destinationView.setText(destination);
} else {
- emailAddressView.setText(null);
+ destinationView.setText(null);
}
+ destinationTypeView.setText(destinationType);
+
if (entry.isFirstLevel()) {
displayNameView.setVisibility(View.VISIBLE);
if (imageView != null) {
@@ -880,7 +902,9 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter
}
} else {
displayNameView.setVisibility(View.GONE);
- if (imageView != null) imageView.setVisibility(View.GONE);
+ if (imageView != null) {
+ imageView.setVisibility(View.INVISIBLE);
+ }
}
return itemView;
}
@@ -913,19 +937,27 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter
protected abstract int getDefaultPhotoResource();
/**
- * Returns an id for TextView in an item View for showing a display name. In default
- * {@link android.R.id#text1} is returned.
+ * Returns an id for TextView in an item View for showing a display name. By default
+ * {@link android.R.id#title} is returned.
*/
protected int getDisplayNameId() {
- return android.R.id.text1;
+ return android.R.id.title;
}
/**
* Returns an id for TextView in an item View for showing a destination
* (an email address or a phone number).
- * In default {@link android.R.id#text2} is returned.
+ * By default {@link android.R.id#text1} is returned.
*/
protected int getDestinationId() {
+ return android.R.id.text1;
+ }
+
+ /**
+ * Returns an id for TextView in an item View for showing the type of the destination.
+ * By default {@link android.R.id#text2} is returned.
+ */
+ protected int getDestinationTypeId() {
return android.R.id.text2;
}
diff --git a/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java b/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java
index 2d45e4c..dd3672d 100644
--- a/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java
+++ b/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java
@@ -53,7 +53,7 @@ public class RecipientAlternatesAdapter extends CursorAdapter {
* may block the UI, so run it in an async task.
*
* @param context Context.
- * @param addresses Array of addresses on which to perform the lookup.
+ * @param inAddresses Array of addresses on which to perform the lookup.
* @return HashMap<String,RecipientEntry>
*/
public static HashMap<String, RecipientEntry> getMatchingRecipients(Context context,
@@ -75,9 +75,9 @@ public class RecipientAlternatesAdapter extends CursorAdapter {
Log.d(TAG, "Doing reverse lookup for " + addresses.toString());
}
+ HashMap<String, RecipientEntry> recipientEntries = new HashMap<String, RecipientEntry>();
Cursor c = context.getContentResolver().query(Email.CONTENT_URI, EmailQuery.PROJECTION,
Email.ADDRESS + " IN (" + bindString.toString() + ")", addresses, null);
- HashMap<String, RecipientEntry> recipientEntries = new HashMap<String, RecipientEntry>();
if (c != null) {
try {
if (c.moveToFirst()) {
@@ -86,6 +86,8 @@ public class RecipientAlternatesAdapter extends CursorAdapter {
recipientEntries.put(address, RecipientEntry.constructTopLevelEntry(
c.getString(EmailQuery.NAME),
c.getString(EmailQuery.ADDRESS),
+ c.getInt(EmailQuery.ADDRESS_TYPE),
+ c.getString(EmailQuery.ADDRESS_LABEL),
c.getLong(EmailQuery.CONTACT_ID),
c.getLong(EmailQuery.DATA_ID),
c.getString(EmailQuery.PHOTO_THUMBNAIL_URI)));
@@ -129,9 +131,11 @@ public class RecipientAlternatesAdapter extends CursorAdapter {
public RecipientEntry getRecipientEntry(int position) {
Cursor c = getCursor();
c.moveToPosition(position);
- return RecipientEntry.constructTopLevelEntry(c.getString(EmailQuery.NAME), c
- .getString(EmailQuery.ADDRESS), c.getLong(EmailQuery.CONTACT_ID), c
- .getLong(EmailQuery.DATA_ID), c.getString(EmailQuery.PHOTO_THUMBNAIL_URI));
+ return RecipientEntry.constructTopLevelEntry(c.getString(EmailQuery.NAME),
+ c.getString(EmailQuery.ADDRESS), c.getInt(EmailQuery.ADDRESS_TYPE),
+ c.getString(EmailQuery.ADDRESS_LABEL),
+ c.getLong(EmailQuery.CONTACT_ID), c.getLong(EmailQuery.DATA_ID),
+ c.getString(EmailQuery.PHOTO_THUMBNAIL_URI));
}
@Override
diff --git a/chips/src/com/android/ex/chips/RecipientEntry.java b/chips/src/com/android/ex/chips/RecipientEntry.java
index 29e21f6..d22d5b1 100644
--- a/chips/src/com/android/ex/chips/RecipientEntry.java
+++ b/chips/src/com/android/ex/chips/RecipientEntry.java
@@ -17,18 +17,22 @@
package com.android.ex.chips;
import android.net.Uri;
+import android.provider.ContactsContract.CommonDataKinds.Email;
/**
* Represents one entry inside recipient auto-complete list.
*/
public class RecipientEntry {
- /*package*/ static final int INVALID_CONTACT = -1;
+ /* package */ static final int INVALID_CONTACT = -1;
/**
* A GENERATED_CONTACT is one that was created based entirely on
* information passed in to the RecipientEntry from an external source
* that is not a real contact.
*/
- /*package*/ static final int GENERATED_CONTACT = -2;
+ /* package */ static final int GENERATED_CONTACT = -2;
+
+ /** Used when {@link #mDestinationType} is invalid and thus shouldn't be used for display. */
+ /* package */ static final int INVALID_DESTINATION_TYPE = -1;
public static final int ENTRY_TYPE_PERSON = 0;
public static final int ENTRY_TYPE_SEP_NORMAL = 1;
@@ -56,6 +60,13 @@ public class RecipientEntry {
private final String mDisplayName;
/** Destination for this contact entry. Would be an email address or a phone number. */
private final String mDestination;
+ /** Type of the destination like {@link Email#TYPE_HOME} */
+ private final int mDestinationType;
+ /**
+ * Label of the destination which will be used when type was {@link Email#TYPE_CUSTOM}.
+ * Can be null when {@link #mDestinationType} is {@link #INVALID_DESTINATION_TYPE}.
+ */
+ private final String mDestinationLabel;
/** ID for the person */
private final long mContactId;
/** ID for the destination */
@@ -74,6 +85,8 @@ public class RecipientEntry {
mEntryType = entryType;
mDisplayName = null;
mDestination = null;
+ mDestinationType = INVALID_DESTINATION_TYPE;
+ mDestinationLabel = null;
mContactId = -1;
mDataId = -1;
mPhotoThumbnailUri = null;
@@ -82,12 +95,15 @@ public class RecipientEntry {
}
private RecipientEntry(
- int entryType, String displayName, String destination, long contactId, long dataId,
- Uri photoThumbnailUri, boolean isFirstLevel) {
+ int entryType, String displayName,
+ String destination, int destinationType, String destinationLabel,
+ long contactId, long dataId, Uri photoThumbnailUri, boolean isFirstLevel) {
mEntryType = entryType;
mIsFirstLevel = isFirstLevel;
mDisplayName = displayName;
mDestination = destination;
+ mDestinationType = destinationType;
+ mDestinationLabel = destinationLabel;
mContactId = contactId;
mDataId = dataId;
mPhotoThumbnailUri = photoThumbnailUri;
@@ -109,8 +125,9 @@ public class RecipientEntry {
* have a contact id or photo.
*/
public static RecipientEntry constructFakeEntry(String address) {
- return new RecipientEntry(ENTRY_TYPE_PERSON, address, address, INVALID_CONTACT,
- INVALID_CONTACT, null, true);
+ return new RecipientEntry(ENTRY_TYPE_PERSON, address, address,
+ INVALID_DESTINATION_TYPE, null,
+ INVALID_CONTACT, INVALID_CONTACT, null, true);
}
/**
@@ -119,30 +136,38 @@ public class RecipientEntry {
* to a contact and therefore does not have a contact id or photo.
*/
public static RecipientEntry constructGeneratedEntry(String display, String address) {
- return new RecipientEntry(ENTRY_TYPE_PERSON, display, address, GENERATED_CONTACT,
- GENERATED_CONTACT, null, true);
+ return new RecipientEntry(ENTRY_TYPE_PERSON, display,
+ address, INVALID_DESTINATION_TYPE, null,
+ GENERATED_CONTACT, GENERATED_CONTACT, null, true);
}
public static RecipientEntry constructTopLevelEntry(
- String displayName, String destination, long contactId, long dataId,
- Uri photoThumbnailUri) {
- return new RecipientEntry(ENTRY_TYPE_PERSON, displayName, destination, contactId, dataId,
+ String displayName, String destination, int destinationType, String destinationLabel,
+ long contactId, long dataId, Uri photoThumbnailUri) {
+ return new RecipientEntry(ENTRY_TYPE_PERSON, displayName,
+ destination, destinationType, destinationLabel,
+ contactId, dataId,
photoThumbnailUri, true);
}
public static RecipientEntry constructTopLevelEntry(
- String displayName, String destination, long contactId, long dataId,
+ String displayName, String destination, int destinationType, String destinationLabel,
+ long contactId, long dataId,
String thumbnailUriAsString) {
return new RecipientEntry(
- ENTRY_TYPE_PERSON, displayName, destination, contactId, dataId,
+ ENTRY_TYPE_PERSON, displayName,
+ destination, destinationType, destinationLabel,
+ contactId, dataId,
(thumbnailUriAsString != null ? Uri.parse(thumbnailUriAsString) : null), true);
}
public static RecipientEntry constructSecondLevelEntry(
- String displayName, String destination, long contactId, long dataId,
- String thumbnailUriAsString) {
+ String displayName, String destination, int destinationType, String destinationLabel,
+ long contactId, long dataId, String thumbnailUriAsString) {
return new RecipientEntry(
- ENTRY_TYPE_PERSON, displayName, destination, contactId, dataId,
+ ENTRY_TYPE_PERSON, displayName,
+ destination, destinationType, destinationLabel,
+ contactId, dataId,
(thumbnailUriAsString != null ? Uri.parse(thumbnailUriAsString) : null), false);
}
@@ -158,6 +183,14 @@ public class RecipientEntry {
return mDestination;
}
+ public int getDestinationType() {
+ return mDestinationType;
+ }
+
+ public String getDestinationLabel() {
+ return mDestinationLabel;
+ }
+
public long getContactId() {
return mContactId;
}