Search in sources :

Example 11 with CenterCrop

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

the class StatusBaseViewHolder method setupCard.

protected void setupCard(StatusViewData.Concrete status, CardViewMode cardViewMode, StatusDisplayOptions statusDisplayOptions, final StatusActionListener listener) {
    final Card card = status.getActionable().getCard();
    if (cardViewMode != CardViewMode.NONE && status.getActionable().getAttachments().size() == 0 && card != null && !TextUtils.isEmpty(card.getUrl()) && (!status.isCollapsible() || !status.isCollapsed())) {
        cardView.setVisibility(View.VISIBLE);
        cardTitle.setText(card.getTitle());
        if (TextUtils.isEmpty(card.getDescription()) && TextUtils.isEmpty(card.getAuthorName())) {
            cardDescription.setVisibility(View.GONE);
        } else {
            cardDescription.setVisibility(View.VISIBLE);
            if (TextUtils.isEmpty(card.getDescription())) {
                cardDescription.setText(card.getAuthorName());
            } else {
                cardDescription.setText(card.getDescription());
            }
        }
        cardUrl.setText(card.getUrl());
        // If media previews are disabled, show placeholder for cards as well
        if (statusDisplayOptions.mediaPreviewEnabled() && !status.getActionable().getSensitive() && !TextUtils.isEmpty(card.getImage())) {
            int topLeftRadius = 0;
            int topRightRadius = 0;
            int bottomRightRadius = 0;
            int bottomLeftRadius = 0;
            int radius = cardImage.getContext().getResources().getDimensionPixelSize(R.dimen.card_radius);
            if (card.getWidth() > card.getHeight()) {
                cardView.setOrientation(LinearLayout.VERTICAL);
                cardImage.getLayoutParams().height = cardImage.getContext().getResources().getDimensionPixelSize(R.dimen.card_image_vertical_height);
                cardImage.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
                cardInfo.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
                cardInfo.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
                topLeftRadius = radius;
                topRightRadius = radius;
            } else {
                cardView.setOrientation(LinearLayout.HORIZONTAL);
                cardImage.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
                cardImage.getLayoutParams().width = cardImage.getContext().getResources().getDimensionPixelSize(R.dimen.card_image_horizontal_width);
                cardInfo.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
                cardInfo.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
                topLeftRadius = radius;
                bottomLeftRadius = radius;
            }
            RequestBuilder<Drawable> builder = Glide.with(cardImage).load(card.getImage());
            if (statusDisplayOptions.useBlurhash() && !TextUtils.isEmpty(card.getBlurhash())) {
                builder = builder.placeholder(decodeBlurHash(card.getBlurhash()));
            }
            builder.transform(new CenterCrop(), new GranularRoundedCorners(topLeftRadius, topRightRadius, bottomRightRadius, bottomLeftRadius)).into(cardImage);
        } else if (statusDisplayOptions.useBlurhash() && !TextUtils.isEmpty(card.getBlurhash())) {
            int radius = cardImage.getContext().getResources().getDimensionPixelSize(R.dimen.card_radius);
            cardView.setOrientation(LinearLayout.HORIZONTAL);
            cardImage.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
            cardImage.getLayoutParams().width = cardImage.getContext().getResources().getDimensionPixelSize(R.dimen.card_image_horizontal_width);
            cardInfo.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
            cardInfo.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
            Glide.with(cardImage).load(decodeBlurHash(card.getBlurhash())).transform(new CenterCrop(), new GranularRoundedCorners(radius, 0, 0, radius)).into(cardImage);
        } else {
            cardView.setOrientation(LinearLayout.HORIZONTAL);
            cardImage.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
            cardImage.getLayoutParams().width = cardImage.getContext().getResources().getDimensionPixelSize(R.dimen.card_image_horizontal_width);
            cardInfo.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
            cardInfo.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
            cardImage.setImageResource(R.drawable.card_image_placeholder);
        }
        View.OnClickListener visitLink = v -> listener.onViewUrl(card.getUrl());
        View.OnClickListener openImage = v -> cardView.getContext().startActivity(ViewMediaActivity.newSingleImageIntent(cardView.getContext(), card.getEmbed_url()));
        cardInfo.setOnClickListener(visitLink);
        // View embedded photos in our image viewer instead of opening the browser
        cardImage.setOnClickListener(card.getType().equals(Card.TYPE_PHOTO) && !TextUtils.isEmpty(card.getEmbed_url()) ? openImage : visitLink);
        cardView.setClipToOutline(true);
    } else {
        cardView.setVisibility(View.GONE);
    }
}
Also used : ImageButton(android.widget.ImageButton) LinearLayout(android.widget.LinearLayout) DateUtils(android.text.format.DateUtils) NonNull(androidx.annotation.NonNull) Date(java.util.Date) ImageView(android.widget.ImageView) RequestBuilder(com.bumptech.glide.RequestBuilder) Utils(at.connyduck.sparkbutton.helpers.Utils) ColorDrawable(android.graphics.drawable.ColorDrawable) DrawableRes(androidx.annotation.DrawableRes) Drawable(android.graphics.drawable.Drawable) Card(com.keylesspalace.tusky.entity.Card) Locale(java.util.Locale) View(android.view.View) Button(android.widget.Button) MetaData(com.keylesspalace.tusky.entity.Attachment.MetaData) RecyclerView(androidx.recyclerview.widget.RecyclerView) ViewMediaActivity(com.keylesspalace.tusky.ViewMediaActivity) SparkButton(at.connyduck.sparkbutton.SparkButton) GranularRoundedCorners(com.bumptech.glide.load.resource.bitmap.GranularRoundedCorners) Focus(com.keylesspalace.tusky.entity.Attachment.Focus) StatusViewData(com.keylesspalace.tusky.viewdata.StatusViewData) StatusActionListener(com.keylesspalace.tusky.interfaces.StatusActionListener) HtmlCompat(androidx.core.text.HtmlCompat) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ViewGroup(android.view.ViewGroup) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) StatusDisplayOptions(com.keylesspalace.tusky.util.StatusDisplayOptions) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) Attachment(com.keylesspalace.tusky.entity.Attachment) PollOptionViewData(com.keylesspalace.tusky.viewdata.PollOptionViewData) CollectionsKt(kotlin.collections.CollectionsKt) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TimestampUtils(com.keylesspalace.tusky.util.TimestampUtils) PollViewDataKt(com.keylesspalace.tusky.viewdata.PollViewDataKt) Context(android.content.Context) Spanned(android.text.Spanned) AlertDialog(androidx.appcompat.app.AlertDialog) PollViewData(com.keylesspalace.tusky.viewdata.PollViewData) Status(com.keylesspalace.tusky.entity.Status) SimpleDateFormat(java.text.SimpleDateFormat) CenterCrop(com.bumptech.glide.load.resource.bitmap.CenterCrop) NumberFormat(java.text.NumberFormat) MaterialButton(com.google.android.material.button.MaterialButton) R(com.keylesspalace.tusky.R) CardViewMode(com.keylesspalace.tusky.util.CardViewMode) CustomEmojiHelper(com.keylesspalace.tusky.util.CustomEmojiHelper) Toast(android.widget.Toast) PollViewDataKt.buildDescription(com.keylesspalace.tusky.viewdata.PollViewDataKt.buildDescription) ThemeUtils(com.keylesspalace.tusky.util.ThemeUtils) Emoji(com.keylesspalace.tusky.entity.Emoji) LinkHelper(com.keylesspalace.tusky.util.LinkHelper) TextUtils(android.text.TextUtils) Glide(com.bumptech.glide.Glide) MediaPreviewImageView(com.keylesspalace.tusky.view.MediaPreviewImageView) ImageLoadingHelper(com.keylesspalace.tusky.util.ImageLoadingHelper) GranularRoundedCorners(com.bumptech.glide.load.resource.bitmap.GranularRoundedCorners) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) CenterCrop(com.bumptech.glide.load.resource.bitmap.CenterCrop) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) MediaPreviewImageView(com.keylesspalace.tusky.view.MediaPreviewImageView) Card(com.keylesspalace.tusky.entity.Card)

