Сообщество IT-специалистов
Ответы на любые вопросы об IT
Профессиональное развитие в IT
Удаленная работа для IT-специалистов
Glide.with(context).load(...) .listener(object : RequestListener<Drawable> { override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean { //TODO handle error images while loading photo return true } override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean { //TODO use "resource" as the photo for your ImageView return true } }).submit()
@Override public boolean onException(Exception e, T model, Target<PictureDrawable> target, boolean isFirstResource) { ImageView view = ((ImageViewTarget<?>) target).getView(); if (Build.VERSION_CODES.HONEYCOMB <= Build.VERSION.SDK_INT) { view.setLayerType(ImageView.LAYER_TYPE_NONE, null); } Glide.with() .load() .into(view); return false; }
@Override public boolean onException(Exception e, T model, Target<PictureDrawable> target, boolean isFirstResource){ ImageView view = ((ImageViewTarget<?>) target).getView(); Glide.with(view.getContext()) .load(R.drawable.ic_launcher_background) .into(view); return false; }
... RecyclerViewAdapter(Context context, List<ListItem> ItemList){ this.context = context; this.ItemList = ItemList; this.requestBuilder = Glide.with(context) .using(Glide.buildStreamModelLoader(Uri.class, context), InputStream.class) .from(Uri.class) .as(SVG.class) .transcode(new SvgDrawableTranscoder(), PictureDrawable.class) .sourceEncoder(new StreamEncoder()) .cacheDecoder(new FileToStreamDecoder<>(new SvgDecoder())) .decoder(new SvgDecoder()) .animate(android.R.anim.fade_in) .listener(new SvgSoftwareLayerSetter<Uri>()); Uri uri = Uri.parse(ItemList .get(position).getUrl()); requestBuilder .diskCacheStrategy(DiskCacheStrategy.SOURCE) .load(uri) .into(holder.image);
public class SvgSoftwareLayerSetter<T> implements RequestListener<T, PictureDrawable> { @Override public boolean onException(Exception e, T model, Target<PictureDrawable> target, boolean isFirstResource) { ImageView view = ((ImageViewTarget<?>) target).getView(); Glide.with(view.getContext()) .load(R.drawable.ic_launcher_background) .into(view); return false; } @Override public boolean onResourceReady(PictureDrawable resource, T model, Target<PictureDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { ImageView view = ((ImageViewTarget<?>) target).getView(); if (Build.VERSION_CODES.HONEYCOMB <= Build.VERSION.SDK_INT) { view.setLayerType(ImageView.LAYER_TYPE_SOFTWARE, null); } return false; } }