Search in sources :

Example 61 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project lzc_app_lib by httplzc.

the class FunUntil method loadImg.

/**
 * 加载图片
 * @param targetWidth
 * @param targetHeight
 * @param simpleDraweeView
 * @param path
 */
public static void loadImg(int targetWidth, int targetHeight, SimpleDraweeView simpleDraweeView, String path) {
    if (StringManagerUtil.CheckNull(path))
        return;
    Uri uri = null;
    try {
        uri = Uri.parse(path);
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri).setResizeOptions(new ResizeOptions(targetWidth, targetHeight)).setLowestPermittedRequestLevel(ImageRequest.RequestLevel.FULL_FETCH).build();
    AbstractDraweeController controller = Fresco.newDraweeControllerBuilder().setOldController(simpleDraweeView.getController()).setImageRequest(request).build();
    simpleDraweeView.setController(controller);
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) AbstractDraweeController(com.facebook.drawee.controller.AbstractDraweeController) Uri(android.net.Uri)

Example 62 with ImageRequest

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

use of com.facebook.imagepipeline.request.ImageRequest in project remusic by aa112901.

the class QuickControlsFragment method updateNowplayingCard.

public void updateNowplayingCard() {
    mTitle.setText(MusicPlayer.getTrackName());
    mArtist.setText(MusicPlayer.getArtistName());
    ControllerListener controllerListener = new BaseControllerListener<ImageInfo>() {

        @Override
        public void onFinalImageSet(String id, @Nullable ImageInfo imageInfo, @Nullable Animatable anim) {
            if (imageInfo == null) {
                return;
            }
            QualityInfo qualityInfo = imageInfo.getQualityInfo();
            FLog.d("Final image received! " + "Size %d x %d", "Quality level %d, good enough: %s, full quality: %s", imageInfo.getWidth(), imageInfo.getHeight(), qualityInfo.getQuality(), qualityInfo.isOfGoodEnoughQuality(), qualityInfo.isOfFullQuality());
        }

        @Override
        public void onIntermediateImageSet(String id, @Nullable ImageInfo imageInfo) {
        // FLog.d("Intermediate image received");
        }

        @Override
        public void onFailure(String id, Throwable throwable) {
            mAlbumArt.setImageURI(Uri.parse("res:/" + R.drawable.placeholder_disk_210));
        }
    };
    Uri uri = null;
    try {
        uri = Uri.parse(MusicPlayer.getAlbumPath());
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (uri != null) {
        ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri).build();
        DraweeController controller = Fresco.newDraweeControllerBuilder().setOldController(mAlbumArt.getController()).setImageRequest(request).setControllerListener(controllerListener).build();
        mAlbumArt.setController(controller);
    } else {
        mAlbumArt.setImageURI(Uri.parse("content://" + MusicPlayer.getAlbumPath()));
    }
}
Also used : BaseControllerListener(com.facebook.drawee.controller.BaseControllerListener) DraweeController(com.facebook.drawee.interfaces.DraweeController) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) Animatable(android.graphics.drawable.Animatable) BaseControllerListener(com.facebook.drawee.controller.BaseControllerListener) ControllerListener(com.facebook.drawee.controller.ControllerListener) QualityInfo(com.facebook.imagepipeline.image.QualityInfo) ImageInfo(com.facebook.imagepipeline.image.ImageInfo) Uri(android.net.Uri) Nullable(android.support.annotation.Nullable)

Example 64 with ImageRequest

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

the class ImagePipelineConfigTest method testImageRequestWhenChanged.

@Test
public void testImageRequestWhenChanged() {
    ImagePipelineConfig.resetDefaultRequestConfig();
    ImagePipelineConfig.getDefaultImageRequestConfig().setProgressiveRenderingEnabled(true);
    final ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(mUri).build();
    assertTrue(imageRequest.getProgressiveRenderingEnabled());
}
Also used : ImageRequest(com.facebook.imagepipeline.request.ImageRequest) Test(org.junit.Test)

Example 65 with ImageRequest

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

the class LocalVideoThumbnailProducer method produceResults.

@Override
public void produceResults(final Consumer<CloseableReference<CloseableImage>> consumer, final ProducerContext producerContext) {
    final ProducerListener2 listener = producerContext.getProducerListener();
    final ImageRequest imageRequest = producerContext.getImageRequest();
    producerContext.putOriginExtra("local", "video");
    final StatefulProducerRunnable cancellableProducerRunnable = new StatefulProducerRunnable<CloseableReference<CloseableImage>>(consumer, listener, producerContext, PRODUCER_NAME) {

        @Override
        protected void onSuccess(@Nullable CloseableReference<CloseableImage> result) {
            super.onSuccess(result);
            listener.onUltimateProducerReached(producerContext, PRODUCER_NAME, result != null);
            producerContext.putOriginExtra("local");
        }

        @Override
        protected void onFailure(Exception e) {
            super.onFailure(e);
            listener.onUltimateProducerReached(producerContext, PRODUCER_NAME, false);
            producerContext.putOriginExtra("local");
        }

        @Override
        @Nullable
        protected CloseableReference<CloseableImage> getResult() throws Exception {
            Bitmap thumbnailBitmap;
            String path;
            try {
                path = getLocalFilePath(imageRequest);
            } catch (IllegalArgumentException e) {
                path = null;
            }
            thumbnailBitmap = path != null ? ThumbnailUtils.createVideoThumbnail(path, calculateKind(imageRequest)) : createThumbnailFromContentProvider(mContentResolver, imageRequest.getSourceUri());
            if (thumbnailBitmap == null) {
                return null;
            }
            CloseableStaticBitmap closeableStaticBitmap = new CloseableStaticBitmap(thumbnailBitmap, SimpleBitmapReleaser.getInstance(), ImmutableQualityInfo.FULL_QUALITY, 0);
            producerContext.setExtra(ProducerContext.ExtraKeys.IMAGE_FORMAT, "thumbnail");
            closeableStaticBitmap.setImageExtras(producerContext.getExtras());
            return CloseableReference.<CloseableImage>of(closeableStaticBitmap);
        }

        @Override
        protected Map<String, String> getExtraMapOnSuccess(@Nullable final CloseableReference<CloseableImage> result) {
            return ImmutableMap.of(CREATED_THUMBNAIL, String.valueOf(result != null));
        }

        @Override
        protected void disposeResult(CloseableReference<CloseableImage> result) {
            CloseableReference.closeSafely(result);
        }
    };
    producerContext.addCallbacks(new BaseProducerContextCallbacks() {

        @Override
        public void onCancellationRequested() {
            cancellableProducerRunnable.cancel();
        }
    });
    mExecutor.execute(cancellableProducerRunnable);
}
Also used : CloseableReference(com.facebook.common.references.CloseableReference) CloseableImage(com.facebook.imagepipeline.image.CloseableImage) FileNotFoundException(java.io.FileNotFoundException) CloseableStaticBitmap(com.facebook.imagepipeline.image.CloseableStaticBitmap) Bitmap(android.graphics.Bitmap) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) CloseableStaticBitmap(com.facebook.imagepipeline.image.CloseableStaticBitmap) Nullable(javax.annotation.Nullable)

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