Search in sources :

Example 26 with CloseableReference

use of com.facebook.common.references.CloseableReference in project apps-android-wikipedia by wikimedia.

the class ImagePipelineBitmapGetter method get.

public void get() {
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(imageUrl)).build();
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(request, WikipediaApp.getInstance());
    dataSource.subscribe(new BitmapDataSubscriber(), UiThreadImmediateExecutorService.getInstance());
}
Also used : BaseBitmapDataSubscriber(com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) CloseableReference(com.facebook.common.references.CloseableReference) ImagePipeline(com.facebook.imagepipeline.core.ImagePipeline)

Example 27 with CloseableReference

use of com.facebook.common.references.CloseableReference in project fresco by facebook.

the class BitmapMemoryCacheProducer method wrapConsumer.

protected Consumer<CloseableReference<CloseableImage>> wrapConsumer(final Consumer<CloseableReference<CloseableImage>> consumer, final CacheKey cacheKey) {
    return new DelegatingConsumer<CloseableReference<CloseableImage>, CloseableReference<CloseableImage>>(consumer) {

        @Override
        public void onNewResultImpl(CloseableReference<CloseableImage> newResult, boolean isLast) {
            // ignore invalid intermediate results and forward the null result if last
            if (newResult == null) {
                if (isLast) {
                    getConsumer().onNewResult(null, true);
                }
                return;
            }
            // stateful results cannot be cached and are just forwarded
            if (newResult.get().isStateful()) {
                getConsumer().onNewResult(newResult, isLast);
                return;
            }
            // forward the already cached result and don't cache the new result.
            if (!isLast) {
                CloseableReference<CloseableImage> currentCachedResult = mMemoryCache.get(cacheKey);
                if (currentCachedResult != null) {
                    try {
                        QualityInfo newInfo = newResult.get().getQualityInfo();
                        QualityInfo cachedInfo = currentCachedResult.get().getQualityInfo();
                        if (cachedInfo.isOfFullQuality() || cachedInfo.getQuality() >= newInfo.getQuality()) {
                            getConsumer().onNewResult(currentCachedResult, false);
                            return;
                        }
                    } finally {
                        CloseableReference.closeSafely(currentCachedResult);
                    }
                }
            }
            // cache and forward the new result
            CloseableReference<CloseableImage> newCachedResult = mMemoryCache.cache(cacheKey, newResult);
            try {
                if (isLast) {
                    getConsumer().onProgressUpdate(1f);
                }
                getConsumer().onNewResult((newCachedResult != null) ? newCachedResult : newResult, isLast);
            } finally {
                CloseableReference.closeSafely(newCachedResult);
            }
        }
    };
}
Also used : CloseableReference(com.facebook.common.references.CloseableReference) CloseableImage(com.facebook.imagepipeline.image.CloseableImage) QualityInfo(com.facebook.imagepipeline.image.QualityInfo)

Example 28 with CloseableReference

use of com.facebook.common.references.CloseableReference in project lzc_app_lib by httplzc.

the class BigImgDataRequestHelper method getHolderData.

// 获取holder 的catch
private void getHolderData(final WrapperUri wrapperUri) {
    final Uri holderUri = wrapperUri.getLowUri();
    if (holderUri == null)
        return;
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(holderUri).setResizeOptions(new ResizeOptions(ScreenData.widthPX / 3, ScreenData.heightPX / 3)).build();
    DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(request, "");
    dataSource.subscribe(new BaseDataSubscriber<CloseableReference<CloseableImage>>() {

        @Override
        protected void onNewResultImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
            if (!dataSource.isFinished()) {
                return;
            }
            CloseableReference<CloseableImage> ref = dataSource.getResult();
            if (ref != null && ref.isValid()) {
                try {
                    if (data.get(wrapperUri.getUri()) == null) {
                        holderData.put(holderUri, ref.clone());
                        if (imgDataLoadCompleteListener != null)
                            imgDataLoadCompleteListener.onHolderDataLoadComplete(wrapperUri);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    CloseableReference.closeSafely(ref);
                }
            }
        }

        @Override
        protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
        }
    }, UiThreadImmediateExecutorService.getInstance());
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) CloseableReference(com.facebook.common.references.CloseableReference) ImagePipeline(com.facebook.imagepipeline.core.ImagePipeline) Uri(android.net.Uri) WrapperUri(com.yioks.lzclib.Data.WrapperUri)

Example 29 with CloseableReference

use of com.facebook.common.references.CloseableReference in project remusic by aa112901.

