Search in sources :

Example 1 with ContactPhoto

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());
}
Also used : Context(android.content.Context) ContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ContactPhoto) DisplayMetrics(android.util.DisplayMetrics) Uri(android.net.Uri) WindowManager(android.view.WindowManager)

Example 2 with ContactPhoto

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);
}
Also used : MaterialColor(org.thoughtcrime.securesms.color.MaterialColor) RecipientsPreferences(org.thoughtcrime.securesms.database.RecipientPreferenceDatabase.RecipientsPreferences) Cursor(android.database.Cursor) ContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ContactPhoto) Uri(android.net.Uri) NonNull(android.support.annotation.NonNull)

Example 3 with ContactPhoto

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);
    }
}
Also used : GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) IOException(java.io.IOException) ContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ContactPhoto) NonNull(android.support.annotation.NonNull)

Aggregations

ContactPhoto (org.thoughtcrime.securesms.contacts.avatars.ContactPhoto)3 Uri (android.net.Uri)2 NonNull (android.support.annotation.NonNull)2 Context (android.content.Context)1 Cursor (android.database.Cursor)1 DisplayMetrics (android.util.DisplayMetrics)1 WindowManager (android.view.WindowManager)1 IOException (java.io.IOException)1 MaterialColor (org.thoughtcrime.securesms.color.MaterialColor)1 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)1 RecipientsPreferences (org.thoughtcrime.securesms.database.RecipientPreferenceDatabase.RecipientsPreferences)1