Search in sources :

Example 6 with MemoryCacheParams

use of com.facebook.imagepipeline.cache.MemoryCacheParams in project ride-read-android by Ride-Read.

the class FrescoApp method configureCaches.

/**
     * 初始化配置
     */
private ImagePipelineConfig configureCaches(Context context) {
    final MemoryCacheParams bitmapCacheParams = new // 内存缓存中总图片的最大大小,以字节为单位。
    MemoryCacheParams(// 内存缓存中总图片的最大大小,以字节为单位。
    50 * ByteConstants.MB, // 内存缓存中图片的最大数量。
    500, // 内存缓存中准备清除但尚未被删除的总图片的最大大小,以字节为单位。
    50 * ByteConstants.MB, // 内存缓存中准备清除的总图片的最大数量。
    500, // 内存缓存中单个图片的最大大小。
    5 * ByteConstants.MB);
    //修改内存图片缓存数量,空间策略(这个方式有点恶心)
    //        Supplier<MemoryCacheParams> mSupplierMemoryCacheParams = new Supplier<MemoryCacheParams>() {
    //            @Override
    //            public MemoryCacheParams get() {
    //                return bitmapCacheParams;
    //            }
    //        };
    //小图片的磁盘配置
    DiskCacheConfig diskSmallCacheConfig = //缓存图片基路径
    DiskCacheConfig.newBuilder(this).setBaseDirectoryPath(new File(FRESCO_PATH)).setBaseDirectoryName(//文件夹名
    IMAGE_PIPELINE_SMALL_CACHE_DIR).setMaxCacheSize(//默认缓存的最大大小。
    MAX_SMALL_DISK_CACHE_SIZE).setMaxCacheSizeOnLowDiskSpace(//缓存的最大大小,使用设备时低磁盘空间。
    MAX_SMALL_DISK_LOW_CACHE_SIZE).setMaxCacheSizeOnVeryLowDiskSpace(//缓存的最大大小,当设备极低磁盘空间
    MAX_SMALL_DISK_VERYLOW_CACHE_SIZE).build();
    //默认图片的磁盘配置
    DiskCacheConfig diskCacheConfig = //缓存图片基路径
    DiskCacheConfig.newBuilder(this).setBaseDirectoryPath(new File(FRESCO_PATH)).setBaseDirectoryName(//文件夹名
    IMAGE_PIPELINE_CACHE_DIR).setMaxCacheSize(//默认缓存的最大大小。
    MAX_DISK_CACHE_SIZE).setMaxCacheSizeOnLowDiskSpace(//缓存的最大大小,使用设备时低磁盘空间。
    MAX_DISK_CACHE_LOW_SIZE).setMaxCacheSizeOnVeryLowDiskSpace(//缓存的最大大小,当设备极低磁盘空间
    MAX_DISK_CACHE_VERYLOW_SIZE).build();
    //缓存图片配置
    Supplier<MemoryCacheParams> bitmapCacheParamsSupplier = new Supplier<MemoryCacheParams>() {

        @Override
        public MemoryCacheParams get() {
            return bitmapCacheParams;
        }
    };
    ImagePipelineConfig.Builder configBuilder = ImagePipelineConfig.newBuilder(context).setBitmapMemoryCacheParamsSupplier(bitmapCacheParamsSupplier).setMainDiskCacheConfig(//磁盘缓存配置(总,三级缓存)
    diskCacheConfig).setSmallImageDiskCacheConfig(//磁盘缓存配置(小图片,可选~三级缓存的小图优化缓存)
    diskSmallCacheConfig);
    return configBuilder.build();
}
Also used : DiskCacheConfig(com.facebook.cache.disk.DiskCacheConfig) ImagePipelineConfig(com.facebook.imagepipeline.core.ImagePipelineConfig) MemoryCacheParams(com.facebook.imagepipeline.cache.MemoryCacheParams) Supplier(com.facebook.common.internal.Supplier) File(java.io.File)

Example 7 with MemoryCacheParams

use of com.facebook.imagepipeline.cache.MemoryCacheParams in project osm-contributor by jawg.

the class OsmTemplateApplication method onCreate.

