/** * Returns a {@link RequestOptions} object with {@link #error(int)}} set. */ @NonNull @CheckResult public static RequestOptions errorOf(@DrawableRes int errorId) { return new RequestOptions().error(errorId); }
/** * Returns a {@link RequestOptions} object with {@link #error(Drawable)} set. */ @NonNull @CheckResult public static RequestOptions errorOf(@Nullable Drawable errorDrawable) { return new RequestOptions().error(errorDrawable); }
private void loadCover(ImageView imageView, String url) { imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setImageResource(R.mipmap.xxx1); Glide.with(this.getApplicationContext()) .setDefaultRequestOptions( new RequestOptions() .frame(3000000) .centerCrop() .error(R.mipmap.xxx2) .placeholder(R.mipmap.xxx1)) .load(url) .into(imageView); }
private void loadCover(ImageView imageView, String url) { imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setImageResource(R.mipmap.xxx1); Glide.with(this.getApplicationContext()) .setDefaultRequestOptions( new RequestOptions() .frame(3000000) .centerCrop() .error(R.mipmap.xxx2) .placeholder(R.mipmap.xxx1)) .load(url) .into(imageView); }
private void loadCover(ImageView imageView, String url) { imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setImageResource(R.mipmap.xxx1); Glide.with(this.getApplicationContext()) .setDefaultRequestOptions( new RequestOptions() .frame(3000000) .centerCrop() .error(R.mipmap.xxx2) .placeholder(R.mipmap.xxx1)) .load(url) .into(imageView); }
public void loadCoverImage(String url, int res) { mCoverOriginUrl = url; mDefaultRes = res; Glide.with(getContext().getApplicationContext()) .setDefaultRequestOptions( new RequestOptions() .frame(1000000) .centerCrop() .error(res) .placeholder(res)) .load(url) .into(mCoverImage); }
public void loadCoverImage(String url, int res) { mCoverOriginUrl = url; mDefaultRes = res; Glide.with(getContext().getApplicationContext()) .setDefaultRequestOptions( new RequestOptions() .frame(1000000) .centerCrop() .error(res) .placeholder(res)) .load(url) .into(mCoverImage); }
/** * 加载第三秒的帧数作为封面 */ private void loadCover(ImageView imageView, String url) { imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setImageResource(R.mipmap.xxx1); Glide.with(this.getApplicationContext()) .setDefaultRequestOptions( new RequestOptions() .frame(3000000) .centerCrop() .error(R.mipmap.xxx2) .placeholder(R.mipmap.xxx1)) .load(url) .into(imageView); }
@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)); }
@Override public void fillData(BGAViewHolderHelper viewHolderHelper, int position, StaggeredModel model) { viewHolderHelper.setText(R.id.tv_item_staggered_desc, model.desc); // 这里不知道当前图片的尺寸,加载成功后会乱跳 Glide.with(mContext) .load(model.icon) .apply(new RequestOptions().placeholder(R.mipmap.staggered_holder).error(R.mipmap.staggered_holder).dontAnimate()) .into((ImageView) viewHolderHelper.getView(R.id.iv_item_staggered_icon)); } }
@Test public void getError_afterApplyingOptionsWithErrorDrawable_returnsNewErrorDrawable() { Drawable expected = new ColorDrawable(Color.GREEN); RequestOptions toApply = new RequestOptions().error(expected); assertThat( options .error(new ColorDrawable(Color.RED)) .apply(toApply) .getErrorPlaceholder()) .isEqualTo(expected); }
@Test public void testNullModelPrefersFallbackDrawable() { Drawable placeholder = new ColorDrawable(Color.GREEN); Drawable error = new ColorDrawable(Color.RED); Drawable fallback = new ColorDrawable(Color.BLUE); requestManager .load(NULL) .apply(placeholderOf(placeholder) .error(error) .fallback(fallback)) .into(target); verify(target).onLoadFailed(eq(fallback)); }
/** * Verifies that we set the flags for error correctly when applying an error via * another RequestOptions. */ @Test public void errorFlag_afterApplyingViaOtherRequestOptions_isSet() { assertThat( options .error(android.R.drawable.star_on) .apply( new RequestOptions() .apply( new RequestOptions() .error(new ColorDrawable(Color.RED)))) .getErrorId()) .isEqualTo(0); }
/** * Verifies that we set the flags for error id correctly when applying a fallback id via * another RequestOptions. */ @Test public void errorIdFlag_afterApplyingViaOtherRequestOptions_isSet() { assertThat( options .error(new ColorDrawable(Color.RED)) .apply( new RequestOptions() .apply( new RequestOptions() .error(android.R.drawable.star_on))) .getErrorPlaceholder()) .isNull(); }
SingleRequest<List> build() { RequestOptions requestOptions = new RequestOptions() .error(errorDrawable) .placeholder(placeholderDrawable) .fallback(fallbackDrawable) .override(overrideWidth, overrideHeight) .priority(priority) .signature(signature) .useUnlimitedSourceGeneratorsPool(useUnlimitedSourceGeneratorsPool); return SingleRequest.obtain( /*context=*/ glideContext, /*glideContext=*/ glideContext, model, transcodeClass, requestOptions, overrideWidth, overrideHeight, priority, target, /*targetListener=*/ null, requestListeners, requestCoordinator, engine, transitionFactory, Executors.directExecutor()); } }