com.facebook.imagepipeline.backends.okhttp3.OkHttpImagePipelineConfigFactory Java Examples

The following examples show how to use com.facebook.imagepipeline.backends.okhttp3.OkHttpImagePipelineConfigFactory. 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: MyApplication.java    From PicKing with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    OkHttpClient okHttpClient = new OkHttpClient.Builder()
            .build();
    ImagePipelineConfig config = OkHttpImagePipelineConfigFactory.newBuilder(this, okHttpClient)
            .setMainDiskCacheConfig(getDiskCacheConfig())
            .setNetworkFetcher(new OkHttpNetworkFetcher(okHttpClient))
            .setDownsampleEnabled(true)
            .build();
    Fresco.initialize(this, config);

    Context context = getApplicationContext();
    String packageName = context.getPackageName();
    String processName = getProcessName(android.os.Process.myPid());
    CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(context);
    strategy.setUploadProcess(processName == null || processName.equals(packageName));
    CrashReport.initCrashReport(getApplicationContext(), "0a6e92fb70", false, strategy);

    registerActivityLifecycleCallbacks(ActivityLifecycleHelper.build());
}
 
Example #3
Source File: MyApplication.java    From TLint with Apache License 2.0 6 votes vote down vote up
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 #4
Source File: DemoApplication.java    From demo4Fish with MIT License 5 votes vote down vote up
private void init() {
    OkHttpClient mOkHttpClient = new OkHttpClient();
    ImagePipelineConfig imagePipelineConfig = OkHttpImagePipelineConfigFactory
            .newBuilder(this, mOkHttpClient)
            .setDownsampleEnabled(true)
            .build();
    Fresco.initialize(this, imagePipelineConfig);
}
 
Example #5
Source File: FrescoLoader.java    From ImageLoader with Apache License 2.0 5 votes vote down vote up
@Override
public void init(final Context context, int cacheSizeInM) {
    DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(context)
            .setMaxCacheSize(cacheSizeInM*1024*1024)
            .setBaseDirectoryName(GlobalConfig.cacheFolderName)
            .setBaseDirectoryPathSupplier(new Supplier<File>() {
                @Override
                public File get() {
                    return context.getCacheDir();
                }
            })
            .build();
    MyImageCacheStatsTracker imageCacheStatsTracker = new MyImageCacheStatsTracker();

    OkHttpClient okHttpClient= MyUtil.getClient(GlobalConfig.ignoreCertificateVerify);
    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)

            //让fresco即时清理内存:http://blog.csdn.net/honjane/article/details/65629799
            .setBitmapMemoryCacheParamsSupplier(new MyBitmapMemoryCacheParamsSupplier((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)))
            .build();
    //Fresco.initialize(context, config);

    BigImageViewer.initialize(BigImageLoader.with(context,config));

}
 
Example #6
Source File: NetworkModule.java    From okuki with Apache License 2.0 5 votes vote down vote up
public NetworkModule(Context context) {
    final HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
    interceptor.setLevel(BuildConfig.DEBUG ? HttpLoggingInterceptor.Level.BODY : HttpLoggingInterceptor.Level.NONE);
    final OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
    bind(OkHttpClient.class).toInstance(client);
    final Moshi moshi = new Moshi.Builder().add(MoshiJsonAdapterFactory.create()).build();
    bind(Moshi.class).toInstance(moshi);
    final ImagePipelineConfig config = OkHttpImagePipelineConfigFactory.newBuilder(context, client).build();
    Fresco.initialize(context, config);
}
 
Example #7
Source File: FrescoUtil.java    From MyImageUtil with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化操作,在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);
}
 
Example #8
Source File: MainActivity.java    From mirror with GNU General Public License v3.0 5 votes vote down vote up
private void setupFresco() {
    OkHttpClient client = new OkHttpClient.Builder().build();
    ImagePipelineConfig config = OkHttpImagePipelineConfigFactory.newBuilder(this, client)
            .setResizeAndRotateEnabledForNetwork(true)
            .setDownsampleEnabled(true)
            .build();
    Fresco.initialize(this, config);
}
 
Example #9
Source File: ImagePipelineConfigFactory.java    From fresco with MIT License 5 votes vote down vote up
/** Creates config using OkHttp as network backed. */
public static ImagePipelineConfig getOkHttpImagePipelineConfig(Context context) {
  if (sOkHttpImagePipelineConfig == null) {
    OkHttpClient okHttpClient =
        new OkHttpClient.Builder().addNetworkInterceptor(new StethoInterceptor()).build();
    ImagePipelineConfig.Builder configBuilder =
        OkHttpImagePipelineConfigFactory.newBuilder(context, okHttpClient);
    configureCaches(configBuilder, context);
    configureLoggingListeners(configBuilder);
    sOkHttpImagePipelineConfig = configBuilder.build();
  }
  return sOkHttpImagePipelineConfig;
}