com.facebook.imagepipeline.core.ImagePipelineFactory Java Examples

The following examples show how to use com.facebook.imagepipeline.core.ImagePipelineFactory. 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: ImagePreviewPresenter.java    From TLint with Apache License 2.0 6 votes vote down vote up
private InputStream getImageBytesFromLocal(Uri loadUri) {
    if (loadUri == null) {
        return null;
    }
    CacheKey cacheKey = DefaultCacheKeyFactory.getInstance()
            .getEncodedCacheKey(ImageRequest.fromUri(loadUri), null);
    try {
        if (ImagePipelineFactory.getInstance().getMainFileCache().hasKey(cacheKey)) {
            return ImagePipelineFactory.getInstance()
                    .getMainFileCache()
                    .getResource(cacheKey)
                    .openStream();
        }
        if (ImagePipelineFactory.getInstance().getSmallImageFileCache().hasKey(cacheKey)) {
            return ImagePipelineFactory.getInstance()
                    .getSmallImageFileCache()
                    .getResource(cacheKey)
                    .openStream();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #2
Source File: ImagePreviewFragment.java    From redgram-for-reddit with GNU General Public License v3.0 6 votes vote down vote up
private void displayCachedImageFromBackgroundThread(ImageRequest request){
    CacheKey cacheKey = DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(ImageRequest.fromUri(request.getSourceUri()));

    if(cacheKey != null){
        BinaryResource resource = ImagePipelineFactory.getInstance().getMainDiskStorageCache().getResource(cacheKey);
        if(resource != null){
            File localFile = ((FileBinaryResource) resource).getFile();
            if(localFile != null){
                Handler handler = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        imagePreview.setImage(ImageSource.uri(localFile.getPath()));
                    }
                });
            }
        }

    }
}
 
Example #3
Source File: FrescoLoader.java    From ImageLoader with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isCached(String url) {
   /* if(TextUtils.isEmpty(url)){
        return false;
    }
    url = MyUtil.appendUrl(url);
    DataSource<Boolean> isIn = Fresco.getImagePipeline().isInDiskCache(Uri.parse(url));
    if(isIn!=null){
        try {
            return isIn.getResult();
        }catch (Exception e){
            return false;
        }
    }else {
        return false;
    }*/


    ImageRequest imageRequest = ImageRequest.fromUri(url);
    CacheKey cacheKey = DefaultCacheKeyFactory.getInstance()
            .getEncodedCacheKey(imageRequest,null);
    return ImagePipelineFactory.getInstance()
            .getMainFileCache().hasKey(cacheKey);
}
 
Example #4
Source File: LinksContainerView.java    From redgram-for-reddit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void viewImageMedia(int position, boolean loaded) {
    if(loaded){
        PostItem item = getItem(position);
        CacheKey cacheKey = DefaultCacheKeyFactory.getInstance()
                .getEncodedCacheKey(ImageRequest
                        .fromUri(Uri.parse(item.getUrl())));
        if(cacheKey != null){
            BinaryResource resource = ImagePipelineFactory.getInstance().getMainDiskStorageCache().getResource(cacheKey);

            File localFile;
            if(resource != null){
                localFile = ((FileBinaryResource) resource).getFile();

                Bundle bundle = new Bundle();

                bundle.putString(getResources().getString(R.string.local_cache_key), localFile.getPath());

                bundle.putString(getResources().getString(R.string.main_data_key), gson.toJson(item));

                ((SlidingUpPanelActivity)context).setPanelView(Fragments.IMAGE_PREVIEW, bundle);
            }
        }
    }
}
 
Example #5
Source File: DefaultFrescoVitoProvider.java    From fresco with MIT License 6 votes vote down vote up
public DefaultFrescoVitoProvider(
    FrescoContext context,
    FrescoVitoConfig config,
    @Nullable Supplier<Boolean> debugOverlayEnabledSupplier) {
  if (!ImagePipelineFactory.hasBeenInitialized()) {
    throw new RuntimeException(
        "Fresco must be initialized before DefaultFrescoVitoProvider can be used!");
  }
  mFrescoVitoConfig = config;
  mFrescoVitoPrefetcher = context.getPrefetcher();
  mVitoImagePipeline =
      new VitoImagePipelineImpl(context.getImagePipeline(), context.getImagePipelineUtils());
  mFrescoController =
      new FrescoController2Impl(
          mFrescoVitoConfig,
          context.getHierarcher(),
          context.getLightweightBackgroundThreadExecutor(),
          context.getUiThreadExecutorService(),
          mVitoImagePipeline,
          null,
          debugOverlayEnabledSupplier == null
              ? new NoOpDebugOverlayFactory2()
              : new DefaultDebugOverlayFactory2(debugOverlayEnabledSupplier));
}
 
