Search in sources :

Example 6 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 7 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)

Example 8 with CenterCrop

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

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

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

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

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

the class DefaultWXImageAdapter method setImage.

@Override
public void setImage(final String url, final ImageView view, WXImageQuality quality, final WXImageStrategy strategy) {
    if (view == null || !(view instanceof HookWXImageView))
        return;
    final String loadUri = url;
    if (HookImage.AUTORECYCLE_URL.equals(loadUri)) {
        // wximage被回收
        view.setImageBitmap(null);
        return;
    }
    final HookWXImageView wxImageView = (HookWXImageView) view;
    if (TextUtils.isEmpty(loadUri)) {
        // 设置的src为null
        wxImageView.setImageBitmap(null);
        handleError(wxImageView);
        if (strategy != null && strategy.getImageListener() != null) {
            strategy.getImageListener().onImageFinish(loadUri, view, true, null);
        }
        return;
    }
    wxImageView.hideErrorBitmap();
    // set placeHolder
    if (isDefaultPlaceHolder(strategy)) {
        int[] wh = WXCommonUtil.getComponentWH(wxImageView.getComponent());
        wxImageView.showLoading(wh[0], wh[1]);
    } else if (isCustomPlaceHolder(strategy)) {
        // customer placeHolder
        BMHookGlide.load(BMWXApplication.getWXApplication(), strategy.placeHolder).apply(new RequestOptions().fitCenter().diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)).into(wxImageView);
    } else {
        // no placeHolder
        // 防止复用出现的问题
        wxImageView.hideLoading();
    }
    DefaultImageViewTarget viewTarget = new DefaultImageViewTarget(wxImageView);
    viewTarget.setImageLoadListener(new DefaultImageViewTarget.ImageLoadListener() {

        @Override
        public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
            if (strategy != null && strategy.getImageListener() != null) {
                strategy.getImageListener().onImageFinish(loadUri, wxImageView, true, null);
            }
            if (isDefaultPlaceHolder(strategy)) {
                wxImageView.hideLoading();
            }
        }

        @Override
        public void onLoadFailed(@Nullable Drawable errorDrawable) {
            handleError((HookWXImageView) wxImageView);
            if (strategy != null && strategy.getImageListener() != null) {
                strategy.getImageListener().onImageFinish(loadUri, wxImageView, true, null);
            }
            if (isDefaultPlaceHolder(strategy)) {
                wxImageView.hideLoading();
            }
        }
    });
    BMHookGlide.load(BMWXApplication.getWXApplication(), loadUri).apply(new RequestOptions().diskCacheStrategy(DiskCacheStrategy.AUTOMATIC).transforms(new CenterCrop())).into(viewTarget);
}
Also used : RequestOptions(com.bumptech.glide.request.RequestOptions) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) GifDrawable(com.bumptech.glide.load.resource.gif.GifDrawable) CenterCrop(com.bumptech.glide.load.resource.bitmap.CenterCrop) HookWXImageView(com.eros.framework.extend.hook.ui.view.HookWXImageView)

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