本文整理匯總了Java中com.bumptech.glide.GlideBuilder.setMemoryCache方法的典型用法代碼示例。如果您正苦於以下問題:Java GlideBuilder.setMemoryCache方法的具體用法?Java GlideBuilder.setMemoryCache怎麽用?Java GlideBuilder.setMemoryCache使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.bumptech.glide.GlideBuilder
的用法示例。
在下文中一共展示了GlideBuilder.setMemoryCache方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: applyOptions
import com.bumptech.glide.GlideBuilder; //導入方法依賴的package包/類
@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));
}
示例2: applyOptions
import com.bumptech.glide.GlideBuilder; //導入方法依賴的package包/類
@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));
}
示例3: applyOptions
import com.bumptech.glide.GlideBuilder; //導入方法依賴的package包/類
@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));
}
示例4: customCacheOptions
import com.bumptech.glide.GlideBuilder; //導入方法依賴的package包/類
/**
* 設置緩存設置
*/
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));
}
示例5: applyOptions
import com.bumptech.glide.GlideBuilder; //導入方法依賴的package包/類
/**
* 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);
}
示例6: applyOptions
import com.bumptech.glide.GlideBuilder; //導入方法依賴的package包/類
@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));
}
示例7: applyOptions
import com.bumptech.glide.GlideBuilder; //導入方法依賴的package包/類
@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);
}
示例8: applyOptions
import com.bumptech.glide.GlideBuilder; //導入方法依賴的package包/類
@Override
public void applyOptions(Context context, GlideBuilder builder) {
AppComponent appComponent = ((App) context.getApplicationContext()).getAppComponent();
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);
}
}
示例9: applyOptions
import com.bumptech.glide.GlideBuilder; //導入方法依賴的package包/類
@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));
}
示例10: applyOptions
import com.bumptech.glide.GlideBuilder; //導入方法依賴的package包/類
@Override
public void applyOptions(Context context, GlideBuilder builder) {
super.applyOptions(context, builder);
builder.setDiskCache(() -> {
// Careful: the external cache directory doesn't enforce permissions
return DiskLruCacheWrapper.get(DataHelper.makeDirs(new File(RepositoryUtils.INSTANCE.obtainRepositoryComponent(context).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));
//Will transfer the opportunity to transfer Glide to GlideImageLoaderStrategy, as you think the framework provides GlideImageLoaderStrategy
//And can not meet their own needs, would like to customize BaseImageLoaderStrategy, then you'd better achieve GlideAppliesOptions
//Because only to become GlideAppliesOptions implementation class, where to call applyGlideOptions (), so you have the right to configure Glide
BaseImageLoaderStrategy imageLoaderStrategy = GmUtils.INSTANCE.obtainGmComponent(context).imageLoader().getStrategy();
if (imageLoaderStrategy instanceof GlideAppliesOptions) {
((GlideAppliesOptions) imageLoaderStrategy).applyGlideOptions(context, builder);
}
}
示例11: applyOptions
import com.bumptech.glide.GlideBuilder; //導入方法依賴的package包/類
@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));
}
示例12: applyOptions
import com.bumptech.glide.GlideBuilder; //導入方法依賴的package包/類
@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);
}
}
示例13: applyOptions
import com.bumptech.glide.GlideBuilder; //導入方法依賴的package包/類
@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));
}
示例14: applyOptions
import com.bumptech.glide.GlideBuilder; //導入方法依賴的package包/類
@Override
public void applyOptions(final Context context, GlideBuilder builder) {
ViewTarget.setTagId(R.id.glide_tag_id);
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.setDiskCache(new InternalCacheDiskCacheFactory(context, cacheSize100MegaBytes));
}
示例15: applyOptions
import com.bumptech.glide.GlideBuilder; //導入方法依賴的package包/類
@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); // 默認(中等質量)
}