com.facebook.imagepipeline.core.ImagePipeline Java Examples

The following examples show how to use com.facebook.imagepipeline.core.ImagePipeline. 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: ImageLoaderModule.java    From react-native-GPay with MIT License 7 votes vote down vote up
@ReactMethod
public void queryCache(final ReadableArray uris, final Promise promise) {
  // perform cache interrogation in async task as disk cache checks are expensive
  new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) {
    @Override
    protected void doInBackgroundGuarded(Void... params) {
      WritableMap result = Arguments.createMap();
      ImagePipeline imagePipeline = Fresco.getImagePipeline();
      for (int i = 0; i < uris.size(); i++) {
        String uriString = uris.getString(i);
        final Uri uri = Uri.parse(uriString);
        if (imagePipeline.isInBitmapMemoryCache(uri)) {
          result.putString(uriString, "memory");
        } else if (imagePipeline.isInDiskCacheSync(uri)) {
          result.putString(uriString, "disk");
        }
      }
      promise.resolve(result);
    }
  }.executeOnExecutor(GuardedAsyncTask.THREAD_POOL_EXECUTOR);
}
 
Example #2
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 #3
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 #4
Source File: FrescoImageloadHelper.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
public static void LoadImageFromURIAndCallBack(SimpleDraweeView destImageView , Uri uri,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)
                    .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 #5
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 #6
Source File: ProfileFragment.java    From BaoKanAndroid 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, "清理缓存完成");
                cacheTextView.setText(FileCacheUtils.getTotalCacheSize(mContext));
            }
        }, 2000);

    }
 
Example #7
Source File: ImagePipelineMultiUriHelper.java    From fresco with MIT License 6 votes vote down vote up
private static Supplier<DataSource<CloseableReference<CloseableImage>>>
    getImageRequestDataSourceSupplier(
        final ImagePipeline imagePipeline,
        final ImageRequest imageRequest,
        final Object callerContext,
        final ImageRequest.RequestLevel requestLevel,
        final RequestListener requestListener,
        final @Nullable String uiComponentId) {
  return new Supplier<DataSource<CloseableReference<CloseableImage>>>() {
    @Override
    public DataSource<CloseableReference<CloseableImage>> get() {
      return getImageRequestDataSource(
          imagePipeline, imageRequest, callerContext, requestListener, uiComponentId);
    }
  };
}
 
Example #8
Source File: FrescoVitoPrefetcherImpl.java    From fresco with MIT License 6 votes vote down vote up
@Nullable
public DataSource<Void> prefetch(
    final PrefetchTarget prefetchTarget,
    final VitoImageRequest imageRequest,
    @Nullable final Object callerContext) {
  final ImageRequest finalImageRequest = imageRequest.finalImageRequest;
  if (finalImageRequest == null) {
    return null;
  }
  mFrescoContext.verifyCallerContext(callerContext);
  final ImagePipeline pipeline = mFrescoContext.getImagePipeline();
  switch (prefetchTarget) {
    case MEMORY_DECODED:
      return pipeline.prefetchToBitmapCache(finalImageRequest, callerContext);
    case MEMORY_ENCODED:
      return pipeline.prefetchToEncodedCache(finalImageRequest, callerContext);
    case DISK:
      return pipeline.prefetchToDiskCache(finalImageRequest, callerContext);
  }
  return DataSources.immediateFailedDataSource(
      new CancellationException("Prefetching is not enabled"));
}
 
Example #9
Source File: FirstAvailableImageSource.java    From fresco with MIT License 5 votes vote down vote up
@Override
public Supplier<DataSource<CloseableReference<CloseableImage>>> createDataSourceSupplier(
    final ImagePipeline imagePipeline,
    final ImagePipelineUtils imagePipelineUtils,
    final ImageOptions imageOptions,
    final @Nullable Object callerContext,
    final @Nullable RequestListener requestListener,
    final String uiComponentId) {
  final List<Supplier<DataSource<CloseableReference<CloseableImage>>>> suppliers =
      new ArrayList<>(mFirstAvailableImageSources.length);
  for (ImageSource source : mFirstAvailableImageSources) {
    if (source instanceof VitoImageSource) {
      suppliers.add(
          ((VitoImageSource) source)
              .createDataSourceSupplier(
                  imagePipeline,
                  imagePipelineUtils,
                  imageOptions,
                  callerContext,
                  requestListener,
                  uiComponentId));
    } else {
      throw new IllegalArgumentException(
          "FirstAvailableImageSource must be VitoImageSource: " + source);
    }
  }
  return FirstAvailableDataSourceSupplier.create(suppliers);
}
 
