com.facebook.datasource.DataSubscriber Java Examples
The following examples show how to use
com.facebook.datasource.DataSubscriber.
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: ProducerToDataSourceAdapterTest.java From fresco with MIT License | 6 votes |
@Before public void setUp() { MockitoAnnotations.initMocks(this); mResult1 = new Object(); mResult2 = new Object(); mResult3 = new Object(); mException = mock(Exception.class); mDataSubscriber1 = mock(DataSubscriber.class); mDataSubscriber2 = mock(DataSubscriber.class); mSettableProducerContext = mock(SettableProducerContext.class); when(mSettableProducerContext.getId()).thenReturn(mRequestId); when(mSettableProducerContext.isPrefetch()).thenReturn(true); mProducer = mock(Producer.class); mDataSource = ProducerToDataSourceAdapter.create(mProducer, mSettableProducerContext, mRequestListener); ArgumentCaptor<Consumer> captor = ArgumentCaptor.forClass(Consumer.class); verify(mRequestListener).onRequestStart(mSettableProducerContext); verify(mProducer).produceResults(captor.capture(), any(SettableProducerContext.class)); mInternalConsumer = captor.getValue(); mDataSource.subscribe(mDataSubscriber1, CallerThreadExecutor.getInstance()); }
Example #2
Source File: CloseableProducerToDataSourceAdapterTest.java From fresco with MIT License | 6 votes |
@Before public void setUp() { MockitoAnnotations.initMocks(this); mResourceReleaser = mock(ResourceReleaser.class); mResultRef1 = CloseableReference.of(new Object(), mResourceReleaser); mResultRef2 = CloseableReference.of(new Object(), mResourceReleaser); mResultRef3 = CloseableReference.of(new Object(), mResourceReleaser); mException = mock(Exception.class); mDataSubscriber1 = mock(DataSubscriber.class); mDataSubscriber2 = mock(DataSubscriber.class); mSettableProducerContext = mock(SettableProducerContext.class); mProducer = mock(Producer.class); mDataSource = CloseableProducerToDataSourceAdapter.create( mProducer, mSettableProducerContext, mRequestListener); ArgumentCaptor<Consumer> captor = ArgumentCaptor.forClass(Consumer.class); verify(mRequestListener).onRequestStart(mSettableProducerContext); verify(mProducer).produceResults(captor.capture(), any(SettableProducerContext.class)); mInternalConsumer = captor.getValue(); mDataSource.subscribe(mDataSubscriber1, CallerThreadExecutor.getInstance()); }
Example #3
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 #4
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 #5
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; }