Java 类com.facebook.cache.disk.DiskCacheConfig 实例源码

项目:GitHub    文件:BoxingFrescoLoader.java   
private void init(Context context) {
    ImagePipelineConfig.Builder builder = ImagePipelineConfig.newBuilder(context)
            .setDownsampleEnabled(true);
    String cache = BoxingFileHelper.getCacheDir(context);

    if (TextUtils.isEmpty(cache)) {
        throw new IllegalStateException("the cache dir is null");
    }
    if (cache != null) {
        DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(context)
                .setBaseDirectoryPath(new File(cache))
                .setBaseDirectoryName(IMAGE_PIPELINE_CACHE_DIR)
                .setMaxCacheSize(MAX_DISK_CACHE_SIZE)
                .setMaxCacheSizeOnLowDiskSpace(MAX_DISK_CACHE_LOW_SIZE)
                .setMaxCacheSizeOnVeryLowDiskSpace(MAX_DISK_CACHE_VERYLOW_SIZE)
                .build();
        builder.setMainDiskCacheConfig(diskCacheConfig);
    }
    ImagePipelineConfig config = builder.build();
    Fresco.initialize(context, config);
}
项目:GitHub    文件:DiskStorageCacheFactory.java   
public static DiskStorageCache buildDiskStorageCache(
    DiskCacheConfig diskCacheConfig,
    DiskStorage diskStorage,
    Executor executorForBackgroundInit) {
  DiskStorageCache.Params params = new DiskStorageCache.Params(
      diskCacheConfig.getMinimumSizeLimit(),
      diskCacheConfig.getLowDiskSpaceSizeLimit(),
      diskCacheConfig.getDefaultSizeLimit());

  return new DiskStorageCache(
      diskStorage,
      diskCacheConfig.getEntryEvictionComparatorSupplier(),
      params,
      diskCacheConfig.getCacheEventListener(),
      diskCacheConfig.getCacheErrorLogger(),
      diskCacheConfig.getDiskTrimmableRegistry(),
      diskCacheConfig.getContext(),
      executorForBackgroundInit,
      diskCacheConfig.getIndexPopulateAtStartupEnabled());
}
项目:Viajes    文件:ImagePipelineConfigFactory.java   
/**
 * Configures disk and memory cache not to exceed common limits
 */
private static void configureCaches(ImagePipelineConfig.Builder configBuilder, Context context) {
    final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(
            MAX_MEMORY_CACHE_SIZE, // Max total size of elements in the cache
            Integer.MAX_VALUE,                     // Max entries in the cache
            MAX_MEMORY_CACHE_SIZE, // Max total size of elements in eviction queue
            Integer.MAX_VALUE,                     // Max length of eviction queue
            Integer.MAX_VALUE);                    // Max cache entry size
    configBuilder
            .setBitmapMemoryCacheParamsSupplier(
                    new Supplier<MemoryCacheParams>() {
                        public MemoryCacheParams get() {
                            return bitmapCacheParams;
                        }
                    })
            .setMainDiskCacheConfig(DiskCacheConfig.newBuilder(context)
                    .setBaseDirectoryPath(getExternalCacheDir(context))
                    .setBaseDirectoryName(IMAGE_PIPELINE_CACHE_DIR)
                    .setMaxCacheSize(MAX_DISK_CACHE_SIZE)
                    .build());
}
项目:boxing    文件:BoxingFrescoLoader.java   
private void init(Context context) {
    ImagePipelineConfig.Builder builder = ImagePipelineConfig.newBuilder(context)
            .setDownsampleEnabled(true);
    String cache = BoxingFileHelper.getCacheDir(context);

    if (TextUtils.isEmpty(cache)) {
        throw new IllegalStateException("the cache dir is null");
    }
    if (!TextUtils.isEmpty(cache)) {
        DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(context)
                .setBaseDirectoryPath(new File(cache))
                .setBaseDirectoryName(IMAGE_PIPELINE_CACHE_DIR)
                .setMaxCacheSize(MAX_DISK_CACHE_SIZE)
                .setMaxCacheSizeOnLowDiskSpace(MAX_DISK_CACHE_LOW_SIZE)
                .setMaxCacheSizeOnVeryLowDiskSpace(MAX_DISK_CACHE_VERYLOW_SIZE)
                .build();
        builder.setMainDiskCacheConfig(diskCacheConfig);
    }
    ImagePipelineConfig config = builder.build();
    Fresco.initialize(context, config);
}
项目:GongXianSheng    文件:ImagePipelineConfigFactory.java   
/**
 * Configures disk and memory cache not to exceed common limits
 */
private static void configureCaches(
    ImagePipelineConfig.Builder configBuilder,
    Context context) {
  final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(
      MAX_MEMORY_CACHE_SIZE, // Max total size of elements in the cache
      Integer.MAX_VALUE,                     // Max entries in the cache
      MAX_MEMORY_CACHE_SIZE, // Max total size of elements in eviction queue
      Integer.MAX_VALUE,                     // Max length of eviction queue
      Integer.MAX_VALUE);                    // Max cache entry size
  configBuilder
      .setBitmapMemoryCacheParamsSupplier(
          new Supplier<MemoryCacheParams>() {
            public MemoryCacheParams get() {
              return bitmapCacheParams;
            }
          })
      .setMainDiskCacheConfig(
          DiskCacheConfig.newBuilder(context)
                  .setBaseDirectoryPath(context.getApplicationContext().getCacheDir())
              .setBaseDirectoryName(IMAGE_PIPELINE_CACHE_DIR)
              .setMaxCacheSize(MAX_DISK_CACHE_SIZE)
              .build());
}
项目:react-native-udesk    文件:ImagePipelineConfigFactory.java   
/**
 * Configures disk and memory cache not to exceed common limits
 */
