Java Code Examples for com.facebook.drawee.backends.pipeline.Fresco#getImagePipeline()

The following examples show how to use com.facebook.drawee.backends.pipeline.Fresco#getImagePipeline() . 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: FrescoImageloadHelper.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
public static void LoadImageFromURLAndCallBack(SimpleDraweeView destImageView , String URL,Context context,BaseBitmapDataSubscriber bbds)
{
    int w = destImageView.getWidth();
    int h  =destImageView.getHeight();
    if(w<1){
        w = destImageView.getLayoutParams().width;
    }
    if(h<1){
        h  =destImageView.getLayoutParams().height;
    }
    ImageRequest imageRequest =
            ImageRequestBuilder.newBuilderWithSource(Uri.parse(URL))
                    .setResizeOptions(new ResizeOptions(w,h))
                    .setProgressiveRenderingEnabled(true)
                    .build();
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);
    dataSource.subscribe(bbds, CallerThreadExecutor.getInstance());
    DraweeController draweeController = Fresco.newDraweeControllerBuilder()
            .setImageRequest(imageRequest)
            .setOldController(destImageView.getController())
            .setAutoPlayAnimations(true)
            .build();
    destImageView.setController(draweeController);
}
 
Example 2
Source File: AMapMarker.java    From react-native-amap with MIT License 6 votes vote down vote up
public void setImage(String uri) {
    if (uri == null) {
        iconBitmapDescriptor = null;
        update();
    } else if (uri.startsWith("http://") || uri.startsWith("https://") ||
            uri.startsWith("file://")) {
        ImageRequest imageRequest = ImageRequestBuilder
                .newBuilderWithSource(Uri.parse(uri))
                .build();

        ImagePipeline imagePipeline = Fresco.getImagePipeline();
        dataSource = imagePipeline.fetchDecodedImage(imageRequest, this);
        DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setImageRequest(imageRequest)
                .setControllerListener(mLogoControllerListener)
                .setOldController(logoHolder.getController())
                .build();
        logoHolder.setController(controller);
    } else {
        iconBitmapDescriptor = getBitmapDescriptorByName(uri);
        update();
    }
}
 
Example 3
Source File: MainActivity.java    From LiuAGeAndroid with MIT License 6 votes vote down vote up
/**
     * 清除缓存
     */
    private void clearCache() {
        // 清理新闻json数据 - 不清理json数据
//        NewsDALManager.shared.clearCache();

        // Fresco清除图片缓存
        ImagePipeline imagePipeline = Fresco.getImagePipeline();
        imagePipeline.clearCaches();

        // 清除缓存目录 - 清除所有缓存目录文件
        FileCacheUtils.clearAllCache(mContext);

        final KProgressHUD hud = ProgressHUD.show(mContext, "正在清理...");
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                hud.dismiss();
                ProgressHUD.showInfo(mContext, "清理缓存完成");
            }
        }, 2000);

    }
 
Example 4
Source File: FrescoImageLoader.java    From ScrollGalleryView with MIT License 5 votes vote down vote up
@Override
public void loadThumbnail(Context context, ImageView thumbnailView, SuccessCallback callback) {
    if (!Fresco.hasBeenInitialized()){
        Fresco.initialize(context);
    }
    ImagePipeline pipeline = Fresco.getImagePipeline();
    DataSubscriber subscriber = getSubscriber(thumbnailView, callback);
    DataSource<CloseableReference<CloseableImage>> dataSource = pipeline.fetchDecodedImage(createImageRequest(thumbnailWidth, thumbnailHeight), context);
    dataSource.subscribe(subscriber, UiThreadImmediateExecutorService.getInstance());
}
 
Example 5
Source File: ImageViewActivity.java    From Fishing with GNU General Public License v3.0 5 votes vote down vote up
@Override
public View instantiateItem(ViewGroup container, int position) {
    View view = LayoutInflater.from(ImageViewActivity.this).inflate(R.layout.item_imagepage, container, false);
    final PhotoView photoView = (PhotoView) view.findViewById(R.id.photoview);
    final View wheel = view.findViewById(R.id.wheel);
    photoView.setOnPhotoTapListener((view1, v, v1) -> finish());

    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(urls.get(position))
            .setResizeOptions(new ResizeOptions(768, 768))
            .build();
    DataSource<CloseableReference<CloseableImage>>
            dataSource = imagePipeline.fetchDecodedImage(request,this);
    DataSubscriber dataSubscriber = new BaseBitmapDataSubscriber() {
        @Override
        protected void onNewResultImpl(Bitmap bitmap) {
              photoView.setImageBitmap(bitmap);
              wheel.setVisibility(View.GONE);
        }

        @Override
        protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> closeableReferenceDataSource) {

        }
    };
    dataSource.subscribe(dataSubscriber, new Executor() {
        @Override
        public void execute(Runnable command) {
            handler.post(command);
        }
    });
    container.addView(view);
    return view;
}
 
