Java 类com.facebook.common.executors.CallerThreadExecutor 实例源码

项目:GitHub    文件:IncreasingQualityDataSourceSupplier.java   
public IncreasingQualityDataSource() {
  mFinishedDataSources = new AtomicInteger(0);
  final int n = mDataSourceSuppliers.size();
  mNumberOfDataSources = n;
  mIndexOfDataSourceWithResult = n;
  mDataSources = new ArrayList<>(n);
  for (int i = 0; i < n; i++) {
    DataSource<T> dataSource = mDataSourceSuppliers.get(i).get();
    mDataSources.add(dataSource);
    dataSource.subscribe(new InternalDataSubscriber(i), CallerThreadExecutor.getInstance());
    // there's no point in creating data sources of lower quality
    // if the data source of a higher quality has some result already
    if (dataSource.hasResult()) {
      break;
    }
  }
}
项目:GitHub    文件:DataSourceTestUtils.java   
public void setUp() {
  mSrc1 = mock(DataSource.class);
  mSrc2 = mock(DataSource.class);
  mSrc3 = mock(DataSource.class);
  mDataSourceSupplier1 = mock(Supplier.class);
  mDataSourceSupplier2 = mock(Supplier.class);
  mDataSourceSupplier3 = mock(Supplier.class);
  when(mDataSourceSupplier1.get()).thenReturn(mSrc1);
  when(mDataSourceSupplier2.get()).thenReturn(mSrc2);
  when(mDataSourceSupplier3.get()).thenReturn(mSrc3);
  mDataSubscriber = mock(DataSubscriber.class);
  mExecutor = CallerThreadExecutor.getInstance();
  mInOrder = inOrder(
      mSrc1,
      mSrc2,
      mSrc3,
      mDataSourceSupplier1,
      mDataSourceSupplier2,
      mDataSourceSupplier3,
      mDataSubscriber);
  mSuppliers = Arrays.asList(
      mDataSourceSupplier1,
      mDataSourceSupplier2,
      mDataSourceSupplier3);
}
项目:GitHub    文件:AbstractDraweeControllerTest.java   
@Before
public void setUp() {
  mDeferredReleaser = mock(DeferredReleaser.class);
  mCallerContext = mock(Object.class);
  mDataSourceSupplier = mock(Supplier.class);
  mDraweeHierarchy = mock(SettableDraweeHierarchy.class);
  mUiThreadExecutor = CallerThreadExecutor.getInstance();
  mController = new FakeDraweeController(
      mDeferredReleaser,
      mUiThreadExecutor,
      mDataSourceSupplier,
      "id",
      mCallerContext);
  doAnswer(
      new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
          ((DeferredReleaser.Releasable) invocation.getArguments()[0]).release();
          return null;
        }
      }).when(mDeferredReleaser).scheduleDeferredRelease(any(DeferredReleaser.Releasable.class));
  when(mDataSourceSupplier.get()).thenReturn(SimpleDataSource.<FakeImage>create());
}
项目:H-Viewer    文件:ImageLoader.java   
public static void loadBitmapFromUrl(Context context, String url, String cookie, String referer, BaseBitmapDataSubscriber dataSubscriber) {
    if (TextUtils.isEmpty(url))
        return;
    Uri uri = Uri.parse(url);
    JsonObject header = new JsonObject();
    header.addProperty("Cookie", cookie);
    header.addProperty("Referer", referer);
    if (HProxy.isEnabled() && HProxy.isAllowPicture()) {
        HProxy proxy = new HProxy(url);
        header.addProperty(proxy.getHeaderKey(), proxy.getHeaderValue());
    }
    MyOkHttpNetworkFetcher.headers.put(uri, getGson().toJson(header));
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(uri);
    ImageRequest request = builder.build();
    DataSource<CloseableReference<CloseableImage>>
            dataSource = imagePipeline.fetchDecodedImage(request, context);
    dataSource.subscribe(dataSubscriber, CallerThreadExecutor.getInstance());
}
项目:H-Viewer    文件:ImageLoader.java   
public static void loadResourceFromUrl(Context context, Uri uri, String cookie, String referer, BaseDataSubscriber dataSubscriber) {
    if (uri.getScheme().startsWith("http")) {
        JsonObject header = new JsonObject();
        header.addProperty("Cookie", cookie);
        header.addProperty("Referer", referer);
        if (HProxy.isEnabled() && HProxy.isAllowPicture()) {
            HProxy proxy = new HProxy(uri.toString());
            header.addProperty(proxy.getHeaderKey(), proxy.getHeaderValue());
        }
        MyOkHttpNetworkFetcher.headers.put(uri, getGson().toJson(header));
    }
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(uri);
    ImageRequest request = builder.build();
    DataSource<CloseableReference<PooledByteBuffer>>
            dataSource = imagePipeline.fetchEncodedImage(request, context);
    dataSource.subscribe(dataSubscriber, CallerThreadExecutor.getInstance());
}
项目:H-Viewer    文件:RetainingDataSourceSupplier.java   
public void setSupplier(@Nullable Supplier<DataSource<T>> supplier) {
    // early return without calling {@code supplier.get()} in case we are closed
    if (isClosed()) {
        return;
    }
    DataSource<T> oldDataSource;
    DataSource<T> newDataSource = (supplier != null) ? supplier.get() : null;
    synchronized (RetainingDataSource.this) {
        if (isClosed()) {
            oldDataSource = newDataSource;
            newDataSource = null;
        } else {
            oldDataSource = mDataSource;
            mDataSource = newDataSource;
        }
    }
    if (newDataSource != null) {
        newDataSource.subscribe(new InternalDataSubscriber(), CallerThreadExecutor.getInstance());
    }
    closeSafely(oldDataSource);
}
项目:nono-android    文件:FrescoImageloadHelper.java   
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);
}
项目:nono-android    文件:FrescoImageloadHelper.java   
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);
}
项目:fresco    文件:RetainingDataSourceSupplier.java   
public void setSupplier(@Nullable Supplier<DataSource<T>> supplier) {
  // early return without calling {@code supplier.get()} in case we are closed
  if (isClosed()) {
    return;
  }
  DataSource<T> oldDataSource;
  DataSource<T> newDataSource = (supplier != null) ? supplier.get() : null;
  synchronized (RetainingDataSource.this) {
    if (isClosed()) {
      closeSafely(newDataSource);
      return;
    } else {
      oldDataSource = mDataSource;
      mDataSource = newDataSource;
    }
  }
  if (newDataSource != null) {
    newDataSource.subscribe(new InternalDataSubscriber(), CallerThreadExecutor.getInstance());
  }
  closeSafely(oldDataSource);
}
项目:fresco    文件:IncreasingQualityDataSourceSupplier.java   
public IncreasingQualityDataSource() {
  mFinishedDataSources = new AtomicInteger(0);
  final int n = mDataSourceSuppliers.size();
  mNumberOfDataSources = n;
  mIndexOfDataSourceWithResult = n;
  mDataSources = new ArrayList<>(n);
  for (int i = 0; i < n; i++) {
    DataSource<T> dataSource = mDataSourceSuppliers.get(i).get();
    mDataSources.add(dataSource);
    dataSource.subscribe(new InternalDataSubscriber(i), CallerThreadExecutor.getInstance());
    // there's no point in creating data sources of lower quality
    // if the data source of a higher quality has some result already
    if (dataSource.hasResult()) {
      break;
    }
  }
}
项目:fresco    文件:DataSourceTestUtils.java   
public void setUp() {
  mSrc1 = mock(DataSource.class);
  mSrc2 = mock(DataSource.class);
  mSrc3 = mock(DataSource.class);
  mDataSourceSupplier1 = mock(Supplier.class);
  mDataSourceSupplier2 = mock(Supplier.class);
  mDataSourceSupplier3 = mock(Supplier.class);
  when(mDataSourceSupplier1.get()).thenReturn(mSrc1);
  when(mDataSourceSupplier2.get()).thenReturn(mSrc2);
  when(mDataSourceSupplier3.get()).thenReturn(mSrc3);
  mDataSubscriber = mock(DataSubscriber.class);
  mExecutor = CallerThreadExecutor.getInstance();
  mInOrder = inOrder(
      mSrc1,
      mSrc2,
      mSrc3,
      mDataSourceSupplier1,
      mDataSourceSupplier2,
      mDataSourceSupplier3,
      mDataSubscriber);
  mSuppliers = Arrays.asList(
      mDataSourceSupplier1,
      mDataSourceSupplier2,
      mDataSourceSupplier3);
}
项目:fresco    文件:AbstractDraweeControllerTest.java   
@Before
public void setUp() {
  mDeferredReleaser = mock(DeferredReleaser.class);
  mCallerContext = mock(Object.class);
  mDataSourceSupplier = mock(Supplier.class);
  mDraweeHierarchy = mock(SettableDraweeHierarchy.class);
  mUiThreadExecutor = CallerThreadExecutor.getInstance();
  mController = new FakeDraweeController(
      mDeferredReleaser,
      mUiThreadExecutor,
      mDataSourceSupplier,
      "id",
      mCallerContext);
  doAnswer(
      new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
          ((DeferredReleaser.Releasable) invocation.getArguments()[0]).release();
          return null;
        }
      }).when(mDeferredReleaser).scheduleDeferredRelease(any(DeferredReleaser.Releasable.class));
  when(mDataSourceSupplier.get()).thenReturn(SimpleDataSource.<FakeImage>create());
}
项目:GitHub    文件:FirstAvailableDataSourceSupplier.java   
private boolean startNextDataSource() {
  Supplier<DataSource<T>> dataSourceSupplier = getNextSupplier();
  DataSource<T> dataSource = (dataSourceSupplier != null) ? dataSourceSupplier.get() : null;
  if (setCurrentDataSource(dataSource) && dataSource != null) {
    dataSource.subscribe(new InternalDataSubscriber(), CallerThreadExecutor.getInstance());
    return true;
  } else {
    closeSafely(dataSource);
    return false;
  }
}
项目:GitHub    文件:ListDataSource.java   
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;
}
项目:GitHub    文件:ProducerToDataSourceAdapterTest.java   
@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.getImageRequest(),
      mSettableProducerContext.getCallerContext(),
      mRequestId,
      mSettableProducerContext.isPrefetch());
  verify(mProducer).produceResults(captor.capture(), any(SettableProducerContext.class));
  mInternalConsumer = captor.getValue();

  mDataSource.subscribe(mDataSubscriber1, CallerThreadExecutor.getInstance());
}
项目:GitHub    文件:ProducerToDataSourceAdapterTest.java   
private void testSubscribe(int expected) {
  mDataSource.subscribe(mDataSubscriber2, CallerThreadExecutor.getInstance());
  switch (expected) {
    case NO_INTERACTIONS:
      break;
    case ON_NEW_RESULT:
      verify(mDataSubscriber2).onNewResult(mDataSource);
      break;
    case ON_FAILURE:
      verify(mDataSubscriber2).onFailure(mDataSource);
      break;
  }
  verifyNoMoreInteractionsAndReset();
}
项目:GitHub    文件:CloseableProducerToDataSourceAdapterTest.java   
@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);
  when(mSettableProducerContext.getId()).thenReturn(mRequestId);
  when(mSettableProducerContext.isPrefetch()).thenReturn(false);
  mProducer = mock(Producer.class);
  mDataSource = CloseableProducerToDataSourceAdapter.create(
      mProducer,
      mSettableProducerContext,
      mRequestListener);
  ArgumentCaptor<Consumer> captor = ArgumentCaptor.forClass(Consumer.class);
  verify(mRequestListener).onRequestStart(
      mSettableProducerContext.getImageRequest(),
      mSettableProducerContext.getCallerContext(),
      mRequestId,
      mSettableProducerContext.isPrefetch());
  verify(mProducer).produceResults(captor.capture(), any(SettableProducerContext.class));
  mInternalConsumer = captor.getValue();

  mDataSource.subscribe(mDataSubscriber1, CallerThreadExecutor.getInstance());
}
项目:GitHub    文件:CloseableProducerToDataSourceAdapterTest.java   
private void testSubscribe(int expected) {
  mDataSource.subscribe(mDataSubscriber2, CallerThreadExecutor.getInstance());
  switch (expected) {
    case NO_INTERACTIONS:
      break;
    case ON_NEW_RESULT:
      verify(mDataSubscriber2).onNewResult(mDataSource);
      break;
    case ON_FAILURE:
      verify(mDataSubscriber2).onFailure(mDataSource);
      break;
  }
  verifyNoMoreInteractionsAndReset();
}
项目:GitHub    文件:ListDataSourceTest.java   
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  mSettableDataSource1 = SettableDataSource.create();
  mSettableDataSource2 = SettableDataSource.create();
  mListDataSource = ListDataSource.create(mSettableDataSource1, mSettableDataSource2);
  mRef1 = CloseableReference.of(1, mResourceReleaser);
  mRef2 = CloseableReference.of(2, mResourceReleaser);
  mRuntimeException = new RuntimeException();
  mListDataSource.subscribe(mDataSubscriber, CallerThreadExecutor.getInstance());
}
项目:GitHub    文件:ThrottlingProducerTest.java   
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  mThrottlingProducer = new ThrottlingProducer<Object>(
      MAX_SIMULTANEOUS_REQUESTS,
      CallerThreadExecutor.getInstance(),
      mInputProducer);
  for (int i = 0; i < 5; i++) {
    mConsumers[i] = mock(Consumer.class);
    mProducerContexts[i] = mock(ProducerContext.class);
    mProducerListeners[i] = mock(ProducerListener.class);
    mRequestIds[i] = Integer.toString(i);
    mResults[i] = mock(Object.class);
    when(mProducerContexts[i].getListener()).thenReturn(mProducerListeners[i]);
    when(mProducerContexts[i].getId()).thenReturn(mRequestIds[i]);
    final int iFinal = i;
    doAnswer(
        new Answer() {
          @Override
          public Object answer(InvocationOnMock invocation) throws Throwable {
            mThrottlerConsumers[iFinal] =
                (Consumer<Object>) invocation.getArguments()[0];
            return null;
          }
        }).when(mInputProducer).produceResults(any(Consumer.class), eq(mProducerContexts[i]));
  }
}
项目:witchpot    文件:MediaUtil.java   
public static void getBitmapWithFresco(Context context, String url, BaseBitmapDataSubscriber baseBitmapDataSubscriber) {
    ImageRequest imageRequest = ImageRequestBuilder
            .newBuilderWithSource(Uri.parse(url))
            .setProgressiveRenderingEnabled(true)
            .build();

    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    DataSource<CloseableReference<CloseableImage>>
            dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);
    dataSource.subscribe(baseBitmapDataSubscriber,
            CallerThreadExecutor.getInstance());
}
项目:nono-android    文件:FrescoImageloadHelper.java   
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);
}
项目:fresco    文件:FirstAvailableDataSourceSupplier.java   
private boolean startNextDataSource() {
  Supplier<DataSource<T>> dataSourceSupplier = getNextSupplier();
  DataSource<T> dataSource = (dataSourceSupplier != null) ? dataSourceSupplier.get() : null;
  if (setCurrentDataSource(dataSource) && dataSource != null) {
    dataSource.subscribe(new InternalDataSubscriber(), CallerThreadExecutor.getInstance());
    return true;
  } else {
    closeSafely(dataSource);
    return false;
  }
}
项目:fresco    文件:ListDataSource.java   
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;
}
项目:fresco    文件:ProducerToDataSourceAdapterTest.java   
@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.getImageRequest(),
      mSettableProducerContext.getCallerContext(),
      mRequestId,
      mSettableProducerContext.isPrefetch());
  verify(mProducer).produceResults(captor.capture(), any(SettableProducerContext.class));
  mInternalConsumer = captor.getValue();

  mDataSource.subscribe(mDataSubscriber1, CallerThreadExecutor.getInstance());
}
项目:fresco    文件:ProducerToDataSourceAdapterTest.java   
private void testSubscribe(int expected) {
  mDataSource.subscribe(mDataSubscriber2, CallerThreadExecutor.getInstance());
  switch (expected) {
    case NO_INTERACTIONS:
      break;
    case ON_NEW_RESULT:
      verify(mDataSubscriber2).onNewResult(mDataSource);
      break;
    case ON_FAILURE:
      verify(mDataSubscriber2).onFailure(mDataSource);
      break;
  }
  verifyNoMoreInteractionsAndReset();
}
项目:fresco    文件:CloseableProducerToDataSourceAdapterTest.java   
@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);
  when(mSettableProducerContext.getId()).thenReturn(mRequestId);
  when(mSettableProducerContext.isPrefetch()).thenReturn(false);
  mProducer = mock(Producer.class);
  mDataSource = CloseableProducerToDataSourceAdapter.create(
      mProducer,
      mSettableProducerContext,
      mRequestListener);
  ArgumentCaptor<Consumer> captor = ArgumentCaptor.forClass(Consumer.class);
  verify(mRequestListener).onRequestStart(
      mSettableProducerContext.getImageRequest(),
      mSettableProducerContext.getCallerContext(),
      mRequestId,
      mSettableProducerContext.isPrefetch());
  verify(mProducer).produceResults(captor.capture(), any(SettableProducerContext.class));
  mInternalConsumer = captor.getValue();

  mDataSource.subscribe(mDataSubscriber1, CallerThreadExecutor.getInstance());
}
项目:fresco    文件:CloseableProducerToDataSourceAdapterTest.java   
private void testSubscribe(int expected) {
  mDataSource.subscribe(mDataSubscriber2, CallerThreadExecutor.getInstance());
  switch (expected) {
    case NO_INTERACTIONS:
      break;
    case ON_NEW_RESULT:
      verify(mDataSubscriber2).onNewResult(mDataSource);
      break;
    case ON_FAILURE:
      verify(mDataSubscriber2).onFailure(mDataSource);
      break;
  }
  verifyNoMoreInteractionsAndReset();
}
项目:fresco    文件:ListDataSourceTest.java   
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  mSettableDataSource1 = SettableDataSource.create();
  mSettableDataSource2 = SettableDataSource.create();
  mListDataSource = ListDataSource.create(mSettableDataSource1, mSettableDataSource2);
  mRef1 = CloseableReference.of(1, mResourceReleaser);
  mRef2 = CloseableReference.of(2, mResourceReleaser);
  mRuntimeException = new RuntimeException();
  mListDataSource.subscribe(mDataSubscriber, CallerThreadExecutor.getInstance());
}
项目:fresco    文件:ThrottlingProducerTest.java   
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  mThrottlingProducer = new ThrottlingProducer<Object>(
      MAX_SIMULTANEOUS_REQUESTS,
      CallerThreadExecutor.getInstance(),
      mInputProducer);
  for (int i = 0; i < 5; i++) {
    mConsumers[i] = mock(Consumer.class);
    mProducerContexts[i] = mock(ProducerContext.class);
    mProducerListeners[i] = mock(ProducerListener.class);
    mRequestIds[i] = Integer.toString(i);
    mResults[i] = mock(Object.class);
    when(mProducerContexts[i].getListener()).thenReturn(mProducerListeners[i]);
    when(mProducerContexts[i].getId()).thenReturn(mRequestIds[i]);
    final int iFinal = i;
    doAnswer(
        new Answer() {
          @Override
          public Object answer(InvocationOnMock invocation) throws Throwable {
            mThrottlerConsumers[iFinal] =
                (Consumer<Object>) invocation.getArguments()[0];
            return null;
          }
        }).when(mInputProducer).produceResults(any(Consumer.class), eq(mProducerContexts[i]));
  }
}
项目:GitHub    文件:DataFetchProducer.java   
public DataFetchProducer(
    PooledByteBufferFactory pooledByteBufferFactory) {
  super(CallerThreadExecutor.getInstance(), pooledByteBufferFactory);
}
项目:materialup    文件:FrescoUtils.java   
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());
}
项目:fresco    文件:DataFetchProducer.java   
public DataFetchProducer(
    PooledByteBufferFactory pooledByteBufferFactory) {
  super(CallerThreadExecutor.getInstance(), pooledByteBufferFactory);
}