private static void configureCaches(ImagePipelineConfig.Builder configBuilder, Context context) {
    final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(
            MAX_MEMORY_CACHE_SIZE, // Max total size of elements in the cache
            Integer.MAX_VALUE,                     // Max entries in the cache
            MAX_MEMORY_CACHE_SIZE, // Max total size of elements in eviction queue
            Integer.MAX_VALUE,                     // Max length of eviction queue
            Integer.MAX_VALUE);                    // Max cache entry size
    configBuilder
            .setBitmapMemoryCacheParamsSupplier(
                    new Supplier<MemoryCacheParams>() {
                        public MemoryCacheParams get() {
                            return bitmapCacheParams;
                        }
                    })
            .setMainDiskCacheConfig(DiskCacheConfig.newBuilder(context)
                    .setBaseDirectoryPath(getExternalCacheDir(context))
                    .setBaseDirectoryName(IMAGE_PIPELINE_CACHE_DIR)
                    .setMaxCacheSize(MAX_DISK_CACHE_SIZE)
                    .build());
}
项目:ModuleFrame    文件:FrescoUtil.java   
/**
 * 初始化
 */
public static void init(@NonNull Application application) {
    DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(application)
            .setBaseDirectoryName(CACHE_DIR_NAME)
            .setBaseDirectoryPath(CacheUtil.getCacheDirectory(application, null))
            .build();
    ImagePipelineConfig config = ImagePipelineConfig.newBuilder(application)
            .setResizeAndRotateEnabledForNetwork(true)
            .setDownsampleEnabled(true)
            .setBitmapMemoryCacheParamsSupplier(new MemoryCacheParamsSupplier(
                    (ActivityManager) application.getSystemService(Context.ACTIVITY_SERVICE)))  // 内存缓存配置
            .setMainDiskCacheConfig(diskCacheConfig)    // 磁盘缓存配置
            .setCacheKeyFactory(DefaultCacheKeyFactory.getInstance())   // 自定义缓存key
            .build();
    Fresco.initialize(application, config);
}
项目:richeditor    文件:AppManager.java   
private void FrescoInit() {
    DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(this)
            .setMaxCacheSize(40 * ByteConstants.MB)
            .setBaseDirectoryPathSupplier(new Supplier<File>() {
                @Override
                public File get() {
                    return getCacheDir();
                }
            })
            .build();

    final FrescoCacheParams bitmapCacheParams = new FrescoCacheParams(activityManager);
    //Set<RequestListener> listeners = new HashSet<>();
    ImagePipelineConfig imagePipelineConfig = OkHttpImagePipelineConfigFactory.newBuilder(this, RetrofitClient.getInstance().getOkHttpClient())
            .setMainDiskCacheConfig(diskCacheConfig)
            .setBitmapMemoryCacheParamsSupplier(bitmapCacheParams)
            .setDownsampleEnabled(true)
            .build();
    Fresco.initialize(this, imagePipelineConfig);
}
项目:ReactNativeSignatureExample    文件:FrescoModule.java   
private static ImagePipelineConfig getDefaultConfig(
    Context context,
    @Nullable RequestListener listener,
    @Nullable DiskCacheConfig diskCacheConfig) {
  HashSet<RequestListener> requestListeners = new HashSet<>();
  requestListeners.add(new SystraceRequestListener());
  if (listener != null) {
    requestListeners.add(listener);
  }

  OkHttpClient okHttpClient = OkHttpClientProvider.getOkHttpClient();
  ImagePipelineConfig.Builder builder =
      OkHttpImagePipelineConfigFactory.newBuilder(context.getApplicationContext(), okHttpClient);

  builder
      .setDownsampleEnabled(false)
      .setRequestListeners(requestListeners);

  if (diskCacheConfig != null) {
    builder.setMainDiskCacheConfig(diskCacheConfig);
  }

  return builder.build();
}
项目:MyTravelingDiary    文件:ImagePipelineConfigFactory.java   
/**
 * Configures disk and memory cache not to exceed common limits
 */
private static void configureCaches(ImagePipelineConfig.Builder configBuilder, Context context) {
    final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(
            MAX_MEMORY_CACHE_SIZE, // Max total size of elements in the cache
            Integer.MAX_VALUE,     // Max entries in the cache
            MAX_MEMORY_CACHE_SIZE, // Max total size of elements in eviction queue
            Integer.MAX_VALUE,     // Max length of eviction queue
            Integer.MAX_VALUE);    // Max cache entry size
    configBuilder
            .setBitmapMemoryCacheParamsSupplier(
                    new Supplier<MemoryCacheParams>() {
                        public MemoryCacheParams get() {
                            return bitmapCacheParams;
                        }
                    })
            .setMainDiskCacheConfig(DiskCacheConfig.newBuilder(context)
                    .setBaseDirectoryPath(getExternalCacheDir(context))
                    .setBaseDirectoryName(IMAGE_PIPELINE_CACHE_DIR)
                    .setMaxCacheSize(MAX_DISK_CACHE_SIZE)
                    .build());
}
项目:android-photo-picker    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder()
            .setBaseDirectoryPath(new File(Environment.getExternalStorageDirectory().getAbsoluteFile(), "Medlinker Pictures"))
            .setBaseDirectoryName("fresco")
            .setMaxCacheSize(Runtime.getRuntime().maxMemory() / 8)
            .build();
    ImagePipelineConfig imagePipelineConfig = ImagePipelineConfig.newBuilder(this)
            .setMainDiskCacheConfig(diskCacheConfig)
            .setDownsampleEnabled(true)
            .build();
    Fresco.initialize(this, imagePipelineConfig);

    setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, options));
}
项目:ChatUp    文件:ImagePipelineConfigFactory.java   
/**
 * Configures disk and memory cache not to exceed common limits
 */