the class RadioDetailActivity method setAlbumart.

private void setAlbumart() {
    albumTitle.setText(albumName);
    albumArtSmall.setImageURI(Uri.parse(albumPath));
    try {
        ImageRequest imageRequest = ImageRequest.fromUri(albumPath);
        CacheKey cacheKey = DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(imageRequest);
        BinaryResource resource = ImagePipelineFactory.getInstance().getMainDiskStorageCache().getResource(cacheKey);
        File file = ((FileBinaryResource) resource).getFile();
        if (file != null) {
            new setBlurredAlbumArt().execute(ImageUtils.getArtworkQuick(file, 300, 300));
            return;
        }
        imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(albumPath)).setProgressiveRenderingEnabled(true).build();
        ImagePipeline imagePipeline = Fresco.getImagePipeline();
        DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, RadioDetailActivity.this);
        dataSource.subscribe(new BaseBitmapDataSubscriber() {

            @Override
            public void onNewResultImpl(@Nullable Bitmap bitmap) {
                // No need to do any cleanup.
                if (bitmap != null) {
                    new setBlurredAlbumArt().execute(bitmap);
                }
                ;
            }

            @Override
            public void onFailureImpl(DataSource dataSource) {
            // No cleanup required here.
            }
        }, CallerThreadExecutor.getInstance());
    // drawable = Drawable.createFromStream( new URL(albumPath).openStream(),"src");
    } catch (Exception e) {
    }
}
Also used : CloseableReference(com.facebook.common.references.CloseableReference) FileBinaryResource(com.facebook.binaryresource.FileBinaryResource) BaseBitmapDataSubscriber(com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber) DataSource(com.facebook.datasource.DataSource) Bitmap(android.graphics.Bitmap) BinaryResource(com.facebook.binaryresource.BinaryResource) FileBinaryResource(com.facebook.binaryresource.FileBinaryResource) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) ImagePipeline(com.facebook.imagepipeline.core.ImagePipeline) File(java.io.File) CacheKey(com.facebook.cache.common.CacheKey)

Example 30 with CloseableReference

use of com.facebook.common.references.CloseableReference in project ride-read-android by Ride-Read.

the class MapFragment method addMoment2Map.

private void addMoment2Map(final MapMoment moment) {
    final LatLng latLng = new LatLng(moment.getLatitude(), moment.getLongitude());
    ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(moment.getPictures().get(0) + QiNiuUtils.CROP_SMALL_100)).setProgressiveRenderingEnabled(true).build();
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, Utils.getAppContext());
    dataSource.subscribe(new BaseBitmapDataSubscriber() {

        @Override
        public void onNewResultImpl(@Nullable Bitmap bitmap) {
            addMomentMarker(latLng, bitmap, moment);
        }

        @Override
        public void onFailureImpl(DataSource dataSource) {
        }
    }, CallerThreadExecutor.getInstance());
}
Also used : Bitmap(android.graphics.Bitmap) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) CloseableReference(com.facebook.common.references.CloseableReference) LatLng(com.amap.api.maps.model.LatLng) ImagePipeline(com.facebook.imagepipeline.core.ImagePipeline) BaseBitmapDataSubscriber(com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber) DataSource(com.facebook.datasource.DataSource)

Aggregations

CloseableReference (com.facebook.common.references.CloseableReference)50 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)24 Bitmap (android.graphics.Bitmap)17 ImagePipeline (com.facebook.imagepipeline.core.ImagePipeline)16 CloseableImage (com.facebook.imagepipeline.image.CloseableImage)14 DataSource (com.facebook.datasource.DataSource)9 BaseBitmapDataSubscriber (com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber)8 Uri (android.net.Uri)7 CloseableStaticBitmap (com.facebook.imagepipeline.image.CloseableStaticBitmap)7 AnimatedImageResult (com.facebook.imagepipeline.animated.base.AnimatedImageResult)5 CloseableAnimatedImage (com.facebook.imagepipeline.image.CloseableAnimatedImage)5 ImageRequestBuilder (com.facebook.imagepipeline.request.ImageRequestBuilder)5 Nullable (javax.annotation.Nullable)5 Test (org.junit.Test)5 SuppressLint (android.annotation.SuppressLint)4 CacheKey (com.facebook.cache.common.CacheKey)3 MemoryTrimType (com.facebook.common.memory.MemoryTrimType)3 ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)3 CloseableBitmap (com.facebook.imagepipeline.image.CloseableBitmap)3 FakeClock (com.facebook.imagepipeline.testing.FakeClock)3