Example 12 with CenterCrop

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

the class Camera1Fragment method onCaptureClicked.

private void onCaptureClicked() {
    orderEnforcer.reset();
    Stopwatch fastCaptureTimer = new Stopwatch("Capture");
    camera.capture((jpegData, frontFacing) -> {
        fastCaptureTimer.split("captured");
        Transformation<Bitmap> transformation = frontFacing ? new MultiTransformation<>(new CenterCrop(), new FlipTransformation()) : new CenterCrop();
        GlideApp.with(this).asBitmap().load(jpegData).transform(transformation).override(cameraPreview.getWidth(), cameraPreview.getHeight()).into(new SimpleTarget<Bitmap>() {

            @Override
            public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                fastCaptureTimer.split("transform");
                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                resource.compress(Bitmap.CompressFormat.JPEG, 80, stream);
                fastCaptureTimer.split("compressed");
                byte[] data = stream.toByteArray();
                fastCaptureTimer.split("bytes");
                fastCaptureTimer.stop(TAG);
                controller.onImageCaptured(data, resource.getWidth(), resource.getHeight());
            }

            @Override
            public void onLoadFailed(@Nullable Drawable errorDrawable) {
                controller.onCameraError();
            }
        });
    });
}
Also used : Bitmap(android.graphics.Bitmap) Stopwatch(org.thoughtcrime.securesms.util.Stopwatch) Drawable(android.graphics.drawable.Drawable) CenterCrop(com.bumptech.glide.load.resource.bitmap.CenterCrop) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 13 with CenterCrop

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

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 14 with CenterCrop

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

