private File getCacheFile(final ImageRequest request) { FileCache mainFileCache = ImagePipelineFactory .getInstance() .getMainFileCache(); final CacheKey cacheKey = DefaultCacheKeyFactory .getInstance() .getEncodedCacheKey(request, false); // we don't need context, but avoid null File cacheFile = request.getSourceFile(); // http://crashes.to/s/ee10638fb31 if (mainFileCache.hasKey(cacheKey) && mainFileCache.getResource(cacheKey) != null) { cacheFile = ((FileBinaryResource) mainFileCache.getResource(cacheKey)).getFile(); } return cacheFile; } }
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(); } }
public static boolean isImageDownloaded(Context context, Uri loadUri) { if (loadUri == null) { return false; } CacheKey cacheKey = DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(ImageRequest.fromUri(loadUri), context); return ImagePipelineFactory.getInstance().getMainFileCache().hasKey(cacheKey) || ImagePipelineFactory.getInstance().getSmallImageFileCache().hasKey(cacheKey); }
public static File getCachedImageOnDisk(CacheKey cacheKey) { File localFile = null; if (cacheKey != null) { if (ImagePipelineFactory.getInstance().getMainFileCache().hasKey(cacheKey)) { BinaryResource resource = ImagePipelineFactory.getInstance().getMainDiskStorageCache().getResource(cacheKey); localFile = ((FileBinaryResource) resource).getFile(); } else if (ImagePipelineFactory.getInstance().getSmallImageFileCache().hasKey(cacheKey)) { BinaryResource resource = ImagePipelineFactory.getInstance().getSmallImageFileCache().getResource(cacheKey); localFile = ((FileBinaryResource) resource).getFile(); } } return localFile; }
@Override public void trim(MemoryTrimType trimType) { final double suggestedTrimRatio = trimType.getSuggestedTrimRatio(); if (MemoryTrimType.OnCloseToDalvikHeapLimit.getSuggestedTrimRatio() == suggestedTrimRatio || MemoryTrimType.OnSystemLowMemoryWhileAppInBackground.getSuggestedTrimRatio() == suggestedTrimRatio || MemoryTrimType.OnSystemLowMemoryWhileAppInForeground.getSuggestedTrimRatio() == suggestedTrimRatio ) { ImagePipelineFactory.getInstance().getImagePipeline().clearMemoryCaches(); } } });
/** * 获取磁盘上主缓存文件缓存的大小 */ public static long getMainFileCache() { Fresco.getImagePipelineFactory().getMainFileCache().trimToMinimum(); return Fresco.getImagePipelineFactory().getMainFileCache().getSize(); }
/** * 获取磁盘上副缓存(小文件)文件缓存的大小 */ public static long getSmallImageFileCache() { Fresco.getImagePipelineFactory().getSmallImageFileCache().trimToMinimum(); return Fresco.getImagePipelineFactory().getSmallImageFileCache().getSize(); }
@Override protected void onNewResultImpl(DataSource<CloseableReference<CloseableImage>> dataSource) { CloseableReference<CloseableImage> result = dataSource.getResult(); if (result != null) { ImageRequest imageRequest = ImageRequest.fromUri(imageUrl); CacheKey cacheKey = DefaultCacheKeyFactory.getInstance() .getEncodedCacheKey(imageRequest); BinaryResource resource = Fresco.getImagePipelineFactory() .getMainDiskStorageCache() .getResource(cacheKey); if (resource instanceof FileBinaryResource) { File cacheFile = ((FileBinaryResource) resource).getFile(); try { FileUtil.copyFile(cacheFile, new File(filePath)); if (listener != null) listener.onSuccess(filePath); return; } catch (IOException e) { e.printStackTrace(); } } } if (listener != null) listener.onFailed(imageUrl); }
private File getCachedImageOnDisk(String url) { CacheKey key = getCacheKey(url); if (key == null) { return null; } File localFile = null; if (ImagePipelineFactory.getInstance().getMainFileCache().hasKey(key)) { BinaryResource resource = ImagePipelineFactory.getInstance().getMainFileCache().getResource(key); if (resource != null) { localFile = ((FileBinaryResource) resource).getFile(); } } else if (ImagePipelineFactory.getInstance().getSmallImageFileCache().hasKey(key)) { BinaryResource resource = ImagePipelineFactory.getInstance().getSmallImageFileCache().getResource(key); if (resource != null) { localFile = ((FileBinaryResource) resource).getFile(); } } return localFile; }
ImagePipeline pipeline = ImagePipelineFactory.getInstance().getImagePipeline(); DataSource<CloseableReference<CloseableImage>> dataSource = pipeline.fetchDecodedImage(request, mApplicationContext);
private boolean addFileToLocalCache(String requestUrl, File file) { CacheKey remoteUrlCacheKey = getCacheKey(requestUrl); InputStream localFileInputStream = null; try { localFileInputStream = new FileInputStream(file); BinaryResource resource = Fresco.getImagePipelineFactory().getMainFileCache().insert(remoteUrlCacheKey, WriterCallbacks.from(localFileInputStream)); return resource != null && resource.size() > 0; } catch (IOException e) { e.printStackTrace(); return false; } finally { try { if (localFileInputStream != null) { localFileInputStream.close(); } } catch (IOException e) { e.printStackTrace(); } } }
public static File getCache(ImageRequest request) { CacheKey cacheKey = DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(request, null); BinaryResource bRes = ImagePipelineFactory.getInstance().getMainFileCache().getResource(cacheKey); return ((FileBinaryResource) bRes).getFile(); }
public static File getCachedImageOnDisk(Context context, Uri loadUri) { File localFile = null; if (loadUri != null) { CacheKey cacheKey = DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(ImageRequest.fromUri(loadUri), context); if (ImagePipelineFactory.getInstance().getMainFileCache().hasKey(cacheKey)) { BinaryResource resource = ImagePipelineFactory.getInstance().getMainFileCache().getResource(cacheKey); localFile = ((FileBinaryResource) resource).getFile(); } else if (ImagePipelineFactory.getInstance().getSmallImageFileCache().hasKey(cacheKey)) { BinaryResource resource = ImagePipelineFactory.getInstance().getSmallImageFileCache().getResource(cacheKey); localFile = ((FileBinaryResource) resource).getFile(); } } return localFile; } }
CacheKey cacheKey = DefaultCacheKeyFactory.getInstance() .getEncodedCacheKey(imageRequest); BinaryResource resource = ImagePipelineFactory.getInstance() .getMainDiskStorageCache().getResource(cacheKey); File file = ((FileBinaryResource) resource).getFile(); if (file != null) {
/** * 获取磁盘缓存的文件路径 * * @param url 文件url * @return 文件路径 */ private static String getDiskCacheFilePath(String url) { FileBinaryResource resource = (FileBinaryResource) Fresco.getImagePipelineFactory() .getMainFileCache() .getResource(new SimpleCacheKey(url)); // 防止中途清除磁盘缓存 导致获取不到 if (resource == null) { return ""; } File file = resource.getFile(); return file.getAbsolutePath(); }
public static byte[] getByte(ImageRequest request) throws IOException { CacheKey cacheKey = DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(request, null); BinaryResource bRes = ImagePipelineFactory.getInstance().getMainFileCache().getResource(cacheKey); return bRes.read(); }
private static File getCacheImage(String url) { ImageRequest imageRequest=ImageRequest.fromUri(url); CacheKey cacheKey= DefaultCacheKeyFactory.getInstance() .getEncodedCacheKey(imageRequest, null); BinaryResource resource = ImagePipelineFactory.getInstance() .getMainDiskStorageCache().getResource(cacheKey); File file= null; try { file = ((FileBinaryResource)resource).getFile(); } catch (Exception e) { e.printStackTrace(); } return file; }
/** * 获取文件缓存 */ public static File getFileCache(String uri) { ImageRequest imageRequest = ImageRequest.fromUri(uri); CacheKey cacheKey = DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(imageRequest, null); BinaryResource resource = ImagePipelineFactory.getInstance() .getMainFileCache().getResource(cacheKey); return ((FileBinaryResource) resource).getFile(); }
private static File getCacheImage(String url) { ImageRequest imageRequest=ImageRequest.fromUri(url); CacheKey cacheKey= DefaultCacheKeyFactory.getInstance() .getEncodedCacheKey(imageRequest, null); BinaryResource resource = ImagePipelineFactory.getInstance() .getMainDiskStorageCache().getResource(cacheKey); File file= null; try { file = ((FileBinaryResource)resource).getFile(); } catch (Exception e) { e.printStackTrace(); } return file; }
public static byte[] getByte(Context context, Uri uri) throws IOException { if (!isCached(context, uri)) return null; ImageRequest imageRequest = ImageRequest.fromUri(uri); CacheKey cacheKey = DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(imageRequest, null); BinaryResource bRes = ImagePipelineFactory.getInstance().getMainFileCache().getResource(cacheKey); return bRes.read(); }