Java 类com.bumptech.glide.GlideBuilder 实例源码

项目:GitHub    文件:GlideConfiguration.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            // Careful: the external cache directory doesn't enforce permissions
            File cacheDirectory = new File(DataHelper.getCacheFile(UiUtils.getContext()), "Glide");
            return DiskLruCacheWrapper.get(DataHelper.makeDirs(cacheDirectory), IMAGE_DISK_CACHE_MAX_SIZE);
        }
    });

    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();

    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);

    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));

}
项目:yyox    文件:GlideConfiguration.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            // Careful: the external cache directory doesn't enforce permissions
            return DiskLruCacheWrapper.get(DataHelper.getCacheFile(UiUtils.getContext()), IMAGE_DISK_CACHE_MAX_SIZE);
        }
    });

    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();

    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);

    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));

}
项目:MVVMFrames    文件:GlideConfiguration.java   
@Override
public void applyOptions(final Context context, GlideBuilder builder) {

    // 缓存目录
    builder.setDiskCache(new DiskCache.Factory() {

        @Override
        public DiskCache build() {
            AppComponent component = ((App) context.getApplicationContext()).getAppComponent();
            return DiskLruCacheWrapper.get(FileUtils.makeDirs(new File(component.cacheFile(), "Glide")), DISK_SIZE);
        }
    });

    // 自定义内存缓存和图片池大小
    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    builder.setMemoryCache(new LruResourceCache((int) (1.2 * calculator.getMemoryCacheSize())));
    builder.setBitmapPool(new LruBitmapPool((int) (1.2 * calculator.getBitmapPoolSize())));

    // 图片格式
    builder.setDecodeFormat(DecodeFormat.PREFER_RGB_565); // 默认
}
项目:moebooru-android    文件:MoeGlideModule.java   
@Override
    public void applyOptions(Context context, GlideBuilder builder) {
        MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context)
                .setMemoryCacheScreens(2)
                .build();
        // default
//        builder.setMemoryCache(new LruResourceCache(calculator.getMemoryCacheSize()));
        Integer m = new SharedPreferencesUtils().getIntValue(mPref, mCacheMemory);
        if (m == 0){
            m = 256;
        }
        int memoryCacheSizeBytes = 1024 * 1024 * m;
        builder.setMemoryCache(new LruResourceCache(memoryCacheSizeBytes));

        Integer d = new SharedPreferencesUtils().getIntValue(mPref, mCacheDisk);
        if (d == 0){
            d = 256;
        }
        int diskCacheSizeBytes = 1024 * 1024 * d;
        builder.setDiskCache(new InternalCacheDiskCacheFactory(context, diskCacheSizeBytes));
        builder.setDefaultRequestOptions(
                new RequestOptions()
                        .diskCacheStrategy(DiskCacheStrategy.ALL));

    }
项目:AppCommonFrame    文件:GlideConfiguration.java   
@Override
public void applyOptions(final Context context, GlideBuilder builder) {
    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            // Careful: the external cache directory doesn't enforce permissions
            return DiskLruCacheWrapper.get(Glide.getPhotoCacheDir(context), ConfigConstants.MAX_DISK_CACHE_SIZE);
        }
    });

    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();

    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);

    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));

}
项目:Hotspot-master-devp    文件:CustomCachingGlideModule.java   
@Override public void applyOptions(final Context context, GlideBuilder builder) {
        builder.setDiskCache(new DiskCache.Factory() {
            @Override
            public DiskCache build() {
                File cacheLocation = new File(AppUtils.getPath(context, AppUtils.StorageFile.cache));
                cacheLocation.mkdirs();
                return DiskLruCacheWrapper.get(cacheLocation, DISK_CACHE_SIZE);
            }
        });
//        MemorySizeCalculator calculator = new MemorySizeCalculator(context);
//        int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
//        int defaultBitmapPoolSize = calculator.getBitmapPoolSize();
//
//        int customMemoryCacheSize = (int) (0.25 * defaultMemoryCacheSize);
//        int customBitmapPoolSize = (int) (0.25* defaultBitmapPoolSize);
//
//        builder.setMemoryCache( new LruResourceCache( customMemoryCacheSize ));
//        builder.setBitmapPool( new LruBitmapPool( customBitmapPoolSize ));
    }
