use of com.bumptech.glide.request.RequestListener in project AmazeFileManager by TeamAmaze.
the class RecyclerAdapter method showRoundedThumbnail.
private void showRoundedThumbnail(ItemViewHolder viewHolder, IconDataParcelable iconData, ImageView view, OnImageProcessed errorListener) {
if (iconData.isImageBroken()) {
View iconBackground = getBoolean(PREFERENCE_USE_CIRCULAR_IMAGES) ? viewHolder.genericIcon : viewHolder.iconLayout;
viewHolder.genericIcon.setVisibility(View.VISIBLE);
iconBackground.setBackgroundColor(grey_color);
GlideApp.with(mainFrag).load(R.drawable.ic_broken_image_white_24dp).into(viewHolder.genericIcon);
view.setVisibility(View.INVISIBLE);
errorListener.onImageProcessed(true);
return;
}
View iconBackground = getBoolean(PREFERENCE_USE_CIRCULAR_IMAGES) ? viewHolder.genericIcon : viewHolder.iconLayout;
iconBackground.setBackgroundColor(iconSkinColor);
viewHolder.genericIcon.setVisibility(View.VISIBLE);
GlideApp.with(mainFrag).load(iconData.loadingImage).into(viewHolder.genericIcon);
view.setVisibility(View.INVISIBLE);
modelProvider.getPreloadRequestBuilder(iconData).listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
iconBackground.setBackgroundColor(grey_color);
GlideApp.with(mainFrag).load(R.drawable.ic_broken_image_white_24dp).into(viewHolder.genericIcon);
errorListener.onImageProcessed(true);
return true;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
viewHolder.genericIcon.setImageDrawable(null);
viewHolder.genericIcon.setVisibility(View.GONE);
view.setVisibility(View.VISIBLE);
errorListener.onImageProcessed(false);
return false;
}
}).into(view);
}
use of com.bumptech.glide.request.RequestListener in project Rocket by mozilla-tw.
the class TabTrayAdapter method loadCachedFavicon.
private void loadCachedFavicon(final Tab tab, final ViewHolder holder) {
RequestOptions options = new RequestOptions().diskCacheStrategy(DiskCacheStrategy.RESOURCE).dontAnimate();
Bitmap favicon = tab.getFavicon();
FaviconModel model = new FaviconModel(tab.getUrl(), FavIconUtils.getFavIconType(holder.itemView.getResources(), favicon), favicon);
requestManager.load(model).apply(options).listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
loadGeneratedFavicon(tab, holder);
return true;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
}).into(new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
updateFavicon(holder, resource);
}
});
}
use of com.bumptech.glide.request.RequestListener in project xabber-android by redsolution.
the class ImageViewerFragment method onViewCreated.
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// get params
Bundle args = getArguments();
if (args == null)
return;
String source;
String uri = args.getString(IMAGE_URL);
final String path = args.getString(IMAGE_PATH);
if (path != null)
source = path;
else
source = uri;
final String attachmentId = args.getString(ATTACHMENT_ID);
// find views
ivPhoto = view.findViewById(R.id.ivPhoto);
progressBar = view.findViewById(R.id.progressBar);
// setup image
progressBar.setVisibility(View.VISIBLE);
Glide.with(getActivity()).load(source).listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
if (e != null)
showError(e.toString());
if (path != null)
MessageManager.setAttachmentLocalPathToNull(attachmentId);
progressBar.setVisibility(View.GONE);
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
progressBar.setVisibility(View.GONE);
return false;
}
}).into(ivPhoto);
}
use of com.bumptech.glide.request.RequestListener in project Signal-Android by WhisperSystems.
the class AvatarPreviewActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState, boolean ready) {
super.onCreate(savedInstanceState, ready);
setTheme(R.style.TextSecure_MediaPreview);
setContentView(R.layout.contact_photo_preview_activity);
if (Build.VERSION.SDK_INT >= 21) {
postponeEnterTransition();
TransitionInflater inflater = TransitionInflater.from(this);
getWindow().setSharedElementEnterTransition(inflater.inflateTransition(R.transition.full_screen_avatar_image_enter_transition_set));
getWindow().setSharedElementReturnTransition(inflater.inflateTransition(R.transition.full_screen_avatar_image_return_transition_set));
}
Toolbar toolbar = findViewById(R.id.toolbar);
EmojiTextView title = findViewById(R.id.title);
ImageView avatar = findViewById(R.id.avatar);
setSupportActionBar(toolbar);
requireSupportActionBar().setDisplayHomeAsUpEnabled(true);
requireSupportActionBar().setDisplayShowTitleEnabled(false);
Context context = getApplicationContext();
RecipientId recipientId = RecipientId.from(getIntent().getStringExtra(RECIPIENT_ID_EXTRA));
Recipient.live(recipientId).observe(this, recipient -> {
ContactPhoto contactPhoto = recipient.isSelf() ? new ProfileContactPhoto(recipient, recipient.getProfileAvatar()) : recipient.getContactPhoto();
FallbackContactPhoto fallbackPhoto = recipient.isSelf() ? new ResourceContactPhoto(R.drawable.ic_profile_outline_40, R.drawable.ic_profile_outline_20, R.drawable.ic_person_large) : recipient.getFallbackContactPhoto();
Resources resources = this.getResources();
GlideApp.with(this).asBitmap().load(contactPhoto).fallback(fallbackPhoto.asCallCard(this)).error(fallbackPhoto.asCallCard(this)).diskCacheStrategy(DiskCacheStrategy.ALL).addListener(new RequestListener<Bitmap>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
Log.w(TAG, "Unable to load avatar, or avatar removed, closing");
finish();
return false;
}
@Override
public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
}).into(new CustomTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
avatar.setImageDrawable(RoundedBitmapDrawableFactory.create(resources, resource));
if (Build.VERSION.SDK_INT >= 21) {
startPostponedEnterTransition();
}
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
title.setText(recipient.getDisplayName(context));
});
FullscreenHelper fullscreenHelper = new FullscreenHelper(this);
findViewById(android.R.id.content).setOnClickListener(v -> fullscreenHelper.toggleUiVisibility());
fullscreenHelper.configureToolbarSpacer(findViewById(R.id.toolbar_cutout_spacer));
fullscreenHelper.showAndHideWithSystemUI(getWindow(), findViewById(R.id.toolbar_layout));
}
use of com.bumptech.glide.request.RequestListener in project xabber-android by redsolution.
the class FileMessageVH method setUpImage.
private void setUpImage(String imagePath, String imageUrl, final String uniqueId, Integer imageWidth, Integer imageHeight, Context context) {
if (!SettingsManager.connectionLoadImages())
return;
if (imagePath != null) {
boolean result = FileManager.loadImageFromFile(context, imagePath, messageImage);
if (result) {
messageImage.setVisibility(View.VISIBLE);
} else {
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 = messageImage.getLayoutParams();
if (imageWidth != null && imageHeight != null) {
FileManager.scaleImage(layoutParams, imageHeight, imageWidth);
Glide.with(context).load(imageUrl).listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
messageImage.setVisibility(View.GONE);
return true;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
}).into(messageImage);
messageImage.setVisibility(View.VISIBLE);
} else {
Glide.with(context).asBitmap().load(imageUrl).placeholder(R.drawable.ic_recent_image_placeholder).error(R.drawable.ic_recent_image_placeholder).into(new CustomTarget<Bitmap>() {
@Override
public void onLoadStarted(@Nullable Drawable placeholder) {
super.onLoadStarted(placeholder);
messageImage.setImageDrawable(placeholder);
messageImage.setVisibility(View.VISIBLE);
}
@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
super.onLoadFailed(errorDrawable);
messageImage.setImageDrawable(errorDrawable);
messageImage.setVisibility(View.VISIBLE);
}
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
final int width = resource.getWidth();
final int height = resource.getHeight();
if (width <= 0 || height <= 0) {
messageImage.setVisibility(View.GONE);
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);
messageImage.setImageBitmap(resource);
messageImage.setVisibility(View.VISIBLE);
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
}
}
}
Aggregations