Search in sources :

Example 1 with Supplier

use of com.facebook.common.internal.Supplier in project fresco by facebook.

the class ShowcaseApplication method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    FLog.setMinimumLoggingLevel(FLog.VERBOSE);
    Set<RequestListener> listeners = new HashSet<>();
    listeners.add(new RequestLoggingListener());
    ImagePipelineConfig imagePipelineConfig = ImagePipelineConfig.newBuilder(this).setRequestListeners(listeners).setImageDecoderConfig(CustomImageFormatConfigurator.createImageDecoderConfig(this)).experiment().setMediaVariationsIndexEnabled(new Supplier<Boolean>() {

        @Override
        public Boolean get() {
            return true;
        }
    }).experiment().setMediaIdExtractor(new ShowcaseMediaIdExtractor()).build();
    DraweeConfig.Builder draweeConfigBuilder = DraweeConfig.newBuilder();
    CustomImageFormatConfigurator.addCustomDrawableFactories(this, draweeConfigBuilder);
    draweeConfigBuilder.setDebugOverlayEnabledSupplier(DebugOverlaySupplierSingleton.getInstance(getApplicationContext()));
    Fresco.initialize(this, imagePipelineConfig, draweeConfigBuilder.build());
}
Also used : RequestListener(com.facebook.imagepipeline.listener.RequestListener) ShowcaseMediaIdExtractor(com.facebook.fresco.samples.showcase.imagepipeline.ShowcaseMediaIdExtractor) ImagePipelineConfig(com.facebook.imagepipeline.core.ImagePipelineConfig) RequestLoggingListener(com.facebook.imagepipeline.listener.RequestLoggingListener) Supplier(com.facebook.common.internal.Supplier) DraweeConfig(com.facebook.drawee.backends.pipeline.DraweeConfig) HashSet(java.util.HashSet)

Example 2 with Supplier

use of com.facebook.common.internal.Supplier in project remusic by aa112901.

the class MainApplication method getConfigureCaches.

private ImagePipelineConfig getConfigureCaches(Context context) {
    final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(// 内存缓存中总图片的最大大小,以字节为单位。
    MAX_MEM, // 内存缓存中图片的最大数量。
    Integer.MAX_VALUE, // 内存缓存中准备清除但尚未被删除的总图片的最大大小,以字节为单位。
    MAX_MEM, // 内存缓存中准备清除的总图片的最大数量。
    Integer.MAX_VALUE, // 内存缓存中单个图片的最大大小。
    Integer.MAX_VALUE / 10);
    Supplier<MemoryCacheParams> mSupplierMemoryCacheParams = new Supplier<MemoryCacheParams>() {

        @Override
        public MemoryCacheParams get() {
            return bitmapCacheParams;
        }
    };
    ImagePipelineConfig.Builder builder = ImagePipelineConfig.newBuilder(context).setDownsampleEnabled(true);
    builder.setBitmapMemoryCacheParamsSupplier(mSupplierMemoryCacheParams);
    // 小图片的磁盘配置
    DiskCacheConfig diskSmallCacheConfig = DiskCacheConfig.newBuilder(context).setBaseDirectoryPath(// 缓存图片基路径
    context.getApplicationContext().getCacheDir()).build();
    // 默认图片的磁盘配置
    DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(context).setBaseDirectoryPath(// 缓存图片基路径
    Environment.getExternalStorageDirectory().getAbsoluteFile()).build();
    // 缓存图片配置
    ImagePipelineConfig.Builder configBuilder = ImagePipelineConfig.newBuilder(context).setBitmapMemoryCacheParamsSupplier(// 内存缓存配置(一级缓存,已解码的图片)
    mSupplierMemoryCacheParams).setMainDiskCacheConfig(// 磁盘缓存配置(总,三级缓存)
    diskCacheConfig);
    return builder.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)

Example 3 with Supplier

use of com.facebook.common.internal.Supplier in project fresco by facebook.

the class AnimatedFactoryV2Impl method createDrawableFactory.

private ExperimentalBitmapAnimationDrawableFactory createDrawableFactory() {
    Supplier<Integer> cachingStrategySupplier = new Supplier<Integer>() {

        @Override
        public Integer get() {
            return ExperimentalBitmapAnimationDrawableFactory.CACHING_STRATEGY_FRESCO_CACHE_NO_REUSING;
        }
    };
    final SerialExecutorService serialExecutorServiceForFramePreparing = mSerialExecutorService == null ? new DefaultSerialExecutorService(mExecutorSupplier.forDecode()) : mSerialExecutorService;
    Supplier<Integer> numberOfFramesToPrepareSupplier = new Supplier<Integer>() {

        @Override
        public Integer get() {
            return NUMBER_OF_FRAMES_TO_PREPARE;
        }
    };
    final Supplier<Boolean> useDeepEquals = Suppliers.BOOLEAN_FALSE;
    return new ExperimentalBitmapAnimationDrawableFactory(getAnimatedDrawableBackendProvider(), UiThreadImmediateExecutorService.getInstance(), serialExecutorServiceForFramePreparing, RealtimeSinceBootClock.get(), mPlatformBitmapFactory, mBackingCache, cachingStrategySupplier, numberOfFramesToPrepareSupplier, useDeepEquals);
}
Also used : DefaultSerialExecutorService(com.facebook.common.executors.DefaultSerialExecutorService) DefaultSerialExecutorService(com.facebook.common.executors.DefaultSerialExecutorService) SerialExecutorService(com.facebook.common.executors.SerialExecutorService) Supplier(com.facebook.common.internal.Supplier) ExecutorSupplier(com.facebook.imagepipeline.core.ExecutorSupplier)

Example 4 with Supplier

use of com.facebook.common.internal.Supplier in project fresco by facebook.

the class ImagePipelineConfigFactory method configureCaches.

/**
 * 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 total size of elements in the cache
    ConfigConstants.MAX_MEMORY_CACHE_SIZE, // Max entries in the cache
    Integer.MAX_VALUE, // Max total size of elements in eviction queue
    ConfigConstants.MAX_MEMORY_CACHE_SIZE, // Max length of eviction queue
    Integer.MAX_VALUE, // Max cache entry size
    Integer.MAX_VALUE, // Interval for checking cache parameters
    TimeUnit.MINUTES.toMillis(5));
    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());
}
Also used : MemoryCacheParams(com.facebook.imagepipeline.cache.MemoryCacheParams) Supplier(com.facebook.common.internal.Supplier)

Example 5 with Supplier

use of com.facebook.common.internal.Supplier in project teaTime by ancfdy.

the class FrescoUtils method configureCaches.

/**
 * 初始化配置
 * @param context
 * @return
 */
private static ImagePipelineConfig configureCaches(Context context) {
    // 内存配置
    final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(// 内存缓存中总图片的最大大小,以字节为单位。
    FrescoUtils.MAX_MEMORY_CACHE_SIZE, // 内存缓存中图片的最大数量。
    Integer.MAX_VALUE, // 内存缓存中准备清除但尚未被删除的总图片的最大大小,以字节为单位。
    FrescoUtils.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).setMaxCacheSize(// 默认缓存的最大大小。
    FrescoUtils.MAX_DISK_CACHE_SIZE).setMaxCacheSizeOnLowDiskSpace(// 缓存的最大大小,使用设备时低磁盘空间。
    MAX_SMALL_DISK_LOW_CACHE_SIZE).setMaxCacheSizeOnVeryLowDiskSpace(// 缓存的最大大小,当设备极低磁盘空间
    MAX_SMALL_DISK_VERYLOW_CACHE_SIZE).build();
    // 默认图片的磁盘配置
    DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(context).setBaseDirectoryPath(// 缓存图片基路径
    Environment.getExternalStorageDirectory().getAbsoluteFile()).setBaseDirectoryName(// 文件夹名
    IMAGE_PIPELINE_CACHE_DIR).setMaxCacheSize(// 默认缓存的最大大小。
    FrescoUtils.MAX_DISK_CACHE_SIZE).setMaxCacheSizeOnLowDiskSpace(// 缓存的最大大小,使用设备时低磁盘空间。
    MAX_DISK_CACHE_LOW_SIZE).setMaxCacheSizeOnVeryLowDiskSpace(// 缓存的最大大小,当设备极低磁盘空间
    MAX_DISK_CACHE_VERYLOW_SIZE).build();
    // 缓存图片配置
    ImagePipelineConfig.Builder configBuilder = ImagePipelineConfig.newBuilder(context).setBitmapMemoryCacheParamsSupplier(// 内存缓存配置(一级缓存,已解码的图片)
    mSupplierMemoryCacheParams).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)

Aggregations

Supplier (com.facebook.common.internal.Supplier)7 MemoryCacheParams (com.facebook.imagepipeline.cache.MemoryCacheParams)5 ImagePipelineConfig (com.facebook.imagepipeline.core.ImagePipelineConfig)5 DiskCacheConfig (com.facebook.cache.disk.DiskCacheConfig)4 DefaultSerialExecutorService (com.facebook.common.executors.DefaultSerialExecutorService)1 SerialExecutorService (com.facebook.common.executors.SerialExecutorService)1 DraweeConfig (com.facebook.drawee.backends.pipeline.DraweeConfig)1 ShowcaseMediaIdExtractor (com.facebook.fresco.samples.showcase.imagepipeline.ShowcaseMediaIdExtractor)1 ExecutorSupplier (com.facebook.imagepipeline.core.ExecutorSupplier)1 RequestListener (com.facebook.imagepipeline.listener.RequestListener)1 RequestLoggingListener (com.facebook.imagepipeline.listener.RequestLoggingListener)1 File (java.io.File)1 HashSet (java.util.HashSet)1