Search in sources :

Example 1 with Avatar

use of org.thoughtcrime.securesms.avatar.Avatar in project Signal-Android by signalapp.

the class GeneratedContactPhoto method asDrawable.

@Override
public Drawable asDrawable(@NonNull Context context, @NonNull AvatarColor color, boolean inverted) {
    int targetSize = this.targetSize > 0 ? this.targetSize : context.getResources().getDimensionPixelSize(R.dimen.contact_photo_target_size);
    String character = NameUtil.getAbbreviation(name);
    if (!TextUtils.isEmpty(character)) {
        Avatars.ForegroundColor foregroundColor = Avatars.getForegroundColor(color);
        Avatar.Text avatar = new Avatar.Text(character, new Avatars.ColorPair(color, foregroundColor), Avatar.DatabaseId.DoNotPersist.INSTANCE);
        Drawable foreground = AvatarRenderer.createTextDrawable(context, avatar, inverted, targetSize, false);
        Drawable background = Objects.requireNonNull(ContextCompat.getDrawable(context, R.drawable.circle_tintable));
        background.setColorFilter(new SimpleColorFilter(inverted ? foregroundColor.getColorInt() : color.colorInt()));
        return new LayerDrawable(new Drawable[] { background, foreground });
    }
    return newFallbackDrawable(context, color, inverted);
}
Also used : Avatars(org.thoughtcrime.securesms.avatar.Avatars) LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) Drawable(android.graphics.drawable.Drawable) SimpleColorFilter(com.airbnb.lottie.SimpleColorFilter) Avatar(org.thoughtcrime.securesms.avatar.Avatar)

Example 2 with Avatar

use of org.thoughtcrime.securesms.avatar.Avatar in project Signal-Android by WhisperSystems.

the class GeneratedContactPhoto method asDrawable.

@Override
public Drawable asDrawable(@NonNull Context context, @NonNull AvatarColor color, boolean inverted) {
    int targetSize = this.targetSize > 0 ? this.targetSize : context.getResources().getDimensionPixelSize(R.dimen.contact_photo_target_size);
    String character = NameUtil.getAbbreviation(name);
    if (!TextUtils.isEmpty(character)) {
        Avatars.ForegroundColor foregroundColor = Avatars.getForegroundColor(color);
        Avatar.Text avatar = new Avatar.Text(character, new Avatars.ColorPair(color, foregroundColor), Avatar.DatabaseId.DoNotPersist.INSTANCE);
        Drawable foreground = AvatarRenderer.createTextDrawable(context, avatar, inverted, targetSize, false);
        Drawable background = Objects.requireNonNull(ContextCompat.getDrawable(context, R.drawable.circle_tintable));
        background.setColorFilter(new SimpleColorFilter(inverted ? foregroundColor.getColorInt() : color.colorInt()));
        return new LayerDrawable(new Drawable[] { background, foreground });
    }
    return newFallbackDrawable(context, color, inverted);
}
Also used : Avatars(org.thoughtcrime.securesms.avatar.Avatars) LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) Drawable(android.graphics.drawable.Drawable) SimpleColorFilter(com.airbnb.lottie.SimpleColorFilter) Avatar(org.thoughtcrime.securesms.avatar.Avatar)

Aggregations

Drawable (android.graphics.drawable.Drawable)2 LayerDrawable (android.graphics.drawable.LayerDrawable)2 SimpleColorFilter (com.airbnb.lottie.SimpleColorFilter)2 Avatar (org.thoughtcrime.securesms.avatar.Avatar)2 Avatars (org.thoughtcrime.securesms.avatar.Avatars)2