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();
}
}
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();
}
}
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;
}
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();
}
}
}
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) {
}
}
Aggregations