com.facebook.imagepipeline.cache.MemoryCacheParams Java Examples
The following examples show how to use
com.facebook.imagepipeline.cache.MemoryCacheParams.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FrescoHelper.java From base-module with Apache License 2.0 | 6 votes |
@Override public MemoryCacheParams get() { //fresco 在 api 21 以下是将图片缓存在 ashm 中,此时不做限制,默认配置,当大于 21 版本,缓存在 java 内存堆时做如下配置 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return new MemoryCacheParams( getMaxCacheSize(), //内存缓存中总图片的最大大小,以字节为单位 MAX_CACHE_ENTRIES, MAX_CACHE_EVICTION_SIZE, MAX_CACHE_EVICTION_ENTRIES, MAX_CACHE_ENTRY_SIZE); } else { return new MemoryCacheParams( getMaxCacheSize(), MAX_CACHE_ASHM_ENTRIES, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE); } }
Example #2
Source File: App.java From APlayer with GNU General Public License v3.0 | 6 votes |
private void loadLibrary() { // bugly Context context = getApplicationContext(); // 获取当前包名 String packageName = context.getPackageName(); // 获取当前进程名 String processName = Util.getProcessName(android.os.Process.myPid()); // 设置是否为上报进程 UserStrategy strategy = new UserStrategy(context); strategy.setUploadProcess(processName == null || processName.equals(packageName)); CrashReport.initCrashReport(this, BuildConfig.BUGLY_APPID, BuildConfig.DEBUG, strategy); CrashReport.setIsDevelopmentDevice(this, BuildConfig.DEBUG); // fresco final int cacheSize = (int) (Runtime.getRuntime().maxMemory() / 8); ImagePipelineConfig config = ImagePipelineConfig.newBuilder(this) .setBitmapMemoryCacheParamsSupplier( () -> new MemoryCacheParams(cacheSize, Integer.MAX_VALUE, cacheSize, Integer.MAX_VALUE, 2 * ByteConstants.MB)) .setBitmapsConfig(Bitmap.Config.RGB_565) .setDownsampleEnabled(true) .build(); Fresco.initialize(this, config); }
Example #3
Source File: FrescoConfigFactory.java From ImageLoadPK with Apache License 2.0 | 6 votes |
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; }
Example #4
Source File: ImagePipelineConfigFactory.java From ZhiHu-TopAnswer with Apache License 2.0 | 6 votes |
/** * 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()); }
Example #5
Source File: ImagePipelineConfigFactory.java From fresco with MIT License | 6 votes |
/** 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 TimeUnit.MINUTES.toMillis(5)); // Interval for checking cache parameters 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()); }
Example #6
Source File: ImagePipelineConfigFactory.java From meiShi with Apache License 2.0 | 6 votes |
/** * 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()); }
Example #7
Source File: MyApplication.java From TLint with Apache License 2.0 | 6 votes |
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); }
Example #8
Source File: AnimatedFrameCacheTest.java From fresco with MIT License | 6 votes |
@Before public void setUp() { MockitoAnnotations.initMocks(this); MemoryCacheParams params = new MemoryCacheParams( 4 * ByteConstants.MB, 256, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, TimeUnit.MINUTES.toMillis(5)); when(mMemoryCacheParamsSupplier.get()).thenReturn(params); CountingMemoryCache<CacheKey, CloseableImage> countingMemoryCache = BitmapCountingMemoryCacheFactory.get( mMemoryCacheParamsSupplier, mMemoryTrimmableRegistry, null); mCacheKey = new SimpleCacheKey("key"); mAnimatedFrameCache = new AnimatedFrameCache(mCacheKey, countingMemoryCache); mFrame1 = CloseableReference.of(mock(CloseableImage.class)); mFrame2 = CloseableReference.of(mock(CloseableImage.class)); }
Example #9
Source File: MainReactPackageWithFrescoCache.java From react-native-image-filter-kit with MIT License | 5 votes |
private Supplier<MemoryCacheParams> createCacheParamsSupplier( final ReactApplicationContext context ) { ActivityManager manager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE); final Supplier<MemoryCacheParams> cacheParamsSupplier = new DefaultBitmapMemoryCacheParamsSupplier(manager) { @Override public MemoryCacheParams get() { MemoryCacheParams params = super.get(); return new MemoryCacheParams( mMaxCacheSizeInBytes == null ? params.maxCacheSize : mMaxCacheSizeInBytes, mMaxCacheEntries == null ? params.maxCacheEntries : mMaxCacheEntries, params.maxEvictionQueueSize, params.maxEvictionQueueEntries, params.maxCacheEntrySize ); } }; String size = String.valueOf(cacheParamsSupplier.get().maxCacheSize / 1024 / 1024); String entries = String.valueOf(cacheParamsSupplier.get().maxCacheEntries); FLog.d( ReactConstants.TAG, "ImageFilterKit: Fresco cache size - " + entries + " entries, " + size + " MB overall" ); return cacheParamsSupplier; }
Example #10
Source File: MyBitmapMemoryCacheParamsSupplier.java From ImageLoader with Apache License 2.0 | 5 votes |
@Override public MemoryCacheParams get() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return new MemoryCacheParams(getMaxCacheSize(), MAX_CACHE_ENTRIES, MAX_CACHE_EVICTION_SIZE, MAX_CACHE_EVICTION_ENTRIES, 1); } else { return new MemoryCacheParams( getMaxCacheSize(), MAX_CACHE_ASHM_ENTRIES, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE); } }
Example #11
Source File: FrescoManager.java From JianshuApp with GNU General Public License v3.0 | 5 votes |
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()); }
Example #12
Source File: ImagePipelineConfig.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 4 votes |
public Builder setEncodedMemoryCacheParamsSupplier( Supplier<MemoryCacheParams> encodedMemoryCacheParamsSupplier) { mEncodedMemoryCacheParamsSupplier = Preconditions.checkNotNull(encodedMemoryCacheParamsSupplier); return this; }
Example #13
Source File: FrescoConfig.java From BlueBoard with Apache License 2.0 | 4 votes |
/** * 初始化配置 */ private static ImagePipelineConfig configureCaches(Context context) { //内存配置 final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams( FrescoConfig.MAX_MEMORY_CACHE_SIZE, // 内存缓存中总图片的最大大小,以字节为单位。 Integer.MAX_VALUE, // 内存缓存中图片的最大数量。 FrescoConfig.MAX_MEMORY_CACHE_SIZE, // 内存缓存中准备清除但尚未被删除的总图片的最大大小,以字节为单位。 Integer.MAX_VALUE, // 内存缓存中准备清除的总图片的最大数量。 Integer.MAX_VALUE); // 内存缓存中单个图片的最大大小。 //修改内存图片缓存数量,空间策略(这个方式有点恶心) Supplier<MemoryCacheParams> mSupplierMemoryCacheParams = new Supplier<MemoryCacheParams>() { @Override public MemoryCacheParams get() { return bitmapCacheParams; } }; //小图片的磁盘配置 DiskCacheConfig diskSmallCacheConfig = DiskCacheConfig.newBuilder(context) .setBaseDirectoryPath(context.getApplicationContext().getCacheDir())//缓存图片基路径 .setBaseDirectoryName(IMAGE_PIPELINE_SMALL_CACHE_DIR)//文件夹名 // .setCacheErrorLogger(cacheErrorLogger)//日志记录器用于日志错误的缓存。 // .setCacheEventListener(cacheEventListener)//缓存事件侦听器。 // .setDiskTrimmableRegistry(diskTrimmableRegistry)//类将包含一个注册表的缓存减少磁盘空间的环境。 .setMaxCacheSize(FrescoConfig.MAX_DISK_CACHE_SIZE)//默认缓存的最大大小。 .setMaxCacheSizeOnLowDiskSpace(MAX_SMALL_DISK_LOW_CACHE_SIZE)//缓存的最大大小,使用设备时低磁盘空间。 .setMaxCacheSizeOnVeryLowDiskSpace(MAX_SMALL_DISK_VERYLOW_CACHE_SIZE)//缓存的最大大小,当设备极低磁盘空间 // .setVersion(version) .build(); //默认图片的磁盘配置 DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(context) .setBaseDirectoryPath(context.getExternalCacheDir().getAbsoluteFile())//缓存图片基路径 .setBaseDirectoryName(IMAGE_PIPELINE_CACHE_DIR)//文件夹名 // .setCacheErrorLogger(cacheErrorLogger)//日志记录器用于日志错误的缓存。 // .setCacheEventListener(cacheEventListener)//缓存事件侦听器。 // .setDiskTrimmableRegistry(diskTrimmableRegistry)//类将包含一个注册表的缓存减少磁盘空间的环境。 .setMaxCacheSize(FrescoConfig.MAX_DISK_CACHE_SIZE)//默认缓存的最大大小。 .setMaxCacheSizeOnLowDiskSpace(MAX_DISK_CACHE_LOW_SIZE)//缓存的最大大小,使用设备时低磁盘空间。 .setMaxCacheSizeOnVeryLowDiskSpace(MAX_DISK_CACHE_VERY_LOW_SIZE)//缓存的最大大小,当设备极低磁盘空间 // .setVersion(version) .build(); //缓存图片配置 ImagePipelineConfig.Builder configBuilder = ImagePipelineConfig.newBuilder(context) // ImagePipelineConfig.Builder configBuilder = OkHttpImagePipelineConfigFactory // .newBuilder(context, new OkHttpClient()) // .setAnimatedImageFactory(AnimatedImageFactory animatedImageFactory)//图片加载动画 .setBitmapMemoryCacheParamsSupplier(mSupplierMemoryCacheParams)//内存缓存配置(一级缓存,已解码的图片) // .setCacheKeyFactory(cacheKeyFactory)//缓存Key工厂 // .setEncodedMemoryCacheParamsSupplier(encodedCacheParamsSupplier)//内存缓存和未解码的内存缓存的配置(二级缓存) // .setExecutorSupplier(executorSupplier)//线程池配置 // .setImageCacheStatsTracker(imageCacheStatsTracker)//统计缓存的命中率 // .setImageDecoder(ImageDecoder imageDecoder) //图片解码器配置 // .setIsPrefetchEnabledSupplier(Supplier<Boolean> isPrefetchEnabledSupplier)//图片预览(缩略图,预加载图等)预加载到文件缓存 .setMainDiskCacheConfig(diskCacheConfig)//磁盘缓存配置(总,三级缓存) // .setMemoryTrimmableRegistry(memoryTrimmableRegistry) //内存用量的缩减,有时我们可能会想缩小内存用量。比如应用中有其他数据需要占用内存,不得不把图片缓存清除或者减小 或者我们想检查看看手机是否已经内存不够了。 // .setNetworkFetchProducer(networkFetchProducer)//自定的网络层配置:如OkHttp,Volley // .setPoolFactory(poolFactory)//线程池工厂配置 // .setProgressiveJpegConfig(progressiveJpegConfig)//渐进式JPEG图 // .setRequestListeners(requestListeners)//图片请求监听 // .setResizeAndRotateEnabledForNetwork(boolean resizeAndRotateEnabledForNetwork)//调整和旋转是否支持网络图片 .setSmallImageDiskCacheConfig(diskSmallCacheConfig);//磁盘缓存配置(小图片,可选~三级缓存的小图优化缓存) return configBuilder.build(); }
Example #14
Source File: ImagePipelineConfig.java From fresco with MIT License | 4 votes |
public Builder setEncodedMemoryCacheParamsSupplier( Supplier<MemoryCacheParams> encodedMemoryCacheParamsSupplier) { mEncodedMemoryCacheParamsSupplier = Preconditions.checkNotNull(encodedMemoryCacheParamsSupplier); return this; }
Example #15
Source File: ImagePipelineConfig.java From fresco with MIT License | 4 votes |
public Builder setBitmapMemoryCacheParamsSupplier( Supplier<MemoryCacheParams> bitmapMemoryCacheParamsSupplier) { mBitmapMemoryCacheParamsSupplier = Preconditions.checkNotNull(bitmapMemoryCacheParamsSupplier); return this; }
Example #16
Source File: ImagePipelineConfig.java From fresco with MIT License | 4 votes |
public Supplier<MemoryCacheParams> getEncodedMemoryCacheParamsSupplier() { return mEncodedMemoryCacheParamsSupplier; }
Example #17
Source File: ImagePipelineConfig.java From fresco with MIT License | 4 votes |
public Supplier<MemoryCacheParams> getBitmapMemoryCacheParamsSupplier() { return mBitmapMemoryCacheParamsSupplier; }
Example #18
Source File: MyBitmapMemoryCacheParamsSupplier.java From FimiX8-RE with MIT License | 4 votes |
public MemoryCacheParams get() { if (VERSION.SDK_INT >= 21) { return new MemoryCacheParams(getMaxCacheSize(), 56, 5, 5, 1); } return new MemoryCacheParams(getMaxCacheSize(), 128, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE); }
Example #19
Source File: ImagePipelineConfig.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 4 votes |
public Builder setBitmapMemoryCacheParamsSupplier( Supplier<MemoryCacheParams> bitmapMemoryCacheParamsSupplier) { mBitmapMemoryCacheParamsSupplier = Preconditions.checkNotNull(bitmapMemoryCacheParamsSupplier); return this; }
Example #20
Source File: ImagePipelineConfig.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 4 votes |
public Supplier<MemoryCacheParams> getEncodedMemoryCacheParamsSupplier() { return mEncodedMemoryCacheParamsSupplier; }
Example #21
Source File: ImagePipelineConfig.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 4 votes |
public Supplier<MemoryCacheParams> getBitmapMemoryCacheParamsSupplier() { return mBitmapMemoryCacheParamsSupplier; }
Example #22
Source File: FrescoImageLoader.java From FimiX8-RE with MIT License | 4 votes |
private static void configureCaches(Builder configBuilder, Context context) { MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(MAX_MEMORY_CACHE_SIZE, Integer.MAX_VALUE, MAX_MEMORY_CACHE_SIZE, Integer.MAX_VALUE, Integer.MAX_VALUE); configBuilder.setDownsampleEnabled(true).setBitmapsConfig(Config.RGB_565).setBitmapMemoryCacheParamsSupplier(new MyBitmapMemoryCacheParamsSupplier((ActivityManager) context.getSystemService("activity"))).setMainDiskCacheConfig(DiskCacheConfig.newBuilder(context).setBaseDirectoryPath(context.getApplicationContext().getCacheDir()).setBaseDirectoryName(IMAGE_PIPELINE_CACHE_DIR).setMaxCacheSize(41943040).build()); }