本文整理汇总了Java中com.facebook.common.executors.CallerThreadExecutor类的典型用法代码示例。如果您正苦于以下问题:Java CallerThreadExecutor类的具体用法?Java CallerThreadExecutor怎么用?Java CallerThreadExecutor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CallerThreadExecutor类属于com.facebook.common.executors包,在下文中一共展示了CallerThreadExecutor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: IncreasingQualityDataSource
import com.facebook.common.executors.CallerThreadExecutor; //导入依赖的package包/类
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;
}
}
}
示例2: setUp
import com.facebook.common.executors.CallerThreadExecutor; //导入依赖的package包/类
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);
}
示例3: setUp
import com.facebook.common.executors.CallerThreadExecutor; //导入依赖的package包/类
@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());
}
示例4: loadBitmapFromUrl
import com.facebook.common.executors.CallerThreadExecutor; //导入依赖的package包/类
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());
}
示例5: loadResourceFromUrl
import com.facebook.common.executors.CallerThreadExecutor; //导入依赖的package包/类
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());
}
示例6: setSupplier
import com.facebook.common.executors.CallerThreadExecutor; //导入依赖的package包/类
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);
}
示例7: LoadImageFromURLAndCallBack
import com.facebook.common.executors.CallerThreadExecutor; //导入依赖的package包/类
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);
}
示例8: LoadImageFromURIAndCallBack
import com.facebook.common.executors.CallerThreadExecutor; //导入依赖的package包/类
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);
}
示例9: setSupplier
import com.facebook.common.executors.CallerThreadExecutor; //导入依赖的package包/类
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);
}
示例10: startNextDataSource
import com.facebook.common.executors.CallerThreadExecutor; //导入依赖的package包/类
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;
}
}
示例11: create
import com.facebook.common.executors.CallerThreadExecutor; //导入依赖的package包/类
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;
}
示例12: setUp
import com.facebook.common.executors.CallerThreadExecutor; //导入依赖的package包/类
@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());
}
示例13: testSubscribe
import com.facebook.common.executors.CallerThreadExecutor; //导入依赖的package包/类
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();
}
示例14: setUp
import com.facebook.common.executors.CallerThreadExecutor; //导入依赖的package包/类
@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());
}
示例15: setUp
import com.facebook.common.executors.CallerThreadExecutor; //导入依赖的package包/类
@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());
}