Example 6
Source File: FrescoImageloadHelper.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
public static void LoadImageFromURLAndCallBack(SimpleDraweeView destImageView , String URL, Context context, BaseBitmapDataSubscriber bbds
, BasePostprocessor postprocessor)
{
    int w = destImageView.getWidth();
    int h  =destImageView.getHeight();
    if(w<1){
        w = destImageView.getLayoutParams().width;
    }
    if(h<1){
        h  =destImageView.getLayoutParams().height;
    }
    ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(URL))
            .setResizeOptions(new ResizeOptions(w,h))
            .setProgressiveRenderingEnabled(true);
    if(postprocessor!=null){
        builder.setPostprocessor(postprocessor);
    }
    ImageRequest imageRequest =
            builder
                    .build();
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);
    dataSource.subscribe(bbds, CallerThreadExecutor.getInstance());
    DraweeController draweeController = Fresco.newDraweeControllerBuilder()
            .setImageRequest(imageRequest)
            .setOldController(destImageView.getController())
            .setAutoPlayAnimations(true)
            .build();
    destImageView.setController(draweeController);
}
 
Example 7
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 8
Source File: FrescoUtils.java    From FrescoUtlis with Apache License 2.0 5 votes vote down vote up
/**
 * 清除单张图片的磁盘缓存
 * @param url
 */
public static void clearCacheByUrl(String url){
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    Uri uri = Uri.parse(url);
   // imagePipeline.evictFromMemoryCache(uri);
    imagePipeline.evictFromDiskCache(uri);
    //imagePipeline.evictFromCache(uri);//这个包含了从内存移除和从硬盘移除
}
 
Example 9
Source File: OverlayMarker.java    From react-native-baidu-map with MIT License 5 votes vote down vote up
public void setIcon(IconInfo iconInfo) {
    if (iconInfo.getUri() == null || iconInfo.getUri().length() == 0) {
        return;
    }
    if (BITMAP_DESCRIPTOR_MAP.containsKey(iconInfo.getUri())) {
        iconBitmapDescriptor = BITMAP_DESCRIPTOR_MAP.get(iconInfo.getUri());
        return;
    }
    Log.i("download", iconInfo.getUri());
    this.iconInfo = iconInfo;
    String uri = iconInfo.getUri();
    if (uri == null) {
        iconBitmapDescriptor = null;
    } else if (uri.startsWith("http://") || uri.startsWith("https://") ||
            uri.startsWith("file://") || uri.startsWith("asset://")) {
        loadingImage = true;
        ImageRequest imageRequest = ImageRequestBuilder
                .newBuilderWithSource(Uri.parse(uri))
                .build();
        ImagePipeline imagePipeline = Fresco.getImagePipeline();
        dataSource = imagePipeline.fetchDecodedImage(imageRequest, this);
        DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setImageRequest(imageRequest)
                .setControllerListener(imageControllerListener)
                .setOldController(imageHolder.getController())
                .build();
        imageHolder.setController(controller);
    } else {
        iconBitmapDescriptor = getBitmapDescriptorByName(uri);
    }
}
 
Example 10
Source File: FrescoUtil.java    From MyImageUtil with Apache License 2.0 5 votes vote down vote up
/**
 * 清除单张图片的磁盘缓存
 * @param url
 */
public static void clearCacheByUrl(String url){
    url = append(url);
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    Uri uri = Uri.parse(url);
   // imagePipeline.evictFromMemoryCache(uri);
    imagePipeline.evictFromDiskCache(uri);
    //imagePipeline.evictFromCache(uri);//这个包含了从内存移除和从硬盘移除
}
 
Example 11
Source File: FrescoLoader.java    From ImageLoader with Apache License 2.0 5 votes vote down vote up
@Override
public void clearMomoryCache(String url) {
    url = MyUtil.appendUrl(url);
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    Uri uri = Uri.parse(url);
    imagePipeline.evictFromMemoryCache(uri);
}
 
Example 12
Source File: OffLineService.java    From TLint with Apache License 2.0 5 votes vote down vote up
private void cacheImage(String url) {
    if (!isImageDownloaded(Uri.parse(url))) {
        ImagePipeline imagePipeline = Fresco.getImagePipeline();
        ImageRequest request = ImageRequest.fromUri(url);
        imagePipeline.prefetchToDiskCache(request, this);
        offlinePictureLength += request.getSourceFile().length();
        offlinePictureCount++;
    }
}
 
Example 13
Source File: ApplicationActivity.java    From react-native-turbolinks with MIT License 5 votes vote down vote up
private void bitmapFor(Bundle image, Context context, BaseBitmapDataSubscriber baseBitmapDataSubscriber) {
    ImageSource source = new ImageSource(context, image.getString("uri"));
    ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(source.getUri()).build();

    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);

    dataSource.subscribe(baseBitmapDataSubscriber, UiThreadImmediateExecutorService.getInstance());
}
 
Example 14
Source File: FrescoController.java    From base-module with Apache License 2.0 5 votes vote down vote up
/**
 * 只下载图片到磁盘,可设置下载回调
 * @param context
 * @param baseDataSubscriber
 */
