@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)); }
@Test public void getFallbackId_afterApplyingOptionsWithFallbackId_returnsNewFallbackId() { RequestOptions toApply = new RequestOptions().fallback(android.R.drawable.star_off); assertThat( options .fallback(android.R.drawable.star_on) .apply(toApply) .getFallbackId()) .isEqualTo(android.R.drawable.star_off); }
/** * Verifies that we set the flags for fallback id correctly when applying a fallback id via * another RequestOptions. */ @Test public void fallbackIdFlag_afterApplyingViaOtherRequestOptions_isSet() { assertThat( options .fallback(new ColorDrawable(Color.RED)) .apply( new RequestOptions() .apply( new RequestOptions() .fallback(android.R.drawable.star_on))) .getFallbackDrawable()) .isNull(); }
@Test public void getFallback_afterApplyingOptionsWithFallbackDrawable_returnsNewDrawable() { RequestOptions toApply = new RequestOptions(); RequestOptions apply = options.fallback(new ColorDrawable(Color.RED)).apply(toApply); assertThat(((ColorDrawable) apply.getFallbackDrawable()).getColor()).isEqualTo(Color.RED); }
/** * Verifies that we set the flags for fallback correctly when applying a fallback via * another RequestOptions. */ @Test public void fallbackFlag_afterApplyingViaOtherRequestOptions_isSet() { assertThat( options .fallback(android.R.drawable.star_on) .apply( new RequestOptions() .apply( new RequestOptions() .fallback(new ColorDrawable(Color.RED)))) .getFallbackId()) .isEqualTo(0); }
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()); } }
new RequestOptions().placeholder(first)) .addEqualityGroup(new RequestOptions().placeholder(second)) .addEqualityGroup(new RequestOptions().fallback(1), new RequestOptions().fallback(1)) .addEqualityGroup(new RequestOptions().fallback(2)) .addEqualityGroup( new RequestOptions().fallback(first), new RequestOptions().fallback(first)) .addEqualityGroup(new RequestOptions().fallback(second)) .addEqualityGroup( new RequestOptions().skipMemoryCache(true),
/** * 加载圆形 * * @param url url * @param imageView imageView */ public static void loadImageCircle(ImageView imageView, String url) { if (TextUtils.isEmpty(url)) { return; } Glide.with(imageView.getContext()) .load(url) .apply(RequestOptions.circleCropTransform() .placeholder(R.drawable.ic_loading_image) .error(new ColorDrawable(Color.WHITE)) .fallback(new ColorDrawable(Color.RED))) .into(imageView); }
/** * 加载网络图片 * * @param url url * @param imageView imageView * @param imageView transformation 转换器 */ public static void loadImage(ImageView imageView, String url) { if (TextUtils.isEmpty(url)) { return; } Glide.with(imageView.getContext()) .load(url) .apply(new RequestOptions() .placeholder(R.drawable.ic_loading_image) .error(new ColorDrawable(Color.WHITE)) .fallback(new ColorDrawable(Color.RED))) .into(imageView); }
/** * 普通加载图片 * * @param obj * @param iv * @param placeholderResource */ public static void loadImg(Object obj, ImageView iv, int placeholderResource) { Glide.with(iv.getContext()).load(obj).apply(getRequestOptions() .error(placeholderResource) .placeholder(placeholderResource) .fallback(placeholderResource) .dontAnimate()).into(iv); }
/** * 普通加载图片 * * @param obj * @param iv * @param placeholder */ public static void loadImg(Object obj, ImageView iv, Drawable placeholder) { Glide.with(iv.getContext()).load(obj).apply(getRequestOptions() .error(placeholder) .placeholder(placeholder) .fallback(placeholder) .dontAnimate()).into(iv); }
/** * 加载圆形图片 * * @param obj * @param iv * @param placeholderResource 占位图 */ public static void loadCircleImg(Object obj, ImageView iv, int placeholderResource) { Glide.with(iv.getContext()).load(obj).apply(getRequestOptions() .error(placeholderResource) .placeholder(placeholderResource) .fallback(placeholderResource) .dontAnimate() .transform(new CircleCrop())).into(iv); }
/** * 加载圆形图片 * * @param obj * @param iv * @param placeholder 占位图 */ public static void loadCircleImg(Object obj, ImageView iv, Drawable placeholder) { Glide.with(iv.getContext()).load(obj).apply(getRequestOptions() .error(placeholder) .placeholder(placeholder) .fallback(placeholder) .dontAnimate() .transform(new CircleCrop())).into(iv); }
/** * Sets an {@link Drawable} to display if the model provided to * {@link com.bumptech.glide.RequestBuilder#load(Object)} is {@code null}. * * <p> If a fallback is not set, null models will cause the error drawable to be displayed. If the * error drawable is not set, the placeholder will be displayed. * * @see #placeholder(Drawable) * @see #placeholder(int) * * @param drawable The drawable to display as a placeholder. * @return This request builder. */ @CheckResult public RequestOptions fallback(Drawable drawable) { if (isAutoCloneEnabled) { return clone().fallback(drawable); } this.fallbackDrawable = drawable; fields |= FALLBACK; return selfOrThrowIfLocked(); }
/** * 加载圆角图片 * * @param obj 加载的图片资源 * @param iv * @param dp 圆角尺寸-dp * @param placeholderResource -占位图 * @param isOfficial-是否官方模式圆角 */ public static void loadRoundImg(Object obj, ImageView iv, float dp, int placeholderResource, boolean isOfficial) { Glide.with(iv.getContext()).load(obj).apply(getRequestOptions() .error(placeholderResource) .placeholder(placeholderResource) .fallback(placeholderResource) .dontAnimate() .transform(isOfficial ? new RoundedCorners(dp2px(dp)) : new GlideRoundTransform(iv.getContext(), dp2px(dp)))).into(iv); }
/** * 加载圆角图片 * * @param obj 加载的图片资源 * @param iv * @param dp 圆角尺寸-dp * @param placeholder -占位图 * @param isOfficial-是否官方模式圆角 */ public static void loadRoundImg(Object obj, ImageView iv, float dp, Drawable placeholder, boolean isOfficial) { Glide.with(iv.getContext()).load(obj).apply(getRequestOptions() .error(placeholder) .placeholder(placeholder) .fallback(placeholder) .dontAnimate() .transform(isOfficial ? new RoundedCorners(dp2px(dp)) : new GlideRoundTransform(dp2px(dp)))).into(iv); }