com.facebook.imagepipeline.core.ImagePipelineConfig Java Examples

The following examples show how to use com.facebook.imagepipeline.core.ImagePipelineConfig. 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: 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 #2
Source File: ImagePipelineConfigFactory.java    From fresco with MIT License 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(
          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 #3
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 #4
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 #5
Source File: BaseProducerContext.java    From fresco with MIT License 6 votes vote down vote up
public BaseProducerContext(
    ImageRequest imageRequest,
    String id,
    ProducerListener2 producerListener,
    Object callerContext,
    ImageRequest.RequestLevel lowestPermittedRequestLevel,
    boolean isPrefetch,
    boolean isIntermediateResultExpected,
    Priority priority,
    ImagePipelineConfig imagePipelineConfig) {
  this(
      imageRequest,
      id,
      null,
      producerListener,
      callerContext,
      lowestPermittedRequestLevel,
      isPrefetch,
      isIntermediateResultExpected,
      priority,
      imagePipelineConfig);
}
 
Example #6
Source File: AopApp.java    From DoraemonKit with Apache License 2.0 6 votes vote down vote up
@Override
    public void onCreate() {
        super.onCreate();
//        List<AbstractKit> kits = new ArrayList<>();
//        kits.add(new DemoKit());
        //测试环境:a49842eeebeb1989b3f9565eb12c276b
        //线上环境:749a0600b5e48dd77cf8ee680be7b1b7
        //new AopTest().test();
        ImagePipelineConfig config = ImagePipelineConfig.newBuilder(this)
                .setDiskCacheEnabled(false)
                .build();
        Fresco.initialize(this, config);

        //是否显示入口icon
        // DoraemonKit.setAwaysShowMainIcon(false);
       // DoraemonKit.disableUpload();
       // DoraemonKit.install(this, "749a0600b5e48dd77cf8ee680be7b1b7");
        //DoraemonKit.install(this, kits, "70e78c27f9174d68668d8a66a2b66483")
    }
 
Example #7
Source File: AopApp.java    From DoraemonKit with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    List<AbstractKit> kits = new ArrayList<>();
    kits.add(new DemoKit());
    //测试环境:a49842eeebeb1989b3f9565eb12c276b
    //线上环境:749a0600b5e48dd77cf8ee680be7b1b7
    //new AopTest().test();
    ImagePipelineConfig config = ImagePipelineConfig.newBuilder(this)
            .setDiskCacheEnabled(false)
            .build();
    Fresco.initialize(this, config);

    //是否显示入口icon
    // DoraemonKit.setAwaysShowMainIcon(false);
    DoraemonKit.disableUpload();
    DoraemonKit.install(this, "749a0600b5e48dd77cf8ee680be7b1b7");
    //DoraemonKit.install(this, kits, "70e78c27f9174d68668d8a66a2b66483")
}
 
Example #8
Source File: MainActivity.java    From AndroidPlayground with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ImagePipelineConfig config = ImagePipelineConfig.newBuilder(getApplicationContext())
            .setDownsampleEnabled(true)
            .setBitmapsConfig(Bitmap.Config.RGB_565)
            .build();
    Fresco.initialize(getApplication(), config);

    setContentView(R.layout.activity_main);

    showGif();

    showShapedDrawee();

    showInnerDrawee();
}
 
Example #9
Source File: SettableProducerContext.java    From fresco with MIT License 6 votes vote down vote up
public SettableProducerContext(
    ImageRequest imageRequest,
    String id,
    @Nullable String uiComponentId,
    ProducerListener2 producerListener,
    Object callerContext,
    ImageRequest.RequestLevel lowestPermittedRequestLevel,
    boolean isPrefetch,
    boolean isIntermediateResultExpected,
    Priority priority,
    ImagePipelineConfig imagePipelineConfig) {
  super(
      imageRequest,
      id,
      uiComponentId,
      producerListener,
      callerContext,
      lowestPermittedRequestLevel,
      isPrefetch,
      isIntermediateResultExpected,
      priority,
      imagePipelineConfig);
}
 
Example #10
Source File: SettableProducerContext.java    From fresco with MIT License 6 votes vote down vote up
public SettableProducerContext(
    ImageRequest imageRequest,
    String id,
    ProducerListener2 producerListener,
    Object callerContext,
    ImageRequest.RequestLevel lowestPermittedRequestLevel,
    boolean isPrefetch,
    boolean isIntermediateResultExpected,
    Priority priority,
    ImagePipelineConfig imagePipelineConfig) {
  super(
      imageRequest,
      id,
      producerListener,
      callerContext,
      lowestPermittedRequestLevel,
      isPrefetch,
      isIntermediateResultExpected,
      priority,
      imagePipelineConfig);
}
 
