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);
});
}
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);
}
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;
}
}
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();
}
});
});
}
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);
}
Aggregations