private static void configureCaches(ImagePipelineConfig.Builder configBuilder, Context context) {
    final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(
            MAX_MEMORY_CACHE_SIZE, // Max total size of elements in the cache
            Integer.MAX_VALUE,                     // Max entries in the cache
            MAX_MEMORY_CACHE_SIZE, // Max total size of elements in eviction queue
            Integer.MAX_VALUE,                     // Max length of eviction queue
            Integer.MAX_VALUE);                    // Max cache entry size
    configBuilder
            .setBitmapMemoryCacheParamsSupplier(
                    new Supplier<MemoryCacheParams>() {
                        public MemoryCacheParams get() {
                            return bitmapCacheParams;
                        }
                    })
            .setMainDiskCacheConfig(DiskCacheConfig.newBuilder(context)
                    .setBaseDirectoryPath(getExternalCacheDir(context))
                    .setBaseDirectoryName(IMAGE_PIPELINE_CACHE_DIR)
                    .setMaxCacheSize(MAX_DISK_CACHE_SIZE)
                    .build());
}
项目:react-native-ibeacon-android    文件:FrescoModule.java   
private static ImagePipelineConfig getDefaultConfig(
    Context context,
    @Nullable RequestListener listener,
    @Nullable DiskCacheConfig diskCacheConfig) {
  HashSet<RequestListener> requestListeners = new HashSet<>();
  requestListeners.add(new SystraceRequestListener());
  if (listener != null) {
    requestListeners.add(listener);
  }

  OkHttpClient okHttpClient = OkHttpClientProvider.getOkHttpClient();
  ImagePipelineConfig.Builder builder =
      OkHttpImagePipelineConfigFactory.newBuilder(context.getApplicationContext(), okHttpClient);

  builder
      .setDownsampleEnabled(false)
      .setRequestListeners(requestListeners);

  if (diskCacheConfig != null) {
    builder.setMainDiskCacheConfig(diskCacheConfig);
  }

  return builder.build();
}
项目:fastDev    文件:FrescoUtils.java   
/**
 * 初始化操作,建议在子线程中进行
 * 添加的依赖:
 *  compile 'com.facebook.fresco:fresco:0.10.0+'
 compile 'com.facebook.fresco:animated-webp:0.10.0'
 compile 'com.facebook.fresco:animated-gif:0.10.0'
 * @param context
 * @param cacheSizeInM  磁盘缓存的大小,以M为单位
 */
public static void init(final Context context,int cacheSizeInM){


    DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(context)
            .setMaxCacheSize(cacheSizeInM*1024*1024)
            .setBaseDirectoryName(PHOTO_FRESCO)
            .setBaseDirectoryPathSupplier(new Supplier<File>() {
                @Override
                public File get() {
                    return context.getCacheDir();
                }
            })
            .build();
    MyImageCacheStatsTracker imageCacheStatsTracker = new MyImageCacheStatsTracker();
    ImagePipelineConfig config = ImagePipelineConfig.newBuilder(context)
            .setMainDiskCacheConfig(diskCacheConfig)
            .setImageCacheStatsTracker(imageCacheStatsTracker)
            .setDownsampleEnabled(true)//Downsampling,它处理图片的速度比常规的裁剪更快,
            // 并且同时支持PNG,JPG以及WEP格式的图片,非常强大,与ResizeOptions配合使用
            .setBitmapsConfig(Bitmap.Config.RGB_565)
            .build();
    Fresco.initialize(context, config);
}
项目:react-native-box-loaders    文件:FrescoModule.java   
private static ImagePipelineConfig getDefaultConfig(
    Context context,
    @Nullable RequestListener listener,
    @Nullable DiskCacheConfig diskCacheConfig) {
  HashSet<RequestListener> requestListeners = new HashSet<>();
  requestListeners.add(new SystraceRequestListener());
  if (listener != null) {
    requestListeners.add(listener);
  }

  OkHttpClient okHttpClient = OkHttpClientProvider.getOkHttpClient();
  ImagePipelineConfig.Builder builder =
      OkHttpImagePipelineConfigFactory.newBuilder(context.getApplicationContext(), okHttpClient);

  builder
      .setDownsampleEnabled(false)
      .setRequestListeners(requestListeners);

  if (diskCacheConfig != null) {
    builder.setMainDiskCacheConfig(diskCacheConfig);
  }

  return builder.build();
}
项目:ImageLoadPK    文件:FrescoConfigFactory.java   
public static ImagePipelineConfig getImagePipelineConfig(Context context) {
    if (sImagePipelineConfig == null) {
        sImagePipelineConfig = ImagePipelineConfig.newBuilder(context)
                .setMainDiskCacheConfig(DiskCacheConfig.newBuilder(context)
                        .setMaxCacheSize(ConfigConstants.MAX_CACHE_DISK_SIZE)
                        .build())
                .setBitmapMemoryCacheParamsSupplier(
                        new Supplier<MemoryCacheParams>() {
                            @Override
                            public MemoryCacheParams get() {
                                return new MemoryCacheParams(ConfigConstants.MAX_CACHE_MEMORY_SIZE,
                                        Integer.MAX_VALUE,
                                        Integer.MAX_VALUE,
                                        Integer.MAX_VALUE,
                                        Integer.MAX_VALUE);
                            }
                        }
                )
                .build();
    }
    return sImagePipelineConfig;
}
项目:ZhiHu-TopAnswer    文件:ImagePipelineConfigFactory.java   
/**
 * Configures disk and memory cache not to exceed common limits
 */