项目:MVPArms_Fragment-fragment    文件:GlideConfiguration.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            // Careful: the external cache directory doesn't enforce permissions
            AppComponent appComponent = ((App) context.getApplicationContext()).getAppComponent();
            return DiskLruCacheWrapper.get(DataHelper.makeDirs(new File(appComponent.cacheFile(), "Glide")), IMAGE_DISK_CACHE_MAX_SIZE);
        }
    });

    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();

    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);

    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));

}
项目:GeekZone    文件:GlideConfiguration.java   
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    // Get default memory cache size
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();
    // Set custom memory cache size
    int customMemoryCacheSize = (int) (1.5 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.5 * defaultBitmapPoolSize);
    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));

    // Set disk cache size
    int diskCacheSize = 1024 * 1024 * 100;
    builder.setDiskCache(new InternalCacheDiskCacheFactory(context, "glide", diskCacheSize));

    // Prefer higher quality images unless we're on a low RAM device
    ActivityManager activityManager = (ActivityManager) context
            .getSystemService(Context.ACTIVITY_SERVICE);
    builder.setDecodeFormat(activityManager.isLowRamDevice() ?
            DecodeFormat.PREFER_RGB_565 : DecodeFormat.PREFER_ARGB_8888);
}
项目:Tribe    文件:OvAppGlideModule.java   
/**
 * 设置缓存设置
 */
private void customCacheOptions(Context context, GlideBuilder builder) {
    //设置内存缓存大小和bitmap池大小
    MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context)
            .setMemoryCacheScreens(2)
            .build();
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapCacheSize = calculator.getBitmapPoolSize();
    //比默认的内存分配大20%
    int customMemoryCacheSize = (int) (4 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (4 * defaultBitmapCacheSize);
    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));

    //设置磁盘缓存
    int cacheSize100MegaBytes =  1024 * 1024 * 100;//200M
    //外部磁盘缓存
    builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, cacheSize100MegaBytes));

}
项目:anitrend-app    文件:ConfigModule.java   
/**
 * Lazily apply options to a {@link GlideBuilder} immediately before the Glide singleton is
 * created.
 * <p>
 * <p>
 * This method will be called once and only once per implementation.
 * </p>
 *
 * @param context An Application {@link Context}.
 * @param builder The {@link GlideBuilder} that will be used to create Glide.
 */
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    // Increasing cache & pool by 25% - default is 250MB
    int memoryCacheSize = (int) (1.25 * calculator.getMemoryCacheSize());
    int bitmapPoolSize = (int) (1.25 * calculator.getBitmapPoolSize());
    int storageCacheSize = 1024 * 1024 * 350;
    if(context.getExternalCacheDir() != null) {
        long total = context.getExternalCacheDir().getUsableSpace();
        storageCacheSize = (int) (total*0.14);
    }

    builder.setMemoryCache(new LruResourceCache(memoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(bitmapPoolSize));
    builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, storageCacheSize));
    builder.setDecodeFormat(ActivityManagerCompat.isLowRamDevice(activityManager) ?
            DecodeFormat.PREFER_RGB_565 : DecodeFormat.PREFER_ARGB_8888);
}
项目:PicShow-zhaipin    文件:GlideConfiguration.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            // Careful: the external cache directory doesn't enforce permissions
            return DiskLruCacheWrapper.get(DataHelper.getCacheFile(UiUtils.getContext()), IMAGE_DISK_CACHE_MAX_SIZE);
        }
    });

    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();

    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);

    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));

}
项目:Simpler    文件:MyGlideModule.java   
@Override
    public void applyOptions(Context context, GlideBuilder builder) {
        ViewTarget.setTagId(R.id.glide_tag_id);
        // Apply options to the builder here.
        // 默认内存和图片池大小
//        MemorySizeCalculator calculator = new MemorySizeCalculator(context);
//        int defaultMemoryCacheSize = calculator.getMemoryCacheSize(); // 默认内存大小
//        int defaultBitmapPoolSize = calculator.getBitmapPoolSize(); // 默认图片池大小
//        builder.setMemoryCache(new LruResourceCache(defaultMemoryCacheSize)); // 该两句无需设置,是默认的
//        builder.setBitmapPool(new LruBitmapPool(defaultBitmapPoolSize));
        //定义图片的本地磁盘缓存
//        File cacheDir = context.getExternalCacheDir();//指定的是数据的缓存地址
//        int diskCacheSize = 1024 * 1024 * 1024;//最多可以缓存多少字节的数据
        //设置磁盘缓存大小
//        builder.setDiskCache(new DiskLruCacheFactory(cacheDir.getPath(), "glide", diskCacheSize));
        // 定义缓存大小和位置
        if (BaseConfig.sSDCardExist) {
            builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, Constants.Dir.IMAGE_CACHE_DIR, extDiskSize)); //外部存储
        } else {
            builder.setDiskCache(new InternalCacheDiskCacheFactory(context, Constants.Dir.IMAGE_CACHE_DIR, intDiskSize));  //内部存储
        }
        // 自定义内存和图片池大小
