summaryrefslogtreecommitdiffstats
path: root/chips/src/com/android/ex/chips/BaseRecipientAdapter.java
diff options
context:
space:
mode:
authorScott Kennedy <skennedy@google.com>2013-11-21 14:31:33 -0800
committerScott Kennedy <skennedy@google.com>2014-02-05 21:33:37 -0800
commitae07c2be104a1f95426b697f3074bea72bc140e1 (patch)
tree0c86989672f1a2876f8a6a6ca41d6e0e179bb1b7 /chips/src/com/android/ex/chips/BaseRecipientAdapter.java
parent95fedd51882128dea2152c3d1c7ff194f8e557bf (diff)
downloadandroid_frameworks_ex-ae07c2be104a1f95426b697f3074bea72bc140e1.tar.gz
android_frameworks_ex-ae07c2be104a1f95426b697f3074bea72bc140e1.tar.bz2
android_frameworks_ex-ae07c2be104a1f95426b697f3074bea72bc140e1.zip
Fix directory lookups
The previous "fix" disabled the lookups. Now we will do the lookups, with the proper lookup key and directory id. We also do a much better job of showing directory images. Bug: 11693322 Bug: 12793279 Change-Id: I372711fd7b485f3183516fce2b11f9eff46a9b23
Diffstat (limited to 'chips/src/com/android/ex/chips/BaseRecipientAdapter.java')
-rw-r--r--chips/src/com/android/ex/chips/BaseRecipientAdapter.java69
1 files changed, 55 insertions, 14 deletions
diff --git a/chips/src/com/android/ex/chips/BaseRecipientAdapter.java b/chips/src/com/android/ex/chips/BaseRecipientAdapter.java
index 531fd37..8233081 100644
--- a/chips/src/com/android/ex/chips/BaseRecipientAdapter.java
+++ b/chips/src/com/android/ex/chips/BaseRecipientAdapter.java
@@ -23,6 +23,8 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.database.Cursor;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Handler;
@@ -45,6 +47,7 @@ import android.widget.Filterable;
import com.android.ex.chips.DropdownChipLayouter.AdapterType;
import java.io.ByteArrayOutputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
@@ -147,10 +150,11 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter
public final int destinationType;
public final String destinationLabel;
public final long contactId;
+ public final Long directoryId;
public final long dataId;
public final String thumbnailUriString;
public final int displayNameSource;
- public final boolean isGalContact;
+ public final String lookupKey;
public TemporaryEntry(
String displayName,
@@ -158,31 +162,34 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter
int destinationType,
String destinationLabel,
long contactId,
+ Long directoryId,
long dataId,
String thumbnailUriString,
int displayNameSource,
- boolean isGalContact) {
+ String lookupKey) {
this.displayName = displayName;
this.destination = destination;
this.destinationType = destinationType;
this.destinationLabel = destinationLabel;
this.contactId = contactId;
+ this.directoryId = directoryId;
this.dataId = dataId;
this.thumbnailUriString = thumbnailUriString;
this.displayNameSource = displayNameSource;
- this.isGalContact = isGalContact;
+ this.lookupKey = lookupKey;
}
- public TemporaryEntry(Cursor cursor, boolean isGalContact) {
+ public TemporaryEntry(Cursor cursor, Long directoryId) {
this.displayName = cursor.getString(Queries.Query.NAME);
this.destination = cursor.getString(Queries.Query.DESTINATION);
this.destinationType = cursor.getInt(Queries.Query.DESTINATION_TYPE);
this.destinationLabel = cursor.getString(Queries.Query.DESTINATION_LABEL);
this.contactId = cursor.getLong(Queries.Query.CONTACT_ID);
+ this.directoryId = directoryId;
this.dataId = cursor.getLong(Queries.Query.DATA_ID);
this.thumbnailUriString = cursor.getString(Queries.Query.PHOTO_THUMBNAIL_URI);
this.displayNameSource = cursor.getInt(Queries.Query.DISPLAY_NAME_SOURCE);
- this.isGalContact = isGalContact;
+ this.lookupKey = cursor.getString(Queries.Query.LOOKUP_KEY);
}
}
@@ -234,7 +241,8 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter
}
try {
- defaultDirectoryCursor = doQuery(constraint, mPreferredMaxResultCount, null);
+ defaultDirectoryCursor = doQuery(constraint, mPreferredMaxResultCount,
+ null /* directoryId */);
if (defaultDirectoryCursor == null) {
if (DEBUG) {
@@ -254,7 +262,7 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter
// Note: At this point each entry doesn't contain any photo
// (thus getPhotoBytes() returns null).
putOneEntry(new TemporaryEntry(defaultDirectoryCursor,
- false /* isGalContact */),
+ null /* directoryId */),
true, entryMap, nonAggregatedEntries, existingDestinations);
}
@@ -385,7 +393,7 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter
if (cursor != null) {
while (cursor.moveToNext()) {
- tempEntries.add(new TemporaryEntry(cursor, true /* isGalContact */));
+ tempEntries.add(new TemporaryEntry(cursor, mParams.directoryId));
}
}
} finally {
@@ -695,8 +703,8 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter
entry.displayName,
entry.displayNameSource,
entry.destination, entry.destinationType, entry.destinationLabel,
- entry.contactId, entry.dataId, entry.thumbnailUriString, true,
- entry.isGalContact));
+ entry.contactId, entry.directoryId, entry.dataId, entry.thumbnailUriString,
+ true, entry.lookupKey));
} else if (entryMap.containsKey(entry.contactId)) {
// We already have a section for the person.
final List<RecipientEntry> entryList = entryMap.get(entry.contactId);
@@ -704,16 +712,16 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter
entry.displayName,
entry.displayNameSource,
entry.destination, entry.destinationType, entry.destinationLabel,
- entry.contactId, entry.dataId, entry.thumbnailUriString, true,
- entry.isGalContact));
+ entry.contactId, entry.directoryId, entry.dataId, entry.thumbnailUriString,
+ true, entry.lookupKey));
} else {
final List<RecipientEntry> entryList = new ArrayList<RecipientEntry>();
entryList.add(RecipientEntry.constructTopLevelEntry(
entry.displayName,
entry.displayNameSource,
entry.destination, entry.destinationType, entry.destinationLabel,
- entry.contactId, entry.dataId, entry.thumbnailUriString, true,
- entry.isGalContact));
+ entry.contactId, entry.directoryId, entry.dataId, entry.thumbnailUriString,
+ true, entry.lookupKey));
entryMap.put(entry.contactId, entryList);
}
}
@@ -879,6 +887,39 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter
} finally {
photoCursor.close();
}
+ } else {
+ InputStream inputStream = null;
+ ByteArrayOutputStream outputStream = null;
+ try {
+ inputStream = mContentResolver.openInputStream(photoThumbnailUri);
+ final Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
+
+ if (bitmap != null) {
+ outputStream = new ByteArrayOutputStream();
+ bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
+ photoBytes = outputStream.toByteArray();
+
+ entry.setPhotoBytes(photoBytes);
+ mPhotoCacheMap.put(photoThumbnailUri, photoBytes);
+ }
+ } catch (final FileNotFoundException e) {
+ Log.w(TAG, "Error opening InputStream for photo", e);
+ } finally {
+ try {
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ } catch (IOException e) {
+ Log.e(TAG, "Error closing photo input stream", e);
+ }
+ try {
+ if (outputStream != null) {
+ outputStream.close();
+ }
+ } catch (IOException e) {
+ Log.e(TAG, "Error closing photo output stream", e);
+ }
+ }
}
}