private static void configureCaches(
    ImagePipelineConfig.Builder configBuilder,
    Context context) {
  final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(
      MAX_MEMORY_CACHE_SIZE, // Max total size of elements in the cache
      Integer.MAX_VALUE,                     // Max entries in the cache
      MAX_MEMORY_CACHE_SIZE, // Max total size of elements in eviction queue
      Integer.MAX_VALUE,                     // Max length of eviction queue
      Integer.MAX_VALUE);                    // Max cache entry size
  configBuilder
      .setBitmapMemoryCacheParamsSupplier(
          new Supplier<MemoryCacheParams>() {
            public MemoryCacheParams get() {
              return bitmapCacheParams;
            }
          })
      .setMainDiskCacheConfig(
          DiskCacheConfig.newBuilder(context)
              .setBaseDirectoryPath(context.getApplicationContext().getCacheDir())
              .setBaseDirectoryName(IMAGE_PIPELINE_CACHE_DIR)
              .setMaxCacheSize(MAX_DISK_CACHE_SIZE)
              .build());
}
项目:WhiteRead    文件:FrescoConfigFactory.java   
public static ImagePipelineConfig getImagePipelineConfig(Context context) {
    if (sImagePipelineConfig == null) {
        sImagePipelineConfig = ImagePipelineConfig.newBuilder(context)
                .setMainDiskCacheConfig(DiskCacheConfig.newBuilder(context)
                        .setMaxCacheSize(ConfigConstants.MAX_CACHE_DISK_SIZE)
                        .build())
                .setBitmapMemoryCacheParamsSupplier(
                        new Supplier<MemoryCacheParams>() {
                            @Override
                            public MemoryCacheParams get() {
                                return new MemoryCacheParams(ConfigConstants.MAX_CACHE_MEMORY_SIZE,
                                        Integer.MAX_VALUE,
                                        Integer.MAX_VALUE,
                                        Integer.MAX_VALUE,
                                        Integer.MAX_VALUE);
                            }
                        }
                )
                .build();
    }
    return sImagePipelineConfig;
}
项目:Elephant    文件:Elephant.java   
@Override
public void onCreate() {
    super.onCreate();
    applicationContext = this;

    /**
     * 设置 Fresco 图片缓存的路径
     */
    DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(getApplicationContext())
            .setBaseDirectoryPath(getOwnCacheDirectory(this, APP_CACHE_PATH))
            .build();
    ImagePipelineConfig config = ImagePipelineConfig.newBuilder(getApplicationContext())
            .setMainDiskCacheConfig(diskCacheConfig)
            .setSmallImageDiskCacheConfig(diskCacheConfig)
            .build();

    //初始化 Fresco 图片缓存库
    Fresco.initialize(this, config);
    //初始化日志输出工具
    JLog.initialize(BuildConfig.LOG_DEBUG);
}
项目:FrescoUtlis    文件:FrescoUtils.java   
/**
 * 初始化操作,建议在子线程中进行
 * 添加的依赖:
 *  compile 'com.facebook.fresco:fresco:0.10.0+'
    compile 'com.facebook.fresco:animated-webp:0.10.0'
    compile 'com.facebook.fresco:animated-gif:0.10.0'
 * @param context
 * @param cacheSizeInM  磁盘缓存的大小,以M为单位
 */
public static void init(final Context context,int cacheSizeInM){


    DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(context)
            .setMaxCacheSize(cacheSizeInM*1024*1024)
            .setBaseDirectoryName(PHOTO_FRESCO)
            .setBaseDirectoryPathSupplier(new Supplier<File>() {
                @Override
                public File get() {
                    return context.getCacheDir();
                }
            })
            .build();
    MyImageCacheStatsTracker imageCacheStatsTracker = new MyImageCacheStatsTracker();
    ImagePipelineConfig config = ImagePipelineConfig.newBuilder(context)
            .setMainDiskCacheConfig(diskCacheConfig)
            .setImageCacheStatsTracker(imageCacheStatsTracker)
            .setDownsampleEnabled(true)//Downsampling,它处理图片的速度比常规的裁剪更快,
            // 并且同时支持PNG,JPG以及WEP格式的图片,非常强大,与ResizeOptions配合使用
            .setBitmapsConfig(Bitmap.Config.RGB_565)
            .build();
    Fresco.initialize(context, config);
}
项目:meiShi    文件:ImagePipelineConfigFactory.java   
/**
 * Configures disk and memory cache not to exceed common limits
 */
private static void configureCaches(
        ImagePipelineConfig.Builder configBuilder,
        Context context) {
    FileUtils.createDirs(ConfigConstants.IMAGE_PIPELINE_CACHE_DIR);
    final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(
            ConfigConstants.MAX_MEMORY_CACHE_SIZE, // Max total size of elements in the cache
            Integer.MAX_VALUE,                     // Max entries in the cache
            ConfigConstants.MAX_MEMORY_CACHE_SIZE, // Max total size of elements in eviction queue
            Integer.MAX_VALUE,                     // Max length of eviction queue
            Integer.MAX_VALUE);                    // Max cache entry size
    configBuilder
            .setBitmapMemoryCacheParamsSupplier(
                    new Supplier<MemoryCacheParams>() {
                        public MemoryCacheParams get() {
                            return bitmapCacheParams;
                        }
                    })
            .setMainDiskCacheConfig(
                    DiskCacheConfig.newBuilder(context)
                            .setBaseDirectoryPath(FileUtils.createDirs(ConfigConstants.IMAGE_PIPELINE_BASE_DIR))
                            .setBaseDirectoryName(ConfigConstants.IMAGE_PIPELINE_CACHE_DIR)
                            .setMaxCacheSize(ConfigConstants.MAX_DISK_CACHE_SIZE)
                            .build());
}
项目:TLint    文件:MyApplication.java   
private void initFrescoConfig() {
    final MemoryCacheParams bitmapCacheParams =
            new MemoryCacheParams(MAX_MEMORY_CACHE_SIZE, // Max total size of elements in the cache
                    Integer.MAX_VALUE,                     // Max entries in the cache
                    MAX_MEMORY_CACHE_SIZE, // Max total size of elements in eviction queue
                    Integer.MAX_VALUE,                     // Max length of eviction queue
                    Integer.MAX_VALUE);
    ImagePipelineConfig config = OkHttpImagePipelineConfigFactory.newBuilder(this, mOkHttpClient)
            .setProgressiveJpegConfig(new SimpleProgressiveJpegConfig())
            .setBitmapMemoryCacheParamsSupplier(new Supplier<MemoryCacheParams>() {
                public MemoryCacheParams get() {
                    return bitmapCacheParams;
                }
            })
            .setMainDiskCacheConfig(
                    DiskCacheConfig.newBuilder(this).setMaxCacheSize(MAX_DISK_CACHE_SIZE).build())
            .setDownsampleEnabled(true)
            .build();
    Fresco.initialize(this, config);
}
项目:HaoCommon    文件:ImagePipelineConfigFactory.java   
/**
 * Configures disk and memory cache not to exceed common limits
 */
