Contacts App modifications for large photos.
Most of the work is on the provider side - essentially, the
provider will now deal with any size photo, downsizing it as
necessary to fit in a display size and thumbnail size. So
on the client we just need to pass in a larger photo to get a
hi-res display image for the contact.
Also switched a few spots to use the PHOTO_URI (with
openAssetFile) instead of PHOTO_THUMB_URI - more likely
remain.
Change-Id: I6ff8dd5453a9ff787907ab113d6e8aa6a71fcae1
diff --git a/src/com/android/contacts/ContactLoader.java b/src/com/android/contacts/ContactLoader.java
index 7ed9d86..f10e6b8 100644
--- a/src/com/android/contacts/ContactLoader.java
+++ b/src/com/android/contacts/ContactLoader.java
@@ -28,6 +28,7 @@
import android.content.Loader;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.res.AssetFileDescriptor;
import android.content.res.Resources;
import android.database.Cursor;
import android.net.Uri;
@@ -45,6 +46,8 @@
import android.util.Log;
import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
@@ -673,6 +676,33 @@
* not found, returns null
*/
private void loadPhotoBinaryData(Result contactData) {
+
+ // If we have a photo URI, try loading that first.
+ String photoUri = contactData.getPhotoUri();
+ if (photoUri != null) {
+ try {
+ AssetFileDescriptor fd = getContext().getContentResolver()
+ .openAssetFileDescriptor(Uri.parse(photoUri), "r");
+ byte[] buffer = new byte[16 * 1024];
+ FileInputStream fis = fd.createInputStream();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try {
+ int size;
+ while ((size = fis.read(buffer)) != -1) {
+ baos.write(buffer, 0, size);
+ }
+ contactData.setPhotoBinaryData(baos.toByteArray());
+ } finally {
+ fis.close();
+ fd.close();
+ }
+ return;
+ } catch (IOException ioe) {
+ // Just fall back to the case below.
+ }
+ }
+
+ // If we couldn't load from a file, fall back to the data blob.
final long photoId = contactData.getPhotoId();
if (photoId <= 0) {
// No photo ID