本文整理了Java中com.bumptech.glide.RequestBuilder
类的一些代码示例,展示了RequestBuilder
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RequestBuilder
类的具体详情如下:
包路径:com.bumptech.glide.RequestBuilder
类名称:RequestBuilder
[英]A generic class that can handle setting options and staring loads for generic resource types.
[中]一个泛型类,可以处理泛型资源类型的设置选项和启动负载。
代码示例来源:origin: bumptech/glide
@Override
public void runTest() {
getNullModelRequest().into(imageView);
}
});
代码示例来源:origin: zhihu/Matisse
@Override
public void loadGifThumbnail(Context context, int resize, Drawable placeholder, ImageView imageView,
Uri uri) {
Glide.with(context)
.asBitmap() // some .jpeg files are actually gif
.load(uri)
.apply(new RequestOptions()
.override(resize, resize)
.placeholder(placeholder)
.centerCrop())
.into(imageView);
}
代码示例来源:origin: bumptech/glide
private void loadNet() {
Uri uri = Uri.parse("http://www.clker.com/cliparts/u/Z/2/b/a/6/android-toy-h.svg");
requestBuilder.load(uri).into(imageViewNet);
}
}
代码示例来源:origin: bumptech/glide
@NonNull
@CheckResult
protected RequestBuilder<File> getDownloadOnlyRequest() {
return new RequestBuilder<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS);
}
代码示例来源:origin: bumptech/glide
@Test
public void testNullModelResolvesToUsePlaceholder() {
Drawable placeholder = new ColorDrawable(Color.GREEN);
requestManager
.load(NULL)
.apply(placeholderOf(placeholder))
.into(target);
verify(target).onLoadFailed(eq(placeholder));
}
代码示例来源:origin: bumptech/glide
@Override
public void run() throws Throwable {
Glide.with(context)
.load(ResourceIds.drawable.shape_drawable)
.apply(centerCropTransform())
.submit()
.get();
}
});
代码示例来源:origin: bumptech/glide
@Test
public void testReceivesRecursiveThumbnailWithPercentage() {
requestManager.load(mockUri("content://first"))
.thumbnail(requestManager.load(mockUri("content://second")).thumbnail(0.5f))
.into(target);
verify(target, times(3)).onResourceReady(isA(Drawable.class), isA(Transition.class));
}
代码示例来源:origin: bumptech/glide
@Test
public void testClone() {
Target<Drawable> firstTarget = mock(Target.class);
doAnswer(new CallSizeReady(100, 100)).when(firstTarget).getSize(isA(SizeReadyCallback.class));
Target<Drawable> secondTarget = mock(Target.class);
doAnswer(new CallSizeReady(100, 100)).when(secondTarget).getSize(isA(SizeReadyCallback.class));
RequestBuilder<Drawable> firstRequest = requestManager
.load(mockUri("content://first"));
firstRequest.into(firstTarget);
firstRequest.clone()
.apply(placeholderOf(new ColorDrawable(Color.RED)))
.into(secondTarget);
verify(firstTarget).onResourceReady(isA(Drawable.class), isA(Transition.class));
verify(secondTarget).onResourceReady(notNull(Drawable.class), isA(Transition.class));
}
代码示例来源:origin: bumptech/glide
@Test
public void load_withStateListDrawableResourceId_asBitmap_withTransformation_nonNullBitmap()
throws ExecutionException, InterruptedException {
Bitmap bitmap = Glide.with(context)
.asBitmap()
.load(ResourceIds.drawable.state_list_drawable)
.apply(centerCropTransform())
.submit()
.get();
assertThat(bitmap).isNotNull();
}
代码示例来源:origin: bumptech/glide
@SuppressLint("CheckResult")
@SuppressWarnings("PMD.ConstructorCallsOverridableMethod")
protected RequestBuilder(Class<TranscodeType> transcodeClass, RequestBuilder<?> other) {
this(other.glide, other.requestManager, transcodeClass, other.context);
model = other.model;
isModelSet = other.isModelSet;
// This is safe because it will always mutate, no one else has access to the object.
apply(other);
}
代码示例来源:origin: bumptech/glide
@Test
public void testListenerApiOverridesListeners() {
getNullModelRequest().addListener(listener1).listener(listener2).into(target);
verify(requestManager).track(any(Target.class), requestCaptor.capture());
requestCaptor.getValue().onResourceReady(new SimpleResource<>(new Object()), DataSource.LOCAL);
// The #listener API removes any previous listeners, so the first listener should not be called.
verify(listener1, never())
.onResourceReady(
any(), any(), isA(Target.class), isA(DataSource.class), anyBoolean());
verify(listener2)
.onResourceReady(
any(), any(), isA(Target.class), isA(DataSource.class), anyBoolean());
}
代码示例来源:origin: bumptech/glide
private void runTestStringDefaultLoader(String string) {
requestManager.load(string).listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(GlideException e, Object model, Target<Drawable> target,
boolean isFirstResource) {
throw new RuntimeException("Load failed");
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target,
DataSource dataSource, boolean isFirstResource) {
return false;
}
}).into(target);
requestManager.load(string).into(imageView);
verify(target).onResourceReady(isA(BitmapDrawable.class), isA(Transition.class));
verify(target).setRequest((Request) notNull());
assertNotNull(imageView.getDrawable());
}
代码示例来源:origin: bumptech/glide
@Test
public void loadBitmapDrawable_asBytes_providesBytesOfBitmap() {
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical);
byte[] data =
concurrency.get(
Glide.with(context)
.as(byte[].class)
.load(new BitmapDrawable(context.getResources(), bitmap))
.submit());
assertThat(data).isNotNull();
assertThat(BitmapFactory.decodeByteArray(data, 0, data.length)).isNotNull();
}
代码示例来源:origin: bumptech/glide
@Test
public void testMultipleRequestListeners() {
getNullModelRequest().addListener(listener1).addListener(listener2).into(target);
verify(requestManager).track(any(Target.class), requestCaptor.capture());
requestCaptor.getValue().onResourceReady(new SimpleResource<>(new Object()), DataSource.LOCAL);
verify(listener1)
.onResourceReady(
any(), any(), isA(Target.class), isA(DataSource.class), anyBoolean());
verify(listener2)
.onResourceReady(
any(), any(), isA(Target.class), isA(DataSource.class), anyBoolean());
}
代码示例来源:origin: bumptech/glide
@Test
public void requestBuilder_intoImageView_withSameByteArrayAndMemoryCacheEnabled_loadsFromMemory()
throws IOException {
final byte[] canonicalBytes = getCanonicalBytes();
concurrency.loadOnMainThread(
Glide.with(context)
.asDrawable()
.load(canonicalBytes)
.apply(skipMemoryCacheOf(false)),
imageView);
Glide.with(context).clear(imageView);
concurrency.loadOnMainThread(
Glide.with(context)
.asDrawable()
.load(canonicalBytes)
.listener(requestListener)
.apply(skipMemoryCacheOf(false)),
imageView);
verify(requestListener).onResourceReady(
anyDrawable(), any(), anyDrawableTarget(), eq(DataSource.MEMORY_CACHE), anyBoolean());
}
代码示例来源:origin: bumptech/glide
@Test
public void requestManager_intoImageView_withSameByteArrayAndMemoryCacheEnabled_loadsFromMemory()
throws IOException {
final byte[] canonicalBytes = getCanonicalBytes();
concurrency.loadOnMainThread(
Glide.with(context)
.load(canonicalBytes)
.apply(skipMemoryCacheOf(false)),
imageView);
Glide.with(context).clear(imageView);
concurrency.loadOnMainThread(
Glide.with(context)
.load(canonicalBytes)
.listener(requestListener)
.apply(skipMemoryCacheOf(false)),
imageView);
verify(requestListener).onResourceReady(
anyDrawable(), any(), anyDrawableTarget(), eq(DataSource.MEMORY_CACHE), anyBoolean());
}
代码示例来源:origin: bumptech/glide
@Nullable
@Override
public RequestBuilder<Drawable> getPreloadRequestBuilder(@NonNull Api.GifResult item) {
return requestBuilder.load(item);
}
}
代码示例来源:origin: bumptech/glide
@SuppressLint("CheckResult")
@SuppressWarnings("PMD.ConstructorCallsOverridableMethod")
protected RequestBuilder(
@NonNull Glide glide,
RequestManager requestManager,
Class<TranscodeType> transcodeClass,
Context context) {
this.glide = glide;
this.requestManager = requestManager;
this.transcodeClass = transcodeClass;
this.context = context;
this.transitionOptions = requestManager.getDefaultTransitionOptions(transcodeClass);
this.glideContext = glide.getGlideContext();
initRequestListeners(requestManager.getDefaultRequestListeners());
apply(requestManager.getDefaultRequestOptions());
}
代码示例来源:origin: bumptech/glide
private RequestBuilder<Object> getNullModelRequest() {
when(glideContext.buildImageViewTarget(isA(ImageView.class), isA(Class.class)))
.thenReturn(mock(ViewTarget.class));
when(glideContext.getDefaultRequestOptions()).thenReturn(new RequestOptions());
when(requestManager.getDefaultRequestOptions())
.thenReturn(new RequestOptions());
when(requestManager.getDefaultTransitionOptions(any(Class.class)))
.thenReturn(new GenericTransitionOptions<>());
return new RequestBuilder<>(glide, requestManager, Object.class, context)
.load((Object) null);
}
}
代码示例来源:origin: bumptech/glide
@Test
public void load_whenEncoderFails_callsUncaughtThrowableStrategy() {
WaitForErrorStrategy strategy = new WaitForErrorStrategy();
Glide.init(context,
new GlideBuilder()
.setAnimationExecutor(GlideExecutor.newAnimationExecutor(/*threadCount=*/ 1, strategy))
.setSourceExecutor(GlideExecutor.newSourceExecutor(strategy))
.setDiskCacheExecutor(GlideExecutor.newDiskCacheExecutor(strategy)));
Glide.get(context).getRegistry().prepend(Bitmap.class, new FailEncoder());
concurrency.get(
Glide.with(context)
.load(ResourceIds.raw.canonical)
.listener(requestListener)
.submit());
// Writing to the disk cache and therefore the exception caused by our FailEncoder may happen
// after the request completes, so we should wait for the expected error explicitly.
ConcurrencyHelper.waitOnLatch(strategy.latch);
assertThat(strategy.error).isEqualTo(FailEncoder.TO_THROW);
verify(requestListener, never())
.onLoadFailed(any(GlideException.class), any(), anyDrawableTarget(), anyBoolean());
}
内容来源于网络,如有侵权,请联系作者删除!