當前位置: 首頁>>代碼示例>>Java>>正文


Java MemorySizeCalculator類代碼示例

本文整理匯總了Java中com.bumptech.glide.load.engine.cache.MemorySizeCalculator的典型用法代碼示例。如果您正苦於以下問題:Java MemorySizeCalculator類的具體用法?Java MemorySizeCalculator怎麽用?Java MemorySizeCalculator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MemorySizeCalculator類屬於com.bumptech.glide.load.engine.cache包,在下文中一共展示了MemorySizeCalculator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: applyOptions

import com.bumptech.glide.load.engine.cache.MemorySizeCalculator; //導入依賴的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));

}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:GlideConfiguration.java

示例2: applyOptions

import com.bumptech.glide.load.engine.cache.MemorySizeCalculator; //導入依賴的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));

}
 
開發者ID:Zyj163,項目名稱:yyox,代碼行數:22,代碼來源:GlideConfiguration.java

示例3: applyOptions

import com.bumptech.glide.load.engine.cache.MemorySizeCalculator; //導入依賴的package包/類
@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); // 默認
}
 
開發者ID:RockyQu,項目名稱:MVVMFrames,代碼行數:22,代碼來源:GlideConfiguration.java

示例4: applyOptions

import com.bumptech.glide.load.engine.cache.MemorySizeCalculator; //導入依賴的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));

    }
 
開發者ID:fiepi,項目名稱:moebooru-android,代碼行數:26,代碼來源:MoeGlideModule.java

示例5: applyOptions

import com.bumptech.glide.load.engine.cache.MemorySizeCalculator; //導入依賴的package包/類
@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));

}
 
開發者ID:VK2012,項目名稱:AppCommonFrame,代碼行數:22,代碼來源:GlideConfiguration.java

示例6: applyOptions

import com.bumptech.glide.load.engine.cache.MemorySizeCalculator; //導入依賴的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
            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));

}
 
開發者ID:yangxp108,項目名稱:MVPArms_Fragment-fragment,代碼行數:23,代碼來源:GlideConfiguration.java

示例7: applyOptions

import com.bumptech.glide.load.engine.cache.MemorySizeCalculator; //導入依賴的package包/類
@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);
}
 
開發者ID:HanyeeWang,項目名稱:GeekZone,代碼行數:24,代碼來源:GlideConfiguration.java

示例8: customCacheOptions

import com.bumptech.glide.load.engine.cache.MemorySizeCalculator; //導入依賴的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));

}
 
開發者ID:funnyzhaov,項目名稱:Tribe,代碼行數:23,代碼來源:OvAppGlideModule.java

示例9: applyOptions

import com.bumptech.glide.load.engine.cache.MemorySizeCalculator; //導入依賴的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);
}
 
開發者ID:wax911,項目名稱:anitrend-app,代碼行數:32,代碼來源:ConfigModule.java

示例10: applyOptions

import com.bumptech.glide.load.engine.cache.MemorySizeCalculator; //導入依賴的package包/類
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            File pathIcons = new File(Configuration.PATH_CACHE_ICONS);
            pathIcons.mkdirs();
            return DiskLruCacheWrapper.get(pathIcons, DEFAULT_DISK_CACHE_SIZE);
        }
    });

    final MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    final int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    builder.setMemoryCache(new LruResourceCache(defaultMemoryCacheSize / 2));
    final int defaultBitmapPoolSize = calculator.getBitmapPoolSize();
    builder.setBitmapPool(new LruBitmapPool(defaultBitmapPoolSize / 2));
}
 
開發者ID:Aptoide,項目名稱:aptoide-client,代碼行數:18,代碼來源:AptoideGlideModule.java

示例11: applyOptions

import com.bumptech.glide.load.engine.cache.MemorySizeCalculator; //導入依賴的package包/類
@Override public void applyOptions(Context context, GlideBuilder builder) {
  builder.setDecodeFormat(DecodeFormat.PREFER_RGB_565);

  // disk cache config
  //builder.setDiskCache(new ExternalCacheDiskCacheFactory(context));
  // using defaults

  MemorySizeCalculator calculator = new MemorySizeCalculator(context);

  // size for memory cache
  int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
  builder.setMemoryCache(new LruResourceCache(defaultMemoryCacheSize));

  // size for bitmap pool
  int defaultBitmapPoolSize = calculator.getBitmapPoolSize();
  builder.setBitmapPool(new LruBitmapPool(defaultBitmapPoolSize));
}
 