private static void configureCaches(ImagePipelineConfig.Builder configBuilder, Context context) {
    final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(
            MAX_MEMORY_CACHE_SIZE, // Max total size of elements in the cache
            Integer.MAX_VALUE,                     // Max entries in the cache
            MAX_MEMORY_CACHE_SIZE, // Max total size of elements in eviction queue
            Integer.MAX_VALUE,                     // Max length of eviction queue
            Integer.MAX_VALUE);                    // Max cache entry size
    configBuilder
            .setBitmapMemoryCacheParamsSupplier(
                    new Supplier<MemoryCacheParams>() {
                        public MemoryCacheParams get() {
                            return bitmapCacheParams;
                        }
                    })
            .setMainDiskCacheConfig(DiskCacheConfig.newBuilder()
                            .setBaseDirectoryPath(getExternalCacheDir(context))
                            .setBaseDirectoryName(IMAGE_PIPELINE_CACHE_DIR)
                            .setMaxCacheSize(MAX_DISK_CACHE_SIZE)
                            .build());
}
项目:fresco    文件:DiskStorageCacheFactory.java   
public static DiskStorageCache buildDiskStorageCache(
    DiskCacheConfig diskCacheConfig,
    DiskStorage diskStorage,
    Executor executorForBackgroundInit) {
  DiskStorageCache.Params params = new DiskStorageCache.Params(
      diskCacheConfig.getMinimumSizeLimit(),
      diskCacheConfig.getLowDiskSpaceSizeLimit(),
      diskCacheConfig.getDefaultSizeLimit());

  return new DiskStorageCache(
      diskStorage,
      diskCacheConfig.getEntryEvictionComparatorSupplier(),
      params,
      diskCacheConfig.getCacheEventListener(),
      diskCacheConfig.getCacheErrorLogger(),
      diskCacheConfig.getDiskTrimmableRegistry(),
      diskCacheConfig.getContext(),
      executorForBackgroundInit,
      diskCacheConfig.getIndexPopulateAtStartupEnabled());
}
项目:fresco    文件:ImagePipelineConfigFactory.java   
/**
 * Configures disk and memory cache not to exceed common limits
 */
private static void configureCaches(
    ImagePipelineConfig.Builder configBuilder,
    Context context) {
  final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(
      ConfigConstants.MAX_MEMORY_CACHE_SIZE, // Max total size of elements in the cache
      Integer.MAX_VALUE,                     // Max entries in the cache
      ConfigConstants.MAX_MEMORY_CACHE_SIZE, // Max total size of elements in eviction queue
      Integer.MAX_VALUE,                     // Max length of eviction queue
      Integer.MAX_VALUE);                    // Max cache entry size
  configBuilder
      .setBitmapMemoryCacheParamsSupplier(
          new Supplier<MemoryCacheParams>() {
            public MemoryCacheParams get() {
              return bitmapCacheParams;
            }
          })
      .setMainDiskCacheConfig(
          DiskCacheConfig.newBuilder(context)
              .setBaseDirectoryPath(context.getApplicationContext().getCacheDir())
              .setBaseDirectoryName(IMAGE_PIPELINE_CACHE_DIR)
              .setMaxCacheSize(ConfigConstants.MAX_DISK_CACHE_SIZE)
              .build());
}
项目:GitHub    文件:DynamicDefaultDiskStorageFactory.java   
@Override
public DiskStorage get(DiskCacheConfig diskCacheConfig) {
  return new DynamicDefaultDiskStorage(
      diskCacheConfig.getVersion(),
      diskCacheConfig.getBaseDirectoryPathSupplier(),
      diskCacheConfig.getBaseDirectoryName(),
      diskCacheConfig.getCacheErrorLogger());
}
项目:GitHub    文件:ImagePipelineFactory.java   
public FileCache getMainFileCache() {
  if (mMainFileCache == null) {
    DiskCacheConfig diskCacheConfig = mConfig.getMainDiskCacheConfig();
    mMainFileCache = mConfig.getFileCacheFactory().get(diskCacheConfig);
  }
  return mMainFileCache;
}
项目:GitHub    文件:ImagePipelineFactory.java   
public FileCache getSmallImageFileCache() {
  if (mSmallImageFileCache == null) {
    DiskCacheConfig diskCacheConfig = mConfig.getSmallImageDiskCacheConfig();
    mSmallImageFileCache = mConfig.getFileCacheFactory().get(diskCacheConfig);
  }
  return mSmallImageFileCache;
}
项目:GitHub    文件:ImagePipelineConfigFactory.java   
/**
 * Configures disk and memory cache not to exceed common limits
 */
