use of org.thoughtcrime.securesms.contacts.avatars.ContactPhoto in project Signal-Android by WhisperSystems.
the class WebRtcCallScreen method setPersonInfo.
private void setPersonInfo(@NonNull final Recipient recipient) {
this.recipient = recipient;
this.recipient.addListener(this);
final Context context = getContext();
new AsyncTask<Void, Void, ContactPhoto>() {
@Override
protected ContactPhoto doInBackground(Void... params) {
DisplayMetrics metrics = new DisplayMetrics();
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Uri contentUri = ContactsContract.Contacts.lookupContact(context.getContentResolver(), recipient.getContactUri());
windowManager.getDefaultDisplay().getMetrics(metrics);
return ContactPhotoFactory.getContactPhoto(context, contentUri, null, metrics.widthPixels);
}
@Override
protected void onPostExecute(final ContactPhoto contactPhoto) {
WebRtcCallScreen.this.photo.setImageDrawable(contactPhoto.asCallCard(context));
}
}.execute();
this.name.setText(recipient.getName());
this.phoneNumber.setText(recipient.getNumber());
}
use of org.thoughtcrime.securesms.contacts.avatars.ContactPhoto in project Signal-Android by WhisperSystems.
the class RecipientProvider method getIndividualRecipientDetails.
@NonNull
private RecipientDetails getIndividualRecipientDetails(Context context, long recipientId, @NonNull String number) {
Optional<RecipientsPreferences> preferences = DatabaseFactory.getRecipientPreferenceDatabase(context).getRecipientsPreferences(new long[] { recipientId });
MaterialColor color = preferences.isPresent() ? preferences.get().getColor() : null;
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
Cursor cursor = context.getContentResolver().query(uri, CALLER_ID_PROJECTION, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
final String resultNumber = cursor.getString(3);
if (resultNumber != null) {
Uri contactUri = Contacts.getLookupUri(cursor.getLong(2), cursor.getString(1));
String name = resultNumber.equals(cursor.getString(0)) ? null : cursor.getString(0);
ContactPhoto contactPhoto = ContactPhotoFactory.getContactPhoto(context, Uri.withAppendedPath(Contacts.CONTENT_URI, cursor.getLong(2) + ""), name);
return new RecipientDetails(cursor.getString(0), resultNumber, contactUri, contactPhoto, color);
} else {
Log.w(TAG, "resultNumber is null");
}
}
} finally {
if (cursor != null)
cursor.close();
}
if (STATIC_DETAILS.containsKey(number))
return STATIC_DETAILS.get(number);
else
return new RecipientDetails(null, number, null, ContactPhotoFactory.getDefaultContactPhoto(null), color);
}
use of org.thoughtcrime.securesms.contacts.avatars.ContactPhoto in project Signal-Android by WhisperSystems.
the class RecipientProvider method getGroupRecipientDetails.
@NonNull
private RecipientDetails getGroupRecipientDetails(Context context, String groupId) {
try {
GroupDatabase.GroupRecord record = DatabaseFactory.getGroupDatabase(context).getGroup(GroupUtil.getDecodedId(groupId));
if (record != null) {
ContactPhoto contactPhoto = ContactPhotoFactory.getGroupContactPhoto(record.getAvatar());
String title = record.getTitle();
if (title == null) {
title = context.getString(R.string.RecipientProvider_unnamed_group);
;
}
return new RecipientDetails(title, groupId, null, contactPhoto, null);
}
return new RecipientDetails(context.getString(R.string.RecipientProvider_unnamed_group), groupId, null, ContactPhotoFactory.getDefaultGroupPhoto(), null);
} catch (IOException e) {
Log.w("RecipientProvider", e);
return new RecipientDetails(context.getString(R.string.RecipientProvider_unnamed_group), groupId, null, ContactPhotoFactory.getDefaultGroupPhoto(), null);
}
}
Aggregations