//        builder.setMemoryCache(new LruResourceCache(memorySize));
//        builder.setBitmapPool(new LruBitmapPool(memorySize));
//        builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
    }
项目:mvparms    文件:GlideConfiguration.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            // Careful: the external cache directory doesn't enforce permissions
            File cacheDirectory = new File(DataHelper.getCacheFile(UiUtils.getContext()), "Glide");
            return DiskLruCacheWrapper.get(DataHelper.makeDirs(cacheDirectory), IMAGE_DISK_CACHE_MAX_SIZE);
        }
    });

    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();

    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);

    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));

}
项目:MVPArmsTest1    文件:GlideConfiguration.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            // Careful: the external cache directory doesn't enforce permissions
            AppComponent appComponent = ((App) context.getApplicationContext()).getAppComponent();
            return DiskLruCacheWrapper.get(DataHelper.makeDirs(new File(appComponent.cacheFile(), "Glide")), IMAGE_DISK_CACHE_MAX_SIZE);
        }
    });

    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();

    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);

    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));

}
项目:GitHub    文件:GifDrawableTransformationTest.java   
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  context = RuntimeEnvironment.application;

  Glide.init(new GlideBuilder().setBitmapPool(bitmapPool).build(context));
  transformation = new GifDrawableTransformation(wrapped);
}
项目:GitHub    文件:FitCenterTest.java   
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  bitmapWidth = 100;
  bitmapHeight = 100;
  Bitmap bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
  when(resource.get()).thenReturn(bitmap);

  BitmapPool pool = new BitmapPoolAdapter();
  context = RuntimeEnvironment.application;
  Glide.init(new GlideBuilder().setBitmapPool(pool).build(context));


  fitCenter = new FitCenter();
}
项目:GitHub    文件:CenterCropTest.java   
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  bitmapWidth = 100;
  bitmapHeight = 100;
  bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
  when(resource.get()).thenReturn(bitmap);

  when(pool.get(anyInt(), anyInt(), any(Bitmap.Config.class)))
      .thenAnswer(new Util.CreateBitmap());
  context = RuntimeEnvironment.application;
  Glide.init(new GlideBuilder().setBitmapPool(pool).build(context));

  centerCrop = new CenterCrop();
}
项目:GitHub    文件:CircleCropTest.java   
@Before
public void setup() {
  MockitoAnnotations.initMocks(this);
  when(bitmapPool.get(anyInt(), anyInt(), any(Bitmap.Config.class)))
      .thenAnswer(new Util.CreateBitmap());
  Context context = RuntimeEnvironment.application;
  Glide.init(new GlideBuilder().setBitmapPool(bitmapPool).build(context));
  circleCrop = new CircleCrop();
}
项目:GitHub    文件:BitmapTransformationTest.java   
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  context = RuntimeEnvironment.application;

  Glide.init(new GlideBuilder().setBitmapPool(bitmapPool).build(context));
}
项目:GitHub    文件:CenterInsideTest.java   
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  bitmapWidth = 100;
  bitmapHeight = 100;
  Bitmap bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
  when(resource.get()).thenReturn(bitmap);

  context = RuntimeEnvironment.application;
  BitmapPool pool = new BitmapPoolAdapter();
  Glide.init(new GlideBuilder().setBitmapPool(pool).build(context));

  centerInside = new CenterInside();
}
项目:GitHub    文件:BitmapDrawableTransformationTest.java   
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  bitmapToTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);

  context = RuntimeEnvironment.application;
  Glide.init(new GlideBuilder().setBitmapPool(bitmapPool).build(context));
  when(drawableResourceToTransform.get()).thenReturn(drawableToTransform);
  when(drawableToTransform.getBitmap()).thenReturn(bitmapToTransform);
  transformation = new BitmapDrawableTransformation(wrapped);
}
项目:GitHub    文件:GifDrawableTransformationTest.java   
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  context = RuntimeEnvironment.application;

  Glide.init(context, new GlideBuilder().setBitmapPool(bitmapPool));
  transformation = new GifDrawableTransformation(wrapped);
}
项目:GitHub    文件:FitCenterTest.java   
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  bitmapWidth = 100;
  bitmapHeight = 100;
  Bitmap bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
  when(resource.get()).thenReturn(bitmap);

  BitmapPool pool = new BitmapPoolAdapter();
  context = RuntimeEnvironment.application;
  Glide.init(context, new GlideBuilder().setBitmapPool(pool));


  fitCenter = new FitCenter();
}
项目:GitHub    文件:CenterCropTest.java   
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  bitmapWidth = 100;
  bitmapHeight = 100;
  bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
  when(resource.get()).thenReturn(bitmap);

  when(pool.get(anyInt(), anyInt(), any(Bitmap.Config.class)))
      .thenAnswer(new Util.CreateBitmap());
  context = RuntimeEnvironment.application;
  Glide.init(context, new GlideBuilder().setBitmapPool(pool));

  centerCrop = new CenterCrop();
}
项目:GitHub    文件:CircleCropTest.java   
@Before
public void setup() {
  MockitoAnnotations.initMocks(this);
  when(bitmapPool.get(anyInt(), anyInt(), any(Bitmap.Config.class)))
      .thenAnswer(new Util.CreateBitmap());
  Context context = RuntimeEnvironment.application;
  Glide.init(context, new GlideBuilder().setBitmapPool(bitmapPool));
  circleCrop = new CircleCrop();
}
项目:GitHub    文件:BitmapTransformationTest.java   
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  context = RuntimeEnvironment.application;

  Glide.init(context, new GlideBuilder().setBitmapPool(bitmapPool));
}
项目:GitHub    文件:DrawableTransformationTest.java   
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  transformation = new DrawableTransformation(bitmapTransformation, /*isRequired=*/ true);
  context = RuntimeEnvironment.application;
  bitmapPool = new BitmapPoolAdapter();
  Glide.init(context, new GlideBuilder().setBitmapPool(bitmapPool));
}
项目:GitHub    文件:CenterInsideTest.java   
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  bitmapWidth = 100;
  bitmapHeight = 100;
  Bitmap bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
  when(resource.get()).thenReturn(bitmap);

  context = RuntimeEnvironment.application;
  BitmapPool pool = new BitmapPoolAdapter();
  Glide.init(context, new GlideBuilder().setBitmapPool(pool));

  centerInside = new CenterInside();
}
项目:GitHub    文件:BitmapDrawableTransformationTest.java   
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  bitmapToTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
  BitmapDrawable drawableToTransform = new BitmapDrawable(bitmapToTransform);

  context = RuntimeEnvironment.application;
  Glide.init(context, new GlideBuilder().setBitmapPool(bitmapPool));
  when(drawableResourceToTransform.get()).thenReturn(drawableToTransform);
  transformation = new BitmapDrawableTransformation(wrapped);
}
项目:GitHub    文件:SampleGlideModule.java   
@Override
public void applyOptions(final Context context, GlideBuilder builder) {
  builder.setDiskCache(
      new DiskCache.Factory() {
        @Override
        public DiskCache build() {
          return DiskLruCacheWrapper.get(
              Glide.getPhotoCacheDir(context),
              ConfigConstants.MAX_DISK_CACHE_SIZE);
        }
      });
  builder.setMemoryCache(new LruResourceCache(ConfigConstants.MAX_MEMORY_CACHE_SIZE));
}
项目:CustomListView    文件:GlideConfiguration.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDiskCache(new InternalCacheDiskCacheFactory(context, IMAGE_DISK_CACHE_MAX_SIZE));

    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();

    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);

    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
}
项目:MVVM-JueJin    文件:GlideConfig.java   
@Override
    public void applyOptions(Context context, GlideBuilder builder) {
        builder
                // 下面三项都是默认的, 不必设置
//                .setMemoryCache(new LruResourceCache(MEMORY_CACHE_SIZE))
//                .setBitmapPool(new LruBitmapPool(MEMORY_CACHE_SIZE))
                // 默认 rgb565
                .setDecodeFormat(DecodeFormat.PREFER_ARGB_8888)
                .setDiskCache(new InternalCacheDiskCacheFactory(context, DISK_CACHE_SIZE));
    }