Example #10
Source File: SingleImageSource.java    From fresco with MIT License 5 votes vote down vote up
@Override
public Supplier<DataSource<CloseableReference<CloseableImage>>> createDataSourceSupplier(
    final ImagePipeline imagePipeline,
    final ImagePipelineUtils imagePipelineUtils,
    final ImageOptions imageOptions,
    final @Nullable Object callerContext,
    final @Nullable RequestListener requestListener,
    final String uiComponentId) {
  return new Supplier<DataSource<CloseableReference<CloseableImage>>>() {
    @Override
    public DataSource<CloseableReference<CloseableImage>> get() {
      final ImageRequest imageRequest =
          maybeExtractFinalImageRequest(imagePipelineUtils, imageOptions);
      if (imageRequest != null) {
        return imagePipeline.fetchDecodedImage(
            imageRequest,
            callerContext,
            ImageRequest.RequestLevel.FULL_FETCH,
            requestListener, // TODO: Check if this is correct !!
            uiComponentId);
      } else {
        return DataSources.immediateFailedDataSource(
            new NullPointerException(
                "Could not extract image request from: " + SingleImageSource.this));
      }
    }
  };
}
 
Example #11
Source File: ImagePipelineMultiUriHelper.java    From fresco with MIT License 5 votes vote down vote up
private static Supplier<DataSource<CloseableReference<CloseableImage>>>
    getImageRequestDataSourceSupplier(
        final ImagePipeline imagePipeline,
        final ImageRequest imageRequest,
        final Object callerContext,
        final RequestListener requestListener,
        final @Nullable String uiComponentId) {
  return getImageRequestDataSourceSupplier(
      imagePipeline,
      imageRequest,
      callerContext,
      ImageRequest.RequestLevel.FULL_FETCH,
      requestListener,
      uiComponentId);
}
 
Example #12
Source File: IncreasingQualityImageSource.java    From fresco with MIT License 5 votes vote down vote up
@Override
public Supplier<DataSource<CloseableReference<CloseableImage>>> createDataSourceSupplier(
    final ImagePipeline imagePipeline,
    final ImagePipelineUtils imagePipelineUtils,
    final ImageOptions imageOptions,
    final @Nullable Object callerContext,
    final @Nullable RequestListener requestListener,
    final String uiComponentId) {
  final List<Supplier<DataSource<CloseableReference<CloseableImage>>>> suppliers =
      new ArrayList<>(2);
  suppliers.add(
      mHighResImageSource.createDataSourceSupplier(
          imagePipeline,
          imagePipelineUtils,
          imageOptions,
          callerContext,
          requestListener,
          uiComponentId));
  suppliers.add(
      mLowResImageSource.createDataSourceSupplier(
          imagePipeline,
          imagePipelineUtils,
          imageOptions,
          callerContext,
          requestListener,
          uiComponentId));
  return IncreasingQualityDataSourceSupplier.create(suppliers);
}
 
Example #13
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 #14
Source File: EmptyImageSource.java    From fresco with MIT License 5 votes vote down vote up
@Override
public Supplier<DataSource<CloseableReference<CloseableImage>>> createDataSourceSupplier(
    final ImagePipeline imagePipeline,
    final ImagePipelineUtils imagePipelineUtils,
    final ImageOptions imageOptions,
    final @Nullable Object callerContext,
    final @Nullable RequestListener requestListener,
    final String uiComponentId) {
  return new Supplier<DataSource<CloseableReference<CloseableImage>>>() {
    @Override
    public DataSource<CloseableReference<CloseableImage>> get() {
      return DataSources.immediateFailedDataSource(NO_REQUEST_EXCEPTION);
    }
  };
}
 
Example #15
Source File: VitoImageSource.java    From fresco with MIT License 5 votes vote down vote up
Supplier<DataSource<CloseableReference<CloseableImage>>> createDataSourceSupplier(
final ImagePipeline imagePipeline,
final ImagePipelineUtils imagePipelineUtils,
final ImageOptions imageOptions,
final @Nullable Object callerContext,
final @Nullable RequestListener requestListener,
final String uiComponentId);
 
Example #16
Source File: ImagePipelineMultiUriHelper.java    From fresco with MIT License 5 votes vote down vote up
private static Supplier<DataSource<CloseableReference<CloseableImage>>>
    getFirstAvailableDataSourceSupplier(
        final ImagePipeline imagePipeline,
        final Object callerContext,
        final @Nullable RequestListener requestListener,
        ImageRequest[] imageRequests,
        boolean tryBitmapCacheOnlyFirst,
        final @Nullable String uiComponentId) {
  List<Supplier<DataSource<CloseableReference<CloseableImage>>>> suppliers =
      new ArrayList<>(imageRequests.length * 2);
  if (tryBitmapCacheOnlyFirst) {
    // we first add bitmap-cache-only suppliers, then the full-fetch ones
    for (int i = 0; i < imageRequests.length; i++) {
      suppliers.add(
          getImageRequestDataSourceSupplier(
              imagePipeline,
              imageRequests[i],
              callerContext,
              ImageRequest.RequestLevel.BITMAP_MEMORY_CACHE,
              requestListener,
              uiComponentId));
    }
  }
  for (int i = 0; i < imageRequests.length; i++) {
    suppliers.add(
        getImageRequestDataSourceSupplier(
            imagePipeline, imageRequests[i], callerContext, requestListener, uiComponentId));
  }
  return FirstAvailableDataSourceSupplier.create(suppliers);
}
 
