use of com.bumptech.glide.request.RequestListener in project Shuttle by timusus.
the class ArtworkView method bindView.
@Override
public void bindView(ViewHolder holder) {
super.bindView(holder);
long time = System.currentTimeMillis();
holder.textContainer.setBackground(null);
holder.progressBar.setVisibility(View.VISIBLE);
holder.lineTwo.setText(null);
Glide.with(holder.itemView.getContext()).using(new TypeLoader(type, file), InputStream.class).from(ArtworkProvider.class).as(BitmapAndSize.class).sourceEncoder(new StreamEncoder()).decoder(new BitmapAndSizeDecoder(holder.itemView.getContext())).diskCacheStrategy(DiskCacheStrategy.NONE).load(artworkProvider).listener(new RequestListener<ArtworkProvider, BitmapAndSize>() {
@Override
public boolean onException(Exception e, ArtworkProvider model, Target<BitmapAndSize> target, boolean isFirstResource) {
if (glideListener != null) {
if (holder.itemView.getHandler() != null) {
holder.itemView.getHandler().postDelayed(() -> glideListener.onArtworkLoadFailed(ArtworkView.this), System.currentTimeMillis() + 1000 - time);
}
}
return false;
}
@Override
public boolean onResourceReady(BitmapAndSize resource, ArtworkProvider model, Target<BitmapAndSize> target, boolean isFromMemoryCache, boolean isFirstResource) {
return false;
}
}).into(new ImageViewTarget<BitmapAndSize>(((ViewHolder) holder).imageView) {
@Override
protected void setResource(BitmapAndSize resource) {
holder.textContainer.setBackgroundResource(R.drawable.text_protection_scrim_reversed);
holder.progressBar.setVisibility(View.GONE);
holder.imageView.setImageBitmap(resource.bitmap);
holder.lineTwo.setText(String.format("%sx%spx", resource.size.width, resource.size.height));
}
});
holder.lineOne.setText(ArtworkModel.getTypeString(type));
if (type == ArtworkProvider.Type.FOLDER && file != null) {
holder.lineOne.setText(file.getName());
}
if (isCustom && file != null && file.getPath().contains("custom_artwork")) {
holder.lineOne.setText(holder.itemView.getContext().getString(R.string.artwork_type_custom));
}
holder.checkView.setVisibility(isSelected() ? View.VISIBLE : View.GONE);
}
use of com.bumptech.glide.request.RequestListener in project xabber-android by redsolution.
the class ChatMessageAdapter method setUpImage.
private void setUpImage(MessageItem messageItem, final Message messageHolder) {
messageHolder.messageImage.setVisibility(View.GONE);
if (!messageItem.isImage() || !SettingsManager.connectionLoadImages()) {
return;
}
if (messageItem.getFilePath() != null) {
boolean result = FileManager.loadImageFromFile(context, messageItem.getFilePath(), messageHolder.messageImage);
if (result) {
messageHolder.messageImage.setVisibility(View.VISIBLE);
messageHolder.messageText.setVisibility(View.GONE);
} else {
final String uniqueId = messageItem.getUniqueId();
final Realm realm = MessageDatabaseManager.getInstance().getRealmUiThread();
realm.executeTransactionAsync(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
MessageItem first = realm.where(MessageItem.class).equalTo(MessageItem.Fields.UNIQUE_ID, uniqueId).findFirst();
if (first != null) {
first.setFilePath(null);
}
}
});
}
} else {
final ViewGroup.LayoutParams layoutParams = messageHolder.messageImage.getLayoutParams();
Integer imageWidth = messageItem.getImageWidth();
Integer imageHeight = messageItem.getImageHeight();
if (imageWidth != null && imageHeight != null) {
FileManager.scaleImage(layoutParams, imageHeight, imageWidth);
Glide.with(context).load(messageItem.getText()).listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
messageHolder.messageImage.setVisibility(View.GONE);
messageHolder.messageText.setVisibility(View.VISIBLE);
return true;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
return false;
}
}).into(messageHolder.messageImage);
messageHolder.messageImage.setVisibility(View.VISIBLE);
messageHolder.messageText.setVisibility(View.GONE);
} else {
final String uniqueId = messageItem.getUniqueId();
Glide.with(context).load(messageItem.getText()).asBitmap().into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(final Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
final int width = resource.getWidth();
final int height = resource.getHeight();
if (width <= 0 || height <= 0) {
messageHolder.messageImage.setVisibility(View.GONE);
messageHolder.messageText.setVisibility(View.VISIBLE);
return;
}
final Realm realm = MessageDatabaseManager.getInstance().getRealmUiThread();
realm.executeTransactionAsync(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
MessageItem first = realm.where(MessageItem.class).equalTo(MessageItem.Fields.UNIQUE_ID, uniqueId).findFirst();
if (first != null) {
first.setImageWidth(width);
first.setImageHeight(height);
}
}
});
FileManager.scaleImage(layoutParams, height, width);
messageHolder.messageImage.setImageBitmap(resource);
messageHolder.messageImage.setVisibility(View.VISIBLE);
messageHolder.messageText.setVisibility(View.GONE);
}
});
}
}
}
use of com.bumptech.glide.request.RequestListener in project glide by bumptech.
the class FullscreenActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fullscreen_activity);
String resultJson = getIntent().getStringExtra(EXTRA_RESULT_JSON);
final Api.GifResult result = new Gson().fromJson(resultJson, Api.GifResult.class);
ImageView gifView = (ImageView) findViewById(R.id.fullscreen_gif);
gifView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("giphy_url", result.images.original.url);
clipboard.setPrimaryClip(clip);
if (gifDrawable != null) {
if (gifDrawable.isRunning()) {
gifDrawable.stop();
} else {
gifDrawable.start();
}
}
}
});
RequestBuilder<Drawable> thumbnailRequest = Glide.with(this).load(result).apply(decodeTypeOf(Bitmap.class));
Glide.with(this).load(result.images.original.url).thumbnail(thumbnailRequest).listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
if (resource instanceof GifDrawable) {
gifDrawable = (GifDrawable) resource;
} else {
gifDrawable = null;
}
return false;
}
}).into(gifView);
}
use of com.bumptech.glide.request.RequestListener in project Douya by DreaminginCodeZH.
the class ImageUtils method loadNavigationHeaderAvatar.
public static void loadNavigationHeaderAvatar(final ImageView view, final String url) {
Context context = view.getContext();
int size = context.getResources().getDimensionPixelSize(R.dimen.navigation_header_avatar_size);
Glide.with(context).load(url).placeholder(R.drawable.avatar_icon_white_inactive_64dp).override(size, size).diskCacheStrategy(DiskCacheStrategy.ALL).dontAnimate().dontTransform().listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
(e != null ? e : new NullPointerException()).printStackTrace();
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
view.setTag(url);
return false;
}
}).into(view);
}
use of com.bumptech.glide.request.RequestListener in project CloudReader by youlookwhat.
the class SlideShadeViewActivity method setData.
/**
* 加载titlebar背景
*/
private void setData() {
if (subjectsBean != null) {
// 高斯模糊背景 原来 参数:12,5 23,4
Glide.with(this).load(subjectsBean.getImages().getLarge()).error(R.drawable.stackblur_default).bitmapTransform(new BlurTransformation(this, 23, 4)).listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
binding.titleToolBar.setBackgroundColor(Color.TRANSPARENT);
binding.ivTitleHeadBg.setImageAlpha(0);
binding.ivTitleHeadBg.setVisibility(View.VISIBLE);
return false;
}
}).into(binding.ivTitleHeadBg);
}
}
Aggregations