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:
parent
53b2381ad8
commit
ca128f033c
4 changed files with 45 additions and 9 deletions
|
@ -180,7 +180,7 @@ public class ConferenceActivity extends ListActivity implements
|
||||||
getContentResolver(),
|
getContentResolver(),
|
||||||
currentCall.getRemoteAddress().getUserName(),
|
currentCall.getRemoteAddress().getUserName(),
|
||||||
currentCall.getRemoteAddress().getDomain());
|
currentCall.getRemoteAddress().getDomain());
|
||||||
LinphoneUtils.setImagePictureFromUri(view, picture, R.drawable.unknown_person);
|
LinphoneUtils.setImagePictureFromUri(this, view, picture, R.drawable.unknown_person);
|
||||||
view.setVisibility(VISIBLE);
|
view.setVisibility(VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -535,7 +535,7 @@ public class ConferenceActivity extends ListActivity implements
|
||||||
String domain = call.getRemoteAddress().getDomain();
|
String domain = call.getRemoteAddress().getDomain();
|
||||||
// May be greatly sped up using a drawable cache
|
// May be greatly sped up using a drawable cache
|
||||||
Uri uri = LinphoneUtils.findPictureOfContact(getContentResolver(), username, domain);
|
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);
|
pictureView.setVisibility(VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
pictureView.setVisibility(GONE);
|
pictureView.setVisibility(GONE);
|
||||||
|
|
|
@ -49,17 +49,25 @@ public class ContactPickerActivityOld extends Activity {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Uri getPhotoUri(Uri photoUri) {
|
private Uri getPhotoUri(Uri photoUriToTest) {
|
||||||
Cursor cursor = getContentResolver().query(photoUri, new String[]{Photos.DATA}, null, null, null);
|
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 {
|
try {
|
||||||
if (cursor == null || !cursor.moveToNext()) {
|
if (cursor == null || !cursor.moveToNext()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
byte[] data = cursor.getBlob(0);
|
byte[] data = cursor.getBlob(0);
|
||||||
if (data == null) {
|
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 null;
|
||||||
}
|
}
|
||||||
return photoUri;
|
return photoUriToTest;
|
||||||
} finally {
|
} finally {
|
||||||
if (cursor != null) cursor.close();
|
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) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ public class IncomingCallActivity extends Activity implements OnClickListener {
|
||||||
String domain = address.getDomain();
|
String domain = address.getDomain();
|
||||||
// May be greatly sped up using a drawable cache
|
// May be greatly sped up using a drawable cache
|
||||||
Uri uri = LinphoneUtils.findPictureOfContact(getContentResolver(), username, domain);
|
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();
|
super.onResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ import org.linphone.mediastream.video.capture.hwconf.Hacks;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
|
@ -105,7 +106,7 @@ public final class LinphoneUtils {
|
||||||
return null;
|
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) {
|
if (uri == null) {
|
||||||
view.setImageResource(notFoundResource);
|
view.setImageResource(notFoundResource);
|
||||||
return;
|
return;
|
||||||
|
@ -115,7 +116,12 @@ public final class LinphoneUtils {
|
||||||
if (bm == null) view.setImageResource(notFoundResource);
|
if (bm == null) view.setImageResource(notFoundResource);
|
||||||
view.setImageBitmap(bm);
|
view.setImageBitmap(bm);
|
||||||
} else {
|
} else {
|
||||||
view.setImageURI(uri);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue