Java Code Examples for com.facebook.imagepipeline.core.ImagePipelineConfig#Builder

The following examples show how to use com.facebook.imagepipeline.core.ImagePipelineConfig#Builder . 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: FrescoModule.java    From react-native-GPay with MIT License 6 votes vote down vote up
/**
 * Get the default Fresco configuration builder.
 * Allows adding of configuration options in addition to the default values.
 *
 * @return {@link ImagePipelineConfig.Builder} that has been initialized with default values
 */
public static ImagePipelineConfig.Builder getDefaultConfigBuilder(ReactContext context) {
  HashSet<RequestListener> requestListeners = new HashSet<>();
  requestListeners.add(new SystraceRequestListener());

  OkHttpClient client = OkHttpClientProvider.createClient();

  // make sure to forward cookies for any requests via the okHttpClient
  // so that image requests to endpoints that use cookies still work
  CookieJarContainer container = (CookieJarContainer) client.cookieJar();
  ForwardingCookieHandler handler = new ForwardingCookieHandler(context);
  container.setCookieJar(new JavaNetCookieJar(handler));

  return OkHttpImagePipelineConfigFactory
    .newBuilder(context.getApplicationContext(), client)
    .setNetworkFetcher(new ReactOkHttpNetworkFetcher(client))
    .setDownsampleEnabled(false)
    .setRequestListeners(requestListeners);
}
 
Example 2
Source File: ImagePipelineConfigFactory.java    From meiShi with Apache License 2.0 6 votes vote down vote up
/**
 * 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 3
Source File: ImagePipelineConfigFactory.java    From ZhiHu-TopAnswer with Apache License 2.0 6 votes vote down vote up
/**
 * 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 4
Source File: BoxingFrescoLoader.java    From boxing with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 5
Source File: FrescoHelper.java    From base-module with Apache License 2.0 6 votes vote down vote up
public void init(Context context, ImagePipelineConfig config) {
    if(config == null) {
        ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

        ImagePipelineConfig.Builder builder = ImagePipelineConfig.newBuilder(context)
                .setResizeAndRotateEnabledForNetwork(true)
                .setBitmapsConfig(Bitmap.Config.ARGB_8888)
                .setBitmapMemoryCacheParamsSupplier(new MyBitmapMemoryCacheParamsSupplier(activityManager))
                .setDownsampleEnabled(true);

        if (isVLoggable || isDLoggable) {
            Set<RequestListener> requestListeners = new HashSet<>();
            requestListeners.add(new RequestLoggingListener());
            builder.setRequestListeners(requestListeners);
            int level = isVLoggable ? FLog.VERBOSE : FLog.DEBUG;
            FLog.setMinimumLoggingLevel(level);
        }

        config = builder.build();
    }

    context.getApplicationContext().registerComponentCallbacks(this);
    Fresco.initialize(context, config);
}
 
Example 6
Source File: ImagePipelineConfigFactory.java    From ZhiHu-TopAnswer with Apache License 2.0 5 votes vote down vote up
/**
   * Creates config using android http stack as network backend.
   */
  public static ImagePipelineConfig getImagePipelineConfig(Context context) {
    if (sImagePipelineConfig == null) {
      ImagePipelineConfig.Builder configBuilder = ImagePipelineConfig.newBuilder(context);
      configureCaches(configBuilder, context);
//      configureLoggingListeners(configBuilder);
      configureOptions(configBuilder);
      sImagePipelineConfig = configBuilder.build();
    }
    return sImagePipelineConfig;
  }
 
Example 7
Source File: HavenApp.java    From haven with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    mPrefs = new PreferenceManager(this);

    ImagePipelineConfig.Builder b = ImagePipelineConfig.newBuilder(this);
    ImagePipelineConfig config = b
            .setProgressiveJpegConfig(new SimpleProgressiveJpegConfig())
            .setResizeAndRotateEnabledForNetwork(true)
            .setDownsampleEnabled(true)
            .build();

    Fresco.initialize(this,config);

    try {
        ImagePipelineNativeLoader.load();
    } catch (UnsatisfiedLinkError e) {
        Fresco.shutDown();
        b.experiment().setNativeCodeDisabled(true);
        config = b.build();
        Fresco.initialize(this, config);
        e.printStackTrace();
    }

    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);

    if (mPrefs.getRemoteAccessActive())
        startServer();

    havenApp = this;
    dataBaseInstance = HavenEventDB.getDatabase(this);

    JobManager.create(this).addJobCreator(new HavenJobCreator());
}
 
Example 8
Source File: ScrollPerfApplication.java    From fresco with MIT License 5 votes vote down vote up
@Override
public void onCreate() {
  super.onCreate();
  final Config config = Config.load(this);
  ImagePipelineConfig.Builder imagePipelineConfigBuilder =
      ImagePipelineConfig.newBuilder(this)
          .setResizeAndRotateEnabledForNetwork(false)
          .setDownsampleEnabled(config.downsampling);
  if (WebpSupportStatus.sIsWebpSupportRequired) {
    imagePipelineConfigBuilder.experiment().setWebpSupportEnabled(config.webpSupportEnabled);
  }
  if (config.decodingThreadCount == 0) {
    imagePipelineConfigBuilder.setExecutorSupplier(
        new DefaultExecutorSupplier(Const.NUMBER_OF_PROCESSORS));
  } else {
    imagePipelineConfigBuilder.setExecutorSupplier(
        new ScrollPerfExecutorSupplier(Const.NUMBER_OF_PROCESSORS, config.decodingThreadCount));
  }
  imagePipelineConfigBuilder.experiment().setDecodeCancellationEnabled(config.decodeCancellation);
  DraweeConfig draweeConfig =
      DraweeConfig.newBuilder().setDrawDebugOverlay(config.draweeOverlayEnabled).build();
  if (BuildConfig.FLAVOR == "noNativeCode") {
    imagePipelineConfigBuilder.setMemoryChunkType(MemoryChunkType.BUFFER_MEMORY);
    Fresco.initialize(this, imagePipelineConfigBuilder.build(), draweeConfig, false);
  } else {
    Fresco.initialize(this, imagePipelineConfigBuilder.build(), draweeConfig, true);
  }
}
 
Example 9
Source File: FrescoManager.java    From JianshuApp with GNU General Public License v3.0 5 votes vote down vote up
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 10
Source File: ImagePipelineConfigFactory.java    From meiShi with Apache License 2.0 5 votes vote down vote up
/**
 * Creates config using OkHttp as network backed.
 */
public static ImagePipelineConfig getOkHttpImagePipelineConfig(Context context,OkHttpClient okHttpClient) {
    if (sOkHttpImagePipelineConfig == null) {
        ImagePipelineConfig.Builder configBuilder =
                OkHttpImagePipelineConfigFactory.newBuilder(context, okHttpClient);
        configureCaches(configBuilder, context);
        configureLoggingListeners(configBuilder);
        sOkHttpImagePipelineConfig = configBuilder.build();
    }
    return sOkHttpImagePipelineConfig;
}
 
Example 11
Source File: ImagePipelineConfigFactory.java    From fresco with MIT License 5 votes vote down vote up
/** Creates config using android http stack as network backend. */
public static ImagePipelineConfig getImagePipelineConfig(Context context) {
  if (sImagePipelineConfig == null) {
    ImagePipelineConfig.Builder configBuilder = ImagePipelineConfig.newBuilder(context);
    configureCaches(configBuilder, context);
    configureLoggingListeners(configBuilder);
    configureOptions(configBuilder);
    sImagePipelineConfig = configBuilder.build();
  }
  return sImagePipelineConfig;
}
 
Example 12
Source File: WebpBitmapFactoryTest.java    From fresco with MIT License 5 votes vote down vote up
@Override
@Before
public void setUp() {
  mInstrumentation = InstrumentationRegistry.getInstrumentation();
  mWebpBitmapFactory = new WebpBitmapFactoryImpl();
  ImagePipelineConfig.Builder configBuilder =
      ImagePipelineConfig.newBuilder(mInstrumentation.getContext())
          .experiment()
          .setWebpBitmapFactory(mWebpBitmapFactory);
  ImagePipelineFactory.initialize(configBuilder.build());
}
 
Example 13
Source File: WebpDecodingTest.java    From fresco with MIT License 5 votes vote down vote up
@Override
@Before
public void setUp() {
  mInstrumentation = InstrumentationRegistry.getInstrumentation();
  mWebpBitmapFactory = new WebpBitmapFactoryImpl();
  ImagePipelineConfig.Builder configBuilder =
      ImagePipelineConfig.newBuilder(mInstrumentation.getContext())
          .experiment()
          .setWebpBitmapFactory(mWebpBitmapFactory);
  ImagePipelineFactory.initialize(configBuilder.build());
}
 
Example 14
Source File: FrescoConfig.java    From BlueBoard with Apache License 2.0 4 votes vote down vote up
/**
     * 初始化配置
     */
    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 15
Source File: ImagePipelineConfigFactory.java    From fresco with MIT License 4 votes vote down vote up
private static void configureOptions(ImagePipelineConfig.Builder configBuilder) {
  configBuilder.setDownsampleEnabled(true);
}
 
Example 16
Source File: OkHttpImagePipelineConfigFactory.java    From fresco with MIT License 4 votes vote down vote up
public static ImagePipelineConfig.Builder newBuilder(Context context, OkHttpClient okHttpClient) {
  return ImagePipelineConfig.newBuilder(context)
      .setNetworkFetcher(new OkHttpNetworkFetcher(okHttpClient));
}
 
Example 17
Source File: ImagePipelineConfigFactory.java    From fresco with MIT License 4 votes vote down vote up
private static void configureLoggingListeners(ImagePipelineConfig.Builder configBuilder) {
  Set<RequestListener> requestListeners = new HashSet<>();
  requestListeners.add(new RequestLoggingListener());
  configBuilder.setRequestListeners(requestListeners);
}
 
Example 18
Source File: ImagePipelineConfigFactory.java    From meiShi with Apache License 2.0 4 votes vote down vote up
private static void configureOptions(ImagePipelineConfig.Builder configBuilder) {
    configBuilder.setDownsampleEnabled(true);
}
 
Example 19
Source File: ImagePipelineConfigFactory.java    From meiShi with Apache License 2.0 4 votes vote down vote up
private static void configureLoggingListeners(ImagePipelineConfig.Builder configBuilder) {
    Set<RequestListener> requestListeners = new HashSet<>();
    requestListeners.add(new RequestLoggingListener());
    configBuilder.setRequestListeners(requestListeners);
}
 
Example 20
Source File: ImagePipelineConfigFactory.java    From ZhiHu-TopAnswer with Apache License 2.0 4 votes vote down vote up
private static void configureOptions(ImagePipelineConfig.Builder configBuilder) {
  configBuilder.setDownsampleEnabled(true);
}