Example #6
Source File: ShareDribbbleImageTask.java    From materialup with Apache License 2.0 6 votes vote down vote up
@Override
    protected File doInBackground(Void... params) {
        final String url = shot.getTeaserUrl();
        try {
            ImageRequest imageRequest = ImageRequest.fromUri(url);
            CacheKey cacheKey = DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(imageRequest);
//            ImagePipeline imagePipeline = Fresco.getImagePipeline();
//            imagePipeline.prefetchToDiskCache(imageRequest,activity);
            BinaryResource resource = ImagePipelineFactory.getInstance().getMainDiskStorageCache().getResource(cacheKey);
            File file = ((FileBinaryResource) resource).getFile();

            String fileName = url;
            fileName = fileName.substring(fileName.lastIndexOf('/') + 1);
            File renamed = new File(file.getParent(), fileName);
            if (!renamed.exists()) {
                FileUtil.copy(file, renamed);
            }
            return renamed;
        } catch (Exception ex) {
            Log.w("SHARE", "Sharing " + url + " failed", ex);
            return null;
        }
    }
 
Example #7
Source File: BaseFrescoStethoPlugin.java    From fresco with MIT License 5 votes vote down vote up
protected void initialize(ImagePipelineFactory factory) {
  mBitmapMemoryCacheInspector =
      new CountingMemoryCacheInspector<>(factory.getBitmapCountingMemoryCache());
  mMainFileCache = factory.getMainFileCache();
  mSmallFileCache = factory.getSmallImageFileCache();
  mImagePipeline = factory.getImagePipeline();
  mInitialized = true;
}
 
Example #8
Source File: OffLineService.java    From TLint with Apache License 2.0 5 votes vote down vote up
private boolean isImageDownloaded(Uri loadUri) {
    if (loadUri == null) {
        return false;
    }
    CacheKey cacheKey = DefaultCacheKeyFactory.getInstance()
            .getEncodedCacheKey(ImageRequest.fromUri(loadUri), null);
    return ImagePipelineFactory.getInstance().getMainFileCache().hasKey(cacheKey)
            || ImagePipelineFactory.getInstance().getSmallImageFileCache().hasKey(cacheKey);
}
 
Example #9
Source File: DraweeSpan.java    From drawee-text-view with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
protected DataSource<CloseableReference<CloseableImage>> fetchDecodedImage() {
    ImagePipelineFactory factory;
    try {
        factory = ImagePipelineFactory.getInstance();
    } catch (NullPointerException e) {
        // Image pipeline is not initialized
        ImagePipelineFactory.initialize(mAttachedView.getContext().getApplicationContext());
        factory = ImagePipelineFactory.getInstance();
    }
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(getImageUri()))
            .setImageDecodeOptions(ImageDecodeOptions.newBuilder().setDecodePreviewFrame(true).build())
            .build();
    return factory.getImagePipeline().fetchDecodedImage(request, null);
}
 
Example #10
Source File: PipelineDraweeControllerBuilderSupplier.java    From fresco with MIT License 5 votes vote down vote up
public PipelineDraweeControllerBuilderSupplier(
    Context context,
    ImagePipelineFactory imagePipelineFactory,
    Set<ControllerListener> boundControllerListeners,
    Set<ControllerListener2> boundControllerListeners2,
    @Nullable DraweeConfig draweeConfig) {
  mContext = context;
  mImagePipeline = imagePipelineFactory.getImagePipeline();

  if (draweeConfig != null && draweeConfig.getPipelineDraweeControllerFactory() != null) {
    mPipelineDraweeControllerFactory = draweeConfig.getPipelineDraweeControllerFactory();
  } else {
    mPipelineDraweeControllerFactory = new PipelineDraweeControllerFactory();
  }
  mPipelineDraweeControllerFactory.init(
      context.getResources(),
      DeferredReleaser.getInstance(),
      imagePipelineFactory.getAnimatedDrawableFactory(context),
      UiThreadImmediateExecutorService.getInstance(),
      mImagePipeline.getBitmapMemoryCache(),
      draweeConfig != null ? draweeConfig.getCustomDrawableFactories() : null,
      draweeConfig != null ? draweeConfig.getDebugOverlayEnabledSupplier() : null);
  mBoundControllerListeners = boundControllerListeners;
  mBoundControllerListeners2 = boundControllerListeners2;

  mDefaultImagePerfDataListener =
      draweeConfig != null ? draweeConfig.getImagePerfDataListener() : null;
}
 