開發者ID:Aptoide,項目名稱:aptoide-client-v8,代碼行數:18,代碼來源:GlideModifications.java

示例12: applyOptions

import com.bumptech.glide.load.engine.cache.MemorySizeCalculator; //導入依賴的package包/類
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    // 設置格式
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
    // 緩存到data目錄下最大50M
    // 緩存目錄為程序內部緩存目錄
    // /data/data/your_package_name/image_manager_disk_cache/
    // (不能被其它應用訪問)且緩存最大為250MB
    builder.setDiskCache(new InternalCacheDiskCacheFactory(context,
            DiskCache.Factory.DEFAULT_DISK_CACHE_DIR,
            DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE));
    // 緩存到外部磁盤SD卡上,字節
    // builder.setDiskCache(new ExternalCacheDiskCacheFactory(
    // context,DiskCache.Factory.DEFAULT_DISK_CACHE_DIR,
    // DiskCache.Factory.DEFAULT_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));
}
 
開發者ID:leibing8912,項目名稱:ImageSwitcher,代碼行數:25,代碼來源:CustomGlideModule.java

示例13: applyOptions

import com.bumptech.glide.load.engine.cache.MemorySizeCalculator; //導入依賴的package包/類
@Override
public void applyOptions(final Context context, GlideBuilder builder) {
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);// Bitmap格式轉換到ARGB_8888
    //內存緩存
    MemorySizeCalculator memorySizeCalculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = memorySizeCalculator.getMemoryCacheSize();
    int defalutBitmapPoolSize = memorySizeCalculator.getBitmapPoolSize();
    builder.setMemoryCache(new LruResourceCache((int) (defalutBitmapPoolSize * 1.2)));//內部
    builder.setBitmapPool(new LruBitmapPool((int) (defalutBitmapPoolSize * 1.2)));
    //磁盤緩存
    builder.setDiskCache(new InternalCacheDiskCacheFactory(context, 1024 * 1024 * 10));//內部磁盤緩存
    builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, 10 * 1024 * 1024));//磁盤緩存到外部存儲
    //指定緩存目錄1
    String downLoadPath = Environment.getDownloadCacheDirectory().getPath();
    builder.setDiskCache(new DiskLruCacheFactory(downLoadPath, defaultMemoryCacheSize));
    //指定緩存目錄2
    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            File cacheLocation = new File(FileUtils.getCacheDir(context), "GlideCache");
            return DiskLruCacheWrapper.get(cacheLocation, 1024 * 1024 * 10);
        }
    });

}
 
開發者ID:dalingge,項目名稱:GankGirl,代碼行數:26,代碼來源:GlideConfiguration.java

示例14: applyOptions

import com.bumptech.glide.load.engine.cache.MemorySizeCalculator; //導入依賴的package包/類
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    //解決setTag問題
    ViewTarget.setTagId(R.id.glide_tag_id);
    //磁盤緩存
    builder.setDiskCache(new DiskLruCacheFactory(AppFileHelper.getAppCachePath(), 50 * 1024 * 1024));
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
    //內存緩存
    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();
    //設置比默認大小大1.5倍的緩存和圖片池大小
    int customMemoryCacheSize = (int) (1.5 * defaultMemoryCacheSize);
    int customBitmapPoolSize = defaultBitmapPoolSize;


    KLog.i("poolSize", "bitmapPoolSize >>>>>   "
            + android.text.format.Formatter.formatFileSize(context, customBitmapPoolSize)
            + "          memorySize>>>>>>>>   " +
            android.text.format.Formatter.formatFileSize(context, customMemoryCacheSize));

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

}
 
開發者ID:razerdp,項目名稱:FriendCircle,代碼行數:26,代碼來源:GlobalGlideConfiguration.java

示例15: applyOptions

import com.bumptech.glide.load.engine.cache.MemorySizeCalculator; //導入依賴的package包/類
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    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 ));

    int cacheSize50MegaBytes = 52428800;

    /*builder.setDiskCache(
            new InternalCacheDiskCacheFactory(context, cacheSize100MegaBytes)
    );*/

    /*builder.setDiskCache(
    new ExternalCacheDiskCacheFactory());*/
    builder.setDiskCache(new DiskLruCacheFactory(Constants.OwnCacheDirectory,"Cache",cacheSize50MegaBytes)) ;
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888); //PREFER_RGB_565
}
 
開發者ID:yeming1001,項目名稱:GankMeiZhi,代碼行數:24,代碼來源:MyGlideModule.java


注:本文中的com.bumptech.glide.load.engine.cache.MemorySizeCalculator類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。