private static void configureCaches(
    ImagePipelineConfig.Builder configBuilder,
    Context context) {
  final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(
      ConfigConstants.MAX_MEMORY_CACHE_SIZE, // Max total size of elements in the cache
      Integer.MAX_VALUE,                     // Max entries in the cache
      ConfigConstants.MAX_MEMORY_CACHE_SIZE, // Max total size of elements in eviction queue
      Integer.MAX_VALUE,                     // Max length of eviction queue
      Integer.MAX_VALUE);                    // Max cache entry size
  configBuilder
      .setBitmapMemoryCacheParamsSupplier(
          new Supplier<MemoryCacheParams>() {
            public MemoryCacheParams get() {
              return bitmapCacheParams;
            }
          })
      .setMainDiskCacheConfig(
          DiskCacheConfig.newBuilder(context)
              .setBaseDirectoryPath(context.getApplicationContext().getCacheDir())
              .setBaseDirectoryName(IMAGE_PIPELINE_CACHE_DIR)
              .setMaxCacheSize(ConfigConstants.MAX_DISK_CACHE_SIZE)
              .build());
}
项目:SwipeCard-    文件:ScvApplication.java   
private ImagePipelineConfig createFrescoConfig() {
        DiskCacheConfig mainDiskCacheConfig = DiskCacheConfig.newBuilder(this)
                .setBaseDirectoryPath(getExternalCacheDir())
                .setBaseDirectoryName("fresco cache")
                .setMaxCacheSize(100 * 1024 * 1024)
                .setMaxCacheSizeOnLowDiskSpace(10 * 1024 * 1024)
                .setMaxCacheSizeOnVeryLowDiskSpace(5 * 1024 * 1024)
                .setVersion(1)
                .build();
        return ImagePipelineConfig.newBuilder(this)
//                .setBitmapMemoryCacheParamsSupplier(bitmapCacheParamsSupplier)
//                .setCacheKeyFactory(cacheKeyFactory)
//                .setEncodedMemoryCacheParamsSupplier(encodedCacheParamsSupplier)
//                .setExecutorSupplier(executorSupplier)
//                .setImageCacheStatsTracker(imageCacheStatsTracker)
                .setMainDiskCacheConfig(mainDiskCacheConfig)
//                .setMemoryTrimmableRegistry(memoryTrimmableRegistry)
//                .setNetworkFetchProducer(networkFetchProducer)
//                .setPoolFactory(poolFactory)
//                .setProgressiveJpegConfig(progressiveJpegConfig)
//                .setRequestListeners(requestListeners)
//                .setSmallImageDiskCacheConfig(smallImageDiskCacheConfig)
                .build();
    }
