Search in sources :

Example 1 with CenterCrop

use of com.bumptech.glide.load.resource.bitmap.CenterCrop in project Signal-Android by WhisperSystems.

the class ThumbnailView method buildPlaceholderGlideRequest.

private RequestBuilder buildPlaceholderGlideRequest(@NonNull GlideRequests glideRequests, @NonNull Slide slide) {
    GlideRequest<Bitmap> bitmap = glideRequests.asBitmap();
    BlurHash placeholderBlur = slide.getPlaceholderBlur();
    if (placeholderBlur != null) {
        bitmap = bitmap.load(placeholderBlur);
    } else {
        bitmap = bitmap.load(slide.getPlaceholderRes(getContext().getTheme()));
    }
    return applySizing(bitmap.diskCacheStrategy(DiskCacheStrategy.NONE), new CenterCrop());
}
Also used : Bitmap(android.graphics.Bitmap) CenterCrop(com.bumptech.glide.load.resource.bitmap.CenterCrop) BlurHash(org.thoughtcrime.securesms.blurhash.BlurHash)

Example 2 with CenterCrop

use of com.bumptech.glide.load.resource.bitmap.CenterCrop in project Signal-Android by WhisperSystems.

the class ThumbnailView method setImageResource.

public ListenableFuture<Boolean> setImageResource(@NonNull GlideRequests glideRequests, @NonNull Uri uri, int width, int height) {
    SettableFuture<Boolean> future = new SettableFuture<>();
    if (transferControls.isPresent())
        getTransferControls().setVisibility(View.GONE);
    GlideRequest request = glideRequests.load(new DecryptableUri(uri)).diskCacheStrategy(DiskCacheStrategy.NONE).transition(withCrossFade());
    if (width > 0 && height > 0) {
        request = request.override(width, height);
    }
    if (radius > 0) {
        request = request.transforms(new CenterCrop(), new RoundedCorners(radius));
    } else {
        request = request.transforms(new CenterCrop());
    }
    request.into(new GlideDrawableListeningTarget(image, future));
    blurhash.setImageDrawable(null);
    return future;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) GlideRequest(org.thoughtcrime.securesms.mms.GlideRequest) DecryptableUri(org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri) CenterCrop(com.bumptech.glide.load.resource.bitmap.CenterCrop) RoundedCorners(com.bumptech.glide.load.resource.bitmap.RoundedCorners)

Example 3 with CenterCrop

use of com.bumptech.glide.load.resource.bitmap.CenterCrop in project Signal-Android by WhisperSystems.

the class BorderlessImageView method setSlide.

public void setSlide(@NonNull GlideRequests glideRequests, @NonNull Slide slide) {
    boolean showControls = slide.asAttachment().getUri() == null;
    if (slide.hasSticker()) {
        image.setFit(new CenterInside());
        image.setImageResource(glideRequests, slide, showControls, false);
    } else {
        image.setFit(new CenterCrop());
        image.setImageResource(glideRequests, slide, showControls, false, slide.asAttachment().getWidth(), slide.asAttachment().getHeight());
    }
    missingShade.setVisibility(showControls ? View.VISIBLE : View.GONE);
}
Also used : CenterCrop(com.bumptech.glide.load.resource.bitmap.CenterCrop) CenterInside(com.bumptech.glide.load.resource.bitmap.CenterInside)

Example 4 with CenterCrop

use of com.bumptech.glide.load.resource.bitmap.CenterCrop 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 5 with CenterCrop

use of com.bumptech.glide.load.resource.bitmap.CenterCrop in project glide by bumptech.

the class RequestOptionsTest method testApplyMultiTransform.

@Test
@SuppressWarnings({ "unchecked", "varargs" })
public void testApplyMultiTransform() {
    options.transforms(new CircleCrop(), new CenterCrop());
    assertThat(options.isTransformationRequired()).isTrue();
    assertThat(options.getTransformations()).containsKey(Bitmap.class);
    assertThat(options.getTransformations().get(Bitmap.class)).isInstanceOf(MultiTransformation.class);
}
Also used : CircleCrop(com.bumptech.glide.load.resource.bitmap.CircleCrop) CenterCrop(com.bumptech.glide.load.resource.bitmap.CenterCrop) Test(org.junit.Test)

Aggregations

CenterCrop (com.bumptech.glide.load.resource.bitmap.CenterCrop)9 Drawable (android.graphics.drawable.Drawable)3 Bitmap (android.graphics.Bitmap)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 Context (android.content.Context)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 SpannableString (android.text.SpannableString)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 Spanned (android.text.Spanned)1 TextUtils (android.text.TextUtils)1 DateUtils (android.text.format.DateUtils)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 Button (android.widget.Button)1 ImageButton (android.widget.ImageButton)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 Toast (android.widget.Toast)1 DrawableRes (androidx.annotation.DrawableRes)1