Search in sources :

Example 21 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project fresco by facebook.

the class DiskCacheReadProducer method produceResults.

public void produceResults(final Consumer<EncodedImage> consumer, final ProducerContext producerContext) {
    final ImageRequest imageRequest = producerContext.getImageRequest();
    if (!imageRequest.isDiskCacheEnabled()) {
        maybeStartInputProducer(consumer, producerContext);
        return;
    }
    producerContext.getListener().onProducerStart(producerContext.getId(), PRODUCER_NAME);
    final AtomicBoolean isCancelled = new AtomicBoolean(false);
    Task<EncodedImage> diskLookupTask = mDiskCachePolicy.createAndStartCacheReadTask(imageRequest, producerContext.getCallerContext(), isCancelled);
    Continuation<EncodedImage, Void> continuation = onFinishDiskReads(consumer, producerContext);
    diskLookupTask.continueWith(continuation);
    subscribeTaskForRequestCancellation(isCancelled, producerContext);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 22 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project fresco by facebook.

the class LocalFetchProducer method produceResults.

@Override
public void produceResults(final Consumer<EncodedImage> consumer, final ProducerContext producerContext) {
    final ProducerListener listener = producerContext.getListener();
    final String requestId = producerContext.getId();
    final ImageRequest imageRequest = producerContext.getImageRequest();
    final StatefulProducerRunnable cancellableProducerRunnable = new StatefulProducerRunnable<EncodedImage>(consumer, listener, getProducerName(), requestId) {

        @Override
        protected EncodedImage getResult() throws Exception {
            EncodedImage encodedImage = getEncodedImage(imageRequest);
            if (encodedImage == null) {
                return null;
            }
            encodedImage.parseMetaData();
            return encodedImage;
        }

        @Override
        protected void disposeResult(EncodedImage result) {
            EncodedImage.closeSafely(result);
        }
    };
    producerContext.addCallbacks(new BaseProducerContextCallbacks() {

        @Override
        public void onCancellationRequested() {
            cancellableProducerRunnable.cancel();
        }
    });
    mExecutor.execute(cancellableProducerRunnable);
}
Also used : ImageRequest(com.facebook.imagepipeline.request.ImageRequest) EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 23 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project fresco by facebook.

the class DraweeRotationFragment method setRotationOptions.

private void setRotationOptions(RotationOptions rotationOptions) {
    ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(URI).setRotationOptions(rotationOptions).build();
    mSimpleDraweeView.setController(Fresco.newDraweeControllerBuilder().setImageRequest(imageRequest).build());
}
Also used : ImageRequest(com.facebook.imagepipeline.request.ImageRequest)

Example 24 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project fresco by facebook.

the class ImagePipelineNotificationFragment method createNotification.

private void createNotification() {
    final ImagePipeline imagePipeline = Fresco.getImagePipeline();
    final ImageRequest imageRequest = ImageRequest.fromUri(URI);
    final DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, null);
    dataSource.subscribe(new BaseBitmapDataSubscriber() {

        @Override
        protected void onNewResultImpl(Bitmap bitmap) {
            displayNotification(bitmap);
        }

        @Override
        protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
            showToastText("Failed to fetch image directly: " + dataSource.getFailureCause());
            // In general, failing to fetch the image should not keep us from displaying the
            // notification. We proceed without the bitmap.
            displayNotification(null);
        }
    }, UiThreadImmediateExecutorService.getInstance());
}
Also used : Bitmap(android.graphics.Bitmap) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) CloseableReference(com.facebook.common.references.CloseableReference) ImagePipeline(com.facebook.imagepipeline.core.ImagePipeline) BaseBitmapDataSubscriber(com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber)

Example 25 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project ride-read-android by Ride-Read.

the class ImgLoader method getDiscCacheFile.

public File getDiscCacheFile(String url) {
    ImageRequest imageRequest = ImageRequest.fromUri(Uri.parse(url));
    CacheKey cacheKey = Utils.getAppContext().getImagePipeLineConfig().getCacheKeyFactory().getEncodedCacheKey(imageRequest, null);
    FileBinaryResource fileBinaryResource = (FileBinaryResource) Fresco.getImagePipelineFactory().getMainDiskStorageCache().getResource(cacheKey);
    if (fileBinaryResource == null) {
        return null;
    } else {
        return fileBinaryResource.getFile();
    }
}
Also used : ImageRequest(com.facebook.imagepipeline.request.ImageRequest) CacheKey(com.facebook.cache.common.CacheKey) FileBinaryResource(com.facebook.binaryresource.FileBinaryResource)

Aggregations

ImageRequest (com.facebook.imagepipeline.request.ImageRequest)62 DraweeController (com.facebook.drawee.interfaces.DraweeController)20 ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)17 CloseableReference (com.facebook.common.references.CloseableReference)14 Uri (android.net.Uri)10 File (java.io.File)10 Bitmap (android.graphics.Bitmap)9 CacheKey (com.facebook.cache.common.CacheKey)9 ImagePipeline (com.facebook.imagepipeline.core.ImagePipeline)8 BaseBitmapDataSubscriber (com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber)8 PipelineDraweeController (com.facebook.drawee.backends.pipeline.PipelineDraweeController)7 DataSource (com.facebook.datasource.DataSource)6 EncodedImage (com.facebook.imagepipeline.image.EncodedImage)5 Animatable (android.graphics.drawable.Animatable)4 Nullable (android.support.annotation.Nullable)4 BaseControllerListener (com.facebook.drawee.controller.BaseControllerListener)4 ImageInfo (com.facebook.imagepipeline.image.ImageInfo)4 QualityInfo (com.facebook.imagepipeline.image.QualityInfo)4 FileSystemReference (im.actor.runtime.files.FileSystemReference)4 Test (org.junit.Test)4