Example #11
Source File: QIMSdk.java    From imsdk-android with MIT License 5 votes vote down vote up
/**
 * 清除缓存
 */
public void clearMemoryCache() {
    InternDatas.cache.evictAll();
    MemoryCache.emptyCache();
    ImagePipelineFactory.getInstance().getImagePipeline().clearMemoryCaches();
    Glide.get(CommonConfig.globalContext).clearMemory();
}
 
Example #12
Source File: PipelineDraweeControllerBuilderSupplier.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
public PipelineDraweeControllerBuilderSupplier(
    Context context,
    ImagePipelineFactory imagePipelineFactory,
    Set<ControllerListener> boundControllerListeners) {
  mContext = context;
  mImagePipeline = imagePipelineFactory.getImagePipeline();
  mPipelineDraweeControllerFactory = new PipelineDraweeControllerFactory(
      context.getResources(),
      DeferredReleaser.getInstance(),
      imagePipelineFactory.getAnimatedDrawableFactory(),
      UiThreadImmediateExecutorService.getInstance());
  mBoundControllerListeners = boundControllerListeners;
}
 
Example #13
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 #14
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 #15
Source File: FrescoHelper.java    From FrescoUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 本地缓存文件
 */
public static File getCache(Context context, Uri uri) {
    if (!isCached(context, uri))
        return null;
    ImageRequest imageRequest = ImageRequest.fromUri(uri);
    CacheKey cacheKey = DefaultCacheKeyFactory.getInstance()
            .getEncodedCacheKey(imageRequest, context);
    BinaryResource resource = ImagePipelineFactory.getInstance()
            .getMainFileCache().getResource(cacheKey);
    File file = ((FileBinaryResource) resource).getFile();
    return file;
}
 
Example #16
Source File: FrescoHelper.java    From FrescoUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 图片是否已经存在了
 */
public static boolean isCached(Context context, Uri uri) {
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    DataSource<Boolean> dataSource = imagePipeline.isInDiskCache(uri);
    if (dataSource == null) {
        return false;
    }
    ImageRequest imageRequest = ImageRequest.fromUri(uri);
    CacheKey cacheKey = DefaultCacheKeyFactory.getInstance()
            .getEncodedCacheKey(imageRequest, context);
    BinaryResource resource = ImagePipelineFactory.getInstance()
            .getMainFileCache().getResource(cacheKey);
    return resource != null && dataSource.getResult() != null && dataSource.getResult();
}
 
Example #17
Source File: FrescoUtils.java    From FrescoUtlis with Apache License 2.0 5 votes vote down vote up
/**
 *this method is return very fast, you can use it in UI thread.
 * @param url
 * @return 该url对应的图片是否已经缓存到本地
 */
public static boolean isCached(String url) {

  // return Fresco.getImagePipeline().isInDiskCache(Uri.parse(url));

    ImageRequest imageRequest = ImageRequest.fromUri(url);
    CacheKey cacheKey = DefaultCacheKeyFactory.getInstance()
            .getEncodedCacheKey(imageRequest);
    return ImagePipelineFactory.getInstance()
            .getMainFileCache().hasKey(cacheKey);
}
 
Example #18
Source File: PhotoActivity.java    From materialup with Apache License 2.0 5 votes vote down vote up
private void save() {
        try {
            ImageRequest imageRequest = ImageRequest.fromUri(mUrl);
            CacheKey cacheKey = DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(imageRequest);
            BinaryResource resource = ImagePipelineFactory.getInstance().getMainDiskStorageCache().getResource(cacheKey);
            File file = ((FileBinaryResource) resource).getFile();

            String fileName = mUrl;
            fileName = fileName.substring(fileName.lastIndexOf('/') + 1);
            if (mTitle != null) {
                fileName = mTitle + fileName;
            }
            File pic = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
            File dir = new File(pic, "material/");
            if (!dir.exists()) {
                dir.mkdirs();
            }
            File renamed = new File(dir, fileName);
            if (!renamed.exists()) {
                renamed.createNewFile();
                FileUtil.copy(file, renamed);
            }
            UI.showToast(this, getString(R.string.image_saved_to, renamed.getAbsolutePath()));
//            Snackbar.make(mDraweeView,R.string.image_is_saved, Snackbar.LENGTH_LONG);
        } catch (Exception ex) {
            Log.w("SHARE", "Sharing " + mUrl + " failed", ex);
        }
    }
 