Example #17
Source File: ImagePipelineMultiUriHelper.java    From fresco with MIT License 5 votes vote down vote up
public static DataSource<CloseableReference<CloseableImage>> getImageRequestDataSource(
    ImagePipeline imagePipeline,
    ImageRequest imageRequest,
    Object callerContext,
    @Nullable RequestListener requestListener,
    @Nullable String uiComponentId) {
  return imagePipeline.fetchDecodedImage(
      imageRequest,
      callerContext,
      ImageRequest.RequestLevel.FULL_FETCH,
      requestListener,
      uiComponentId);
}
 
Example #18
Source File: PipelineDraweeControllerBuilder.java    From fresco with MIT License 5 votes vote down vote up
public PipelineDraweeControllerBuilder(
    Context context,
    PipelineDraweeControllerFactory pipelineDraweeControllerFactory,
    ImagePipeline imagePipeline,
    Set<ControllerListener> boundControllerListeners,
    Set<ControllerListener2> boundControllerListeners2) {
  super(context, boundControllerListeners, boundControllerListeners2);
  mImagePipeline = imagePipeline;
  mPipelineDraweeControllerFactory = pipelineDraweeControllerFactory;
}
 
Example #19
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 #20
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 #21
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 #22
Source File: FrescoImageLoader.java    From ScrollGalleryView with MIT License 5 votes vote down vote up
@Override
public void loadMedia(Context context, final ImageView imageView, SuccessCallback callback) {
    if (!Fresco.hasBeenInitialized()) {
        Fresco.initialize(context);
    }
    ImagePipeline pipeline = Fresco.getImagePipeline();
    DataSubscriber subscriber = getSubscriber(imageView, callback);
    DataSource<CloseableReference<CloseableImage>> dataSource = pipeline.fetchDecodedImage(createImageRequest(), context);
    dataSource.subscribe(subscriber, UiThreadImmediateExecutorService.getInstance());
}
 
Example #23
Source File: FrescoControllerImplTest.java    From fresco with MIT License 5 votes vote down vote up
@Before
public void setup() {
  mFrescoContext = mock(FrescoContext.class);
  mImagePipeline = mock(ImagePipeline.class);
  mHierarcher = mock(Hierarcher.class);
  mFrescoState = mock(FrescoState.class);
  mFrescoDrawable = mock(FrescoDrawable.class);
  mResources = mock(Resources.class);
  mImageOptions = mock(ImageOptions.class);
  mOverlayDrawable = mock(Drawable.class);
  mLightweightBackgroundThreadExecutor =
      new Executor() {
        @Override
        public void execute(Runnable command) {
          command.run();
        }
      };

  mFrescoExperiments = new FrescoExperiments();

  when(mFrescoContext.getHierarcher()).thenReturn(mHierarcher);
  when(mFrescoContext.getExperiments()).thenReturn(mFrescoExperiments);
  when(mFrescoContext.getImagePipeline()).thenReturn(mImagePipeline);
  when(mFrescoContext.getLightweightBackgroundThreadExecutor())
      .thenReturn(mLightweightBackgroundThreadExecutor);

  when(mFrescoState.getId()).thenReturn(IMAGE_ID);
  when(mFrescoState.getStringId()).thenReturn(IMAGE_ID_STRING);
  when(mFrescoState.getCallerContext()).thenReturn(CALLER_CONTEXT);
  when(mFrescoState.getFrescoDrawable()).thenReturn(mFrescoDrawable);
  when(mFrescoState.getResources()).thenReturn(mResources);
  when(mFrescoState.getImageOptions()).thenReturn(mImageOptions);
  when(mFrescoState.getOverlayDrawable()).thenReturn(mOverlayDrawable);
  when(mFrescoState.isAttached()).thenReturn(true);

  mFrescoController =
      new FrescoControllerImpl(mFrescoContext, new NoOpDebugOverlayFactory(), false, null);
}
 
Example #24
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 #25
Source File: PipelineDraweeControllerBuilder.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
public PipelineDraweeControllerBuilder(
    Context context,
    PipelineDraweeControllerFactory pipelineDraweeControllerFactory,
    ImagePipeline imagePipeline,
    Set<ControllerListener> boundControllerListeners) {
  super(context, boundControllerListeners);
  mImagePipeline = imagePipeline;
  mPipelineDraweeControllerFactory = pipelineDraweeControllerFactory;
}
 
Example #26
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 #27
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 #28
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 #29
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 #30
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());
    }
}