Search in sources :

Example 46 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project SherlockAdapter by EvilBT.

the class FrescoUtil method setWrapImage.

public static void setWrapImage(@NonNull final SimpleDraweeView view, @NonNull final String path) {
    Preconditions.checkNotNull(view);
    Preconditions.checkNotNull(path);
    ControllerListener<ImageInfo> controllerListener = new BaseControllerListener<ImageInfo>() {

        @Override
        public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
            if (imageInfo == null) {
                return;
            }
            final float width = imageInfo.getWidth();
            final float height = imageInfo.getHeight();
            if (width * height != 0.0f) {
                view.setAspectRatio(width / height);
            }
        }
    };
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(path)).build();
    view.setController(Fresco.newDraweeControllerBuilder().setImageRequest(request).setOldController(view.getController()).setControllerListener(controllerListener).build());
}
Also used : BaseControllerListener(com.facebook.drawee.controller.BaseControllerListener) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) Animatable(android.graphics.drawable.Animatable) ImageInfo(com.facebook.imagepipeline.image.ImageInfo)

Example 47 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project SherlockAdapter by EvilBT.

the class FrescoUtil method setResizeImage.

public static void setResizeImage(@NonNull final SimpleDraweeView view, @NonNull final String path, @NonNull ResizeOptions resize) {
    Preconditions.checkNotNull(view);
    Preconditions.checkNotNull(path);
    Preconditions.checkNotNull(resize);
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(path)).setResizeOptions(resize).build();
    view.setController(Fresco.newDraweeControllerBuilder().setImageRequest(request).setOldController(view.getController()).setAutoPlayAnimations(true).build());
}
Also used : ImageRequest(com.facebook.imagepipeline.request.ImageRequest)

Example 48 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest 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 49 with ImageRequest

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

the class MediaVariationsFallbackProducer method produceResults.

public void produceResults(final Consumer<EncodedImage> consumer, final ProducerContext producerContext) {
    final ImageRequest imageRequest = producerContext.getImageRequest();
    final ResizeOptions resizeOptions = imageRequest.getResizeOptions();
    final MediaVariations mediaVariations = imageRequest.getMediaVariations();
    if (!imageRequest.isDiskCacheEnabled() || resizeOptions == null || resizeOptions.height <= 0 || resizeOptions.width <= 0) {
        startInputProducerWithExistingConsumer(consumer, producerContext);
        return;
    }
    final String mediaId;
    @MediaVariations.Source final String source;
    if (mediaVariations == null) {
        if (mMediaIdExtractor == null) {
            mediaId = null;
            source = null;
        } else {
            mediaId = mMediaIdExtractor.getMediaIdFrom(imageRequest.getSourceUri());
            source = MediaVariations.SOURCE_ID_EXTRACTOR;
        }
    } else {
        mediaId = mediaVariations.getMediaId();
        source = MediaVariations.SOURCE_INDEX_DB;
    }
    if (mediaVariations == null && mediaId == null) {
        startInputProducerWithExistingConsumer(consumer, producerContext);
        return;
    }
    producerContext.getListener().onProducerStart(producerContext.getId(), PRODUCER_NAME);
    final AtomicBoolean isCancelled = new AtomicBoolean(false);
    if (mediaVariations != null && mediaVariations.getVariantsCount() > 0) {
        chooseFromVariants(consumer, producerContext, imageRequest, mediaVariations, resizeOptions, isCancelled);
    } else {
        MediaVariations.Builder mediaVariationsBuilder = MediaVariations.newBuilderForMediaId(mediaId).setForceRequestForSpecifiedUri(mediaVariations != null && mediaVariations.shouldForceRequestForSpecifiedUri()).setSource(source);
        Task<MediaVariations> indexedMediaVariationsTask = mMediaVariationsIndex.getCachedVariants(mediaId, mediaVariationsBuilder);
        indexedMediaVariationsTask.continueWith(new Continuation<MediaVariations, Object>() {

            @Override
            public Object then(Task<MediaVariations> task) throws Exception {
                if (task.isCancelled() || task.isFaulted()) {
                    return task;
                } else {
                    try {
                        if (task.getResult() == null) {
                            startInputProducerWithWrappedConsumer(consumer, producerContext, mediaId);
                            return null;
                        } else {
                            return chooseFromVariants(consumer, producerContext, imageRequest, task.getResult(), resizeOptions, isCancelled);
                        }
                    } catch (Exception e) {
                        return null;
                    }
                }
            }
        });
    }
    subscribeTaskForRequestCancellation(isCancelled, producerContext);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) CancellationException(java.util.concurrent.CancellationException) MediaVariations(com.facebook.imagepipeline.request.MediaVariations)

Example 50 with ImageRequest

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

the class MediaVariationsFallbackProducer method attemptCacheReadForVariant.

private Task attemptCacheReadForVariant(final Consumer<EncodedImage> consumer, final ProducerContext producerContext, ImageRequest imageRequest, MediaVariations mediaVariations, List<MediaVariations.Variant> sortedVariants, int index, AtomicBoolean isCancelled) {
    final MediaVariations.Variant variant = sortedVariants.get(index);
    final CacheKey cacheKey = mCacheKeyFactory.getEncodedCacheKey(imageRequest, variant.getUri(), producerContext.getCallerContext());
    final ImageRequest.CacheChoice cacheChoice;
    if (variant.getCacheChoice() == null) {
        cacheChoice = imageRequest.getCacheChoice();
    } else {
        cacheChoice = variant.getCacheChoice();
    }
    final BufferedDiskCache preferredCache = cacheChoice == ImageRequest.CacheChoice.SMALL ? mSmallImageBufferedDiskCache : mDefaultBufferedDiskCache;
    Task<EncodedImage> readTask = preferredCache.get(cacheKey, isCancelled);
    Continuation<EncodedImage, Void> continuation = onFinishDiskReads(consumer, producerContext, imageRequest, mediaVariations, sortedVariants, index, isCancelled);
    return readTask.continueWith(continuation);
}
Also used : BufferedDiskCache(com.facebook.imagepipeline.cache.BufferedDiskCache) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) CacheKey(com.facebook.cache.common.CacheKey) MediaVariations(com.facebook.imagepipeline.request.MediaVariations)

Aggregations

ImageRequest (com.facebook.imagepipeline.request.ImageRequest)100 ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)26 DraweeController (com.facebook.drawee.interfaces.DraweeController)25 CloseableReference (com.facebook.common.references.CloseableReference)24 Uri (android.net.Uri)18 ImagePipeline (com.facebook.imagepipeline.core.ImagePipeline)17 Test (org.junit.Test)14 Bitmap (android.graphics.Bitmap)13 CacheKey (com.facebook.cache.common.CacheKey)12 File (java.io.File)11 DataSource (com.facebook.datasource.DataSource)10 BaseBitmapDataSubscriber (com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber)9 CloseableImage (com.facebook.imagepipeline.image.CloseableImage)8 ImageRequestBuilder (com.facebook.imagepipeline.request.ImageRequestBuilder)8 Animatable (android.graphics.drawable.Animatable)7 PipelineDraweeController (com.facebook.drawee.backends.pipeline.PipelineDraweeController)7 BaseControllerListener (com.facebook.drawee.controller.BaseControllerListener)7 ImageOptions (com.facebook.fresco.vito.options.ImageOptions)7 ImageInfo (com.facebook.imagepipeline.image.ImageInfo)7 EncodedImage (com.facebook.imagepipeline.image.EncodedImage)6