Search in sources :

Example 1 with FileBinaryResource

use of com.facebook.binaryresource.FileBinaryResource in project remusic by aa112901.

the class PlaylistActivity method setAlbumart.

private void setAlbumart() {
    playlistTitleView.setText(playlistName);
    if (albumPath == null) {
        albumArtSmall.setImageResource(R.drawable.placeholder_disk_210);
    } else {
        albumArtSmall.setImageURI(Uri.parse(albumPath));
    }
    try {
        if (isLocalPlaylist && !URLUtil.isNetworkUrl(albumPath)) {
            new setBlurredAlbumArt().execute(ImageUtils.getArtworkQuick(PlaylistActivity.this, Uri.parse(albumPath), 300, 300));
            L.D(d, TAG, "albumpath = " + albumPath);
        } else {
            // drawable = Drawable.createFromStream( new URL(albumPath).openStream(),"src");
            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));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : BinaryResource(com.facebook.binaryresource.BinaryResource) FileBinaryResource(com.facebook.binaryresource.FileBinaryResource) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) File(java.io.File) CacheKey(com.facebook.cache.common.CacheKey) FileBinaryResource(com.facebook.binaryresource.FileBinaryResource)

Example 2 with FileBinaryResource

use of com.facebook.binaryresource.FileBinaryResource 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)

Example 3 with FileBinaryResource

use of com.facebook.binaryresource.FileBinaryResource in project SherlockAdapter by EvilBT.

the class FrescoUtil method save.

public static Boolean save(@NonNull String url, @NonNull File outputFile) throws IOException {
    ImagePipelineFactory factory = Fresco.getImagePipelineFactory();
    ImagePipeline pipeline = factory.getImagePipeline();
    boolean isInCache = pipeline.isInDiskCacheSync(Uri.parse(url));
    if (isInCache) {
        BinaryResource resource = factory.getMainFileCache().getResource(new SimpleCacheKey(url));
        if (resource instanceof FileBinaryResource) {
            FileBinaryResource fileResource = (FileBinaryResource) resource;
            FileChannel input = new FileInputStream(fileResource.getFile()).getChannel();
            FileChannel output = new FileOutputStream(outputFile).getChannel();
            output.transferFrom(input, 0, input.size());
            input.close();
            output.close();
            return true;
        }
    }
    boolean isMemoryCache = pipeline.isInBitmapMemoryCache(Uri.parse(url));
    if (!isMemoryCache) {
        return false;
    }
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url)).build();
    DataSource<CloseableReference<CloseableImage>> dataSource = pipeline.fetchImageFromBitmapCache(request, null);
    if (!dataSource.isFinished()) {
        return false;
    }
    CloseableReference<CloseableImage> closeableImageRef = dataSource.getResult();
    Bitmap bitmap = null;
    if (closeableImageRef != null && closeableImageRef.get() instanceof CloseableBitmap) {
        bitmap = ((CloseableBitmap) closeableImageRef.get()).getUnderlyingBitmap();
    }
    if (bitmap == null) {
        return false;
    }
    FileOutputStream outputStream = new FileOutputStream(outputFile);
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
    outputStream.flush();
    outputStream.close();
    return true;
}
Also used : ImagePipelineFactory(com.facebook.imagepipeline.core.ImagePipelineFactory) FileChannel(java.nio.channels.FileChannel) CloseableReference(com.facebook.common.references.CloseableReference) CloseableImage(com.facebook.imagepipeline.image.CloseableImage) FileBinaryResource(com.facebook.binaryresource.FileBinaryResource) FileInputStream(java.io.FileInputStream) CloseableBitmap(com.facebook.imagepipeline.image.CloseableBitmap) CloseableBitmap(com.facebook.imagepipeline.image.CloseableBitmap) Bitmap(android.graphics.Bitmap) BinaryResource(com.facebook.binaryresource.BinaryResource) FileBinaryResource(com.facebook.binaryresource.FileBinaryResource) FileOutputStream(java.io.FileOutputStream) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) ImagePipeline(com.facebook.imagepipeline.core.ImagePipeline)

Example 4 with FileBinaryResource

use of com.facebook.binaryresource.FileBinaryResource in project lzc_app_lib by httplzc.

the class BigImgViewRealImgHelper method initBitmapRegion.

// 初始化原始图信息
public void initBitmapRegion(Uri uri) {
    BinaryResource binaryResource = Fresco.getImagePipelineFactory().getMainFileCache().getResource(new SimpleCacheKey(uri.toString()));
    if (binaryResource instanceof FileBinaryResource) {
        imgRotate = FileUntil.readPictureDegree(((FileBinaryResource) binaryResource).getFile().getPath());
    // Log.i("lzc", "imgRotate  " + imgRotate);
    }
    InputStream inputStream = null;
    try {
        if (binaryResource == null) {
            if (uri.getScheme().equals("res")) {
                inputStream = imageView.getResources().openRawResource(Integer.valueOf(uri.getPathSegments().get(uri.getPathSegments().size() - 1)));
            } else {
                String path = FileUntil.UriToFile(uri, null);
                if (path == null)
                    return;
                inputStream = new FileInputStream(new File(path));
            }
        } else {
            inputStream = binaryResource.openStream();
        }
        if (inputStream != null) {
            bitmapRegionDecoder = BitmapRegionDecoder.newInstance(inputStream, false);
            bigImgRealWidth = imgRotate == 0 || imgRotate == 180 ? bitmapRegionDecoder.getWidth() : bitmapRegionDecoder.getHeight();
            bigImgRealHeight = imgRotate == 0 || imgRotate == 180 ? bitmapRegionDecoder.getHeight() : bitmapRegionDecoder.getWidth();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (inputStream != null)
                inputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : BinaryResource(com.facebook.binaryresource.BinaryResource) FileBinaryResource(com.facebook.binaryresource.FileBinaryResource) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) IOException(java.io.IOException) File(java.io.File) FileBinaryResource(com.facebook.binaryresource.FileBinaryResource) FileInputStream(java.io.FileInputStream)

Example 5 with FileBinaryResource

use of com.facebook.binaryresource.FileBinaryResource 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)

Aggregations

FileBinaryResource (com.facebook.binaryresource.FileBinaryResource)8 BinaryResource (com.facebook.binaryresource.BinaryResource)5 File (java.io.File)5 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)4 CacheKey (com.facebook.cache.common.CacheKey)3 Bitmap (android.graphics.Bitmap)2 SimpleCacheKey (com.facebook.cache.common.SimpleCacheKey)2 CloseableReference (com.facebook.common.references.CloseableReference)2 ImagePipeline (com.facebook.imagepipeline.core.ImagePipeline)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 DataSource (com.facebook.datasource.DataSource)1 ImagePipelineFactory (com.facebook.imagepipeline.core.ImagePipelineFactory)1 BaseBitmapDataSubscriber (com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber)1 CloseableBitmap (com.facebook.imagepipeline.image.CloseableBitmap)1 CloseableImage (com.facebook.imagepipeline.image.CloseableImage)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 FileChannel (java.nio.channels.FileChannel)1 Test (org.junit.Test)1