Example #19
Source File: FrescoContextImpl.java    From fresco with MIT License 5 votes vote down vote up
@Override
public ImagePipelineFactory getImagePipelineFactory() {
  if (mImagePipelineFactory == null) {
    mImagePipelineFactory = ImagePipelineFactory.getInstance();
  }
  return mImagePipelineFactory;
}
 
Example #20
Source File: FrescoUtil.java    From MyImageUtil with Apache License 2.0 5 votes vote down vote up
/**
 *this method is return very fast, you can use it in UI thread.
 * @param url
 * @return 该url对应的图片是否已经缓存到本地
 */
public static boolean isCached(String url) {
    url = append(url);
  // return Fresco.getImagePipeline().isInDiskCache(Uri.parse(url));

    ImageRequest imageRequest = ImageRequest.fromUri(url);
    CacheKey cacheKey = DefaultCacheKeyFactory.getInstance()
            .getEncodedCacheKey(imageRequest,null);
    return ImagePipelineFactory.getInstance()
            .getMainFileCache().hasKey(cacheKey);
}
 
Example #21
Source File: RegResult.java    From Android-HTTPS-based-on-MVVM with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ActivityRegResultBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_reg_result);
    ImagePipelineFactory.initialize(this);
    binding.setViewModel(new ResultViewModel(this, (UserBean) getIntent().getSerializableExtra("user")));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
 
Example #22
Source File: BigImageLoader.java    From ImageLoader with Apache License 2.0 5 votes vote down vote up
private File getCacheFile(final ImageRequest request) {
    FileCache mainFileCache = ImagePipelineFactory
            .getInstance()
            .getMainFileCache();
    final CacheKey cacheKey = DefaultCacheKeyFactory
            .getInstance()
            .getEncodedCacheKey(request, false); // we don't need context, but avoid null
    File cacheFile = request.getSourceFile();
    // http://crashes.to/s/ee10638fb31
    if (mainFileCache.hasKey(cacheKey) && mainFileCache.getResource(cacheKey) != null) {
        cacheFile = ((FileBinaryResource) mainFileCache.getResource(cacheKey)).getFile();
    }
    return cacheFile;
}
 
Example #23
Source File: Fresco.java    From fresco with MIT License 4 votes vote down vote up
/** Shuts Fresco down. */
public static void shutDown() {
  sDraweeControllerBuilderSupplier = null;
  SimpleDraweeView.shutDown();
  ImagePipelineFactory.shutDown();
}
 
Example #24
Source File: Fresco.java    From fresco with MIT License 4 votes vote down vote up
public static ImagePipelineFactory getImagePipelineFactory() {
  return ImagePipelineFactory.getInstance();
}
 
Example #25
Source File: FrescoContextImpl.java    From fresco with MIT License 4 votes vote down vote up
@Override
public void setImagePipelineFactory(@Nullable ImagePipelineFactory imagePipelineFactory) {
  mImagePipelineFactory = imagePipelineFactory;
}
 
Example #26
Source File: BaseFrescoStethoPlugin.java    From fresco with MIT License 4 votes vote down vote up
protected BaseFrescoStethoPlugin(ImagePipelineFactory factory) {
  initialize(factory);
}
 
Example #27
Source File: Fresco.java    From FanXin-based-HuanXin with GNU General Public License v2.0 4 votes vote down vote up
public static ImagePipelineFactory getImagePipelineFactory() {
  return ImagePipelineFactory.getInstance();
}
 
Example #28
Source File: PipelineDraweeControllerBuilderSupplier.java    From fresco with MIT License 4 votes vote down vote up
public PipelineDraweeControllerBuilderSupplier(
    Context context,
    ImagePipelineFactory imagePipelineFactory,
    @Nullable DraweeConfig draweeConfig) {
  this(context, imagePipelineFactory, null, null, draweeConfig);
}
 
Example #29
Source File: PipelineDraweeControllerBuilderSupplier.java    From fresco with MIT License 4 votes vote down vote up
public PipelineDraweeControllerBuilderSupplier(
    Context context, @Nullable DraweeConfig draweeConfig) {
  this(context, ImagePipelineFactory.getInstance(), draweeConfig);
}
 
Example #30
Source File: Fresco.java    From FanXin-based-HuanXin with GNU General Public License v2.0 4 votes vote down vote up
/** Shuts Fresco down. */
public static void shutDown() {
  sDraweeControllerBuilderSupplier = null;
  SimpleDraweeView.shutDown();
  ImagePipelineFactory.shutDown();
}