Search in sources :

Example 1 with RoundedDrawable

use of com.makeramen.roundedimageview.RoundedDrawable in project Signal-Android by signalapp.

the class ResourceContactPhoto method asDrawable.

@Override
public Drawable asDrawable(Context context, int color, boolean inverted) {
    Drawable background = TextDrawable.builder().buildRound(" ", inverted ? Color.WHITE : color);
    RoundedDrawable foreground = (RoundedDrawable) RoundedDrawable.fromDrawable(context.getResources().getDrawable(resourceId));
    foreground.setScaleType(ImageView.ScaleType.CENTER);
    if (inverted) {
        foreground.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    }
    return new ExpandingLayerDrawable(new Drawable[] { background, foreground });
}
Also used : RoundedDrawable(com.makeramen.roundedimageview.RoundedDrawable) TextDrawable(com.amulyakhare.textdrawable.TextDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) RoundedDrawable(com.makeramen.roundedimageview.RoundedDrawable) Drawable(android.graphics.drawable.Drawable)

Example 2 with RoundedDrawable

use of com.makeramen.roundedimageview.RoundedDrawable in project Signal-Android by WhisperSystems.

the class ConversationListItem method createFinalBodyWithMediaIcon.

private static LiveData<CharSequence> createFinalBodyWithMediaIcon(@NonNull Context context, @NonNull String body, @NonNull ThreadRecord thread, @NonNull GlideRequests glideRequests, @Px int thumbSize, @NonNull GlideLiveDataTarget thumbTarget) {
    if (thread.getSnippetUri() == null) {
        return LiveDataUtil.just(body);
    }
    final String bodyWithoutMediaPrefix;
    if (body.startsWith(EmojiStrings.GIF)) {
        bodyWithoutMediaPrefix = body.replaceFirst(EmojiStrings.GIF, "");
    } else if (body.startsWith(EmojiStrings.VIDEO)) {
        bodyWithoutMediaPrefix = body.replaceFirst(EmojiStrings.VIDEO, "");
    } else if (body.startsWith(EmojiStrings.PHOTO)) {
        bodyWithoutMediaPrefix = body.replaceFirst(EmojiStrings.PHOTO, "");
    } else if (thread.getExtra() != null && thread.getExtra().getStickerEmoji() != null && body.startsWith(thread.getExtra().getStickerEmoji())) {
        bodyWithoutMediaPrefix = body.replaceFirst(thread.getExtra().getStickerEmoji(), "");
    } else {
        return LiveDataUtil.just(body);
    }
    glideRequests.asBitmap().load(new DecryptableStreamUriLoader.DecryptableUri(thread.getSnippetUri())).override(thumbSize, thumbSize).transform(new OverlayTransformation(ContextCompat.getColor(context, R.color.transparent_black_08)), new CenterCrop()).into(thumbTarget);
    return Transformations.map(thumbTarget.getLiveData(), bitmap -> {
        if (bitmap == null) {
            return body;
        }
        RoundedDrawable drawable = RoundedDrawable.fromBitmap(bitmap);
        drawable.setBounds(0, 0, thumbSize, thumbSize);
        drawable.setCornerRadius(DimensionUnit.DP.toPixels(4));
        drawable.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        CharSequence thumbnailSpan = SpanUtil.buildCenteredImageSpan(drawable);
        return new SpannableStringBuilder().append(thumbnailSpan).append(bodyWithoutMediaPrefix);
    });
}
Also used : RoundedDrawable(com.makeramen.roundedimageview.RoundedDrawable) OverlayTransformation(org.thoughtcrime.securesms.OverlayTransformation) CenterCrop(com.bumptech.glide.load.resource.bitmap.CenterCrop) SpannableString(android.text.SpannableString) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 3 with RoundedDrawable

use of com.makeramen.roundedimageview.RoundedDrawable in project Signal-Android by WhisperSystems.

the class ResourceContactPhoto method asDrawable.

@Override
public Drawable asDrawable(Context context, int color, boolean inverted) {
    Drawable background = TextDrawable.builder().buildRound(" ", inverted ? Color.WHITE : color);
    RoundedDrawable foreground = (RoundedDrawable) RoundedDrawable.fromDrawable(context.getResources().getDrawable(resourceId));
    foreground.setScaleType(ImageView.ScaleType.CENTER);
    if (inverted) {
        foreground.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    }
    return new ExpandingLayerDrawable(new Drawable[] { background, foreground });
}
Also used : RoundedDrawable(com.makeramen.roundedimageview.RoundedDrawable) TextDrawable(com.amulyakhare.textdrawable.TextDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) RoundedDrawable(com.makeramen.roundedimageview.RoundedDrawable) Drawable(android.graphics.drawable.Drawable)

Example 4 with RoundedDrawable

use of com.makeramen.roundedimageview.RoundedDrawable in project Signal-Android by WhisperSystems.

the class ResourceContactPhoto method buildDrawable.

@NonNull
private Drawable buildDrawable(@NonNull Context context, int resourceId, @NonNull AvatarColor color, boolean inverted) {
    Avatars.ForegroundColor foregroundColor = Avatars.getForegroundColor(color);
    Drawable background = Objects.requireNonNull(ContextCompat.getDrawable(context, R.drawable.circle_tintable));
    RoundedDrawable foreground = (RoundedDrawable) RoundedDrawable.fromDrawable(AppCompatResources.getDrawable(context, resourceId));
    // noinspection ConstantConditions
    foreground.setScaleType(scaleType);
    background.setColorFilter(inverted ? foregroundColor.getColorInt() : color.colorInt(), PorterDuff.Mode.SRC_IN);
    foreground.setColorFilter(inverted ? color.colorInt() : foregroundColor.getColorInt(), PorterDuff.Mode.SRC_ATOP);
    return new ExpandingLayerDrawable(new Drawable[] { background, foreground });
}
Also used : RoundedDrawable(com.makeramen.roundedimageview.RoundedDrawable) Avatars(org.thoughtcrime.securesms.avatar.Avatars) LayerDrawable(android.graphics.drawable.LayerDrawable) RoundedDrawable(com.makeramen.roundedimageview.RoundedDrawable) Drawable(android.graphics.drawable.Drawable) NonNull(androidx.annotation.NonNull)

Aggregations

RoundedDrawable (com.makeramen.roundedimageview.RoundedDrawable)4 Drawable (android.graphics.drawable.Drawable)3 LayerDrawable (android.graphics.drawable.LayerDrawable)3 TextDrawable (com.amulyakhare.textdrawable.TextDrawable)2 SpannableString (android.text.SpannableString)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 NonNull (androidx.annotation.NonNull)1 CenterCrop (com.bumptech.glide.load.resource.bitmap.CenterCrop)1 OverlayTransformation (org.thoughtcrime.securesms.OverlayTransformation)1 Avatars (org.thoughtcrime.securesms.avatar.Avatars)1