本文整理匯總了Java中com.bumptech.glide.load.model.ModelLoader類的典型用法代碼示例。如果您正苦於以下問題:Java ModelLoader類的具體用法?Java ModelLoader怎麽用?Java ModelLoader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ModelLoader類屬於com.bumptech.glide.load.model包,在下文中一共展示了ModelLoader類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getLoadData
import com.bumptech.glide.load.model.ModelLoader; //導入依賴的package包/類
List<LoadData<?>> getLoadData() {
if (!isLoadDataSet) {
isLoadDataSet = true;
loadData.clear();
List<ModelLoader<Object, ?>> modelLoaders = glideContext.getRegistry().getModelLoaders(model);
int size = modelLoaders.size();
for (int i = 0; i < size; i++) {
ModelLoader<Object, ?> modelLoader = modelLoaders.get(i);
LoadData<?> current =
modelLoader.buildLoadData(model, width, height, options);
if (current != null) {
loadData.add(current);
}
}
}
return loadData;
}
示例2: registerFailFactory
import com.bumptech.glide.load.model.ModelLoader; //導入依賴的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);
}
示例3: mockStreamModelLoader
import com.bumptech.glide.load.model.ModelLoader; //導入依賴的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;
}
示例4: registerMockModelLoader
import com.bumptech.glide.load.model.ModelLoader; //導入依賴的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);
}
示例5: testBuildsNewUrlIfNotPresentInCache
import com.bumptech.glide.load.model.ModelLoader; //導入依賴的package包/類
@Test
public void testBuildsNewUrlIfNotPresentInCache() {
int width = 10;
int height = 11;
urlLoader.resultUrl = "fakeUrl";
when(wrapped.buildLoadData(any(GlideUrl.class), eq(width), eq(height), eq(options)))
.thenAnswer(new Answer<ModelLoader.LoadData<InputStream>>() {
@Override
public ModelLoader.LoadData<InputStream> answer(InvocationOnMock invocationOnMock)
throws Throwable {
GlideUrl glideUrl = (GlideUrl) invocationOnMock.getArguments()[0];
assertEquals(urlLoader.resultUrl, glideUrl.toStringUrl());
return new ModelLoader.LoadData<>(mock(Key.class), fetcher);
}
});
assertEquals(fetcher,
urlLoader.buildLoadData(new GlideUrl(urlLoader.resultUrl), width, height, options).fetcher);
}
示例6: registerFailFactory
import com.bumptech.glide.load.model.ModelLoader; //導入依賴的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);
}
示例7: testBuildsNewUrlIfNotPresentInCache
import com.bumptech.glide.load.model.ModelLoader; //導入依賴的package包/類
@Test
public void testBuildsNewUrlIfNotPresentInCache() {
int width = 10;
int height = 11;
urlLoader.resultUrl = "fakeUrl";
when(wrapped.buildLoadData(any(GlideUrl.class), eq(width), eq(height), eq(options)))
.thenAnswer(new Answer<ModelLoader.LoadData<InputStream>>() {
@Override
public ModelLoader.LoadData<InputStream> answer(InvocationOnMock invocationOnMock)
throws Throwable {
GlideUrl glideUrl = (GlideUrl) invocationOnMock.getArguments()[0];
assertEquals(urlLoader.resultUrl, glideUrl.toStringUrl());
return new ModelLoader.LoadData<>(mock(Key.class), fetcher);
}
});
assertEquals(
fetcher,
Preconditions.checkNotNull(
urlLoader.buildLoadData(
new GlideUrl(urlLoader.resultUrl), width, height, options)).fetcher);
}
示例8: testDoesNotInteractWithModelCacheIfNull
import com.bumptech.glide.load.model.ModelLoader; //導入依賴的package包/類
@Test
public void testDoesNotInteractWithModelCacheIfNull() {
TestLoader urlLoader = new TestLoader(wrapped, null);
urlLoader.resultUrl = "fakeUrl";
int width = 456;
int height = 789;
when(wrapped.buildLoadData(any(GlideUrl.class), eq(width), eq(height), eq(options)))
.thenReturn(new ModelLoader.LoadData<>(mock(Key.class), fetcher));
assertEquals(
fetcher,
Preconditions.checkNotNull(
urlLoader.buildLoadData(new Object(), width, height, options)).fetcher);
}
示例9: onSizeReady
import com.bumptech.glide.load.model.ModelLoader; //導入依賴的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;
}
示例10: startNext
import com.bumptech.glide.load.model.ModelLoader; //導入依賴的package包/類
@Override
public boolean startNext() {
while (modelLoaders == null || !hasNextModelLoader()) {
sourceIdIndex++;
if (sourceIdIndex >= cacheKeys.size()) {
return false;
}
Key sourceId = cacheKeys.get(sourceIdIndex);
Key originalKey = new DataCacheKey(sourceId, helper.getSignature());
cacheFile = helper.getDiskCache().get(originalKey);
if (cacheFile != null) {
this.sourceKey = sourceId;
modelLoaders = helper.getModelLoaders(cacheFile);
modelLoaderIndex = 0;
}
}
loadData = null;
boolean started = false;
while (!started && hasNextModelLoader()) {
ModelLoader<File, ?> modelLoader = modelLoaders.get(modelLoaderIndex++);
loadData =
modelLoader.buildLoadData(cacheFile, helper.getWidth(), helper.getHeight(),
helper.getOptions());
if (loadData != null && helper.hasLoadPath(loadData.fetcher.getDataClass())) {
started = true;
loadData.fetcher.loadData(helper.getPriority(), this);
}
}
return started;
}
示例11: getModelLoaders
import com.bumptech.glide.load.model.ModelLoader; //導入依賴的package包/類
public <Model> List<ModelLoader<Model, ?>> getModelLoaders(Model model) {
List<ModelLoader<Model, ?>> result = modelLoaderRegistry.getModelLoaders(model);
if (result.isEmpty()) {
throw new NoModelLoaderAvailableException(model);
}
return result;
}
示例12: registerMockStreamModelLoader
import com.bumptech.glide.load.model.ModelLoader; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private <T> void registerMockStreamModelLoader(final Class<T> modelClass) {
ModelLoader<T, InputStream> modelLoader = mockStreamModelLoader(modelClass);
ModelLoaderFactory<T, InputStream> modelLoaderFactory = mock(ModelLoaderFactory.class);
when(modelLoaderFactory.build(isA(MultiModelLoaderFactory.class))).thenReturn(modelLoader);
Glide.get(RuntimeEnvironment.application).getRegistry()
.prepend(modelClass, InputStream.class, modelLoaderFactory);
}
示例13: testReturnsUrlFromCacheIfPresent
import com.bumptech.glide.load.model.ModelLoader; //導入依賴的package包/類
@Test
public void testReturnsUrlFromCacheIfPresent() {
Object model = new Object();
int width = 100;
int height = 200;
GlideUrl expectedUrl = mock(GlideUrl.class);
when(modelCache.get(eq(model), eq(width), eq(height))).thenReturn(expectedUrl);
when(wrapped.buildLoadData(eq(expectedUrl), eq(width), eq(height), eq(options)))
.thenReturn(new ModelLoader.LoadData<>(mock(Key.class), fetcher));
assertEquals(fetcher, urlLoader.buildLoadData(model, width, height, options).fetcher);
}
示例14: testDoesNotInteractWithModelCacheIfNull
import com.bumptech.glide.load.model.ModelLoader; //導入依賴的package包/類
@Test
public void testDoesNotInteractWithModelCacheIfNull() {
TestLoader urlLoader = new TestLoader(wrapped, null);
urlLoader.resultUrl = "fakeUrl";
int width = 456;
int height = 789;
when(wrapped.buildLoadData(any(GlideUrl.class), eq(width), eq(height), eq(options)))
.thenReturn(new ModelLoader.LoadData<>(mock(Key.class), fetcher));
assertEquals(fetcher, urlLoader.buildLoadData(new Object(), width, height, options).fetcher);
}
示例15: registerMockStreamModelLoader
import com.bumptech.glide.load.model.ModelLoader; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private <T> void registerMockStreamModelLoader(final Class<T> modelClass) {
ModelLoader<T, InputStream> modelLoader = mockStreamModelLoader(modelClass);
ModelLoaderFactory<T, InputStream> modelLoaderFactory = mock(ModelLoaderFactory.class);
when(modelLoaderFactory.build(isA(MultiModelLoaderFactory.class))).thenReturn(modelLoader);
Glide.get(context).getRegistry()
.prepend(modelClass, InputStream.class, modelLoaderFactory);
}