public void downloadOnly(Context context, BaseDataSubscriber baseDataSubscriber) {
    ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(mUri)
            .setProgressiveRenderingEnabled(true)
            .build();
    ImagePipeline imagePipeline = Fresco.getImagePipeline();

    DataSource<Void> dataSource = imagePipeline.prefetchToDiskCache(imageRequest, context.getApplicationContext());
    if(baseDataSubscriber != null) {
        dataSource.subscribe(baseDataSubscriber, UiThreadImmediateExecutorService.getInstance());
    }
}
 
Example 15
Source File: FrescoController.java    From base-module with Apache License 2.0 5 votes vote down vote up
/**
 * 加载图片获取 Bitmap 对象
 * @param subscriber
 */
public void intoTarget(BaseBitmapDataSubscriber subscriber) {
    ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(mUri)
            .setProgressiveRenderingEnabled(true);

    if (mWidth > 0 && mHeight > 0) {
        builder.setResizeOptions(new ResizeOptions(mWidth, mHeight));
    }

    ImageRequest imageRequest = builder.build();
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, this);
    dataSource.subscribe(subscriber, UiThreadImmediateExecutorService.getInstance());
}
 
Example 16
Source File: FrescoImageProvider.java    From HybridCache with MIT License 5 votes vote down vote up
private DataSource<Void> prefetchToDiskCache(String url, ImageRequestListener listener) {
    if (!TextUtils.isEmpty(url)) {
        ImagePipeline imagePipeline = Fresco.getImagePipeline();
        ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url));
        if (listener != null) {
            builder.setRequestListener(new ImageRequestWrapper(listener));
        }
        return imagePipeline.prefetchToDiskCache(builder.build(), null);
    }
    if (listener != null) {
        listener.onFailed(null, new Exception("url is empty"));
    }

    return null;
}
 
Example 17
Source File: FrescoImageLoader.java    From FimiX8-RE with MIT License 4 votes vote down vote up
public static void clearCache() {
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    imagePipeline.clearMemoryCaches();
    imagePipeline.clearDiskCaches();
}
 
Example 18
Source File: FrescoUtils.java    From materialup with Apache License 2.0 4 votes vote down vote up
private static final void setSubscribe(Context context, ImageRequest request, BaseDataSubscriber subscriber) {
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    DataSource<CloseableReference<CloseableImage>> dataSource =
            imagePipeline.fetchDecodedImage(request, context);
    dataSource.subscribe(subscriber, CallerThreadExecutor.getInstance());
}
 
Example 19
Source File: BigImageLoader.java    From ImageLoader with Apache License 2.0 4 votes vote down vote up
@Override
public void prefetch(Uri uri) {
    ImagePipeline pipeline = Fresco.getImagePipeline();
    pipeline.prefetchToDiskCache(ImageRequest.fromUri(uri),
            false); // we don't need context, but avoid null
}
 
Example 20
Source File: BigImageLoader.java    From ImageLoader with Apache License 2.0 4 votes vote down vote up
@Override
public void loadImage(final Uri uri) {
    ImageRequest request = ImageRequest.fromUri(uri);

    final File localCache = getCacheFile(request);
    if (localCache!=null && localCache.exists()) {
        Log.e("onResourceReady","cache onResourceReady  --"+ localCache.getAbsolutePath());
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if(localCache.length() >100){

                    EventBus.getDefault().postSticky(new CacheHitEvent(localCache,uri.toString()));
                }else {
                    EventBus.getDefault().postSticky(new ErrorEvent(uri.toString()));
                }
            }
        },300);


    } else {
        //EventBus.getDefault().post(new StartEvent(uri.toString()));
        //EventBus.getDefault().post(new ProgressEvent(0,false,uri.toString()));
       // callback.onStart(); // ensure `onStart` is called before `onProgress` and `onFinish`
       // callback.onProgress(0); // show 0 progress immediately

        ImagePipeline pipeline = Fresco.getImagePipeline();
        DataSource<CloseableReference<PooledByteBuffer>> source
                = pipeline.fetchEncodedImage(request, true);
        source.subscribe(new ImageDownloadSubscriber(mAppContext) {
            @Override
            protected void onProgress(int progress) {
                //callback.onProgress(progress);
                EventBus.getDefault().post(new ProgressEvent(progress,progress==100,uri.toString()));
            }

            @Override
            protected void onSuccess(File image) {
                //EventBus.getDefault().post(new ProgressEvent(100,true,uri.toString()));
                Log.e("onResourceReady","download onResourceReady  --"+ image.getAbsolutePath());
                if(image.length() >100){
                    EventBus.getDefault().postSticky(new CacheHitEvent(image,uri.toString()));
                }else {
                    EventBus.getDefault().postSticky(new ErrorEvent(uri.toString()));
                }
                //callback.onFinish();
                //callback.onCacheMiss(image);

            }

            @Override
            protected void onFail(Throwable t) {
                // TODO: 12/11/2016 fail
                t.printStackTrace();
                EventBus.getDefault().post(new ErrorEvent(uri.toString()));
            }
        }, mExecutorSupplier.forBackgroundTasks());
    }
}