Java Code Examples for com.facebook.datasource.DataSource#subscribe()
The following examples show how to use
com.facebook.datasource.DataSource#subscribe() .
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: FrescoImageloadHelper.java From nono-android with GNU General Public License v3.0 | 6 votes |
public static void LoadImageFromURLAndCallBack(SimpleDraweeView destImageView , String URL,Context context,BaseBitmapDataSubscriber bbds) { int w = destImageView.getWidth(); int h =destImageView.getHeight(); if(w<1){ w = destImageView.getLayoutParams().width; } if(h<1){ h =destImageView.getLayoutParams().height; } ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(URL)) .setResizeOptions(new ResizeOptions(w,h)) .setProgressiveRenderingEnabled(true) .build(); ImagePipeline imagePipeline = Fresco.getImagePipeline(); DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context); dataSource.subscribe(bbds, CallerThreadExecutor.getInstance()); DraweeController draweeController = Fresco.newDraweeControllerBuilder() .setImageRequest(imageRequest) .setOldController(destImageView.getController()) .setAutoPlayAnimations(true) .build(); destImageView.setController(draweeController); }
Example 2
Source File: FrescoImageloadHelper.java From nono-android with GNU General Public License v3.0 | 6 votes |
public static void LoadImageFromURIAndCallBack(SimpleDraweeView destImageView , Uri uri,Context context,BaseBitmapDataSubscriber bbds) { int w = destImageView.getWidth(); int h =destImageView.getHeight(); if(w<1){ w = destImageView.getLayoutParams().width; } if(h<1){ h =destImageView.getLayoutParams().height; } ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(uri) .setResizeOptions(new ResizeOptions(w,h)) .setProgressiveRenderingEnabled(true) .build(); ImagePipeline imagePipeline = Fresco.getImagePipeline(); DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context); dataSource.subscribe(bbds, CallerThreadExecutor.getInstance()); DraweeController draweeController = Fresco.newDraweeControllerBuilder() .setImageRequest(imageRequest) .setOldController(destImageView.getController()) .setAutoPlayAnimations(true) .build(); destImageView.setController(draweeController); }
Example 3
Source File: FrescoController.java From base-module with Apache License 2.0 | 5 votes |
/** * 加载图片获取 Bitmap 对象 * @param subscriber */ public void intoTarget(BaseBitmapDataSubscriber subscriber) { ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(mUri) .setProgressiveRenderingEnabled(true); if (mWidth > 0 && mHeight > 0) { builder.setResizeOptions(new ResizeOptions(mWidth, mHeight)); } ImageRequest imageRequest = builder.build(); ImagePipeline imagePipeline = Fresco.getImagePipeline(); DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, this); dataSource.subscribe(subscriber, UiThreadImmediateExecutorService.getInstance()); }
Example 4
Source File: FrescoController.java From base-module with Apache License 2.0 | 5 votes |
/** * 只下载图片到磁盘,可设置下载回调 * @param context * @param baseDataSubscriber */ public void downloadOnly(Context context, BaseDataSubscriber baseDataSubscriber) { ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(mUri) .setProgressiveRenderingEnabled(true) .build(); ImagePipeline imagePipeline = Fresco.getImagePipeline(); DataSource<Void> dataSource = imagePipeline.prefetchToDiskCache(imageRequest, context.getApplicationContext()); if(baseDataSubscriber != null) { dataSource.subscribe(baseDataSubscriber, UiThreadImmediateExecutorService.getInstance()); } }
Example 5
Source File: ApplicationActivity.java From react-native-turbolinks with MIT License | 5 votes |
private void bitmapFor(Bundle image, Context context, BaseBitmapDataSubscriber baseBitmapDataSubscriber) { ImageSource source = new ImageSource(context, image.getString("uri")); ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(source.getUri()).build(); ImagePipeline imagePipeline = Fresco.getImagePipeline(); DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context); dataSource.subscribe(baseBitmapDataSubscriber, UiThreadImmediateExecutorService.getInstance()); }
Example 6
Source File: ListDataSource.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 5 votes |
public static <T> ListDataSource<T> create( DataSource<CloseableReference<T>>... dataSources) { Preconditions.checkNotNull(dataSources); Preconditions.checkState(dataSources.length > 0); ListDataSource<T> listDataSource = new ListDataSource<T>(dataSources); for (DataSource<CloseableReference<T>> dataSource : dataSources) { dataSource.subscribe( listDataSource.new InternalDataSubscriber(), CallerThreadExecutor.getInstance()); } return listDataSource; }
Example 7
Source File: FrescoImageloadHelper.java From nono-android with GNU General Public License v3.0 | 5 votes |
public static void LoadImageFromURLAndCallBack(SimpleDraweeView destImageView , String URL, Context context, BaseBitmapDataSubscriber bbds , BasePostprocessor postprocessor) { int w = destImageView.getWidth(); int h =destImageView.getHeight(); if(w<1){ w = destImageView.getLayoutParams().width; } if(h<1){ h =destImageView.getLayoutParams().height; } ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(URL)) .setResizeOptions(new ResizeOptions(w,h)) .setProgressiveRenderingEnabled(true); if(postprocessor!=null){ builder.setPostprocessor(postprocessor); } ImageRequest imageRequest = builder .build(); ImagePipeline imagePipeline = Fresco.getImagePipeline(); DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context); dataSource.subscribe(bbds, CallerThreadExecutor.getInstance()); DraweeController draweeController = Fresco.newDraweeControllerBuilder() .setImageRequest(imageRequest) .setOldController(destImageView.getController()) .setAutoPlayAnimations(true) .build(); destImageView.setController(draweeController); }
Example 8
Source File: FrescoImageLoader.java From ScrollGalleryView with MIT License | 5 votes |
@Override public void loadMedia(Context context, final ImageView imageView, SuccessCallback callback) { if (!Fresco.hasBeenInitialized()) { Fresco.initialize(context); } ImagePipeline pipeline = Fresco.getImagePipeline(); DataSubscriber subscriber = getSubscriber(imageView, callback); DataSource<CloseableReference<CloseableImage>> dataSource = pipeline.fetchDecodedImage(createImageRequest(), context); dataSource.subscribe(subscriber, UiThreadImmediateExecutorService.getInstance()); }
Example 9
Source File: FrescoImageLoader.java From ScrollGalleryView with MIT License | 5 votes |
@Override public void loadThumbnail(Context context, ImageView thumbnailView, SuccessCallback callback) { if (!Fresco.hasBeenInitialized()){ Fresco.initialize(context); } ImagePipeline pipeline = Fresco.getImagePipeline(); DataSubscriber subscriber = getSubscriber(thumbnailView, callback); DataSource<CloseableReference<CloseableImage>> dataSource = pipeline.fetchDecodedImage(createImageRequest(thumbnailWidth, thumbnailHeight), context); dataSource.subscribe(subscriber, UiThreadImmediateExecutorService.getInstance()); }
Example 10
Source File: ImageViewActivity.java From Fishing with GNU General Public License v3.0 | 5 votes |
@Override public View instantiateItem(ViewGroup container, int position) { View view = LayoutInflater.from(ImageViewActivity.this).inflate(R.layout.item_imagepage, container, false); final PhotoView photoView = (PhotoView) view.findViewById(R.id.photoview); final View wheel = view.findViewById(R.id.wheel); photoView.setOnPhotoTapListener((view1, v, v1) -> finish()); ImagePipeline imagePipeline = Fresco.getImagePipeline(); ImageRequest request = ImageRequestBuilder.newBuilderWithSource(urls.get(position)) .setResizeOptions(new ResizeOptions(768, 768)) .build(); DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(request,this); DataSubscriber dataSubscriber = new BaseBitmapDataSubscriber() { @Override protected void onNewResultImpl(Bitmap bitmap) { photoView.setImageBitmap(bitmap); wheel.setVisibility(View.GONE); } @Override protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> closeableReferenceDataSource) { } }; dataSource.subscribe(dataSubscriber, new Executor() { @Override public void execute(Runnable command) { handler.post(command); } }); container.addView(view); return view; }
Example 11
Source File: ListDataSource.java From fresco with MIT License | 5 votes |
public static <T> ListDataSource<T> create(DataSource<CloseableReference<T>>... dataSources) { Preconditions.checkNotNull(dataSources); Preconditions.checkState(dataSources.length > 0); ListDataSource<T> listDataSource = new ListDataSource<T>(dataSources); for (DataSource<CloseableReference<T>> dataSource : dataSources) { if (dataSource != null) { dataSource.subscribe( listDataSource.new InternalDataSubscriber(), CallerThreadExecutor.getInstance()); } } return listDataSource; }
Example 12
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 13
Source File: FrescoUtils.java From materialup with Apache License 2.0 | 4 votes |
private static final void setSubscribe(Context context, ImageRequest request, BaseDataSubscriber subscriber) { ImagePipeline imagePipeline = Fresco.getImagePipeline(); DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(request, context); dataSource.subscribe(subscriber, CallerThreadExecutor.getInstance()); }
Example 14
Source File: FrescoController2Impl.java From fresco with MIT License | 4 votes |
@Override public boolean fetch( final FrescoDrawable2 frescoDrawable, final VitoImageRequest imageRequest, final @Nullable Object callerContext, final @Nullable ImageListener listener, final @Nullable Rect viewportDimensions) { // Save viewport dimension for future use frescoDrawable.setViewportDimensions(viewportDimensions); // Check if we already fetched the image if (frescoDrawable.getDrawableDataSubscriber() == this && frescoDrawable.isFetchSubmitted() && imageRequest.equals(frescoDrawable.getImageRequest())) { frescoDrawable.cancelReleaseNextFrame(); frescoDrawable.cancelReleaseDelayed(); return true; // already set } // We didn't -> Reset everything frescoDrawable.close(); // Basic setup frescoDrawable.setDrawableDataSubscriber(this); frescoDrawable.setImageRequest(imageRequest); frescoDrawable.setCallerContext(callerContext); frescoDrawable.setImageListener(listener); frescoDrawable.setVitoImageRequestListener(mGlobalImageListener); // Set layers that are always visible mHierarcher.setupOverlayDrawable( frescoDrawable, imageRequest.resources, imageRequest.imageOptions, null); // We're fetching a new image, so we're updating the ID final long imageId = VitoUtils.generateIdentifier(); frescoDrawable.setImageId(imageId); // Notify listeners that we're about to fetch an image frescoDrawable .getImageListener() .onSubmit(imageId, imageRequest, callerContext, obtainExtras(null, null, frescoDrawable)); // Check if the image is in cache CloseableReference<CloseableImage> cachedImage = mImagePipeline.getCachedImage(imageRequest); try { if (CloseableReference.isValid(cachedImage)) { frescoDrawable.setImageOrigin(ImageOrigin.MEMORY_BITMAP_SHORTCUT); // Immediately display the actual image. setActualImage(frescoDrawable, imageRequest, cachedImage, true, null); frescoDrawable.setFetchSubmitted(true); mDebugOverlayFactory.update(frescoDrawable); return true; } } finally { CloseableReference.closeSafely(cachedImage); } // The image is not in cache -> Set up layers visible until the image is available frescoDrawable.setProgressDrawable( mHierarcher.buildProgressDrawable(imageRequest.resources, imageRequest.imageOptions)); Drawable placeholder = mHierarcher.buildPlaceholderDrawable(imageRequest.resources, imageRequest.imageOptions); frescoDrawable.setPlaceholderDrawable(placeholder); frescoDrawable.setImageDrawable(null); frescoDrawable.getImageListener().onPlaceholderSet(imageId, imageRequest, placeholder); // Fetch the image final Runnable fetchRunnable = new Runnable() { @Override public void run() { if (imageId != frescoDrawable.getImageId()) { return; // We're trying to load a different image -> ignore } DataSource<CloseableReference<CloseableImage>> dataSource = mImagePipeline.fetchDecodedImage( imageRequest, callerContext, frescoDrawable.getImageOriginListener(), imageId); frescoDrawable.setDataSource(dataSource); dataSource.subscribe(frescoDrawable, mUiThreadExecutor); } }; if (mConfig.submitFetchOnBgThread()) { mLightweightBackgroundThreadExecutor.execute(fetchRunnable); } else { fetchRunnable.run(); } frescoDrawable.setFetchSubmitted(true); mDebugOverlayFactory.update(frescoDrawable); return false; }