Old API contact picture from number (a bit hackish)

To workaround exception on setting view backgroung from uri,
the people uri is returned and the bitmap is extracted directly
in the LinphoneUtils helper class.
This commit is contained in:
Guillaume Beraudo 2011-10-04 12:32:30 +02:00
parent 53b2381ad8
commit ca128f033c
4 changed files with 45 additions and 9 deletions

View file

@ -180,7 +180,7 @@ public class ConferenceActivity extends ListActivity implements
getContentResolver(),
currentCall.getRemoteAddress().getUserName(),
currentCall.getRemoteAddress().getDomain());
LinphoneUtils.setImagePictureFromUri(view, picture, R.drawable.unknown_person);
LinphoneUtils.setImagePictureFromUri(this, view, picture, R.drawable.unknown_person);
view.setVisibility(VISIBLE);
}
@ -535,7 +535,7 @@ public class ConferenceActivity extends ListActivity implements
String domain = call.getRemoteAddress().getDomain();
// May be greatly sped up using a drawable cache
Uri uri = LinphoneUtils.findPictureOfContact(getContentResolver(), username, domain);
LinphoneUtils.setImagePictureFromUri(pictureView, uri, R.drawable.unknown_person);
LinphoneUtils.setImagePictureFromUri(ConferenceActivity.this, pictureView, uri, R.drawable.unknown_person);
pictureView.setVisibility(VISIBLE);
} else {
pictureView.setVisibility(GONE);

View file

@ -49,17 +49,25 @@ public class ContactPickerActivityOld extends Activity {
}
private Uri getPhotoUri(Uri photoUri) {
Cursor cursor = getContentResolver().query(photoUri, new String[]{Photos.DATA}, null, null, null);
private Uri getPhotoUri(Uri photoUriToTest) {
return retrievePhotoUri(getContentResolver(), photoUriToTest);
}
private static Uri retrievePhotoUri(ContentResolver resolver, Uri photoUriToTest) {
Cursor cursor = resolver.query(photoUriToTest, new String[]{Photos.DATA}, null, null, null);
try {
if (cursor == null || !cursor.moveToNext()) {
return null;
}
byte[] data = cursor.getBlob(0);
if (data == null) {
// TODO: simplify all this stuff
// which is here only to check that the
// photoUri really points to some data.
// Not retrieving the data now would be better.
return null;
}
return photoUri;
return photoUriToTest;
} finally {
if (cursor != null) cursor.close();
}
@ -93,7 +101,29 @@ public class ContactPickerActivityOld extends Activity {
}
}
private static Uri retrievePhotoUriAndCloseC(ContentResolver resolver, Cursor c, String column) {
if (c == null) return null;
while (c.moveToNext()) {
long id = c.getLong(c.getColumnIndex(column));
Uri personUri = ContentUris.withAppendedId(People.CONTENT_URI, id);
Uri potentialPictureUri = Uri.withAppendedPath(personUri, Contacts.Photos.CONTENT_DIRECTORY);
Uri pictureUri = retrievePhotoUri(resolver, potentialPictureUri);
if (pictureUri != null) {
c.close();
return personUri; // FIXME, see LinphoneUtils
}
}
c.close();
return null;
}
public static Uri findUriPictureOfContact(ContentResolver resolver, String username, String domain) {
throw new RuntimeException("not implemented");
// A direct qery on the number column doesn't work as the number is stored
// with hyphens inside it.
Uri contactUri = Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL, Uri.encode("0952636505"));
String[] projection = {Contacts.Phones.PERSON_ID};
Cursor c = resolver.query(contactUri, projection, null, null, null);
return retrievePhotoUriAndCloseC(resolver, c, Contacts.Phones.PERSON_ID);
}
}

View file

@ -95,7 +95,7 @@ public class IncomingCallActivity extends Activity implements OnClickListener {
String domain = address.getDomain();
// May be greatly sped up using a drawable cache
Uri uri = LinphoneUtils.findPictureOfContact(getContentResolver(), username, domain);
LinphoneUtils.setImagePictureFromUri(mPictureView, uri, R.drawable.unknown_person);
LinphoneUtils.setImagePictureFromUri(this, mPictureView, uri, R.drawable.unknown_person);
super.onResume();
}

View file

@ -29,6 +29,7 @@ import org.linphone.mediastream.video.capture.hwconf.Hacks;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@ -105,7 +106,7 @@ public final class LinphoneUtils {
return null;
}
public static void setImagePictureFromUri(ImageView view, Uri uri, int notFoundResource) {
public static void setImagePictureFromUri(Context c, ImageView view, Uri uri, int notFoundResource) {
if (uri == null) {
view.setImageResource(notFoundResource);
return;
@ -115,7 +116,12 @@ public final class LinphoneUtils {
if (bm == null) view.setImageResource(notFoundResource);
view.setImageBitmap(bm);
} else {
if (Version.sdkAboveOrEqual(Version.API06_ECLAIR_20)) {
view.setImageURI(uri);
} else {
Bitmap bitmap = android.provider.Contacts.People.loadContactPhoto(c, uri, notFoundResource, null);
view.setImageBitmap(bitmap);
}
}
}