summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Lehmann <lehmannd@google.com>2011-07-14 22:16:21 -0700
committerDaniel Lehmann <lehmannd@google.com>2011-07-14 22:16:21 -0700
commitf5d4652e028c5a8ec3d151521e63c9c9191e9149 (patch)
treed10497ead8540f091654da2b7c3e9ed9622cdcb1
parent8cfe3d2d957d72e61222c1d51a44d1403aa73239 (diff)
downloadframeworks_base-f5d4652e028c5a8ec3d151521e63c9c9191e9149.zip
frameworks_base-f5d4652e028c5a8ec3d151521e63c9c9191e9149.tar.gz
frameworks_base-f5d4652e028c5a8ec3d151521e63c9c9191e9149.tar.bz2
Use higher resolution in in-call UI if available.
In the process, I created a second overload to the function that returns the photo to allow returning either the high-res or the thumbnail version Bug:5033899 Change-Id: I7be257eb54b296445e20561d318a70c382d6ade9
-rw-r--r--api/current.txt1
-rw-r--r--core/java/android/pim/ContactsAsyncHelper.java2
-rw-r--r--core/java/android/provider/ContactsContract.java49
3 files changed, 42 insertions, 10 deletions
diff --git a/api/current.txt b/api/current.txt
index 6ded422..52ed750 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -15862,6 +15862,7 @@ package android.provider {
method public static android.net.Uri getLookupUri(long, java.lang.String);
method public static android.net.Uri lookupContact(android.content.ContentResolver, android.net.Uri);
method public static void markAsContacted(android.content.ContentResolver, long);
+ method public static java.io.InputStream openContactPhotoInputStream(android.content.ContentResolver, android.net.Uri, boolean);
method public static java.io.InputStream openContactPhotoInputStream(android.content.ContentResolver, android.net.Uri);
field public static final android.net.Uri CONTENT_FILTER_URI;
field public static final android.net.Uri CONTENT_GROUP_URI;
diff --git a/core/java/android/pim/ContactsAsyncHelper.java b/core/java/android/pim/ContactsAsyncHelper.java
index 7c78a81..21fc594 100644
--- a/core/java/android/pim/ContactsAsyncHelper.java
+++ b/core/java/android/pim/ContactsAsyncHelper.java
@@ -186,7 +186,7 @@ public class ContactsAsyncHelper extends Handler {
InputStream inputStream = null;
try {
inputStream = Contacts.openContactPhotoInputStream(
- args.context.getContentResolver(), args.uri);
+ args.context.getContentResolver(), args.uri, true);
} catch (Exception e) {
Log.e(LOG_TAG, "Error opening photo input stream", e);
}
diff --git a/core/java/android/provider/ContactsContract.java b/core/java/android/provider/ContactsContract.java
index 0dd9a4d..76f198c 100644
--- a/core/java/android/provider/ContactsContract.java
+++ b/core/java/android/provider/ContactsContract.java
@@ -28,6 +28,7 @@ import android.content.CursorEntityIterator;
import android.content.Entity;
import android.content.EntityIterator;
import android.content.Intent;
+import android.content.res.AssetFileDescriptor;
import android.content.res.Resources;
import android.database.Cursor;
import android.database.DatabaseUtils;
@@ -40,6 +41,7 @@ import android.util.Pair;
import android.view.View;
import java.io.ByteArrayInputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
@@ -1757,8 +1759,8 @@ public final class ContactsContract {
*
* </p>
* <p>You may also consider using the convenience method
- * {@link ContactsContract.Contacts#openContactPhotoInputStream(ContentResolver, Uri)}
- * to retrieve the raw photo contents of the thumbnail-sized photo.
+ * {@link ContactsContract.Contacts#openContactPhotoInputStream(ContentResolver, Uri, boolean)}
+ * to retrieve the raw photo contents of either the thumbnail-sized or the full-sized photo.
* </p>
* <p>
* This directory can be used either with a {@link #CONTENT_URI} or
@@ -1799,22 +1801,37 @@ public final class ContactsContract {
}
/**
- * Opens an InputStream for the contacts's default photo and returns the
- * photo as a byte stream. If there is not photo null will be returned.
- *
+ * Opens an InputStream for the contacts's photo and returns the
+ * photo as a byte stream.
+ * @param cr The content resolver to use for querying
* @param contactUri the contact whose photo should be used. This can be used with
* either a {@link #CONTENT_URI} or a {@link #CONTENT_LOOKUP_URI} URI.
- * </p>
-
+ * @param preferHighres If this is true and the contact has a higher resolution photo
+ * available, it is returned. If false, this function always tries to get the thumbnail
* @return an InputStream of the photo, or null if no photo is present
*/
- public static InputStream openContactPhotoInputStream(ContentResolver cr, Uri contactUri) {
+ public static InputStream openContactPhotoInputStream(ContentResolver cr, Uri contactUri,
+ boolean preferHighres) {
+ if (preferHighres) {
+ final Uri displayPhotoUri = Uri.withAppendedPath(contactUri,
+ Contacts.Photo.DISPLAY_PHOTO);
+ InputStream inputStream;
+ try {
+ AssetFileDescriptor fd = cr.openAssetFileDescriptor(displayPhotoUri, "r");
+ return fd.createInputStream();
+ } catch (IOException e) {
+ // fallback to the thumbnail code
+ }
+ }
+
Uri photoUri = Uri.withAppendedPath(contactUri, Photo.CONTENT_DIRECTORY);
if (photoUri == null) {
return null;
}
Cursor cursor = cr.query(photoUri,
- new String[]{ContactsContract.CommonDataKinds.Photo.PHOTO}, null, null, null);
+ new String[] {
+ ContactsContract.CommonDataKinds.Photo.PHOTO
+ }, null, null, null);
try {
if (cursor == null || !cursor.moveToNext()) {
return null;
@@ -1830,6 +1847,20 @@ public final class ContactsContract {
}
}
}
+
+ /**
+ * Opens an InputStream for the contacts's thumbnail photo and returns the
+ * photo as a byte stream.
+ * @param cr The content resolver to use for querying
+ * @param contactUri the contact whose photo should be used. This can be used with
+ * either a {@link #CONTENT_URI} or a {@link #CONTENT_LOOKUP_URI} URI.
+ * @return an InputStream of the photo, or null if no photo is present
+ * @see #openContactPhotoInputStream(ContentResolver, Uri, boolean), if instead
+ * of the thumbnail the high-res picture is preferred
+ */
+ public static InputStream openContactPhotoInputStream(ContentResolver cr, Uri contactUri) {
+ return openContactPhotoInputStream(cr, contactUri, false);
+ }
}
/**