Java Code Examples for com.bumptech.glide.request.RequestOptions#diskCacheStrategy()

The following examples show how to use com.bumptech.glide.request.RequestOptions#diskCacheStrategy() . 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: TinyGifDrawableLoader.java    From BaseProject with Apache License 2.0 6 votes vote down vote up
/**
 * 加载不一定是本地图片资源
 * (即也可以是网络资源)
 * 并且也可以不是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 2
Source File: ImageLoadUtils.java    From Tok-Android with GNU General Public License v3.0 5 votes vote down vote up
private static RequestOptions getOptions() {
    RequestOptions requestOptions = new RequestOptions();
    //requestOptions.placeholder(R.drawable.img_place_holder);
    requestOptions.error(R.drawable.img_error);
    requestOptions.diskCacheStrategy(DiskCacheStrategy.NONE);
    requestOptions.skipMemoryCache(true);
    return requestOptions;
}
 
Example 3
Source File: ImageLoadUtils.java    From Tok-Android with GNU General Public License v3.0 5 votes vote down vote up
private static RequestOptions getPortraitOptions() {
    RequestOptions requestOptions = new RequestOptions();
    //if placeholder exist,if load images,it will placeholder first,and has s blink when the real image show
    requestOptions.diskCacheStrategy(DiskCacheStrategy.NONE);
    requestOptions.skipMemoryCache(true);
    return requestOptions;
}
 
Example 4
Source File: ImageLoadUtils.java    From Tok-Android with GNU General Public License v3.0 5 votes vote down vote up
private static RequestOptions getVideoOptions() {
    RequestOptions requestOptions = RequestOptions.frameOf(1);
    requestOptions.set(FRAME_OPTION, MediaMetadataRetriever.OPTION_CLOSEST);
    //requestOptions.placeholder(R.drawable.img_place_holder);
    requestOptions.error(R.drawable.img_error);
    requestOptions.diskCacheStrategy(DiskCacheStrategy.RESOURCE);
    requestOptions.skipMemoryCache(true);
    return requestOptions;
}
 
Example 5
Source File: TinyGifDrawableLoader.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
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 6
Source File: GlideImageLoaderStrategy.java    From NewFastFrame with Apache License 2.0 4 votes vote down vote up
@Override
public void loadImage(Context context, GlideImageLoaderConfig config) {
    if (config == null || context == null) {
        return;
    }
    RequestBuilder drawableRequestBuilder;
    if (config.asGif()) {
        drawableRequestBuilder = Glide.with(context).asGif().load(config.getUrl());
    } else {
        drawableRequestBuilder = Glide.with(context).load(config.getUrl());
    }
    RequestOptions options = new RequestOptions();
    switch (config.getCacheStrategy()) {
        case GlideImageLoaderConfig.CACHE_ALL:
            options.diskCacheStrategy(DiskCacheStrategy.ALL);
            break;
        case GlideImageLoaderConfig.CACHE_NONE:
            options.diskCacheStrategy(DiskCacheStrategy.NONE);
            break;
        case GlideImageLoaderConfig.CACHE_SOURCE:
            options.diskCacheStrategy(DiskCacheStrategy.RESOURCE);
            break;
        case GlideImageLoaderConfig.CACHE_RESULT:
            options.diskCacheStrategy(DiskCacheStrategy.DATA);
            break;
        default:
            break;
    }
    if (config.isCenterInside()) {
        options = options.fitCenter();
    } else {
        options = options.centerCrop();
    }
    if (config.getBitmapTransformation() != null) {
        options = options.transforms(config.getBitmapTransformation());
    }
    if (config.getErrorResId() != 0) {
        options = options.error(config.getErrorResId());
    }
    if (config.getPlaceHolderResId() != 0) {
        options = options.placeholder(config.getPlaceHolderResId());
    }
    if (config.getWidth() != 0 && config.getHeight() != 0) {
        options = options.override(config.getWidth(), config.getHeight());
    }


    if (config.getView() instanceof ImageView) {
        drawableRequestBuilder.apply(options).into((ImageView) config.getView());
    } else {
        drawableRequestBuilder.apply(options).into(new SimpleTarget<Drawable>() {
            @Override
            public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
                if (config.getView()!=null) {
                    config.getView().setBackground(resource);
                }
            }
        });
    }
}