com.bumptech.glide.RequestBuilder.apply()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(111)

本文整理了Java中com.bumptech.glide.RequestBuilder.apply方法的一些代码示例,展示了RequestBuilder.apply的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RequestBuilder.apply方法的具体详情如下:
包路径:com.bumptech.glide.RequestBuilder
类名称:RequestBuilder
方法名:apply

RequestBuilder.apply介绍

[英]Applies the given options to the request.

As with RequestOptions#apply(BaseRequestOptions), #apply only replaces those values that are explicitly set in the given RequestOptions object. If you need to completely reset all previously set options, create a new RequestBuilder instead of using this method.
[中]将给定选项应用于请求。
与RequestOptions#apply(BaseRequestOptions)一样,#apply只替换在给定RequestOptions对象中显式设置的值。如果需要完全重置之前设置的所有选项,请创建一个新的RequestBuilder,而不是使用此方法。

代码示例

代码示例来源: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

@NonNull
@CheckResult
protected RequestBuilder<File> getDownloadOnlyRequest() {
 return new RequestBuilder<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS);
}

代码示例来源:origin: bumptech/glide

/**
 * Attempts to always load the resource as a {@link android.graphics.Bitmap}, even if it could
 * actually be animated.
 *
 * @return A new request builder for loading a {@link android.graphics.Bitmap}
 */
@NonNull
@CheckResult
public RequestBuilder<Bitmap> asBitmap() {
 return as(Bitmap.class).apply(DECODE_TYPE_BITMAP);
}

代码示例来源:origin: bumptech/glide

@SuppressWarnings("unchecked")
@Test
public void testSetFrameTransformationSetsTransformationOnRequestBuilder() {
 verify(requestBuilder, times(2)).apply(isA(RequestOptions.class));
 Transformation<Bitmap> transformation = mock(Transformation.class);
 loader.setFrameTransformation(transformation, firstFrame);
 verify(requestBuilder, times(3)).apply(isA(RequestOptions.class));
}

代码示例来源:origin: bumptech/glide

void setFrameTransformation(Transformation<Bitmap> transformation, Bitmap firstFrame) {
 this.transformation = Preconditions.checkNotNull(transformation);
 this.firstFrame = Preconditions.checkNotNull(firstFrame);
 requestBuilder = requestBuilder.apply(new RequestOptions().transform(transformation));
}

代码示例来源: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

@Test
public void testNullModelPrefersErrorDrawable() {
 Drawable placeholder = new ColorDrawable(Color.GREEN);
 Drawable error = new ColorDrawable(Color.RED);
 requestManager
   .load(NULL)
   .apply(placeholderOf(placeholder)
     .error(error))
   .into(target);
 verify(target).onLoadFailed(eq(error));
}

代码示例来源:origin: bumptech/glide

@Test
public void testGetNextFrameIncrementsSignatureAndAdvancesDecoderBeforeStartingLoad() {
 InOrder order = inOrder(gifDecoder, requestBuilder);
 order.verify(gifDecoder).advance();
 order.verify(requestBuilder).apply(isA(RequestOptions.class));
 order.verify(requestBuilder).into(aTarget());
}

代码示例来源:origin: bumptech/glide

@Override
 public void run() throws Throwable {
  Glide.with(context)
    .load(ResourceIds.drawable.shape_drawable)
    .apply(centerCropTransform())
    .submit()
    .get();
 }
});

代码示例来源:origin: bumptech/glide

private static RequestBuilder<Bitmap> getRequestBuilder(
  RequestManager requestManager, int width, int height) {
 return requestManager
   .asBitmap()
   .apply(
     diskCacheStrategyOf(DiskCacheStrategy.NONE)
       .useAnimationPool(true)
       .skipMemoryCache(true)
       .override(width, height));
}

代码示例来源:origin: bumptech/glide

@Override
 public void run() throws Throwable {
  Glide.with(context)
    .load(colorDrawable)
    .apply(new RequestOptions()
      .centerCrop())
    .submit()
    .get();
 }
});

