com.facebook.imagepipeline.cache.DefaultCacheKeyFactory Java Examples
The following examples show how to use
com.facebook.imagepipeline.cache.DefaultCacheKeyFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FrescoLoader.java From ImageLoader with Apache License 2.0 | 6 votes |
@Override public boolean isCached(String url) { /* if(TextUtils.isEmpty(url)){ return false; } url = MyUtil.appendUrl(url); DataSource<Boolean> isIn = Fresco.getImagePipeline().isInDiskCache(Uri.parse(url)); if(isIn!=null){ try { return isIn.getResult(); }catch (Exception e){ return false; } }else { return false; }*/ ImageRequest imageRequest = ImageRequest.fromUri(url); CacheKey cacheKey = DefaultCacheKeyFactory.getInstance() .getEncodedCacheKey(imageRequest,null); return ImagePipelineFactory.getInstance() .getMainFileCache().hasKey(cacheKey); }
Example #2
Source File: ShareDribbbleImageTask.java From materialup with Apache License 2.0 | 6 votes |
@Override protected File doInBackground(Void... params) { final String url = shot.getTeaserUrl(); try { ImageRequest imageRequest = ImageRequest.fromUri(url); CacheKey cacheKey = DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(imageRequest); // ImagePipeline imagePipeline = Fresco.getImagePipeline(); // imagePipeline.prefetchToDiskCache(imageRequest,activity); BinaryResource resource = ImagePipelineFactory.getInstance().getMainDiskStorageCache().getResource(cacheKey); File file = ((FileBinaryResource) resource).getFile(); String fileName = url; fileName = fileName.substring(fileName.lastIndexOf('/') + 1); File renamed = new File(file.getParent(), fileName); if (!renamed.exists()) { FileUtil.copy(file, renamed); } return renamed; } catch (Exception ex) { Log.w("SHARE", "Sharing " + url + " failed", ex); return null; } }
Example #3
Source File: LinksContainerView.java From redgram-for-reddit with GNU General Public License v3.0 | 6 votes |
@Override public void viewImageMedia(int position, boolean loaded) { if(loaded){ PostItem item = getItem(position); CacheKey cacheKey = DefaultCacheKeyFactory.getInstance() .getEncodedCacheKey(ImageRequest .fromUri(Uri.parse(item.getUrl()))); if(cacheKey != null){ BinaryResource resource = ImagePipelineFactory.getInstance().getMainDiskStorageCache().getResource(cacheKey); File localFile; if(resource != null){ localFile = ((FileBinaryResource) resource).getFile(); Bundle bundle = new Bundle(); bundle.putString(getResources().getString(R.string.local_cache_key), localFile.getPath()); bundle.putString(getResources().getString(R.string.main_data_key), gson.toJson(item)); ((SlidingUpPanelActivity)context).setPanelView(Fragments.IMAGE_PREVIEW, bundle); } } } }
Example #4
Source File: ImagePreviewFragment.java From redgram-for-reddit with GNU General Public License v3.0 | 6 votes |
private void displayCachedImageFromBackgroundThread(ImageRequest request){ CacheKey cacheKey = DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(ImageRequest.fromUri(request.getSourceUri())); if(cacheKey != null){ BinaryResource resource = ImagePipelineFactory.getInstance().getMainDiskStorageCache().getResource(cacheKey); if(resource != null){ File localFile = ((FileBinaryResource) resource).getFile(); if(localFile != null){ Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override public void run() { imagePreview.setImage(ImageSource.uri(localFile.getPath())); } }); } } } }
Example #5
Source File: ImagePreviewPresenter.java From TLint with Apache License 2.0 | 6 votes |
private InputStream getImageBytesFromLocal(Uri loadUri) { if (loadUri == null) { return null; } CacheKey cacheKey = DefaultCacheKeyFactory.getInstance() .getEncodedCacheKey(ImageRequest.fromUri(loadUri), null); try { if (ImagePipelineFactory.getInstance().getMainFileCache().hasKey(cacheKey)) { return ImagePipelineFactory.getInstance() .getMainFileCache() .getResource(cacheKey) .openStream(); } if (ImagePipelineFactory.getInstance().getSmallImageFileCache().hasKey(cacheKey)) { return ImagePipelineFactory.getInstance() .getSmallImageFileCache() .getResource(cacheKey) .openStream(); } } catch (Exception e) { e.printStackTrace(); } return null; }
Example #6
Source File: FrescoImageProvider.java From HybridCache with MIT License | 5 votes |
private CacheKey getCacheKey(String url) { if (cachKeyProvider == null) { cachKeyProvider = new FrescoCacheKeyProvider() { @Override public CacheKey getCacheKey(String url) { if (TextUtils.isEmpty(url)) { return null; } return DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(ImageRequest.fromUri(Uri.parse(url)), null); } }; } return cachKeyProvider.getCacheKey(url); }
Example #7
Source File: BigImageLoader.java From ImageLoader with Apache License 2.0 | 5 votes |
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; }
Example #8
Source File: FrescoUtil.java From ImageLoader with Apache License 2.0 | 5 votes |
public static void putIntoPool(Bitmap bitmap,String uriString) { final ImageRequest requestBmp = ImageRequest.fromUri(uriString); // 赋值 // 获得 Key CacheKey cacheKey = DefaultCacheKeyFactory.getInstance().getBitmapCacheKey(requestBmp, ImageLoader.context); // 获得 closeableReference CloseableReference<CloseableImage> closeableReference = CloseableReference.<CloseableImage>of( new CloseableStaticBitmap(bitmap, SimpleBitmapReleaser.getInstance(), ImmutableQualityInfo.FULL_QUALITY, 0)); // 存入 Fresco Fresco.getImagePipelineFactory().getBitmapMemoryCache().cache(cacheKey, closeableReference); }
Example #9
Source File: FrescoUtil.java From MyImageUtil with Apache License 2.0 | 5 votes |
/** *this method is return very fast, you can use it in UI thread. * @param url * @return 该url对应的图片是否已经缓存到本地 */ public static boolean isCached(String url) { url = append(url); // return Fresco.getImagePipeline().isInDiskCache(Uri.parse(url)); ImageRequest imageRequest = ImageRequest.fromUri(url); CacheKey cacheKey = DefaultCacheKeyFactory.getInstance() .getEncodedCacheKey(imageRequest,null); return ImagePipelineFactory.getInstance() .getMainFileCache().hasKey(cacheKey); }
Example #10
Source File: PhotoActivity.java From materialup with Apache License 2.0 | 5 votes |
private void save() { try { ImageRequest imageRequest = ImageRequest.fromUri(mUrl); CacheKey cacheKey = DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(imageRequest); BinaryResource resource = ImagePipelineFactory.getInstance().getMainDiskStorageCache().getResource(cacheKey); File file = ((FileBinaryResource) resource).getFile(); String fileName = mUrl; fileName = fileName.substring(fileName.lastIndexOf('/') + 1); if (mTitle != null) { fileName = mTitle + fileName; } File pic = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File dir = new File(pic, "material/"); if (!dir.exists()) { dir.mkdirs(); } File renamed = new File(dir, fileName); if (!renamed.exists()) { renamed.createNewFile(); FileUtil.copy(file, renamed); } UI.showToast(this, getString(R.string.image_saved_to, renamed.getAbsolutePath())); // Snackbar.make(mDraweeView,R.string.image_is_saved, Snackbar.LENGTH_LONG); } catch (Exception ex) { Log.w("SHARE", "Sharing " + mUrl + " failed", ex); } }
Example #11
Source File: FrescoUtils.java From FrescoUtlis with Apache License 2.0 | 5 votes |
/** *this method is return very fast, you can use it in UI thread. * @param url * @return 该url对应的图片是否已经缓存到本地 */ public static boolean isCached(String url) { // return Fresco.getImagePipeline().isInDiskCache(Uri.parse(url)); ImageRequest imageRequest = ImageRequest.fromUri(url); CacheKey cacheKey = DefaultCacheKeyFactory.getInstance() .getEncodedCacheKey(imageRequest); return ImagePipelineFactory.getInstance() .getMainFileCache().hasKey(cacheKey); }
Example #12
Source File: FrescoHelper.java From FrescoUtils with Apache License 2.0 | 5 votes |
/** * 图片是否已经存在了 */ public static boolean isCached(Context context, Uri uri) { ImagePipeline imagePipeline = Fresco.getImagePipeline(); DataSource<Boolean> dataSource = imagePipeline.isInDiskCache(uri); if (dataSource == null) { return false; } ImageRequest imageRequest = ImageRequest.fromUri(uri); CacheKey cacheKey = DefaultCacheKeyFactory.getInstance() .getEncodedCacheKey(imageRequest, context); BinaryResource resource = ImagePipelineFactory.getInstance() .getMainFileCache().getResource(cacheKey); return resource != null && dataSource.getResult() != null && dataSource.getResult(); }
Example #13
Source File: FrescoHelper.java From FrescoUtils with Apache License 2.0 | 5 votes |
/** * 本地缓存文件 */ public static File getCache(Context context, Uri uri) { if (!isCached(context, uri)) return null; ImageRequest imageRequest = ImageRequest.fromUri(uri); CacheKey cacheKey = DefaultCacheKeyFactory.getInstance() .getEncodedCacheKey(imageRequest, context); BinaryResource resource = ImagePipelineFactory.getInstance() .getMainFileCache().getResource(cacheKey); File file = ((FileBinaryResource) resource).getFile(); return file; }
Example #14
Source File: OffLineService.java From TLint with Apache License 2.0 | 5 votes |
private boolean isImageDownloaded(Uri loadUri) { if (loadUri == null) { return false; } CacheKey cacheKey = DefaultCacheKeyFactory.getInstance() .getEncodedCacheKey(ImageRequest.fromUri(loadUri), null); return ImagePipelineFactory.getInstance().getMainFileCache().hasKey(cacheKey) || ImagePipelineFactory.getInstance().getSmallImageFileCache().hasKey(cacheKey); }
Example #15
Source File: ImagePipelineConfig.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 4 votes |
private ImagePipelineConfig(Builder builder) { mBitmapMemoryCacheParamsSupplier = builder.mBitmapMemoryCacheParamsSupplier == null ? new DefaultBitmapMemoryCacheParamsSupplier( (ActivityManager) builder.mContext.getSystemService(Context.ACTIVITY_SERVICE)) : builder.mBitmapMemoryCacheParamsSupplier; mCacheKeyFactory = builder.mCacheKeyFactory == null ? DefaultCacheKeyFactory.getInstance() : builder.mCacheKeyFactory; mContext = Preconditions.checkNotNull(builder.mContext); mEncodedMemoryCacheParamsSupplier = builder.mEncodedMemoryCacheParamsSupplier == null ? new DefaultEncodedMemoryCacheParamsSupplier() : builder.mEncodedMemoryCacheParamsSupplier; mExecutorSupplier = builder.mExecutorSupplier == null ? new DefaultExecutorSupplier() : builder.mExecutorSupplier; mImageCacheStatsTracker = builder.mImageCacheStatsTracker == null ? NoOpImageCacheStatsTracker.getInstance() : builder.mImageCacheStatsTracker; mIsPrefetchEnabledSupplier = builder.mIsPrefetchEnabledSupplier == null ? new Supplier<Boolean>() { @Override public Boolean get() { return true; } } : builder.mIsPrefetchEnabledSupplier; mMainDiskCacheConfig = builder.mMainDiskCacheConfig == null ? getDefaultMainDiskCacheConfig(builder.mContext) : builder.mMainDiskCacheConfig; mMemoryTrimmableRegistry = builder.mMemoryTrimmableRegistry == null ? NoOpMemoryTrimmableRegistry.getInstance() : builder.mMemoryTrimmableRegistry; mPoolFactory = builder.mPoolFactory == null ? new PoolFactory(PoolConfig.newBuilder().build()) : builder.mPoolFactory; mProgressiveJpegConfig = builder.mProgressiveJpegConfig == null ? getDefaultProgressiveJpegConfig() : builder.mProgressiveJpegConfig; mRequestListeners = builder.mRequestListeners == null ? new HashSet<RequestListener>() : builder.mRequestListeners; mResizeAndRotateEnabledForNetwork = builder.mResizeAndRotateEnabledForNetwork; mSmallImageDiskCacheConfig = builder.mSmallImageDiskCacheConfig == null ? mMainDiskCacheConfig : builder.mSmallImageDiskCacheConfig; mAnimatedDrawableUtil = new AnimatedDrawableUtil(); AnimatedDrawableBackendProvider animatedDrawableBackendProvider = new AnimatedDrawableBackendProvider() { @Override public AnimatedDrawableBackend get(AnimatedImageResult imageResult, Rect bounds) { return new AnimatedDrawableBackendImpl(mAnimatedDrawableUtil, imageResult, bounds); } }; mAnimatedImageFactory = builder.mAnimatedImageFactory == null ? new AnimatedImageFactory(animatedDrawableBackendProvider) : builder.mAnimatedImageFactory; GingerbreadBitmapFactory factoryGingerbread = new GingerbreadBitmapFactory(); DalvikBitmapFactory factoryICS = new DalvikBitmapFactory( new EmptyJpegGenerator(mPoolFactory.getPooledByteBufferFactory()), mPoolFactory.getSingleByteArrayPool()); ArtBitmapFactory factoryLollipop = new ArtBitmapFactory(mPoolFactory.getBitmapPool()); mPlatformBitmapFactory = new PlatformBitmapFactory( factoryGingerbread, factoryICS, factoryLollipop); mImageDecoder = builder.mImageDecoder == null ? new ImageDecoder(mAnimatedImageFactory, mPlatformBitmapFactory) : builder.mImageDecoder; mNetworkFetchProducer = builder.mNetworkFetchProducer == null ? new HttpURLConnectionNetworkFetchProducer( mPoolFactory.getPooledByteBufferFactory(), mPoolFactory.getCommonByteArrayPool()) : builder.mNetworkFetchProducer; }