项目:PicKing    文件:MyApplication.java   
private DiskCacheConfig getDiskCacheConfig() {
    return DiskCacheConfig.newBuilder(this)
            .setBaseDirectoryPath(getDiskCacheDir(this))
            .setBaseDirectoryName("ImagePipelineCacheDefault")
            .setMaxCacheSize(MAX_DISK_CACHE_SIZE)
            .setMaxCacheSizeOnLowDiskSpace(MAX_DISK_CACHE_LOW_SIZE)
            .setMaxCacheSizeOnVeryLowDiskSpace(MAX_DISK_CACHE_VERYLOW_SIZE)
            .setDiskTrimmableRegistry(NoOpDiskTrimmableRegistry.getInstance())
            .build();
}
项目:GongXianSheng    文件:FrecoFactory.java   
public void initFresco(){
    String sign = PreferencesHelper.getCookie();
    DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(mContext)
            .setBaseDirectoryPath(mContext.getFilesDir())
            .setBaseDirectoryName("image_cache")
            .setMaxCacheSize(50 * ByteConstants.MB)
            .setMaxCacheSizeOnLowDiskSpace(10 * ByteConstants.MB)
            .setMaxCacheSizeOnVeryLowDiskSpace(2 * ByteConstants.MB)
            .build();
    ImagePipelineConfig config = ImagePipelineConfig.newBuilder(mContext)
            .setNetworkFetcher(new ElnImageDownloaderFetcher(sign,mContext))
            .setMainDiskCacheConfig(diskCacheConfig).build();
    Fresco.initialize(mContext, config);
}
项目:react-native-udesk    文件:UdeskSDKManager.java   
public void init(final Context context) {
    final int MAX_HEAP_SIZE = (int) Runtime.getRuntime().maxMemory();
    final int MAX_DISK_CACHE_SIZE = 300 * ByteConstants.MB;
    final int MAX_MEMORY_CACHE_SIZE = MAX_HEAP_SIZE / 3;
    final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(
            MAX_MEMORY_CACHE_SIZE,
            Integer.MAX_VALUE,
            MAX_MEMORY_CACHE_SIZE,
            Integer.MAX_VALUE,
            Integer.MAX_VALUE);

    DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(context)
            .setMaxCacheSize(MAX_DISK_CACHE_SIZE)//最大缓存
            .setBaseDirectoryName("udesk")//子目录
            .setBaseDirectoryPathSupplier(new Supplier<File>() {
                @Override
                public File get() {
                    return UdeskUtil.getExternalCacheDir(context);
                }
            })
            .build();
    ImagePipelineConfig config = ImagePipelineConfig.newBuilder(context)
            .setBitmapMemoryCacheParamsSupplier(
                    new Supplier<MemoryCacheParams>() {
                        public MemoryCacheParams get() {
                            return bitmapCacheParams;
                        }
                    })
            .setMainDiskCacheConfig(diskCacheConfig)
            .setDownsampleEnabled(true)
            .setBitmapsConfig(Bitmap.Config.RGB_565)
            .build();

    Fresco.initialize(context, config);
}
项目:JianshuApp    文件:FrescoManager.java   
public static void init(Context context, File baseDirectoryPath) {
    ImagePipelineConfig.Builder imagePipelineConfigBuilder = ImagePipelineConfig.newBuilder(context)
            .setMainDiskCacheConfig(DiskCacheConfig.newBuilder(context)
                    .setBaseDirectoryPath(baseDirectoryPath)
                    .setBaseDirectoryName("original")
                    .build())
            .setDownsampleEnabled(true);
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    Supplier<MemoryCacheParams> memoryCacheParamsSupplier = new DefaultBitmapMemoryCacheParamsSupplier(activityManager) {
        @Override
        public MemoryCacheParams get() {
            int maxCacheEntries = 256;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                maxCacheEntries = 64;
            }
            return new MemoryCacheParams(
                    getMaxCacheSize(),
                    maxCacheEntries,
                    Integer.MAX_VALUE,
                    Integer.MAX_VALUE,
                    Integer.MAX_VALUE);
        }
        private int getMaxCacheSize() {
            final int maxMemory = Math.min(activityManager.getMemoryClass() * ByteConstants.MB, Integer.MAX_VALUE);

            if (maxMemory < 32 * ByteConstants.MB) {
                return 4 * ByteConstants.MB;
            } else if (maxMemory < 64 * ByteConstants.MB) {
                return 6 * ByteConstants.MB;
            } else {
                return maxMemory / 4;
            }
        }
    };
    imagePipelineConfigBuilder.setBitmapMemoryCacheParamsSupplier(memoryCacheParamsSupplier);
    Fresco.initialize(context, imagePipelineConfigBuilder.build());
}
项目:FrescoCustomCacheKey    文件:FrescoConfig.java   
public static ImagePipelineConfig.Builder getConfigBuilder(Context context, File baseDirectoryPath, OkHttpClient okHttpClient) {

        DiskCacheConfig smallDiskCacheConfig = DiskCacheConfig
                .newBuilder(context).setBaseDirectoryPath(baseDirectoryPath)
                .setBaseDirectoryName(IMAGE_PIPELINE_SMALL_CACHE_DIR)
                .setMaxCacheSize(MAX_DISK_CACHE_SIZE)
                .setMaxCacheSizeOnLowDiskSpace(MAX_DISK_CACHE_LOW_SIZE)
                .setMaxCacheSizeOnVeryLowDiskSpace(MAX_DISK_CACHE_VERYLOW_SIZE)
                .build();
        DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(context)
                                                         .setBaseDirectoryPath(baseDirectoryPath)//缓存图片基路径
                                                         .setBaseDirectoryName(IMAGE_PIPELINE_CACHE_DIR)//文件夹名
                                                         .setMaxCacheSize(MAX_DISK_CACHE_SIZE)//默认缓存的最大大小。
                                                         .setMaxCacheSizeOnLowDiskSpace(MAX_DISK_CACHE_LOW_SIZE)//缓存的最大大小,当设备磁盘空间低时。
                                                         .setMaxCacheSizeOnVeryLowDiskSpace(MAX_DISK_CACHE_VERYLOW_SIZE)//缓存的最大大小,当设备磁盘空间极低时。
                                                         .build();
        OkHttpNetworkFetcher networkFetcher = new OkHttpNetworkFetcher(okHttpClient);
        return ImagePipelineConfig.newBuilder(context)
                                  .setNetworkFetcher(networkFetcher)//自定的网络层配置:如OkHttp,Volley
                                  .setCacheKeyFactory(LJCacheKeyFactory
                                          .getInstance())//缓存Key工厂
                                  .setBitmapMemoryCacheParamsSupplier(new LJBitmapMemoryCacheSupplier((ActivityManager) context
                                          .getSystemService(Context.ACTIVITY_SERVICE)))
                                  //内存缓存配置(一级缓存,已解码的图片)
                                  .setMainDiskCacheConfig(diskCacheConfig)//磁盘缓存配置(总,三级缓存)
                                  .setSmallImageDiskCacheConfig(smallDiskCacheConfig);//磁盘缓存配置(小图片,可选~三级缓存的小图优化缓存)
    }
项目:MyImageUtil    文件:FrescoUtil.java   
/**
 * 初始化操作,在Application的onCreate方法中初始化,建议在子线程中进行
 *
 * 添加的依赖:
             compile 'com.facebook.fresco:fresco:0.12.0'
             // 在 API < 14 上的机器支持 WebP 时,需要添加
             compile 'com.facebook.fresco:animated-base-support:0.12.0'
             // 支持 GIF 动图,需要添加
             compile 'com.facebook.fresco:animated-gif:0.12.0'
             // 支持 WebP (静态图+动图),需要添加
             compile 'com.facebook.fresco:animated-webp:0.12.0'
             compile 'com.facebook.fresco:webpsupport:0.12.0'
             compile "com.facebook.fresco:imagepipeline-okhttp3:0.12.0+"
 * @param context
 * @param cacheSizeInM  磁盘缓存的大小,以M为单位

 */
