com.bumptech.glide.DrawableTypeRequest Java Examples
The following examples show how to use
com.bumptech.glide.DrawableTypeRequest.
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: AFGlideUtil.java From AFBaseLibrary with Apache License 2.0 | 6 votes |
public static void loadImgBackground(Object obj, final View v, SimpleTarget simpleTarget) { DrawableTypeRequest drawableTypeRequest = getDrawableTypeRequest(obj, v); if (drawableTypeRequest == null) { drawableTypeRequest = getDrawableTypeRequest(sCommonPlaceholder, v); } if (drawableTypeRequest != null) { drawableTypeRequest .asBitmap() .centerCrop() .dontAnimate() .error(sCommonPlaceholder) .placeholder(sCommonPlaceholder) .diskCacheStrategy(DiskCacheStrategy.RESULT) .into(simpleTarget != null ? simpleTarget : new SimpleTarget<Bitmap>() { @Override public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { BitmapDrawable drawable = new BitmapDrawable(resource); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { v.setBackground(drawable); } else { v.setBackgroundDrawable(drawable); } } }); } }
Example #2
Source File: AFGlideUtil.java From AFBaseLibrary with Apache License 2.0 | 6 votes |
public static void loadImgBlur(Object obj, ImageView img) { DrawableTypeRequest drawableTypeRequest = getDrawableTypeRequest(obj, img); if (drawableTypeRequest == null) { drawableTypeRequest = getDrawableTypeRequest(sCommonPlaceholder, img); } if (drawableTypeRequest != null) { drawableTypeRequest .centerCrop() .dontAnimate() .error(sCommonPlaceholder) .placeholder(sCommonPlaceholder) .bitmapTransform(new BlurTransformation(img.getContext(), 16, 4)) .diskCacheStrategy(DiskCacheStrategy.RESULT) .into(img); } }
Example #3
Source File: AFGlideUtil.java From AFBaseLibrary with Apache License 2.0 | 6 votes |
/** * 加载圆形图片 * * @param obj 要加载的资源 * @param img 被加载的图片 */ public static void loadCircleImg(Object obj, ImageView img) { DrawableTypeRequest drawableTypeRequest = getDrawableTypeRequest(obj, img); if (drawableTypeRequest == null) { drawableTypeRequest = getDrawableTypeRequest(sCirclePlaceholder, img); } if (drawableTypeRequest != null) { drawableTypeRequest .centerCrop() .dontAnimate() .transform(new AFGlideUtil.GlideCircleTransform(img.getContext())) .error(sCirclePlaceholder) .placeholder(sCirclePlaceholder). diskCacheStrategy(DiskCacheStrategy.RESULT).into(img); } }
Example #4
Source File: ImageLoader.java From LbaizxfPulltoRefresh with Apache License 2.0 | 6 votes |
/** * 图片加载 * @author leibing * @createTime 2016/8/15 * @lastModify 2016/8/15 * @param context 上下文 * @param imageView 图片显示控件 * @param localPath 图片本地链接 * @param defaultImage 默认占位图片 * @param errorImage 加载失败后图片 * @return */ public void load(Context context, ImageView imageView, File localPath, Drawable defaultImage, Drawable errorImage){ // 图片加载库采用Glide框架 DrawableTypeRequest request = Glide.with(context).load(localPath); request.thumbnail(0.1f) //用原图的1/10作为缩略图 .placeholder(defaultImage) //设置资源加载过程中的占位Drawable .crossFade() //设置加载渐变动画 .priority(Priority.NORMAL) //指定加载的优先级,优先级越高越优先加载, // 但不保证所有图片都按序加载 // 枚举Priority.IMMEDIATE,Priority.HIGH,Priority.NORMAL,Priority.LOW // 默认为Priority.NORMAL .fallback(null) //设置model为空时要显示的Drawable // 如果没设置fallback,model为空时将显示error的Drawable, // 如果error的Drawable也没设置,就显示placeholder的Drawable .error(errorImage) //设置load失败时显示的Drawable .skipMemoryCache(true) //设置跳过内存缓存,但不保证一定不被缓存 // (比如请求已经在加载资源且没设置跳过内存缓存,这个资源就会被缓存在内存中) .diskCacheStrategy(DiskCacheStrategy.RESULT) //缓存策略DiskCacheStrategy.SOURCE: // 缓存原始数据,DiskCacheStrategy.RESULT: // 缓存变换(如缩放、裁剪等)后的资源数据, // DiskCacheStrategy.NONE:什么都不缓存, // DiskCacheStrategy.ALL:缓存SOURC和RESULT。 // 默认采用DiskCacheStrategy.RESULT策略, // 对于download only操作要使用DiskCacheStrategy.SOURCE .into(imageView); }
Example #5
Source File: AFGlideUtil.java From AFBaseLibrary with Apache License 2.0 | 6 votes |
/** * 加载圆角图片 * * @param obj 要加载的资源 * @param img 被加载的图片 * @param dp 圆角大小 */ public static void loadRoundImg(Object obj, ImageView img, int dp) { DrawableTypeRequest drawableTypeRequest = getDrawableTypeRequest(obj, img); if (drawableTypeRequest == null) { drawableTypeRequest = getDrawableTypeRequest(sRoundPlaceholder, img); } if (drawableTypeRequest != null) { drawableTypeRequest .centerCrop() .dontAnimate() .transform(new BitmapTransformation[]{new AFGlideUtil.GlideRoundTransform(img.getContext(), dp)}) .error(sRoundPlaceholder) .placeholder(sRoundPlaceholder). diskCacheStrategy(DiskCacheStrategy.RESULT).into(img); } }
Example #6
Source File: AFGlideUtil.java From AFBaseLibrary with Apache License 2.0 | 6 votes |
@Nullable private static DrawableTypeRequest getDrawableTypeRequest(Object obj, View img) { if (img == null || obj == null) return null; Context context = img.getContext(); RequestManager manager = Glide.with(context); DrawableTypeRequest drawableTypeRequest = null; if (obj instanceof String) { drawableTypeRequest = manager.load((String) obj); } else if (obj instanceof Integer) { drawableTypeRequest = manager.load((Integer) obj); } else if (obj instanceof Uri) { drawableTypeRequest = manager.load((Uri) obj); } else if (obj instanceof File) { drawableTypeRequest = manager.load((File) obj); } return drawableTypeRequest; }
Example #7
Source File: SongGlideRequest.java From Orin with GNU General Public License v3.0 | 5 votes |
public static DrawableTypeRequest createBaseRequest(RequestManager requestManager, Song song, boolean ignoreMediaStore) { if (ignoreMediaStore) { return requestManager.load(new AudioFileCover(song.data)); } else { return requestManager.loadFromMediaStore(MusicUtil.getMediaStoreAlbumCoverUri(song.albumId)); } }
Example #8
Source File: UsageExampleNetworkDependent.java From android-tutorials-glide with MIT License | 5 votes |
private void loadNetworkDependent() { RequestManager requestManager = Glide.with(context); DrawableTypeRequest<String> request; // if you need transformations or other options specific for the load, chain them here if (deviceOnWifi()) { request = requestManager.load("http://www.placehold.it/750x750"); } else { request = requestManager.load("http://www.placehold.it/100x100"); } request.into(imageView1); }
Example #9
Source File: ArtistGlideRequest.java From Phonograph with GNU General Public License v3.0 | 5 votes |
public static DrawableTypeRequest createBaseRequest(RequestManager requestManager, Artist artist, boolean noCustomImage) { boolean hasCustomImage = CustomArtistImageUtil.getInstance(App.getInstance()).hasCustomArtistImage(artist); if (noCustomImage || !hasCustomImage) { final List<AlbumCover> songs = new ArrayList<>(); for (final Album album : artist.albums) { final Song song = album.safeGetFirstSong(); songs.add(new AlbumCover(album.getYear(), song.data)); } return requestManager.load(new ArtistImage(artist.getName(), songs)); } else { return requestManager.load(CustomArtistImageUtil.getFile(artist)); } }
Example #10
Source File: SongGlideRequest.java From Phonograph with GNU General Public License v3.0 | 5 votes |
public static DrawableTypeRequest createBaseRequest(RequestManager requestManager, Song song, boolean ignoreMediaStore) { if (ignoreMediaStore) { return requestManager.load(new AudioFileCover(song.data)); } else { return requestManager.loadFromMediaStore(MusicUtil.getMediaStoreAlbumCoverUri(song.albumId)); } }
Example #11
Source File: ImageLoader.java From LbaizxfPulltoRefresh with Apache License 2.0 | 5 votes |
/** * 图片加载 * @author leibing * @createTime 2016/8/15 * @lastModify 2016/8/15 * @param context 上下文 * @param imageView 图片显示控件 * @param localPath 图片本地链接 * @param defaultImage 默认占位图片 * @param errorImage 加载失败后图片 * @param isCropCircle 是否圆角 * @return */ public void load(Context context, ImageView imageView, File localPath, Drawable defaultImage, Drawable errorImage , boolean isCropCircle){ // 图片加载库采用Glide框架 DrawableTypeRequest request = Glide.with(context).load(localPath); // 设置scaleType request.centerCrop(); // 圆角裁切 if (isCropCircle) request.bitmapTransform(new CropCircleTransformation(context)); request.thumbnail(0.1f) //用原图的1/10作为缩略图 .placeholder(defaultImage) //设置资源加载过程中的占位Drawable .crossFade() //设置加载渐变动画 .priority(Priority.NORMAL) //指定加载的优先级,优先级越高越优先加载, // 但不保证所有图片都按序加载 // 枚举Priority.IMMEDIATE,Priority.HIGH,Priority.NORMAL,Priority.LOW // 默认为Priority.NORMAL .fallback(null) //设置model为空时要显示的Drawable // 如果没设置fallback,model为空时将显示error的Drawable, // 如果error的Drawable也没设置,就显示placeholder的Drawable .error(errorImage) //设置load失败时显示的Drawable .skipMemoryCache(true) //设置跳过内存缓存,但不保证一定不被缓存 // (比如请求已经在加载资源且没设置跳过内存缓存,这个资源就会被缓存在内存中) .diskCacheStrategy(DiskCacheStrategy.RESULT) //缓存策略DiskCacheStrategy.SOURCE: // 缓存原始数据,DiskCacheStrategy.RESULT: // 缓存变换(如缩放、裁剪等)后的资源数据, // DiskCacheStrategy.NONE:什么都不缓存, // DiskCacheStrategy.ALL:缓存SOURC和RESULT。 // 默认采用DiskCacheStrategy.RESULT策略, // 对于download only操作要使用DiskCacheStrategy.SOURCE .into(imageView); }
Example #12
Source File: ImageLoader.java From HttpRequest with Apache License 2.0 | 5 votes |
/** * 图片加载 * @author leibing * @createTime 2016/8/15 * @lastModify 2016/8/15 * @param context 上下文 * @param imageView 图片显示控件 * @param localPath 图片本地链接 * @param defaultImage 默认占位图片 * @param errorImage 加载失败后图片 * @param isCropCircle 是否圆角 * @return */ public void load(Context context, ImageView imageView, File localPath, Drawable defaultImage, Drawable errorImage , boolean isCropCircle){ // 图片加载库采用Glide框架 DrawableTypeRequest request = Glide.with(context).load(localPath); // 设置scaleType request.centerCrop(); // 圆角裁切 if (isCropCircle) request.bitmapTransform(new CropCircleTransformation(context)); request.thumbnail(0.1f) //用原图的1/10作为缩略图 .placeholder(defaultImage) //设置资源加载过程中的占位Drawable .crossFade() //设置加载渐变动画 .priority(Priority.NORMAL) //指定加载的优先级,优先级越高越优先加载, // 但不保证所有图片都按序加载 // 枚举Priority.IMMEDIATE,Priority.HIGH,Priority.NORMAL,Priority.LOW // 默认为Priority.NORMAL .fallback(null) //设置model为空时要显示的Drawable // 如果没设置fallback,model为空时将显示error的Drawable, // 如果error的Drawable也没设置,就显示placeholder的Drawable .error(errorImage) //设置load失败时显示的Drawable .skipMemoryCache(true) //设置跳过内存缓存,但不保证一定不被缓存 // (比如请求已经在加载资源且没设置跳过内存缓存,这个资源就会被缓存在内存中) .diskCacheStrategy(DiskCacheStrategy.RESULT) //缓存策略DiskCacheStrategy.SOURCE: // 缓存原始数据,DiskCacheStrategy.RESULT: // 缓存变换(如缩放、裁剪等)后的资源数据, // DiskCacheStrategy.NONE:什么都不缓存, // DiskCacheStrategy.ALL:缓存SOURC和RESULT。 // 默认采用DiskCacheStrategy.RESULT策略, // 对于download only操作要使用DiskCacheStrategy.SOURCE .into(imageView); }
Example #13
Source File: ArtistGlideRequest.java From RetroMusicPlayer with GNU General Public License v3.0 | 5 votes |
public static DrawableTypeRequest createBaseRequest(RequestManager requestManager, Artist artist, boolean noCustomImage, boolean forceDownload) { boolean hasCustomImage = CustomArtistImageUtil.getInstance(RetroApplication.getInstance()).hasCustomArtistImage(artist); if (noCustomImage || !hasCustomImage) { return requestManager.load(new ArtistImage(artist.getName(), forceDownload)); } else { return requestManager.load(CustomArtistImageUtil.getFile(artist)); } }
Example #14
Source File: SongGlideRequest.java From RetroMusicPlayer with GNU General Public License v3.0 | 5 votes |
public static DrawableTypeRequest createBaseRequest(RequestManager requestManager, Song song, boolean ignoreMediaStore) { if (ignoreMediaStore) { return requestManager.load(new AudioFileCover(song.data)); } else { return requestManager.loadFromMediaStore(MusicUtil.getMediaStoreAlbumCoverUri(song.albumId)); } }
Example #15
Source File: GlideImageStrategy.java From android-slideshow with MIT License | 5 votes |
@Override public void preload(final FileItem item) { final DrawableTypeRequest<String> glideLoad = Glide .with(context) .load(item.getPath()); if (PLAY_GIF) { // Play GIFs glideLoad.preload(); } else { // Force bitmap so GIFs don't play glideLoad.asBitmap().preload(); } }
Example #16
Source File: SongGlideRequest.java From Music-Player with GNU General Public License v3.0 | 5 votes |
public static DrawableTypeRequest createBaseRequest(RequestManager requestManager, Song song, boolean ignoreMediaStore) { if (ignoreMediaStore) { return requestManager.load(new AudioFileCover(song.data)); } else { return requestManager.loadFromMediaStore(MusicUtil.getMediaStoreAlbumCoverUri(song.albumId)); } }
Example #17
Source File: GlideLoader.java From ImageLoader with Apache License 2.0 | 5 votes |
@Nullable private DrawableTypeRequest getDrawableTypeRequest(SingleConfig config, RequestManager requestManager) { DrawableTypeRequest request = null; if(!TextUtils.isEmpty(config.getUrl())){ request= requestManager.load(MyUtil.appendUrl(config.getUrl())); }else if(!TextUtils.isEmpty(config.getFilePath())){ request= requestManager.load(config.getFilePath()); }else if(!TextUtils.isEmpty(config.getContentProvider())){ request= requestManager.loadFromMediaStore(Uri.parse(config.getContentProvider())); }else if(config.getResId() != 0){ request= requestManager.load(config.getResId()); }else if(config.getBytes() != null){ request = requestManager.load(config.getBytes()); } else { //request= requestManager.load("http://www.baidu.com/1.jpg");//故意失败 int resId = getUseableResId(config); if(resId != 0){ request = requestManager.load(resId); }else { request= requestManager.load(""); } } /* if(!TextUtils.isEmpty(config.getUrl()) && config.getUrl().contains(".gif")){ request.diskCacheStrategy(DiskCacheStrategy.ALL);//只缓存result }else{ request.diskCacheStrategy(DiskCacheStrategy.SOURCE);//只缓存原图 }*/ request.diskCacheStrategy(DiskCacheStrategy.SOURCE);//只缓存原图 return request; }
Example #18
Source File: AFGlideUtil.java From AFBaseLibrary with Apache License 2.0 | 5 votes |
public static void loadImgBlurNoPlace(Object obj, ImageView img) { DrawableTypeRequest drawableTypeRequest = getDrawableTypeRequest(obj, img); if (drawableTypeRequest != null) { drawableTypeRequest .centerCrop() .dontAnimate() .bitmapTransform(new BlurTransformation(img.getContext(), 16, 4)) .diskCacheStrategy(DiskCacheStrategy.RESULT) .into(img); } }
Example #19
Source File: AFGlideUtil.java From AFBaseLibrary with Apache License 2.0 | 5 votes |
/** * 加载圆形图片 * * @param obj 要加载的资源 * @param img 被加载的图片 */ public static void loadCircleImgNoPlace(Object obj, ImageView img) { DrawableTypeRequest drawableTypeRequest = getDrawableTypeRequest(obj, img); if (drawableTypeRequest != null) { drawableTypeRequest .centerCrop() .dontAnimate() .transform(new AFGlideUtil.GlideCircleTransform(img.getContext())) .diskCacheStrategy(DiskCacheStrategy.RESULT).into(img); } }
Example #20
Source File: AFGlideUtil.java From AFBaseLibrary with Apache License 2.0 | 5 votes |
public static void loadImage(Object obj, ImageView img) { DrawableTypeRequest drawableTypeRequest = getDrawableTypeRequest(obj, img); if (drawableTypeRequest == null) { drawableTypeRequest = getDrawableTypeRequest(sCommonPlaceholder, img); } if (drawableTypeRequest != null) { drawableTypeRequest .centerCrop() .dontAnimate() .error(sCommonPlaceholder) .placeholder(sCommonPlaceholder) .diskCacheStrategy(DiskCacheStrategy.RESULT) .into(img); } }
Example #21
Source File: ArtistGlideRequest.java From Music-Player with GNU General Public License v3.0 | 5 votes |
public static DrawableTypeRequest createBaseRequest(RequestManager requestManager, Artist artist, boolean noCustomImage) { boolean hasCustomImage = CustomArtistImageUtil.getInstance(App.getInstance()).hasCustomArtistImage(artist); if (noCustomImage || !hasCustomImage) { final List<AlbumCover> songs = new ArrayList<>(); for (final Album album : artist.albums) { final Song song = album.safeGetFirstSong(); songs.add(new AlbumCover(album.getYear(), song.data)); } return requestManager.load(new ArtistImage(artist.getName(), songs)); } else { return requestManager.load(CustomArtistImageUtil.getFile(artist)); } }
Example #22
Source File: GlideImageGetter.java From RichText with MIT License | 4 votes |
@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; }
Example #23
Source File: CatViewerAnalyticsTest.java From android-aop-analytics with Apache License 2.0 | 4 votes |
private void initMockGlideRequestManager() { when(mockGlideRequestManager.load(TEST_CAT_IMAGE.getLink())) .thenReturn(mock(DrawableTypeRequest.class)); }
Example #24
Source File: GlideImageSpec.java From litho-glide with MIT License | 4 votes |
@OnMount static void onMount(ComponentContext c, ImageView imageView, @Prop(optional = true) String imageUrl, @Prop(optional = true) File file, @Prop(optional = true) Uri uri, @Prop(optional = true) Integer resourceId, @Prop(optional = true) RequestManager glideRequestManager, @Prop(optional = true, resType = DRAWABLE) Drawable failureImage, @Prop(optional = true, resType = DRAWABLE) Drawable fallbackImage, @Prop(optional = true, resType = DRAWABLE) Drawable placeholderImage, @Prop(optional = true) DiskCacheStrategy diskCacheStrategy, @Prop(optional = true) RequestListener requestListener, @Prop(optional = true) boolean asBitmap, @Prop(optional = true) boolean asGif, @Prop(optional = true) boolean crossFade, @Prop(optional = true) int crossFadeDuration, @Prop(optional = true) boolean centerCrop, @Prop(optional = true) boolean fitCenter, @Prop(optional = true) boolean skipMemoryCache, @Prop(optional = true) Target target) { if (imageUrl == null && file == null && uri == null && resourceId == null) { throw new IllegalArgumentException( "You must provide at least one of String, File, Uri or ResourceId"); } if (glideRequestManager == null) { glideRequestManager = Glide.with(c.getAndroidContext()); } DrawableTypeRequest request; if (imageUrl != null) { request = glideRequestManager.load(imageUrl); } else if (file != null) { request = glideRequestManager.load(file); } else if (uri != null) { request = glideRequestManager.load(uri); } else { request = glideRequestManager.load(resourceId); } if (request == null) { throw new IllegalStateException("Could not instantiate DrawableTypeRequest"); } if (diskCacheStrategy != null) { request.diskCacheStrategy(diskCacheStrategy); } if (asBitmap) { request.asBitmap(); } if (asGif) { request.asGif(); } if (crossFade) { request.crossFade(); } if (crossFadeDuration != DEFAULT_INT_VALUE) { request.crossFade(crossFadeDuration); } if (centerCrop) { request.centerCrop(); } if (failureImage != null) { request.error(failureImage); } if (fallbackImage != null) { request.fallback(fallbackImage); } if (fitCenter) { request.fitCenter(); } if (requestListener != null) { request.listener(requestListener); } if (placeholderImage != null) { request.placeholder(placeholderImage); } request.skipMemoryCache(skipMemoryCache); if (target != null) { request.into(target); } else { request.into(imageView); } }