Java Code Examples for com.facebook.imagepipeline.request.ImageRequest#fromUri()
The following examples show how to use
com.facebook.imagepipeline.request.ImageRequest#fromUri() .
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: PriorityNetworkFetcherTest.java From fresco with MIT License | 6 votes |
private PriorityFetchState<FetchState> fetch( PriorityNetworkFetcher<FetchState> fetcher, String uri, NetworkFetcher.Callback callback, boolean isHiPri) { Consumer<EncodedImage> consumer = mock(Consumer.class); SettableProducerContext context = new SettableProducerContext( ImageRequest.fromUri(uri), "dontcare", null, null, null, !isHiPri, false, isHiPri ? HIGH : LOW, null); FetchState delegateFetchState = new FetchState(consumer, context); when(delegate.createFetchState(eq(consumer), eq(context))).thenReturn(delegateFetchState); PriorityFetchState<FetchState> fetchState = fetcher.createFetchState(consumer, context); fetcher.fetch(fetchState, callback); return fetchState; }
Example 2
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 3
Source File: BindingSetters.java From materialup with Apache License 2.0 | 6 votes |
@BindingAdapter({"bind:normalUrl", "bind:teaserUrl"}) public static void loadImage(SimpleDraweeView view, String normal, String teaser) { ImageRequest imageRequest = ImageRequest.fromUri(normal); ImageRequest lowRequest = null; if (!TextUtils.isEmpty(teaser)) { lowRequest = ImageRequest.fromUri(teaser); } DraweeController draweeController = Fresco.newDraweeControllerBuilder() .setImageRequest(imageRequest) .setLowResImageRequest(lowRequest) .setOldController(view.getController()) .setAutoPlayAnimations(true) .build(); view.setController(draweeController); }
Example 4
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 5
Source File: FrescoUtils.java From droidddle with Apache License 2.0 | 6 votes |
public static final void setShotUrl(DraweeView view, String url, String thumbnail/*, BaseControllerListener listener*/) { ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url)) // .setResizeOptions( // new ResizeOptions(300, 400)) .setProgressiveRenderingEnabled(true) .build(); ImageRequest lowRequest = null; if (!TextUtils.isEmpty(thumbnail)) { lowRequest = ImageRequest.fromUri(thumbnail); } DraweeController draweeController = Fresco.newDraweeControllerBuilder() .setImageRequest(imageRequest) .setLowResImageRequest(lowRequest) .setOldController(view.getController()) .setAutoPlayAnimations(true) // .setControllerListener(listener) .build(); view.setController(draweeController); }
Example 6
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 7
Source File: PipelineDraweeControllerBuilder.java From fresco with MIT License | 5 votes |
@Override public PipelineDraweeControllerBuilder setUri(@Nullable String uriString) { if (uriString == null || uriString.isEmpty()) { return super.setImageRequest(ImageRequest.fromUri(uriString)); } return setUri(Uri.parse(uriString)); }
Example 8
Source File: OffLineService.java From TLint with Apache License 2.0 | 5 votes |
private void cacheImage(String url) { if (!isImageDownloaded(Uri.parse(url))) { ImagePipeline imagePipeline = Fresco.getImagePipeline(); ImageRequest request = ImageRequest.fromUri(url); imagePipeline.prefetchToDiskCache(request, this); offlinePictureLength += request.getSourceFile().length(); offlinePictureCount++; } }
Example 9
Source File: FrescoFactory.java From FrescoUtils with Apache License 2.0 | 5 votes |
public static ImageRequest buildLowImageRequest(BaseFrescoImageView fresco){ String lowThumbnail = null; if(TextUtils.isEmpty(fresco.getLowThumbnailUrl())){ return null; } lowThumbnail = fresco.getLowThumbnailUrl(); Uri uri = Uri.parse(lowThumbnail); return ImageRequest.fromUri(uri); }
Example 10
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 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: 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 13
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 14
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 15
Source File: BigImageLoader.java From ImageLoader with Apache License 2.0 | 4 votes |
@Override public void loadImage(final Uri uri) { ImageRequest request = ImageRequest.fromUri(uri); final File localCache = getCacheFile(request); if (localCache!=null && localCache.exists()) { Log.e("onResourceReady","cache onResourceReady --"+ localCache.getAbsolutePath()); handler.postDelayed(new Runnable() { @Override public void run() { if(localCache.length() >100){ EventBus.getDefault().postSticky(new CacheHitEvent(localCache,uri.toString())); }else { EventBus.getDefault().postSticky(new ErrorEvent(uri.toString())); } } },300); } else { //EventBus.getDefault().post(new StartEvent(uri.toString())); //EventBus.getDefault().post(new ProgressEvent(0,false,uri.toString())); // callback.onStart(); // ensure `onStart` is called before `onProgress` and `onFinish` // callback.onProgress(0); // show 0 progress immediately ImagePipeline pipeline = Fresco.getImagePipeline(); DataSource<CloseableReference<PooledByteBuffer>> source = pipeline.fetchEncodedImage(request, true); source.subscribe(new ImageDownloadSubscriber(mAppContext) { @Override protected void onProgress(int progress) { //callback.onProgress(progress); EventBus.getDefault().post(new ProgressEvent(progress,progress==100,uri.toString())); } @Override protected void onSuccess(File image) { //EventBus.getDefault().post(new ProgressEvent(100,true,uri.toString())); Log.e("onResourceReady","download onResourceReady --"+ image.getAbsolutePath()); if(image.length() >100){ EventBus.getDefault().postSticky(new CacheHitEvent(image,uri.toString())); }else { EventBus.getDefault().postSticky(new ErrorEvent(uri.toString())); } //callback.onFinish(); //callback.onCacheMiss(image); } @Override protected void onFail(Throwable t) { // TODO: 12/11/2016 fail t.printStackTrace(); EventBus.getDefault().post(new ErrorEvent(uri.toString())); } }, mExecutorSupplier.forBackgroundTasks()); } }
Example 16
Source File: PipelineDraweeControllerBuilder.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 4 votes |
@Override public PipelineDraweeControllerBuilder setUri(Uri uri) { return super.setImageRequest(ImageRequest.fromUri(uri)); }
Example 17
Source File: FrescoImageLoader.java From ScrollGalleryView with MIT License | 4 votes |
private ImageRequest createImageRequest() { return ImageRequest.fromUri(Uri.parse(url)); }
Example 18
Source File: FrescoUtils.java From materialup with Apache License 2.0 | 4 votes |
public static final void setShotUrl(DraweeView view, String url, String thumbnail, BaseDataSubscriber subscriber, boolean full) { if (TextUtils.isEmpty(thumbnail) && TextUtils.isEmpty(url)) { return; } ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url)) // .setResizeOptions( // new ResizeOptions(300, 400)) .setProgressiveRenderingEnabled(true) .build(); ImageRequest lowRequest = null; if (!TextUtils.isEmpty(thumbnail)) { lowRequest = ImageRequest.fromUri(thumbnail); } if (subscriber != null) { if (lowRequest != null && !full) { setSubscribe(view.getContext(), lowRequest, subscriber); } else if (imageRequest != null) { setSubscribe(view.getContext(), imageRequest, subscriber); } } DraweeController draweeController = Fresco.newDraweeControllerBuilder() .setImageRequest(imageRequest) .setLowResImageRequest(lowRequest) .setOldController(view.getController()) .setAutoPlayAnimations(true) // .setControllerListener(listener) .build(); // ImagePipeline imagePipeline = Fresco.getImagePipeline(); // ImageRequest request = lowRequest == null ? imageRequest : lowRequest; // DataSource<CloseableReference<CloseableImage>> dataSource = // imagePipeline.fetchDecodedImage(request, view.getContext()); // dataSource.subscribe(new BaseBitmapDataSubscriber() { // @Override // protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) { // // } // // @Override protected void onNewResultImpl(@Nullable Bitmap bitmap) { // Palette.from(bitmap).maximumColorCount(3).generate(new Palette.PaletteAsyncListener() { // @Override public void onGenerated(Palette palette) { // } // }); // } // }, CallerThreadExecutor.getInstance()); view.setController(draweeController); }