public static void init(final Context context, int cacheSizeInM){
    isWWW = true;
    DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(context)
            .setMaxCacheSize(cacheSizeInM*1024*1024)
            .setBaseDirectoryName(PHOTO_FRESCO)
            .setBaseDirectoryPathSupplier(new Supplier<File>() {
                @Override
                public File get() {
                    return context.getCacheDir();
                }
            })
            .build();
    MyImageCacheStatsTracker imageCacheStatsTracker = new MyImageCacheStatsTracker();


    OkHttpClient okHttpClient= getAllPassClient(context);


    ImagePipelineConfig config = OkHttpImagePipelineConfigFactory.newBuilder(context,okHttpClient)
   // ImagePipelineConfig config = ImagePipelineConfig.newBuilder(context)
            .setMainDiskCacheConfig(diskCacheConfig)
            .setImageCacheStatsTracker(imageCacheStatsTracker)
            .setDownsampleEnabled(true)//Downsampling,它处理图片的速度比常规的裁剪更快,
            // 并且同时支持PNG,JPG以及WEP格式的图片,非常强大,与ResizeOptions配合使用
            .setBitmapsConfig(Bitmap.Config.RGB_565)
            .build();
    Fresco.initialize(context, config);

    WindowManager wm = (WindowManager) context.getSystemService(
            Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    screenWidth = display.getWidth() - dip2px(context,15);
}
项目:FrescoPlus    文件:FrescoPlusInitializer.java   
private void initialize(FrescoPlusConfig config) {
    final FrescoPlusConfig frescoPlusConfig;
    if (config == null)
        config = FrescoPlusConfig.newBuilder(mContext).build();
    frescoPlusConfig = config;

    isDebug = frescoPlusConfig.isDebug();
    logTag = frescoPlusConfig.getLogTag();

    printWDImageConfigLog(frescoPlusConfig);

    DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder()
            .setBaseDirectoryName(DefaultConfigCentre.DEFAULT_DISK_CACHE_DIR_NAME)
            .setBaseDirectoryPath(frescoPlusConfig.getDiskCacheDir())
            .setMaxCacheSize(frescoPlusConfig.getMaxDiskCacheSize() * DefaultConfigCentre.MB)
            .setMaxCacheSizeOnLowDiskSpace(DefaultConfigCentre.DEFAULT_LOW_SPACE_DISK_CACHE_SIZE)
            .setMaxCacheSizeOnVeryLowDiskSpace(DefaultConfigCentre.DEFAULT_VERY_LOW_SPACE_DISK_CACHE_SIZE)
            .build();

    ImagePipelineConfig pipelineConfig = ImagePipelineConfig.newBuilder(mContext)
            .setBitmapsConfig(frescoPlusConfig.getBitmapConfig())
            .setImageCacheStatsTracker(FrescoCacheStatsTracker.getInstance())
            .setDownsampleEnabled(true)
            .setResizeAndRotateEnabledForNetwork(true)
            .setMainDiskCacheConfig(diskCacheConfig)
            .build();

    FrescoPlusCore.init(mContext, pipelineConfig);
}
项目:MediaMonkey    文件:PluginAccessHelper.java   
@WorkerThread
public void sendOnCreate(Context applicationContext, AppDelegateImpl appDelegate) {
    ensurePluginInjected();
    Timber.d("[sendOnCreate] dexFile : %s", dexFile);
    Timber.d("[sendOnCreate] manifest: %s", manifest);
    Timber.d("[sendOnCreate] instance: %s", instance);
    File cacheDir = new File(applicationContext.getExternalCacheDir(), manifest.getPackageName());
    Timber.d("[sendOnCreate] cache dir: %s", cacheDir);

    DiskCacheConfig config = DiskCacheConfig.newBuilder(applicationContext)
            .setBaseDirectoryPath(cacheDir)
            .build();

    ImagePipelineConfig ipConfig = ImagePipelineConfig.newBuilder(applicationContext)
            .setMainDiskCacheConfig(config)
            .build();

    // Fresco complains about this, but any other approaches to set cache dir name dynamically?
    Fresco.shutDown();
    Fresco.initialize(applicationContext, ipConfig);

    instance.onCreate(applicationContext, appDelegate);

    DataStoreInterface dsInterface = instance.getDataStoreInterface();
    if (null != dsInterface) {
        this.dataStoreServiceImpl = (DataStoreServiceImpl) appDelegate.getDataStoreService();
        dataStoreServiceImpl.onPluginRequestsDatabase(dsInterface);
    }
}
项目:gank-examples    文件:MyApplication.java   
private void initialize() {
        mApplication = this;
        mContext = this.getApplicationContext();
        mResources = this.getResources();
        Builder builder = Logcat.newBuilder();
        builder.logCatLogLevel(Logcat.SHOW_VERBOSE_LOG);
//        builder.logCatLogLevel(Logcat.NOT_SHOW_LOG);
//        Logcat.initialize(this, builder.build());
        Logcat.initialize(this);
        if (IS_DEBUG_ACTIVITYLIFE) {
            mActivityLifecycle = new MyActivityLifecycle();
            this.registerActivityLifecycleCallbacks(mActivityLifecycle);
        }
        //
        Set<RequestListener> requestListeners = new HashSet<>();
        requestListeners.add(new RequestLoggingListener());
        ImagePipelineConfig config = ImagePipelineConfig.newBuilder(this)
                // other setters
                .setRequestListeners(requestListeners)
                //配置图片磁盘缓存
                .setMainDiskCacheConfig(DiskCacheConfig.newBuilder(this)
                        .setBaseDirectoryName("image") //父目录下的文件夹名
                        .setBaseDirectoryPath(StorageUtils.getAppCacheFile(this)) //保存父目录
                        .build())
                .build();
        Fresco.initialize(this, config);
        FLog.setMinimumLoggingLevel(FLog.DEBUG);

        try {
            CrashHandler crashHandler = CrashHandler.getInstance();
            crashHandler.init(this, Config.CARSH_LOG_PATH);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
项目:android-jungle-framework    文件:FrescoImageLoaderEngine.java   
protected ImagePipelineConfig getFrescoConfig(Context context, String imgCachePath) {
    DiskCacheConfig diskCache = DiskCacheConfig
            .newBuilder(context)
            .setBaseDirectoryPath(new File(imgCachePath))
            .setBaseDirectoryName("imgcache")
            .setMaxCacheSize(64 * ByteConstants.MB)
            .setMaxCacheSizeOnLowDiskSpace(10 * ByteConstants.MB)
            .setMaxCacheSizeOnVeryLowDiskSpace(2 * ByteConstants.MB)
            .build();

    return ImagePipelineConfig.newBuilder(context)
            .setMainDiskCacheConfig(diskCache)
            .setDownsampleEnabled(true)
            .build();
}