/*=========================================*/
/*---------------OVERRIDE------------------*/
/*=========================================*/
@Override
public void onCreate() {
    super.onCreate();
    if (BuildConfig.DEBUG) {
        Timber.plant(new Timber.DebugTree());
    }
    Fabric.with(this, new Crashlytics());
    // Init Stetho for debug purpose (database)
    Stetho.initializeWithDefaults(this);
    // Init Dagger
    osmTemplateComponent = DaggerOsmTemplateComponent.builder().osmTemplateModule(new OsmTemplateModule(this)).build();
    osmTemplateComponent.inject(this);
    // Init Flickr object
    StoreConfigManager configManager = new StoreConfigManager();
    flickr = new Flickr(configManager.getFlickrApiKey(), configManager.getFlickrApiKeySecret(), new REST());
    // Cache Disk for Fresco
    DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(this).setBaseDirectoryPath(new File(Environment.getExternalStorageDirectory().getAbsoluteFile(), getPackageName())).setBaseDirectoryName("images").build();
    // Cache Memory for Fresco
    ImagePipelineConfig imagePipelineConfig = ImagePipelineConfig.newBuilder(this).setBitmapMemoryCacheParamsSupplier(new Supplier<MemoryCacheParams>() {

        @Override
        public MemoryCacheParams get() {
            return new MemoryCacheParams(10485760, 100, 100, 100, 100);
        }
    }).setMainDiskCacheConfig(diskCacheConfig).build();
    // Init Fresco
    Fresco.initialize(this, imagePipelineConfig);
    // Init event bus
    EventBus bus = osmTemplateComponent.getEventBus();
    bus.register(getOsmTemplateComponent().getLoginManager());
    bus.register(getOsmTemplateComponent().getEditPoiManager());
    bus.register(getOsmTemplateComponent().getPoiManager());
    bus.register(getOsmTemplateComponent().getNoteManager());
    bus.register(getOsmTemplateComponent().getSyncManager());
    bus.register(getOsmTemplateComponent().getTypeManager());
    bus.register(getOsmTemplateComponent().getPresetsManager());
    bus.register(getOsmTemplateComponent().getGeocoder());
    bus.register(getOsmTemplateComponent().getEditVectorialWayManager());
    SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
    if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean(getString(R.string.shared_prefs_preset_default), false)) {
        editor.putBoolean(getString(R.string.shared_prefs_preset_default), true);
    }
    editor.apply();
    MapboxAccountManager.start(this, BuildConfig.MAPBOX_TOKEN);
}
Also used : SharedPreferences(android.content.SharedPreferences) Timber(timber.log.Timber) ImagePipelineConfig(com.facebook.imagepipeline.core.ImagePipelineConfig) EventBus(org.greenrobot.eventbus.EventBus) Crashlytics(com.crashlytics.android.Crashlytics) OsmTemplateModule(io.jawg.osmcontributor.modules.OsmTemplateModule) Flickr(com.flickr4java.flickr.Flickr) REST(com.flickr4java.flickr.REST) DiskCacheConfig(com.facebook.cache.disk.DiskCacheConfig) StoreConfigManager(io.jawg.osmcontributor.utils.core.StoreConfigManager) MemoryCacheParams(com.facebook.imagepipeline.cache.MemoryCacheParams) File(java.io.File)

Example 8 with MemoryCacheParams

use of com.facebook.imagepipeline.cache.MemoryCacheParams in project fresco by facebook.

the class AnimatedFrameCacheTest method setUp.

@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 = new CountingLruBitmapMemoryCacheFactory().create(mMemoryCacheParamsSupplier, mMemoryTrimmableRegistry, new BitmapMemoryCacheTrimStrategy(), false, false, null);
    mCacheKey = new SimpleCacheKey("key");
    mAnimatedFrameCache = new AnimatedFrameCache(mCacheKey, countingMemoryCache);
    mFrame1 = CloseableReference.of(mock(CloseableImage.class));
    mFrame2 = CloseableReference.of(mock(CloseableImage.class));
}
Also used : MemoryCacheParams(com.facebook.imagepipeline.cache.MemoryCacheParams) BitmapMemoryCacheTrimStrategy(com.facebook.imagepipeline.cache.BitmapMemoryCacheTrimStrategy) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) CloseableImage(com.facebook.imagepipeline.image.CloseableImage) CacheKey(com.facebook.cache.common.CacheKey) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) CountingLruBitmapMemoryCacheFactory(com.facebook.imagepipeline.cache.CountingLruBitmapMemoryCacheFactory) Before(org.junit.Before)

Aggregations

MemoryCacheParams (com.facebook.imagepipeline.cache.MemoryCacheParams)8 DiskCacheConfig (com.facebook.cache.disk.DiskCacheConfig)6 ImagePipelineConfig (com.facebook.imagepipeline.core.ImagePipelineConfig)6 Supplier (com.facebook.common.internal.Supplier)5 File (java.io.File)2 SharedPreferences (android.content.SharedPreferences)1 Crashlytics (com.crashlytics.android.Crashlytics)1 CacheKey (com.facebook.cache.common.CacheKey)1 SimpleCacheKey (com.facebook.cache.common.SimpleCacheKey)1 MemoryTrimType (com.facebook.common.memory.MemoryTrimType)1 MemoryTrimmable (com.facebook.common.memory.MemoryTrimmable)1 MemoryTrimmableRegistry (com.facebook.common.memory.MemoryTrimmableRegistry)1 NoOpMemoryTrimmableRegistry (com.facebook.common.memory.NoOpMemoryTrimmableRegistry)1 PipelineDraweeControllerBuilder (com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder)1 OkHttpNetworkFetcher (com.facebook.imagepipeline.backends.okhttp3.OkHttpNetworkFetcher)1 BitmapMemoryCacheTrimStrategy (com.facebook.imagepipeline.cache.BitmapMemoryCacheTrimStrategy)1 CountingLruBitmapMemoryCacheFactory (com.facebook.imagepipeline.cache.CountingLruBitmapMemoryCacheFactory)1 SimpleProgressiveJpegConfig (com.facebook.imagepipeline.decoder.SimpleProgressiveJpegConfig)1 CloseableImage (com.facebook.imagepipeline.image.CloseableImage)1 RequestListener (com.facebook.imagepipeline.listener.RequestListener)1