the class WebRtcCallView method updateLocalCallParticipant.

public void updateLocalCallParticipant(@NonNull WebRtcLocalRenderState state, @NonNull CallParticipant localCallParticipant, @NonNull CallParticipant focusedParticipant, boolean displaySmallSelfPipInLandscape) {
    largeLocalRender.setMirror(localCallParticipant.getCameraDirection() == CameraState.Direction.FRONT);
    smallLocalRender.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL);
    largeLocalRender.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL);
    localCallParticipant.getVideoSink().getLockableEglBase().performWithValidEglBase(eglBase -> {
        largeLocalRender.init(eglBase);
    });
    videoToggle.setChecked(localCallParticipant.isVideoEnabled(), false);
    smallLocalRender.setRenderInPip(true);
    if (state == WebRtcLocalRenderState.EXPANDED) {
        expandPip(localCallParticipant, focusedParticipant);
        return;
    } else if ((state == WebRtcLocalRenderState.SMALL_RECTANGLE || state == WebRtcLocalRenderState.GONE) && pictureInPictureExpansionHelper.isExpandedOrExpanding()) {
        shrinkPip(localCallParticipant);
        return;
    } else {
        smallLocalRender.setCallParticipant(localCallParticipant);
        smallLocalRender.setMirror(localCallParticipant.getCameraDirection() == CameraState.Direction.FRONT);
    }
    switch(state) {
        case GONE:
            largeLocalRender.attachBroadcastVideoSink(null);
            largeLocalRenderFrame.setVisibility(View.GONE);
            smallLocalRenderFrame.setVisibility(View.GONE);
            break;
        case SMALL_RECTANGLE:
            smallLocalRenderFrame.setVisibility(View.VISIBLE);
            animatePipToLargeRectangle(displaySmallSelfPipInLandscape);
            largeLocalRender.attachBroadcastVideoSink(null);
            largeLocalRenderFrame.setVisibility(View.GONE);
            break;
        case SMALLER_RECTANGLE:
            smallLocalRenderFrame.setVisibility(View.VISIBLE);
            animatePipToSmallRectangle();
            largeLocalRender.attachBroadcastVideoSink(null);
            largeLocalRenderFrame.setVisibility(View.GONE);
            break;
        case LARGE:
            largeLocalRender.attachBroadcastVideoSink(localCallParticipant.getVideoSink());
            largeLocalRenderFrame.setVisibility(View.VISIBLE);
            largeLocalRenderNoVideo.setVisibility(View.GONE);
            largeLocalRenderNoVideoAvatar.setVisibility(View.GONE);
            smallLocalRenderFrame.setVisibility(View.GONE);
            break;
        case LARGE_NO_VIDEO:
            largeLocalRender.attachBroadcastVideoSink(null);
            largeLocalRenderFrame.setVisibility(View.VISIBLE);
            largeLocalRenderNoVideo.setVisibility(View.VISIBLE);
            largeLocalRenderNoVideoAvatar.setVisibility(View.VISIBLE);
            GlideApp.with(getContext().getApplicationContext()).load(new ProfileContactPhoto(localCallParticipant.getRecipient(), localCallParticipant.getRecipient().getProfileAvatar())).transform(new CenterCrop(), new BlurTransformation(getContext(), 0.25f, BlurTransformation.MAX_RADIUS)).diskCacheStrategy(DiskCacheStrategy.ALL).into(largeLocalRenderNoVideoAvatar);
            smallLocalRenderFrame.setVisibility(View.GONE);
            break;
    }
}
Also used : ProfileContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto) BlurTransformation(org.thoughtcrime.securesms.util.BlurTransformation) CenterCrop(com.bumptech.glide.load.resource.bitmap.CenterCrop)

Example 15 with CenterCrop

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

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)

Aggregations

CenterCrop (com.bumptech.glide.load.resource.bitmap.CenterCrop)15 Bitmap (android.graphics.Bitmap)4 Drawable (android.graphics.drawable.Drawable)4 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 SpannableString (android.text.SpannableString)2 SpannableStringBuilder (android.text.SpannableStringBuilder)2 CenterInside (com.bumptech.glide.load.resource.bitmap.CenterInside)2 RoundedCorners (com.bumptech.glide.load.resource.bitmap.RoundedCorners)2 RoundedDrawable (com.makeramen.roundedimageview.RoundedDrawable)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OverlayTransformation (org.thoughtcrime.securesms.OverlayTransformation)2 ProfileContactPhoto (org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto)2 DecryptableUri (org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri)2 GlideRequest (org.thoughtcrime.securesms.mms.GlideRequest)2 BlurTransformation (org.thoughtcrime.securesms.util.BlurTransformation)2 Stopwatch (org.thoughtcrime.securesms.util.Stopwatch)2 SettableFuture (org.thoughtcrime.securesms.util.concurrent.SettableFuture)2 Context (android.content.Context)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Spanned (android.text.Spanned)1