com.bumptech.glide.RequestBuilder Java Examples
The following examples show how to use
com.bumptech.glide.RequestBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TyUtils.java From tysq-android with GNU General Public License v3.0 | 6 votes |
private static void getGlideRequest(Context context, String url, RequestOptions options, ImageView imageView) { RequestBuilder<Drawable> requestBuilder; List<Cookie> cookies = PersistentCookieStore.getInstance().getCookies(); if (TextUtils.isEmpty(url)) { requestBuilder = Glide.with(context).load(url); } else if (cookies == null || cookies.size() <= 0) { requestBuilder = Glide.with(context).load(url); } else { LazyHeaders.Builder builder = new LazyHeaders.Builder(); for (int i = 0; i < cookies.size(); i++) { Cookie cookie = cookies.get(i); String value = cookie.name() + "=" + cookie.value(); builder.setHeader("Cookie", value); } GlideUrl glideUrl = new GlideUrl(url, builder.build()); requestBuilder = Glide.with(context).load(glideUrl); } if (options != null) { requestBuilder.apply(options); } requestBuilder.into(imageView); }
Example #2
Source File: GlideImagesPlugin.java From Markwon with Apache License 2.0 | 6 votes |
@NonNull public static GlideImagesPlugin create(@NonNull final Context context) { return create(new GlideStore() { @NonNull @Override public RequestBuilder<Drawable> load(@NonNull AsyncDrawable drawable) { return Glide.with(context) .load(drawable.getDestination()); } @Override public void cancel(@NonNull Target<?> target) { Glide.with(context) .clear(target); } }); }
Example #3
Source File: GlideImageGeter.java From NewFastFrame with Apache License 2.0 | 6 votes |
@Override public Drawable getDrawable(String url) { final UrlDrawable urlDrawable = new UrlDrawable(); RequestBuilder load; final Target target; if (isGif(url)) { load = Glide.with(mContext).asGif().load(url); target = new GifTarget(urlDrawable); } else { load = Glide.with(mContext).asBitmap().load(url); target = new BitmapTarget(urlDrawable); } targets.add(target); load.into(target); return urlDrawable; }
Example #4
Source File: ZoomFragment.java From NClientV2 with Apache License 2.0 | 6 votes |
@Nullable private RequestBuilder<Drawable> loadPage() { RequestBuilder<Drawable> request; RequestManager glide=GlideX.with(photoView); if(glide==null)return null; File file=LocalGallery.getPage(galleryFolder,page+1); if(file!=null){ request=glide.load(file); }else { if (url==null) request = glide.load(R.mipmap.ic_launcher); else { LogUtility.d("Requested url glide: "+ url); request = glide.load(url); } } return request; }
Example #5
Source File: TinyGifDrawableLoader.java From BaseProject with Apache License 2.0 | 6 votes |
/** * 加载不一定是本地图片资源 * (即也可以是网络资源) * 并且也可以不是gif图片 * @param context * @param model * @param iv * @param playTimes */ public void loadMaybeGifDrawable(Context context,Object model,ImageView iv,int playTimes) { if (context == null || iv == null) { return; } iv.setVisibility(View.VISIBLE); theDisPlayImageView = new WeakReference<>(iv); this.playTimes = playTimes; RequestBuilder builder = Glide.with(context.getApplicationContext()) .asGif() ; if (loadCallback != null || playTimes >=1) {//指定了播放次数,则需要监听动画执行的结束 builder.listener(this); } RequestOptions options = new RequestOptions(); options.diskCacheStrategy(DiskCacheStrategy.RESOURCE); builder.apply(options) .load(model) .into(iv) ; }
Example #6
Source File: NowPlayingActivity.java From PainlessMusicPlayer with Apache License 2.0 | 6 votes |
private void setAlbumArt(@Nullable final String artUri) { if (!mTransitionPostponed && (hasCoverTransition || hasListViewTransition)) { mTransitionPostponed = true; supportPostponeEnterTransition(); } if (TextUtils.isEmpty(artUri)) { mRequestManager.clear(albumArt); albumArt.setImageResource(R.drawable.album_art_placeholder); onArtProcessed(); } else { RequestBuilder<Drawable> b = mRequestManager .asDrawable() .load(artUri); if (hasCoverTransition || hasListViewTransition) { b = b.apply(requestOptionsDontAnimate); } else { b = b.apply(requestOptions); } b.listener(new AlbumArtRequestListener()).into(albumArt); } }
Example #7
Source File: MsgThumbImageView.java From NIM_Android_UIKit with MIT License | 6 votes |
public void loadAsPath(final String path, final int width, final int height, final int maskId, final String ext) { if (TextUtils.isEmpty(path)) { loadAsResource(R.drawable.nim_image_default, maskId); return; } setBlendDrawable(maskId); RequestBuilder builder; if (ImageUtil.isGif(ext)) { builder = Glide.with(getContext().getApplicationContext()).asGif().load(new File(path)); } else { RequestOptions options = new RequestOptions() .override(width, height) .fitCenter() .placeholder(R.drawable.nim_image_default) .error(R.drawable.nim_image_default); builder = Glide.with(getContext().getApplicationContext()) .asBitmap() .apply(options) .load(new File(path)) ; } builder.into(this); }
Example #8
Source File: DemoGlideHelper.java From GestureViews with Apache License 2.0 | 6 votes |
public static void loadFlickrThumb(Photo photo, ImageView image) { final RequestOptions options = new RequestOptions() .diskCacheStrategy(DiskCacheStrategy.DATA) .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) .dontTransform(); final RequestBuilder<Drawable> thumbRequest = Glide.with(image) .load(photo.getThumbnailUrl()) .apply(options) .transition(DrawableTransitionOptions.with(TRANSITION_FACTORY)); Glide.with(image).load(photo.getMediumUrl()) .apply(options) .thumbnail(thumbRequest) .into(image); }
Example #9
Source File: DemoGlideHelper.java From GestureViews with Apache License 2.0 | 6 votes |
public static void loadFlickrFull(Photo photo, ImageView image, LoadingListener listener) { final String photoUrl = photo.getLargeSize() == null ? photo.getMediumUrl() : photo.getLargeUrl(); final RequestOptions options = new RequestOptions() .diskCacheStrategy(DiskCacheStrategy.DATA) .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) .dontTransform(); final RequestBuilder<Drawable> thumbRequest = Glide.with(image) .load(photo.getMediumUrl()) .apply(options); Glide.with(image) .load(photoUrl) .apply(new RequestOptions().apply(options).placeholder(image.getDrawable())) .thumbnail(thumbRequest) .listener(new RequestListenerWrapper<>(listener)) .into(image); }
Example #10
Source File: ImageLoadMnanger.java From star-zone-android with Apache License 2.0 | 6 votes |
RequestBuilder getGlide(Object o, ImageView iv) { RequestManager manager = Glide.with(getImageContext(iv)); if (o instanceof String) { try { int t = Integer.parseInt(String.valueOf(o)); return getGlideInteger(manager, t, iv); } catch (Exception e) { return getGlideString(manager, (String) o, iv); } } else if (o instanceof Integer) { return getGlideInteger(manager, (Integer) o, iv); } else if (o instanceof Uri) { return getGlideUri(manager, (Uri) o, iv); } else if (o instanceof File) { return getGlideFile(manager, (File) o, iv); } return getGlideString(manager, "", iv); }
Example #11
Source File: GlideHelper.java From GestureViews with Apache License 2.0 | 6 votes |
/** * Loads thumbnail and then replaces it with full image. */ public static void loadFull(ImageView image, int imageId, int thumbId) { // We don't want Glide to crop or resize our image final RequestOptions options = new RequestOptions() .diskCacheStrategy(DiskCacheStrategy.NONE) .override(Target.SIZE_ORIGINAL) .dontTransform(); final RequestBuilder<Drawable> thumbRequest = Glide.with(image) .load(thumbId) .apply(options); Glide.with(image) .load(imageId) .apply(options) .thumbnail(thumbRequest) .into(image); }
Example #12
Source File: ArtistGlideRequest.java From MusicPlayer with GNU General Public License v3.0 | 5 votes |
public RequestBuilder<Drawable> buildRequestDrawable() { //noinspection unchecked return createBaseRequestForDrawable(builder.requestManager, builder.artist, builder.noCustomImage, builder.forceDownload, builder.mLoadOriginalImage, builder.mImageNumber) .diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY) .priority(Priority.LOW) .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) .signature(createSignature(builder.artist,builder.mLoadOriginalImage, builder.mImageNumber)); }
Example #13
Source File: ArtistGlideRequest.java From MusicPlayer with GNU General Public License v3.0 | 5 votes |
public RequestBuilder<Bitmap> build() { //noinspection unchecked return createBaseRequest(builder.requestManager, builder.artist, builder.noCustomImage, builder.forceDownload, builder.mLoadOriginalImage, builder.mImageNumber) .diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY) .priority(Priority.LOW) .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) .signature(createSignature(builder.artist,builder.mLoadOriginalImage, builder.mImageNumber)); }
Example #14
Source File: GiphyAdapter.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
@Override public void onBindViewHolder(@NonNull GiphyViewHolder holder, int position) { GiphyImage image = images.get(position); holder.modelReady = false; holder.image = image; holder.thumbnail.setAspectRatio(image.getGifAspectRatio()); holder.gifProgress.setVisibility(View.GONE); RequestBuilder<Drawable> thumbnailRequest = GlideApp.with(context) .load(new ChunkedImageUrl(image.getStillUrl(), image.getStillSize())) .diskCacheStrategy(DiskCacheStrategy.ALL); if (Util.isLowMemory(context)) { glideRequests.load(new ChunkedImageUrl(image.getStillUrl(), image.getStillSize())) .placeholder(new ColorDrawable(Util.getRandomElement(MaterialColor.values()).toConversationColor(context))) .diskCacheStrategy(DiskCacheStrategy.ALL) .transition(DrawableTransitionOptions.withCrossFade()) .listener(holder) .into(holder.thumbnail); holder.setModelReady(); } else { glideRequests.load(new ChunkedImageUrl(image.getGifUrl(), image.getGifSize())) .thumbnail(thumbnailRequest) .placeholder(new ColorDrawable(Util.getRandomElement(MaterialColor.values()).toConversationColor(context))) .diskCacheStrategy(DiskCacheStrategy.ALL) .transition(DrawableTransitionOptions.withCrossFade()) .listener(holder) .into(holder.thumbnail); } }
Example #15
Source File: ArtistGlideRequest.java From MusicPlayer with GNU General Public License v3.0 | 5 votes |
public RequestBuilder<Bitmap> build() { //noinspection unchecked return createBaseRequest(builder.requestManager, builder.artist, builder.noCustomImage, builder.forceDownload, builder.mLoadOriginalImage, builder.mImageNumber) //.transcode(new BitmapPaletteTranscoder(context), BitmapPaletteWrapper.class) .diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY) .transition(GenericTransitionOptions.with(DEFAULT_ANIMATION)) .priority(Priority.LOW) .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) .signature(createSignature(builder.artist,builder.mLoadOriginalImage, builder.mImageNumber)); }
Example #16
Source File: ArtistGlideRequest.java From MusicPlayer with GNU General Public License v3.0 | 5 votes |
public RequestBuilder<Drawable> buildRequestDrawable() { //noinspection unchecked return createBaseRequestForDrawable(builder.requestManager, builder.artist, builder.noCustomImage, builder.forceDownload, builder.mLoadOriginalImage, builder.mImageNumber) .diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY) .priority(Priority.LOW) .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) .signature(createSignature(builder.artist,builder.mLoadOriginalImage, builder.mImageNumber)); }
Example #17
Source File: ArtistGlideRequest.java From MusicPlayer with GNU General Public License v3.0 | 5 votes |
public static RequestBuilder<Drawable> createBaseRequestForDrawable( RequestManager requestManager, Artist artist, boolean noCustomImage, boolean forceDownload, boolean loadOriginal, int imageNumber) { RequestBuilder<Drawable> builder; boolean hasCustomImage = CustomArtistImageUtil.getInstance(App.getInstance()).hasCustomArtistImage(artist); if (noCustomImage || !hasCustomImage) { builder = requestManager.load(new ArtistImage(artist.getName(), forceDownload, loadOriginal, imageNumber)); } else { builder = requestManager.load(CustomArtistImageUtil.getFile(artist)); } return builder; }
Example #18
Source File: ArtistGlideRequest.java From MusicPlayer with GNU General Public License v3.0 | 5 votes |
public static RequestBuilder<Bitmap> createBaseRequest( RequestManager requestManager, Artist artist, boolean noCustomImage, boolean forceDownload, boolean loadOriginal, int imageNumber) { RequestBuilder<Bitmap> builder; boolean hasCustomImage = CustomArtistImageUtil.getInstance(App.getInstance()).hasCustomArtistImage(artist); if (noCustomImage || !hasCustomImage) { builder = requestManager.asBitmap().load(new ArtistImage(artist.getName(), forceDownload, loadOriginal, imageNumber)); } else { builder = requestManager.asBitmap().load(CustomArtistImageUtil.getFile(artist)); } return builder; }
Example #19
Source File: GlideImagesPlugin.java From Markwon with Apache License 2.0 | 5 votes |
@NonNull public static GlideImagesPlugin create(@NonNull final RequestManager requestManager) { return create(new GlideStore() { @NonNull @Override public RequestBuilder<Drawable> load(@NonNull AsyncDrawable drawable) { return requestManager.load(drawable.getDestination()); } @Override public void cancel(@NonNull Target<?> target) { requestManager.clear(target); } }); }
Example #20
Source File: ImagesActivity.java From Markwon with Apache License 2.0 | 5 votes |
private void glideSingleImageWithPlaceholder() { final String md = "[![undefined](https://img.youtube.com/vi/gs1I8_m4AOM/0.jpg)](https://www.youtube.com/watch?v=gs1I8_m4AOM)"; final Context context = this; final Markwon markwon = Markwon.builder(context) .usePlugin(GlideImagesPlugin.create(new GlideImagesPlugin.GlideStore() { @NonNull @Override public RequestBuilder<Drawable> load(@NonNull AsyncDrawable drawable) { // final Drawable placeholder = ContextCompat.getDrawable(context, R.drawable.ic_home_black_36dp); // placeholder.setBounds(0, 0, 100, 100); return Glide.with(context) .load(drawable.getDestination()) // .placeholder(ContextCompat.getDrawable(context, R.drawable.ic_home_black_36dp)); // .placeholder(placeholder); .placeholder(R.drawable.ic_home_black_36dp); } @Override public void cancel(@NonNull Target<?> target) { Glide.with(context) .clear(target); } })) .build(); markwon.setMarkdown(textView, md); }
Example #21
Source File: EntryListView.java From Aegis with GNU General Public License v3.0 | 5 votes |
@Nullable @Override public RequestBuilder getPreloadRequestBuilder(@NonNull VaultEntry entry) { return Glide.with(EntryListView.this) .asDrawable() .load(entry) .diskCacheStrategy(DiskCacheStrategy.NONE) .skipMemoryCache(false); }
Example #22
Source File: ImageUtil.java From BaseProject with Apache License 2.0 | 5 votes |
public static void loadImage(Context context, String picUrl, int newWidth, int newHeight, Drawable holderDrawable, Drawable errorDrawable, ImageView targetIv , RequestListener callback) { RequestBuilder requestBuilder = loadImageRequest(context, picUrl); RequestOptions options = new RequestOptions(); if (newWidth > 0 && newHeight > 0) { options.override(newWidth,newHeight).centerCrop(); } else{ // loadRequest.fit(); } if (holderDrawable != null) { options.placeholder(holderDrawable); } else{ // loadRequest.noPlaceholder(); } if (errorDrawable != null) { options.error(errorDrawable); } options.dontAnimate(); if (callback != null) { requestBuilder.listener(callback); } requestBuilder.apply(options) .into(targetIv); }
Example #23
Source File: TinyGifDrawableLoader.java From BaseProject with Apache License 2.0 | 5 votes |
public void loadGifDrawable(Context context, @RawRes @DrawableRes int gifDrawableResId, ImageView iv, int playTimes) { if (context == null || iv == null) { return; } iv.setVisibility(View.VISIBLE); theDisPlayImageView = new WeakReference<>(iv);//added by fee 2019-07-08: 将当前要显示的ImageView控件引用起来,但不适用本类用于给不同的ImageView加载 this.playTimes = playTimes; //注:如果不是gif资源,则在asGif()时会抛异常 RequestBuilder<GifDrawable> requestBuilder = Glide.with(context.getApplicationContext()) .asGif() // .load(gifDrawableResId) ; if ( playTimes >= 1 || loadCallback != null) {//指定了播放次数,则需要监听动画执行的结束 requestBuilder.listener(this) ; } RequestOptions options = new RequestOptions(); options.diskCacheStrategy(DiskCacheStrategy.RESOURCE); requestBuilder.apply(options) // listener(this) .load(gifDrawableResId) .into(iv) ; }
Example #24
Source File: QueueActivity.java From PainlessMusicPlayer with Apache License 2.0 | 5 votes |
@SuppressLint("CheckResult") private void loadAlbumArt(@NonNull final String uri) { final RequestBuilder<Drawable> b = mRequestManager .asDrawable() .load(uri); if (hasCoverTransition || hasItemViewTransition) { supportPostponeEnterTransition(); b.apply(dontAnimateOptions); } else { b.apply(requestOptions); } b.listener(new AlbumArtRequestListener()).into(albumArt); }
Example #25
Source File: MessageImageView.java From Socket.io-FLSocketIM-Android with MIT License | 5 votes |
public void loadAsPath(final String path, final int width, final int height, final int maskId, final String ext) { if (TextUtils.isEmpty(path)) { return; } setBlendDrawable(maskId); RequestBuilder builder; RequestOptions options = new RequestOptions() .override(width, height) .fitCenter(); builder = Glide.with(getContext().getApplicationContext()).asBitmap().apply(options).load(new File(path)); builder.into(this); }
Example #26
Source File: ThumbnailView.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
private RequestBuilder buildPlaceholderGlideRequest(@NonNull GlideRequests glideRequests, @NonNull Slide slide) { GlideRequest<Bitmap> bitmap = glideRequests.asBitmap(); BlurHash placeholderBlur = slide.getPlaceholderBlur(); if (placeholderBlur != null) { bitmap = bitmap.load(placeholderBlur); } else { bitmap = bitmap.load(slide.getPlaceholderRes(getContext().getTheme())); } return applySizing(bitmap.diskCacheStrategy(DiskCacheStrategy.NONE), new CenterCrop()); }
Example #27
Source File: DialogUtils.java From SoloPi with Apache License 2.0 | 5 votes |
/** * 初始化监听器 */ private void initData() { img.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ImageDialog.this.dismiss(); } }); // 对于resourceId类型,暂时只能走直接设置 if (id != null) { img.setImageResource(id); return; } RequestManager manager = GlideApp.with(img.getContext()); RequestBuilder<?> request; if (file != null) { request = manager.load(file); } else if (path != null) { request = manager.load(path); } else if (uri != null) { request = manager.load(uri); } else if (bitmap != null){ request = manager.load(bitmap); } else if (data != null){ request = manager.load(data); } else { return; } request.apply(RequestOptions.fitCenterTransform()).into(img); }
Example #28
Source File: ZoomFragment.java From NClientV2 with Apache License 2.0 | 5 votes |
private void loadImage(){ cancelRequest(); RequestBuilder<Drawable>dra=loadPage(); if(dra==null)return; dra .transform(new Rotate(degree)) .placeholder(R.drawable.ic_launcher_foreground) .error(R.drawable.ic_refresh) .into(target); }
Example #29
Source File: DokitGlideTransform.java From DoraemonKit with Apache License 2.0 | 5 votes |
@NonNull @Override public Resource<Bitmap> transform(@NonNull Context context, @NonNull Resource<Bitmap> resource, int outWidth, int outHeight) { try { if (mWrap != null) { resource = mWrap.transform(context, resource, outWidth, outHeight); } if (PerformanceSpInfoConfig.isLargeImgOpen()) { String url = ""; if (mRequestBuilder instanceof RequestBuilder) { if (ReflectUtils.reflect(mRequestBuilder).field("model").get() instanceof String) { url = ReflectUtils.reflect(mRequestBuilder).field("model").get(); } else if (ReflectUtils.reflect(mRequestBuilder).field("model").get() instanceof Integer) { url = "" + ReflectUtils.reflect(mRequestBuilder).field("model").get(); } } Bitmap bitmap = resource.get(); double imgSize = ConvertUtils.byte2MemorySize(bitmap.getByteCount(), MemoryConstants.MB); LargePictureManager.getInstance().saveImageInfo(url, imgSize, bitmap.getWidth(), bitmap.getHeight(), "Glide"); } } catch (Exception e) { if (mWrap != null) { resource = mWrap.transform(context, resource, outWidth, outHeight); } } return resource; }
Example #30
Source File: ArtistGlideRequest.java From MusicPlayer with GNU General Public License v3.0 | 5 votes |
public RequestBuilder<Bitmap> build() { return createBaseRequest(requestManager, artist, noCustomImage, forceDownload, mLoadOriginalImage, mImageNumber) .diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY) .transition(GenericTransitionOptions.with(DEFAULT_ANIMATION)) .priority(Priority.LOW) //.override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) .signature(createSignature(artist,mLoadOriginalImage, mImageNumber)); }