Example #11
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 #12
Source File: MyApplication.java    From Mobike with Apache License 2.0 6 votes vote down vote up
private void initMyApplication() {
    //tencent bugly
    CrashReport.initCrashReport(getApplicationContext(), "e1a62089c6", false);
    //Fresco
    ImagePipelineConfig config = ImagePipelineConfig.newBuilder(this)
            .setProgressiveJpegConfig(new SimpleProgressiveJpegConfig())
            .build();
    Fresco.initialize(this, config);
    //baidu map sdk
    SDKInitializer.initialize(this);
    //Bmob
    Bmob.initialize(this, "b0cb494256d9b86fc931ca930a055b75");
    //Logger
    Logger.addLogAdapter(new AndroidLogAdapter(){
        @Override
        public boolean isLoggable(int priority, String tag) {
            return true;// TODO: 2017/6/5
        }
    });
    //locail use data
    initUser();
}
 
Example #13
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 #14
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 #15
Source File: App.java    From APlayer with GNU General Public License v3.0 6 votes vote down vote up
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 #16
Source File: FrescoConfigFactory.java    From ImageLoadPK with Apache License 2.0 6 votes vote down vote up
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 #17
Source File: App.java    From droidddle with Apache License 2.0 6 votes vote down vote up
@Override
    public void onCreate() {
        super.onCreate();
        sThis = this;
//        com.squareup.leakcanary.LeakCanary.install(this);
        initialize(this);
//        Glide.get(this).register(GlideUrl.class, InputStream.class,
//                new OkHttpUrlLoader.Factory(ApiFactory.getOkHttpClient(this)));
        ImagePipelineConfig config = OkHttpImagePipelineConfigFactory
                .newBuilder(this, ApiFactory.getOkHttpClient(this))
                .build();
        Fresco.initialize(this, config);

        if (true || OAuthUtils.haveToken(this)) {
//            Intent watchfaceLoader = new Intent();
//            watchfaceLoader.setClass(this, BucketWatchFaceLoader.class);
//            startService(BucketWatchFaceLoader.getServiceIntent(this));
            startService(FollowingCheckService.getServiceIntent(this));
        }
    }
 
Example #18
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 #19
Source File: Elephant.java    From Elephant with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    applicationContext = this;

    /**
     * 设置 Fresco 图片缓存的路径
     */
    DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(getApplicationContext())
            .setBaseDirectoryPath(getOwnCacheDirectory(this, APP_CACHE_PATH))
            .build();
    ImagePipelineConfig config = ImagePipelineConfig.newBuilder(getApplicationContext())
            .setMainDiskCacheConfig(diskCacheConfig)
            .setSmallImageDiskCacheConfig(diskCacheConfig)
            .build();

    //初始化 Fresco 图片缓存库
    Fresco.initialize(this, config);
    //初始化日志输出工具
    JLog.initialize(BuildConfig.LOG_DEBUG);
}
 
Example #20
Source File: FrescoUtils.java    From FrescoUtlis with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化操作,建议在子线程中进行
 * 添加的依赖:
 *  compile 'com.facebook.fresco:fresco:0.10.0+'
    compile 'com.facebook.fresco:animated-webp:0.10.0'
    compile 'com.facebook.fresco:animated-gif:0.10.0'
 * @param context
 * @param cacheSizeInM  磁盘缓存的大小,以M为单位
 */
public static void init(final Context context,int cacheSizeInM){


    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();
    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);
}
 
Example #21
Source File: OkHttpImagePipelineConfigFactory.java    From FanXin-based-HuanXin with GNU General Public License v2.0 6 votes vote down vote up
public static ImagePipelineConfig.Builder newBuilder(Context context, OkHttpClient okHttpClient) {
  // Before creating OkHttpNetworkFetchProducer we need to configure and get pool factory -
  // OkHttpNetworkFetchProducer requires pooled byte buffer factory and common byte array pool.
  PoolConfig poolConfig = PoolConfig.newBuilder().build();
  PoolFactory poolFactory = new PoolFactory(poolConfig);

  // Create OkHttpNetworkFetchProducer
  OkHttpNetworkFetchProducer producer = new OkHttpNetworkFetchProducer(
      okHttpClient,
      true,
      poolFactory.getPooledByteBufferFactory(),
      poolFactory.getCommonByteArrayPool());

  // Pass OkHttpNetworkFetchProducer and PoolFactory we created above the pipeline configuration
  return ImagePipelineConfig.newBuilder(context)
      .setNetworkFetchProducer(producer)
      .setPoolFactory(poolFactory);
}
 
