public void displayImage(final String uri, final ImageView imageView, int defaultIcon, final DisplayListener listener) { GenericRequestBuilder req = Glide.with(imageView.getContext().getApplicationContext()).load(uri).asBitmap().diskCacheStrategy(mDiskCacheStrategy); if (defaultIcon > 0) { req.placeholder(defaultIcon); } req.into(new BitmapImageViewTarget(imageView) { @Override public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { super.onResourceReady(resource, glideAnimation); if (listener != null) { listener.onLoadCompleted(uri, imageView, resource); } } @Override public void onLoadFailed(Exception e, Drawable errorDrawable) { super.onLoadFailed(e, errorDrawable); if (listener != null) { listener.onLoadFailed(uri, imageView); } } }); }
private static GenericRequestBuilder<GifDecoder, GifDecoder, Bitmap, Bitmap> getRequestBuilder(Context context, GifDecoder gifDecoder, int width, int height, BitmapPool bitmapPool) { GifFrameResourceDecoder frameResourceDecoder = new GifFrameResourceDecoder(bitmapPool); GifFrameModelLoader frameLoader = new GifFrameModelLoader(); Encoder<GifDecoder> sourceEncoder = NullEncoder.get(); return Glide.with(context) .using(frameLoader, GifDecoder.class) .load(gifDecoder) .as(Bitmap.class) .sourceEncoder(sourceEncoder) .decoder(frameResourceDecoder) .skipMemoryCache(true) .diskCacheStrategy(DiskCacheStrategy.NONE) .override(width, height); }
/** * 核心图片加载函数 * context : Context/Activity/Fragment 最好传activity 可与生命周期绑定 * 参数uri : 网络图片url/本地图片path/资源文件ID/byte[] * view : 要展示图片的控件 * defaultIcon : 默认占位图 */ public void displayImage(Context context, String uri, ImageView view , int defaultIcon){ GenericRequestBuilder req = Glide.with(context) .load(uri) .diskCacheStrategy(mDiskCacheStrategy); if(defaultIcon >0 ){ req.placeholder(defaultIcon) .error(defaultIcon); } req.into(view); }
/** * 重载方法 加载展示圆角图片 * @param round 圆角矢量 由调用方控制 */ public void displayImage(Context context, String uri, ImageView view, int defaultIcon, int round) { GenericRequestBuilder req = Glide.with(context) .load(uri) .diskCacheStrategy(mDiskCacheStrategy) .transform(new GlideRoundTransform(context,round)); if(defaultIcon >0) { req.placeholder(defaultIcon) .error(defaultIcon); } req.into(view); }
private GenericRequestBuilder buildThumbnailGlideRequest(@NonNull Slide slide, @NonNull MasterSecret masterSecret) { @SuppressWarnings("ConstantConditions") DrawableRequestBuilder<DecryptableUri> builder = Glide.with(getContext()) .load(new DecryptableUri(masterSecret, slide.getThumbnailUri())) .diskCacheStrategy(DiskCacheStrategy.NONE) .crossFade() .transform(new RoundedCorners(getContext(), true, radius, backgroundColorHint)); if (slide.isInProgress()) return builder; else return builder.error(R.drawable.ic_missing_thumbnail_picture); }
private GenericRequestBuilder buildPlaceholderGlideRequest(Slide slide) { return Glide.with(getContext()) .load(slide.getPlaceholderRes(getContext().getTheme())) .asBitmap() .diskCacheStrategy(DiskCacheStrategy.NONE) .fitCenter(); }
public static GenericRequestBuilder applyDimens(@NonNull GenericRequestBuilder requestBuilder, @NonNull GlideTaskParams payload) { final Media media = payload.getMedia(); if (media != null) { requestBuilder.override(media.getWidth(), media.getHeight()); } return requestBuilder; }
public static <T extends ImageView> void load(@NonNull final GenericRequestBuilder requestBuilder, @NonNull final GlideTaskParams<T> payload) { if (payload.isThumbnail()) { requestBuilder.thumbnail(payload.getThumbnailMultiplier()); } requestBuilder.placeholder(payload.getPlaceholder()) .into(new GlideDrawableImageViewTarget(payload.getTarget()) { @Override public void onLoadFailed(Exception e, Drawable errorDrawable) { if (payload.getCurrentRetry() < payload.getMaxRetry()) { payload.incrementCurrentRetry(); load(requestBuilder, payload); } else { super.onLoadFailed(e, errorDrawable); payload.getListener().failure(payload.getTarget(), errorDrawable); } } @Override public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> animation) { super.onResourceReady(resource, animation); payload.getListener().success(payload.getTarget(), resource); } }); }
@Override public Drawable getDrawable(@NonNull String url) { final UrlDrawable urlDrawable = new UrlDrawable(); if (container != null && container.get() != null) { Context context = container.get().getContext(); final GenericRequestBuilder load = Glide.with(context) .load(url) .dontAnimate(); final GlideDrawableTarget target = new GlideDrawableTarget(urlDrawable, container, width); load.into(target); cachedTargets.add(target); } return urlDrawable; }
@Singleton @Provides GenericRequestBuilder<Media, InputStream, byte[], GifDrawable> provideGifRequestBuilder( RequestManager requestManager) { return requestManager.using(new MediaLoader(mView), InputStream.class) .from(Media.class) .as(byte[].class) .transcode(new GifDrawableBytesTranscoder(), GifDrawable.class) .diskCacheStrategy(DiskCacheStrategy.SOURCE) .decoder(new StreamByteArrayResourceDecoder()) .sourceEncoder(new StreamEncoder()) .cacheDecoder(new FileToStreamDecoder<>(new StreamByteArrayResourceDecoder())); }
public static GenericRequestBuilder<Uri, InputStream, SVG, PictureDrawable> create(Context context, Drawable placeholder) { return Glide.with(context.getApplicationContext()) .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()) .placeholder(placeholder) .listener(new SvgSoftwareLayerSetter()); }
private GenericRequestBuilder buildGlideRequest(@NonNull Slide slide, @Nullable MasterSecret masterSecret) { final GenericRequestBuilder builder; if (slide.getPart().isPendingPush()) { builder = buildPendingGlideRequest(slide); } else if (slide.getThumbnailUri() != null) { builder = buildThumbnailGlideRequest(slide, masterSecret); } else { builder = buildPlaceholderGlideRequest(slide); } return builder.error(R.drawable.ic_missing_thumbnail_picture); }
private GenericRequestBuilder buildThumbnailGlideRequest(Slide slide, MasterSecret masterSecret) { final GenericRequestBuilder builder; if (slide.isDraft()) builder = buildDraftGlideRequest(slide); else builder = buildEncryptedPartGlideRequest(slide, masterSecret); return builder; }
private GenericRequestBuilder buildEncryptedPartGlideRequest(Slide slide, MasterSecret masterSecret) { if (masterSecret == null) { throw new IllegalStateException("null MasterSecret when loading non-draft thumbnail"); } return Glide.with(getContext()).load(new DecryptableUri(masterSecret, slide.getThumbnailUri())) .transform(new ThumbnailTransform(getContext())); }
private GenericRequestBuilder buildThumbnailGlideRequest(@NonNull Slide slide, @NonNull MasterSecret masterSecret) { @SuppressWarnings("ConstantConditions") DrawableRequestBuilder<DecryptableUri> builder = Glide.with(getContext()).load(new DecryptableUri(masterSecret, slide.getThumbnailUri())) .crossFade() .transform(new RoundedCorners(getContext(), true, radius, backgroundColorHint)); if (slide.isInProgress()) return builder; else return builder.error(R.drawable.ic_missing_thumbnail_picture); }
@Singleton @Provides GenericRequestBuilder<GlideUrl, InputStream, byte[], GifDrawable> provideGifRequestBuilder( RequestManager requestManager, OkHttpClient okHttpClient) { return requestManager.using(new OkHttpUrlLoader(okHttpClient), InputStream.class) .from(GlideUrl.class) .as(byte[].class) .transcode(new GifDrawableBytesTranscoder(), GifDrawable.class) .diskCacheStrategy(DiskCacheStrategy.SOURCE) .decoder(new StreamByteArrayResourceDecoder()) .sourceEncoder(new StreamEncoder()) .cacheDecoder(new FileToStreamDecoder<>(new StreamByteArrayResourceDecoder())); }
@Bindable public GenericRequestBuilder getHeroImage() { if (mLfmReference != null) { Image hero = mLfmReference.getImageBySize(Image.Size.MEGA); if (hero != null) { return Glide.with(getContext()) .load(hero.getUrl()) .diskCacheStrategy(DiskCacheStrategy.SOURCE) .centerCrop() .animate(android.R.anim.fade_in); } } return null; }
GifFrameLoader(FrameCallback callback, GifDecoder gifDecoder, Handler handler, GenericRequestBuilder<GifDecoder, GifDecoder, Bitmap, Bitmap> requestBuilder) { if (handler == null) { handler = new Handler(Looper.getMainLooper(), new FrameLoaderCallback()); } this.callback = callback; this.gifDecoder = gifDecoder; this.handler = handler; this.requestBuilder = requestBuilder; }
public GenericRequestBuilder<String, InputStream, ImageWrapper, Drawable> glide() { return mRequestBuilder; }
public LoadCycler(GenericRequestBuilder<M, ?, ?, T> request, ImageView imageView) { this(request, new DrawableImageViewTarget(imageView)); }
public LoadCycler(GenericRequestBuilder<M, ?, ?, T> request, Target<? super T> target) { this.target = target; prev = copy(request); curr = copy(request); next = copy(request); }
private GenericRequestBuilder<M, ?, ?, T> copy(GenericRequestBuilder<M, ?, ?, T> request) { return request.clone().dontAnimate().thumbnail(null).listener(null).load(null); }
private void rotate() { GenericRequestBuilder<M, ?, ?, T> temp = prev; prev = curr; curr = next; next = temp; }
private GenericRequestBuilder buildPendingGlideRequest(Slide slide) { return Glide.with(getContext()).load(R.drawable.stat_sys_download_anim0) .dontTransform() .skipMemoryCache(true) .crossFade(); }
private GenericRequestBuilder buildDraftGlideRequest(Slide slide) { return Glide.with(getContext()).load(slide.getThumbnailUri()).asBitmap() .fitCenter() .listener(new PduThumbnailSetListener(slide.getPart())); }
private GenericRequestBuilder buildPlaceholderGlideRequest(Slide slide) { return Glide.with(getContext()).load(slide.getPlaceholderRes(getContext().getTheme())) .fitCenter() .crossFade(); }
private GenericRequestBuilder buildPlaceholderGlideRequest(Slide slide) { return Glide.with(getContext()).load(slide.getPlaceholderRes(getContext().getTheme())) .asBitmap() .fitCenter(); }
@BindingAdapter("android:src") public static void bindImage(ImageView imageView, GenericRequestBuilder request) { if (request != null) { request.into(imageView); } }
@Bindable public GenericRequestBuilder getHeroImage() { return Glide.with(getContext()).load(mAlbum.getArtUri()).centerCrop(); }
@Override public GenericRequestBuilder getPreloadRequestBuilder(FodexLayoutSpecItem item) { return mPreloadRequest.load(item.fodexItem.uri); }
@Override protected GenericRequestBuilder getRequestBuilder(String url) { return mImageLoader.beginImageLoad(url, null, true /*crop*/); }
@Override public Drawable getDrawable(ImageHolder holder, final RichTextConfig config, TextView textView) { final ImageTarget target; final GenericRequestBuilder load; DrawableTypeRequest dtr; DrawableWrapper drawableWrapper = new DrawableWrapper(); byte[] src = Base64.decode(holder.getSource()); if (src != null) { dtr = Glide.with(textView.getContext()).load(src); } else { dtr = Glide.with(textView.getContext()).load(holder.getSource()); } Rect rect = null; if (config.cacheType >= CacheType.LAYOUT) { rect = loadCache(holder.getSource()); if (rect != null) { drawableWrapper.setBounds(rect); } } else { drawableWrapper.setBounds(0, 0, holder.getWidth(), holder.getHeight()); } if (holder.isGif()) { target = new ImageTargetGif(textView, drawableWrapper, holder, config, this, rect); load = dtr.asGif(); } else { target = new ImageTargetBitmap(textView, drawableWrapper, holder, config, this, rect); load = dtr.asBitmap().atMost(); } checkTag(textView); targets.add(target); if (!config.resetSize && holder.isInvalidateSize()) { load.override(holder.getWidth(), holder.getHeight()); } if (holder.getScaleType() == ImageHolder.ScaleType.CENTER_CROP) { if (holder.isGif()) { //noinspection ConstantConditions ((GifTypeRequest) load).centerCrop(); } else { //noinspection ConstantConditions ((BitmapTypeRequest) load).centerCrop(); } } else if (holder.getScaleType() == ImageHolder.ScaleType.FIT_CENTER) { if (holder.isGif()) { //noinspection ConstantConditions ((GifTypeRequest) load).fitCenter(); } else { //noinspection ConstantConditions ((BitmapTypeRequest) load).fitCenter(); } } textView.post(new Runnable() { @Override public void run() { load.placeholder(config.placeHolder).error(config.errorImage).into(target); } }); drawableWrapper.setCallback(textView); return drawableWrapper; }
@Override public GenericRequestBuilder getPreloadRequestBuilder(Entry item) { return Glide.with(mContext).load(item.getUrl()).bitmapTransform(new CenterCrop(mPool), new RoundedCornersTransformation(mPool, 8, 0)) //.crossFade() .diskCacheStrategy(DiskCacheStrategy.ALL); }