项目:BaseVLayoutAdapterHelper    文件:CustomGlideModule.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context)
            .setMemoryCacheScreens(2)
            .build();
    //设置手机默认推荐缓存大小
    builder.setMemoryCache(new LruResourceCache(calculator.getMemoryCacheSize()));
    // 自定义缓存大小.
    int memoryCacheSizeBytes = 1024 * 1024 * 20; // 20mb
    builder.setMemoryCache(new LruResourceCache(memoryCacheSizeBytes));
    //自定义内置磁盘缓存大小(可以指明路径)
    int diskCacheSizeBytes = 1024 * 1024 * 100; // 100 MB
    builder.setDiskCache(new InternalCacheDiskCacheFactory(context, diskCacheSizeBytes));

}
项目:TestChat    文件:OkHttpGlideModule.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);

    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();

    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);

    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));
}
项目:Hitalk    文件:VideoListGlideModule.java   
@Override
public void applyOptions(final Context context, GlideBuilder builder) {
    builder.setDiskCache(new DiskLruCacheFactory(new DiskLruCacheFactory.CacheDirectoryGetter
            () {
        @Override
        public File getCacheDirectory() {
            return context.getExternalCacheDir();
        }
    }, DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE));
}
项目:MoligyMvpArms    文件:GlideConfiguration.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    AppComponent appComponent = ArmsUtils.obtainAppComponentFromContext(context);
    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            // Careful: the external cache directory doesn't enforce permissions
            return DiskLruCacheWrapper.get(DataHelper.makeDirs(new File(appComponent.cacheFile(), "Glide")), IMAGE_DISK_CACHE_MAX_SIZE);
        }
    });

    MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context).build();
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();

    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);

    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));

    //将配置 Glide 的机会转交给 GlideImageLoaderStrategy,如你觉得框架提供的 GlideImageLoaderStrategy
    //并不能满足自己的需求,想自定义 BaseImageLoaderStrategy,那请你最好实现 GlideAppliesOptions
    //因为只有成为 GlideAppliesOptions 的实现类,这里才能调用 applyGlideOptions(),让你具有配置 Glide 的权利
    BaseImageLoaderStrategy loadImgStrategy = appComponent.imageLoader().getLoadImgStrategy();
    if (loadImgStrategy instanceof GlideAppliesOptions) {
        ((GlideAppliesOptions) loadImgStrategy).applyGlideOptions(context, builder);
    }
}
项目:lrs_android    文件:MyGlideModuleConfig.java   
@Override
    public void applyOptions(Context context, GlideBuilder builder) {
//        builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
        if (AppUtil.hasSDCard()) {
            builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, "GlideCache", 500 * 1024 * 1024));
            LogUtil.e("Glide使用SD卡缓存");
        } else {
            builder.setDiskCache(new InternalCacheDiskCacheFactory(context, "GlideCache", 250 * 1024 * 1024));
            LogUtil.e("Glide使用内部缓存");
        }
        builder.setMemoryCache(new LruResourceCache(100 * 1024 * 1024));
    }
项目:leisure-glance    文件:GankGlideModule.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    final int cacheSize250M = 262144000;// glide默认磁盘缓存大小为250m
    builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, "pic_cache", cacheSize250M));
    // 默认内存缓存为两个屏幕像素字节大小w*h*4*2

    // 设置默认的请求选项
}
项目:XinFramework    文件:GlideConfig.java   
@Override
public void applyOptions(final Context context, final GlideBuilder builder) {
    builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, 1024 * 1024 * 500));
    MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context).build();
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();

    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);

    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));
}
项目:Coder    文件:GlideConfig.java   
@Override
    public void applyOptions(Context context, GlideBuilder builder) {
        // 定义缓存大小和位置
        builder.setDiskCache(new InternalCacheDiskCacheFactory(context, diskSize));  // 内存中
        builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, "cache", diskSize)); // sd卡中

        // 自定义内存和图片池大小
        builder.setMemoryCache(new LruResourceCache(memorySize)); // 自定义内存大小
        builder.setBitmapPool(new LruBitmapPool(memorySize)); // 自定义图片池大小

        // 定义图片格式
         builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888); // 高质量
//        builder.setDecodeFormat(DecodeFormat.PREFER_RGB_565); // 默认(中等质量)
    }