代码示例来源:origin: bumptech/glide

@Test
public void load_withShapeDrawableResourceId_asDrawable_withTransformation_validSize_succeeds()
  throws ExecutionException, InterruptedException {
 Drawable drawable = Glide.with(context)
   .load(ResourceIds.drawable.shape_drawable)
   .apply(bitmapTransform(new RoundedCorners(10)))
   .submit(100, 200)
   .get();
 assertThat(drawable).isNotNull();
 assertThat(drawable.getIntrinsicWidth()).isEqualTo(100);
 assertThat(drawable.getIntrinsicHeight()).isEqualTo(200);
}

代码示例来源:origin: bumptech/glide

@Test
public void load_withStateListDrawableResourceId_asDrawable_withTransformation_nonNullDrawable()
  throws ExecutionException, InterruptedException {
 Drawable drawable = Glide.with(context)
   .load(ResourceIds.drawable.state_list_drawable)
   .apply(centerCropTransform())
   .submit()
   .get();
 assertThat(drawable).isNotNull();
}

代码示例来源:origin: bumptech/glide

@Test
public void load_withVectorDrawableResourceId_asDrawable_withTransformation_nonNullDrawable()
  throws ExecutionException, InterruptedException {
 Drawable drawable = Glide.with(context)
   .load(ResourceIds.drawable.vector_drawable)
   .apply(centerCropTransform())
   .submit()
   .get();
 assertThat(drawable).isNotNull();
}

代码示例来源:origin: bumptech/glide

@Test
public void load_withBitmapResourceId_asDrawable_withTransformation_producesNonNullBitmap()
  throws ExecutionException, InterruptedException {
 Drawable drawable = Glide.with(context)
   .load(android.R.drawable.star_big_off)
   .apply(centerCropTransform())
   .submit()
   .get();
 assertThat(drawable).isNotNull();
}

代码示例来源:origin: bumptech/glide

@Test
public void load_withNinePatchResourceId_asDrawable_withTransformation_producesNonNullDrawable()
  throws ExecutionException, InterruptedException {
 Drawable drawable = Glide.with(context)
   .load(ResourceIds.drawable.googlelogo_color_120x44dp)
   .apply(centerCropTransform())
   .submit()
   .get();
 assertThat(drawable).isNotNull();
}

代码示例来源:origin: bumptech/glide

@Test
public void load_withBitmapAliasResourceId_asDrawable_withTransformation_producesNonNullDrawable()
  throws ExecutionException, InterruptedException {
 Drawable drawable = Glide.with(context)
   .load(ResourceIds.drawable.bitmap_alias)
   .apply(centerCropTransform())
   .submit()
   .get();
 assertThat(drawable).isNotNull();
}

代码示例来源:origin: bumptech/glide

@Test
public void testToBytesOption() {
 Uri uri = Uri.parse("content://something/else");
 mockUri(uri);
 requestManager.as(byte[].class).apply(decodeTypeOf(Bitmap.class)).load(uri).into(target);
 verify(target).onResourceReady(isA(byte[].class), isA(Transition.class));
}

代码示例来源:origin: bumptech/glide

@Test
public void testReceivesGifBytes() {
 String fakeUri = "content://fake";
 InputStream testGifData = openGif();
 mockUri(Uri.parse(fakeUri), testGifData);
 requestManager.as(byte[].class).apply(decodeTypeOf(GifDrawable.class)).load(fakeUri)
   .into(target);
 verify(target).onResourceReady(isA(byte[].class), isA(Transition.class));
}

代码示例来源:origin: bumptech/glide

@Test
public void testReceivesBitmapBytes() {
 String fakeUri = "content://fake";
 mockUri(fakeUri);
 requestManager.as(byte[].class).apply(decodeTypeOf(Bitmap.class)).load(fakeUri).into(target);
 verify(target).onResourceReady(isA(byte[].class), isA(Transition.class));
}

相关文章