Example #22
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 #23
Source File: EncodedMemoryCacheProducerTest.java    From fresco with MIT License 5 votes vote down vote up
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  mEncodedMemoryCacheProducer =
      new EncodedMemoryCacheProducer(mMemoryCache, mCacheKeyFactory, mInputProducer);
  mPooledByteBuffer1 = mock(PooledByteBuffer.class);
  mPooledByteBuffer2 = mock(PooledByteBuffer.class);
  mFinalImageReference = CloseableReference.of(mPooledByteBuffer1);
  mIntermediateImageReference = CloseableReference.of(mPooledByteBuffer2);
  mFinalImageReferenceClone = mFinalImageReference.clone();
  mFinalEncodedImage = new EncodedImage(mFinalImageReference);
  mFinalEncodedImage.setImageFormat(new ImageFormat("jpeg", null));
  mFinalEncodedImage.setWidth(100);
  mFinalEncodedImage.setHeight(100);
  mImagePipelineConfig = mock(ImagePipelineConfig.class);
  mImagePipelineExperiments = mock(ImagePipelineExperiments.class);

  mFinalEncodedImageFormatUnknown = new EncodedImage(mFinalImageReference);
  mIntermediateEncodedImage = new EncodedImage(mIntermediateImageReference);
  mFinalEncodedImageClone = new EncodedImage(mFinalImageReferenceClone);
  List<CacheKey> list = new ArrayList<>();
  list.add(new SimpleCacheKey("http://dummy.uri"));
  mCacheKey = new MultiCacheKey(list);
  when(mCacheKeyFactory.getEncodedCacheKey(mImageRequest, mCallerContext)).thenReturn(mCacheKey);

  when(mMemoryCache.cache(mCacheKey, mFinalImageReference)).thenReturn(mFinalImageReferenceClone);
  when(mProducerContext.getImageRequest()).thenReturn(mImageRequest);
  when(mProducerContext.getCallerContext()).thenReturn(mCallerContext);
  when(mProducerContext.getProducerListener()).thenReturn(mProducerListener);
  when(mProducerListener.requiresExtraMap(mProducerContext, PRODUCER_NAME)).thenReturn(true);
  when(mProducerContext.getLowestPermittedRequestLevel())
      .thenReturn(ImageRequest.RequestLevel.FULL_FETCH);
  when(mProducerContext.getImagePipelineConfig()).thenReturn(mImagePipelineConfig);
  when(mImagePipelineConfig.getExperiments()).thenReturn(mImagePipelineExperiments);
  when(mImagePipelineExperiments.isEncodedCacheEnabled()).thenReturn(true);

  when(mImageRequest.isMemoryCacheEnabled()).thenReturn(true);
}
 
Example #24
Source File: ZoomableApplication.java    From fresco with MIT License 5 votes vote down vote up
@Override
public void onCreate() {
  super.onCreate();
  FLog.setMinimumLoggingLevel(FLog.VERBOSE);
  Set<RequestListener> listeners = new HashSet<>();
  listeners.add(new RequestLoggingListener());
  ImagePipelineConfig config =
      ImagePipelineConfig.newBuilder(this).setRequestListeners(listeners).build();
  Fresco.initialize(this, config);
}
 
Example #25
Source File: MainApplication.java    From drawee-text-view with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    // initialize fresco with enabled webp
    Fresco.initialize(this, ImagePipelineConfig.newBuilder(this)
            .experiment()
            .setWebpSupportEnabled(true)
            .build());
    // for debug
    if (BuildConfig.DEBUG) {
        FLogDefaultLoggingDelegate.getInstance().setApplicationTag("Drawee-text");
        FLog.setMinimumLoggingLevel(Log.VERBOSE);
    }
}
 
Example #26
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 #27
Source File: FrescoConfig.java    From BlueBoard with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化配置,单例
 */
public static ImagePipelineConfig getImagePipelineConfig(Context context) {
    if (sImagePipelineConfig == null) {
        sImagePipelineConfig = configureCaches(context);
    }
    return sImagePipelineConfig;
}
 
Example #28
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 #29
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 #30
Source File: ImageUtil.java    From ONE-Unofficial with Apache License 2.0 5 votes vote down vote up
public static void init(Context context) {
    File cacheDir = new File(FileManager.getAppDir());

    //Fresco配置和初始化
    DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder()
            .setBaseDirectoryPath(cacheDir)                     //缓存文件夹所在的路径
            .setBaseDirectoryName(FileManager.DIR_IMG_CACHE)    //缓存文件夹名称
            .setMaxCacheSize(MAX_IMG_CACHE_SIZE).build();       //最大缓存文件大小,必须设置
    ImagePipelineConfig imagePipelineConfig = ImagePipelineConfig.newBuilder(context).setMainDiskCacheConfig(diskCacheConfig).build();
    Fresco.initialize(context, imagePipelineConfig);
}