本文整理汇总了Java中com.facebook.datasource.DataSource类的典型用法代码示例。如果您正苦于以下问题:Java DataSource类的具体用法?Java DataSource怎么用?Java DataSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DataSource类属于com.facebook.datasource包,在下文中一共展示了DataSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newController
import com.facebook.datasource.DataSource; //导入依赖的package包/类
public PipelineDraweeController newController(
Supplier<DataSource<CloseableReference<CloseableImage>>> dataSourceSupplier,
String id,
CacheKey cacheKey,
Object callerContext,
@Nullable ImmutableList<DrawableFactory> customDrawableFactories) {
Preconditions.checkState(mResources != null, "init() not called");
// Field values passed as arguments so that any subclass of PipelineDraweeControllerFactory
// can simply override internalCreateController() and return a custom Drawee controller
PipelineDraweeController controller = internalCreateController(
mResources,
mDeferredReleaser,
mAnimatedDrawableFactory,
mUiThreadExecutor,
mMemoryCache,
mDrawableFactories,
customDrawableFactories,
dataSourceSupplier,
id,
cacheKey,
callerContext);
if (mDebugOverlayEnabledSupplier != null) {
controller.setDrawDebugOverlay(mDebugOverlayEnabledSupplier.get());
}
return controller;
}
示例2: internalCreateController
import com.facebook.datasource.DataSource; //导入依赖的package包/类
protected PipelineDraweeController internalCreateController(
Resources resources,
DeferredReleaser deferredReleaser,
DrawableFactory animatedDrawableFactory,
Executor uiThreadExecutor,
MemoryCache<CacheKey, CloseableImage> memoryCache,
@Nullable ImmutableList<DrawableFactory> globalDrawableFactories,
@Nullable ImmutableList<DrawableFactory> customDrawableFactories,
Supplier<DataSource<CloseableReference<CloseableImage>>> dataSourceSupplier,
String id,
CacheKey cacheKey,
Object callerContext) {
PipelineDraweeController controller = new PipelineDraweeController(
resources,
deferredReleaser,
animatedDrawableFactory,
uiThreadExecutor,
memoryCache,
dataSourceSupplier,
id,
cacheKey,
callerContext,
globalDrawableFactories);
controller.setCustomDrawableFactories(customDrawableFactories);
return controller;
}
示例3: PipelineDraweeController
import com.facebook.datasource.DataSource; //导入依赖的package包/类
public PipelineDraweeController(
Resources resources,
DeferredReleaser deferredReleaser,
DrawableFactory animatedDrawableFactory,
Executor uiThreadExecutor,
MemoryCache<CacheKey, CloseableImage> memoryCache,
Supplier<DataSource<CloseableReference<CloseableImage>>> dataSourceSupplier,
String id,
CacheKey cacheKey,
Object callerContext) {
this(
resources,
deferredReleaser,
animatedDrawableFactory,
uiThreadExecutor,
memoryCache,
dataSourceSupplier,
id,
cacheKey,
callerContext,
null);
}
示例4: onNewResultImpl
import com.facebook.datasource.DataSource; //导入依赖的package包/类
@Override
public void onNewResultImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
if (!dataSource.isFinished()) {
return;
}
CloseableReference<CloseableImage> closeableImageRef = dataSource.getResult();
Bitmap bitmap = null;
if (closeableImageRef != null &&
closeableImageRef.get() instanceof CloseableBitmap) {
bitmap = ((CloseableBitmap) closeableImageRef.get()).getUnderlyingBitmap();
}
try {
onNewResultImpl(bitmap);
} finally {
CloseableReference.closeSafely(closeableImageRef);
}
}
示例5: getDataSourceSupplier
import com.facebook.datasource.DataSource; //导入依赖的package包/类
/**
* Returns a DataSource supplier that will on get submit the request for execution and return a
* DataSource representing the pending results of the task.
*
* @param imageRequest the request to submit (what to execute).
* @param callerContext the caller context of the caller of data source supplier
* @param requestLevel which level to look down until for the image
* @return a DataSource representing pending results and completion of the request
*/
public Supplier<DataSource<CloseableReference<CloseableImage>>> getDataSourceSupplier(
final ImageRequest imageRequest,
final Object callerContext,
final ImageRequest.RequestLevel requestLevel) {
return new Supplier<DataSource<CloseableReference<CloseableImage>>>() {
@Override
public DataSource<CloseableReference<CloseableImage>> get() {
return fetchDecodedImage(imageRequest, callerContext, requestLevel);
}
@Override
public String toString() {
return Objects.toStringHelper(this)
.add("uri", imageRequest.getSourceUri())
.toString();
}
};
}
示例6: getEncodedImageDataSourceSupplier
import com.facebook.datasource.DataSource; //导入依赖的package包/类
/**
* Returns a DataSource supplier that will on get submit the request for execution and return a
* DataSource representing the pending results of the task.
*
* @param imageRequest the request to submit (what to execute).
* @return a DataSource representing pending results and completion of the request
*/
public Supplier<DataSource<CloseableReference<PooledByteBuffer>>>
getEncodedImageDataSourceSupplier(
final ImageRequest imageRequest,
final Object callerContext) {
return new Supplier<DataSource<CloseableReference<PooledByteBuffer>>>() {
@Override
public DataSource<CloseableReference<PooledByteBuffer>> get() {
return fetchEncodedImage(imageRequest, callerContext);
}
@Override
public String toString() {
return Objects.toStringHelper(this)
.add("uri", imageRequest.getSourceUri())
.toString();
}
};
}
示例7: fetchDecodedImage
import com.facebook.datasource.DataSource; //导入依赖的package包/类
/**
* Submits a request for execution and returns a DataSource representing the pending decoded
* image(s).
* <p>The returned DataSource must be closed once the client has finished with it.
*
* @param imageRequest the request to submit
* @param callerContext the caller context for image request
* @param lowestPermittedRequestLevelOnSubmit the lowest request level permitted for image request
* @return a DataSource representing the pending decoded image(s)
*/
public DataSource<CloseableReference<CloseableImage>> fetchDecodedImage(
ImageRequest imageRequest,
Object callerContext,
ImageRequest.RequestLevel lowestPermittedRequestLevelOnSubmit) {
try {
Producer<CloseableReference<CloseableImage>> producerSequence =
mProducerSequenceFactory.getDecodedImageProducerSequence(imageRequest);
return submitFetchRequest(
producerSequence,
imageRequest,
lowestPermittedRequestLevelOnSubmit,
callerContext);
} catch (Exception exception) {
return DataSources.immediateFailedDataSource(exception);
}
}
示例8: prefetchToBitmapCache
import com.facebook.datasource.DataSource; //导入依赖的package包/类
/**
* Submits a request for prefetching to the bitmap cache.
*
* <p> Beware that if your network fetcher doesn't support priorities prefetch requests may slow
* down images which are immediately required on screen.
*
* @param imageRequest the request to submit
* @return a DataSource that can safely be ignored.
*/
public DataSource<Void> prefetchToBitmapCache(
ImageRequest imageRequest,
Object callerContext) {
if (!mIsPrefetchEnabledSupplier.get()) {
return DataSources.immediateFailedDataSource(PREFETCH_EXCEPTION);
}
try {
Producer<Void> producerSequence = mSuppressBitmapPrefetchingSupplier.get()
? mProducerSequenceFactory.getEncodedImagePrefetchProducerSequence(imageRequest)
: mProducerSequenceFactory.getDecodedImagePrefetchProducerSequence(imageRequest);
return submitPrefetchRequest(
producerSequence,
imageRequest,
ImageRequest.RequestLevel.FULL_FETCH,
callerContext,
Priority.MEDIUM);
} catch (Exception exception) {
return DataSources.immediateFailedDataSource(exception);
}
}
示例9: prefetchToDiskCache
import com.facebook.datasource.DataSource; //导入依赖的package包/类
/**
* Submits a request for prefetching to the disk cache.
*
* <p> Beware that if your network fetcher doesn't support priorities prefetch requests may slow
* down images which are immediately required on screen.
*
* @param imageRequest the request to submit
* @param priority custom priority for the fetch
* @return a DataSource that can safely be ignored.
*/
public DataSource<Void> prefetchToDiskCache(
ImageRequest imageRequest,
Object callerContext,
Priority priority) {
if (!mIsPrefetchEnabledSupplier.get()) {
return DataSources.immediateFailedDataSource(PREFETCH_EXCEPTION);
}
try {
Producer<Void> producerSequence =
mProducerSequenceFactory.getEncodedImagePrefetchProducerSequence(imageRequest);
return submitPrefetchRequest(
producerSequence,
imageRequest,
ImageRequest.RequestLevel.FULL_FETCH,
callerContext,
priority);
} catch (Exception exception) {
return DataSources.immediateFailedDataSource(exception);
}
}
示例10: verifyState
import com.facebook.datasource.DataSource; //导入依赖的package包/类
private void verifyState(
boolean isFinished,
boolean hasResult,
Object result,
boolean hasFailed,
Throwable failureCause) {
DataSource<Object> dataSource = mDataSource;
assertEquals("isFinished", isFinished, dataSource.isFinished());
assertEquals("hasResult", hasResult, dataSource.hasResult());
assertSame("getResult", result, dataSource.getResult());
assertEquals("hasFailed", hasFailed, dataSource.hasFailed());
if (failureCause == NPE) {
assertNotNull("failure", dataSource.getFailureCause());
assertSame("failure", NullPointerException.class, dataSource.getFailureCause().getClass());
} else {
assertSame("failure", failureCause, dataSource.getFailureCause());
}
}
示例11: verifyState
import com.facebook.datasource.DataSource; //导入依赖的package包/类
private void verifyState(
boolean isFinished,
boolean hasResult,
CloseableReference<Object> resultRef,
boolean hasFailed,
Throwable failureCause) {
DataSource<CloseableReference<Object>> dataSource = mDataSource;
assertEquals("isFinished", isFinished, dataSource.isFinished());
assertEquals("hasResult", hasResult, dataSource.hasResult());
CloseableReference<Object> dataSourceRef = dataSource.getResult();
assertReferencesSame("getResult", resultRef, dataSourceRef);
CloseableReference.closeSafely(dataSourceRef);
assertEquals("hasFailed", hasFailed, dataSource.hasFailed());
if (failureCause == NPE) {
assertNotNull("failure", dataSource.getFailureCause());
assertSame("failure", NullPointerException.class, dataSource.getFailureCause().getClass());
} else {
assertSame("failure", failureCause, dataSource.getFailureCause());
}
}
示例12: testPrefetchToBitmapCache
import com.facebook.datasource.DataSource; //导入依赖的package包/类
@Test
public void testPrefetchToBitmapCache() {
Producer<Void> prefetchProducerSequence = mock(Producer.class);
when(mProducerSequenceFactory.getDecodedImagePrefetchProducerSequence(mImageRequest))
.thenReturn(prefetchProducerSequence);
DataSource<Void> dataSource =
mImagePipeline.prefetchToBitmapCache(mImageRequest, mCallerContext);
assertTrue(!dataSource.isFinished());
verify(mRequestListener1).onRequestStart(mImageRequest, mCallerContext, "0", true);
verify(mRequestListener2).onRequestStart(mImageRequest, mCallerContext, "0", true);
ArgumentCaptor<ProducerContext> producerContextArgumentCaptor =
ArgumentCaptor.forClass(ProducerContext.class);
verify(prefetchProducerSequence)
.produceResults(any(Consumer.class), producerContextArgumentCaptor.capture());
assertFalse(producerContextArgumentCaptor.getValue().isIntermediateResultExpected());
assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.MEDIUM);
}
示例13: testFetchDecodedImage
import com.facebook.datasource.DataSource; //导入依赖的package包/类
@Test
public void testFetchDecodedImage() {
Producer<CloseableReference<CloseableImage>> decodedSequence = mock(Producer.class);
when(mProducerSequenceFactory.getDecodedImageProducerSequence(mImageRequest))
.thenReturn(decodedSequence);
DataSource<CloseableReference<CloseableImage>> dataSource =
mImagePipeline.fetchDecodedImage(mImageRequest, mCallerContext);
assertFalse(dataSource.isFinished());
verify(mRequestListener1).onRequestStart(mImageRequest, mCallerContext, "0", false);
verify(mRequestListener2).onRequestStart(mImageRequest, mCallerContext, "0", false);
ArgumentCaptor<ProducerContext> producerContextArgumentCaptor =
ArgumentCaptor.forClass(ProducerContext.class);
verify(decodedSequence)
.produceResults(any(Consumer.class), producerContextArgumentCaptor.capture());
assertTrue(producerContextArgumentCaptor.getValue().isIntermediateResultExpected());
assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.HIGH);
}
示例14: testFetchDecodedImageWithRequestLevel
import com.facebook.datasource.DataSource; //导入依赖的package包/类
@Test
public void testFetchDecodedImageWithRequestLevel() {
Producer<CloseableReference<CloseableImage>> decodedSequence = mock(Producer.class);
when(mProducerSequenceFactory.getDecodedImageProducerSequence(mImageRequest))
.thenReturn(decodedSequence);
DataSource<CloseableReference<CloseableImage>> dataSource =
mImagePipeline.fetchDecodedImage(
mImageRequest,
mCallerContext,
ImageRequest.RequestLevel.DISK_CACHE);
assertFalse(dataSource.isFinished());
verify(mRequestListener1).onRequestStart(mImageRequest, mCallerContext, "0", false);
verify(mRequestListener2).onRequestStart(mImageRequest, mCallerContext, "0", false);
ArgumentCaptor<ProducerContext> producerContextArgumentCaptor =
ArgumentCaptor.forClass(ProducerContext.class);
verify(decodedSequence)
.produceResults(any(Consumer.class), producerContextArgumentCaptor.capture());
assertTrue(producerContextArgumentCaptor.getValue().isIntermediateResultExpected());
assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.HIGH);
assertEquals(
producerContextArgumentCaptor.getValue().getLowestPermittedRequestLevel(),
ImageRequest.RequestLevel.DISK_CACHE);
}
示例15: testGetBitmapCacheGetSupplier
import com.facebook.datasource.DataSource; //导入依赖的package包/类
@Test
public void testGetBitmapCacheGetSupplier() {
Supplier<DataSource<CloseableReference<CloseableImage>>> dataSourceSupplier =
mImagePipeline.getDataSourceSupplier(
mImageRequest,
mCallerContext,
ImageRequest.RequestLevel.BITMAP_MEMORY_CACHE);
Producer<CloseableReference<CloseableImage>> bitmapCacheSequence = mock(Producer.class);
when(mProducerSequenceFactory.getDecodedImageProducerSequence(mImageRequest))
.thenReturn(bitmapCacheSequence);
dataSourceSupplier.get();
verify(mRequestListener1).onRequestStart(mImageRequest, mCallerContext, "0", false);
verify(mRequestListener2).onRequestStart(mImageRequest, mCallerContext, "0", false);
ArgumentCaptor<ProducerContext> producerContextArgumentCaptor =
ArgumentCaptor.forClass(ProducerContext.class);
verify(bitmapCacheSequence)
.produceResults(any(Consumer.class), producerContextArgumentCaptor.capture());
assertTrue(producerContextArgumentCaptor.getValue().isIntermediateResultExpected());
assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.HIGH);
}