本文整理汇总了Java中com.bumptech.glide.load.data.DataFetcher类的典型用法代码示例。如果您正苦于以下问题:Java DataFetcher类的具体用法?Java DataFetcher怎么用?Java DataFetcher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DataFetcher类属于com.bumptech.glide.load.data包,在下文中一共展示了DataFetcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResourceFetcher
import com.bumptech.glide.load.data.DataFetcher; //导入依赖的package包/类
@Override
public DataFetcher<InputStream> getResourceFetcher(final String model, int i, int i1) {
return new DataFetcher<InputStream>() {
@Override
public InputStream loadData(Priority priority) throws Exception {
throw new IOException();
}
@Override
public void cleanup() {
}
@Override
public String getId() {
return model;
}
@Override
public void cancel() {
}
};
}
示例2: decodeFromData
import com.bumptech.glide.load.data.DataFetcher; //导入依赖的package包/类
private <Data> Resource<R> decodeFromData(DataFetcher<?> fetcher, Data data,
DataSource dataSource) throws GlideException {
try {
if (data == null) {
return null;
}
long startTime = LogTime.getLogTime();
Resource<R> result = decodeFromFetcher(data, dataSource);
if (Log.isLoggable(TAG, Log.VERBOSE)) {
logWithTimeAndKey("Decoded result " + result, startTime);
}
return result;
} finally {
fetcher.cleanup();
}
}
示例3: buildLoadData
import com.bumptech.glide.load.data.DataFetcher; //导入依赖的package包/类
@Override
public LoadData<Data> buildLoadData(Model model, int width, int height,
Options options) {
Key sourceKey = null;
int size = modelLoaders.size();
List<DataFetcher<Data>> fetchers = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
ModelLoader<Model, Data> modelLoader = modelLoaders.get(i);
if (modelLoader.handles(model)) {
LoadData<Data> loadData = modelLoader.buildLoadData(model, width, height, options);
if (loadData != null) {
sourceKey = loadData.sourceKey;
fetchers.add(loadData.fetcher);
}
}
}
return !fetchers.isEmpty()
? new LoadData<>(sourceKey, new MultiFetcher<>(fetchers, exceptionListPool)) : null;
}
示例4: registerFailFactory
import com.bumptech.glide.load.data.DataFetcher; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <T, Z> void registerFailFactory(Class<T> failModel, Class<Z> failResource)
throws Exception {
DataFetcher<Z> failFetcher = mock(DataFetcher.class);
doAnswer(new Util.CallDataReady<>(null))
.when(failFetcher)
.loadData(isA(Priority.class), isA(DataFetcher.DataCallback.class));
when(failFetcher.getDataClass()).thenReturn(failResource);
ModelLoader<T, Z> failLoader = mock(ModelLoader.class);
when(failLoader.buildLoadData(isA(failModel), anyInt(), anyInt(), isA(Options.class)))
.thenReturn(new ModelLoader.LoadData<>(mock(Key.class), failFetcher));
when(failLoader.handles(isA(failModel))).thenReturn(true);
ModelLoaderFactory<T, Z> failFactory = mock(ModelLoaderFactory.class);
when(failFactory.build(isA(MultiModelLoaderFactory.class))).thenReturn(failLoader);
Glide.get(getContext()).getRegistry().prepend(failModel, failResource, failFactory);
}
示例5: mockStreamModelLoader
import com.bumptech.glide.load.data.DataFetcher; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <T> ModelLoader<T, InputStream> mockStreamModelLoader(final Class<T> modelClass) {
ModelLoader<T, InputStream> modelLoader = mock(ModelLoader.class);
DataFetcher<InputStream> fetcher = mock(DataFetcher.class);
try {
doAnswer(new Util.CallDataReady<>(new ByteArrayInputStream(new byte[0]))).when(fetcher)
.loadData(isA(Priority.class), isA(DataFetcher.DataCallback.class));
} catch (Exception e) {
// Do nothing.
}
when(fetcher.getDataClass()).thenReturn(InputStream.class);
when(modelLoader.buildLoadData(isA(modelClass), anyInt(), anyInt(), isA(Options.class)))
.thenReturn(new ModelLoader.LoadData<>(mock(Key.class), fetcher));
when(modelLoader.handles(isA(modelClass))).thenReturn(true);
return modelLoader;
}
示例6: registerMockModelLoader
import com.bumptech.glide.load.data.DataFetcher; //导入依赖的package包/类
private static <X, Y> void registerMockModelLoader(Class<X> modelClass, Class<Y> dataClass,
Y loadedData, Registry registry) {
DataFetcher<Y> mockStreamFetcher = mock(DataFetcher.class);
when(mockStreamFetcher.getDataClass()).thenReturn(dataClass);
try {
doAnswer(new Util.CallDataReady<>(loadedData))
.when(mockStreamFetcher)
.loadData(isA(Priority.class), isA(DataFetcher.DataCallback.class));
} catch (Exception e) {
throw new RuntimeException(e);
}
ModelLoader<X, Y> mockUrlLoader = mock(ModelLoader.class);
when(mockUrlLoader.buildLoadData(isA(modelClass), anyInt(), anyInt(), isA(Options.class)))
.thenReturn(new ModelLoader.LoadData<>(mock(Key.class), mockStreamFetcher));
when(mockUrlLoader.handles(isA(modelClass))).thenReturn(true);
ModelLoaderFactory<X, Y> mockUrlLoaderFactory = mock(ModelLoaderFactory.class);
when(mockUrlLoaderFactory.build(isA(MultiModelLoaderFactory.class)))
.thenReturn(mockUrlLoader);
registry.replace(modelClass, dataClass, mockUrlLoaderFactory);
}
示例7: onDataFetcherReady
import com.bumptech.glide.load.data.DataFetcher; //导入依赖的package包/类
@Override
public void onDataFetcherReady(Key sourceKey, Object data, DataFetcher<?> fetcher,
DataSource dataSource, Key attemptedKey) {
this.currentSourceKey = sourceKey;
this.currentData = data;
this.currentFetcher = fetcher;
this.currentDataSource = dataSource;
this.currentAttemptingKey = attemptedKey;
if (Thread.currentThread() != currentThread) {
runReason = RunReason.DECODE_DATA;
callback.reschedule(this);
} else {
TraceCompat.beginSection("DecodeJob.decodeFromRetrievedData");
try {
decodeFromRetrievedData();
} finally {
TraceCompat.endSection();
}
}
}
示例8: registerFailFactory
import com.bumptech.glide.load.data.DataFetcher; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <T, Z> void registerFailFactory(Class<T> failModel, Class<Z> failResource) {
DataFetcher<Z> failFetcher = mock(DataFetcher.class);
doAnswer(new Util.CallDataReady<>(null))
.when(failFetcher)
.loadData(isA(Priority.class), isA(DataFetcher.DataCallback.class));
when(failFetcher.getDataClass()).thenReturn(failResource);
ModelLoader<T, Z> failLoader = mock(ModelLoader.class);
when(failLoader.buildLoadData(isA(failModel), anyInt(), anyInt(), isA(Options.class)))
.thenReturn(new ModelLoader.LoadData<>(mock(Key.class), failFetcher));
when(failLoader.handles(isA(failModel))).thenReturn(true);
ModelLoaderFactory<T, Z> failFactory = mock(ModelLoaderFactory.class);
when(failFactory.build(isA(MultiModelLoaderFactory.class))).thenReturn(failLoader);
Glide.get(context).getRegistry().prepend(failModel, failResource, failFactory);
}
示例9: getResourceFetcher
import com.bumptech.glide.load.data.DataFetcher; //导入依赖的package包/类
@Override
public DataFetcher<InputStream> getResourceFetcher(final String model, int width, int height) {
return new DataFetcher<InputStream>() {
@Override
public InputStream loadData(Priority priority) throws Exception {
throw new IOException("Forced Glide network failure");
}
@Override
public void cleanup() {
}
@Override
public String getId() {
return model;
}
@Override
public void cancel() {
}
};
}
示例10: getResourceFetcher
import com.bumptech.glide.load.data.DataFetcher; //导入依赖的package包/类
@Override
public DataFetcher<InputStream> getResourceFetcher(final AppInfo model, int width, int height) {
return new DataFetcher<InputStream>() {
@Override
public InputStream loadData(Priority priority) throws Exception {
mCancelled = false;
PackageManager pm = mContext.getPackageManager();
if (mCancelled) return null;
return drawableToStream(pm.getApplicationInfo(model.packageName, 0).loadIcon(pm));
}
@Override
public void cleanup() {
}
@Override
public String getId() {
return String.valueOf(model.packageName.hashCode());
}
@Override
public void cancel() {
mCancelled = true;
}
};
}
示例11: getResourceFetcher
import com.bumptech.glide.load.data.DataFetcher; //导入依赖的package包/类
@Override
public DataFetcher<InputStream> getResourceFetcher(final Uri model, int width, int height) {
return new DataFetcher<InputStream>() {
@Override
public InputStream loadData(Priority priority) throws Exception {
throw new IOException();
}
@Override
public void cleanup() {
}
@Override
public String getId() {
return model.toString();
}
@Override
public void cancel() {
}
};
}
示例12: getResourceFetcher
import com.bumptech.glide.load.data.DataFetcher; //导入依赖的package包/类
@Override
public DataFetcher<InputStream> getResourceFetcher(final String model, int i, int i1) {
return new DataFetcher<InputStream>() {
@Override
public InputStream loadData(Priority priority) {
return null;
}
@Override
public void cleanup() {
}
@Override
public String getId() {
return model;
}
@Override
public void cancel() {
}
};
}
示例13: getResourceFetcher
import com.bumptech.glide.load.data.DataFetcher; //导入依赖的package包/类
@Override
public DataFetcher<InputStream> getResourceFetcher(final String model, int width, int height) {
return new DataFetcher<InputStream>() {
@Override
public InputStream loadData(Priority priority) throws Exception {
return new NfsFileInputStream(ctx, model);
}
@Override
public void cleanup() { }
@Override
public String getId() {
return model;
}
@Override
public void cancel() { }
};
}
示例14: onSizeReady
import com.bumptech.glide.load.data.DataFetcher; //导入依赖的package包/类
@Override
public void onSizeReady(int width, int height) {
if (isCancelled) {
return;
}
width = Math.round(sizeMultiplier * width);
height = Math.round(sizeMultiplier * height);
ResourceDecoder<InputStream, Z> cacheDecoder = loadProvider.getCacheDecoder();
ResourceDecoder<T, Z> decoder = loadProvider.getSourceDecoder();
ResourceEncoder <Z> encoder = loadProvider.getEncoder();
ResourceTranscoder<Z, R> transcoder = loadProvider.getTranscoder();
ModelLoader<A, T> modelLoader = loadProvider.getModelLoader();
final String id = modelLoader.getId(model);
final DataFetcher<T> dataFetcher = modelLoader.getResourceFetcher(model, width, height);
loadedFromMemoryCache = true;
loadStatus = engine.load(id, width, height, cacheDecoder, dataFetcher, decoder, transformation,
encoder, transcoder, priority, isMemoryCacheable, this);
loadedFromMemoryCache = resource != null;
}
示例15: getResourceFetcher
import com.bumptech.glide.load.data.DataFetcher; //导入依赖的package包/类
@Override
public DataFetcher<InputStream> getResourceFetcher(T model, int width, int height) {
final String id = getId(model);
GlideUrl result = null;
if (modelCache != null) {
result = modelCache.get(id, width, height);
}
if (result == null) {
String stringURL = getUrl(model, width, height);
result = new GlideUrl(stringURL);
if (modelCache != null) {
modelCache.put(id, width, height, result);
}
}
return concreteLoader.getResourceFetcher(result, width, height);
}