/** * Returns a {@link RequestOptions} object with {@link #placeholder(Drawable)} set. */ @NonNull @CheckResult public static RequestOptions placeholderOf(@Nullable Drawable placeholder) { return new RequestOptions().placeholder(placeholder); }
/** * Returns a {@link RequestOptions} object with {@link #placeholder(int)} set. */ @NonNull @CheckResult public static RequestOptions placeholderOf(@DrawableRes int placeholderId) { return new RequestOptions().placeholder(placeholderId); }
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); }
@Test public void getPlaceholderId_afterSettingPlaceholderDrawable_returnsZero() { assertThat( options .placeholder(android.R.drawable.star_on) .placeholder(new ColorDrawable(Color.RED)) .getPlaceholderId()) .isEqualTo(0); }
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); }
@Test public void getPlaceholder_afterSettingPlaceholderId_returnsNul() { assertThat( options .placeholder(new ColorDrawable(Color.RED)) .placeholder(android.R.drawable.star_on) .getPlaceholderDrawable()) .isNull(); }
/** * 加载第三秒的帧数作为封面 */ 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); }
@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); }
@Override public void loadThumbnail(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); }
@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 getPlaceholder_afterApplyingOptionsWithPlaceholderDrawable_returnsNewDrawable() { Drawable expected = new ColorDrawable(Color.GREEN); RequestOptions toApply = new RequestOptions().placeholder(expected); assertThat( options .placeholder(new ColorDrawable(Color.RED)) .apply(toApply) .getPlaceholderDrawable()) .isEqualTo(expected); }
@Test public void getPlaceholderId_afterApplyingOptionsWithPlaceholderDrawable_returnsZero() { RequestOptions toApply = new RequestOptions().placeholder(new ColorDrawable(Color.RED)); assertThat( options .placeholder(android.R.drawable.star_on) .apply(toApply) .getPlaceholderId()) .isEqualTo(0); }
@Test public void getPlaceholder_afterApplyingOptionsWithPlaceholderId_returnsNull() { RequestOptions toApply = new RequestOptions().placeholder(android.R.drawable.star_on); assertThat( options .placeholder(new ColorDrawable(Color.RED)) .apply(toApply) .getPlaceholderDrawable()) .isNull(); }
@Test public void getPlaceholderId_afterApplyingOptionsWithId_returnsNewId() { int expectedId = android.R.drawable.star_off; RequestOptions toApply = new RequestOptions().placeholder(expectedId); assertThat( options .placeholder(android.R.drawable.star_on) .apply(toApply) .getPlaceholderId()) .isEqualTo(expectedId); }
/** * Verifies that we set the flags for placeholder id correctly when applying a placeholder id via * another RequestOptions. */ @Test public void placeholderIdFlag_afterApplyingIdViaOtherRequestOptions_isSet() { assertThat( options .placeholder(new ColorDrawable(Color.RED)) .apply( new RequestOptions() .apply( new RequestOptions() .placeholder(android.R.drawable.star_on))) .getPlaceholderDrawable()) .isNull(); }
/** * Verifies that we set the flags for placeholder correctly when applying a placeholder via * another RequestOptions. */ @Test public void placeholderFlag_afterApplyingViaOtherRequestOptions_isSet() { assertThat( options .placeholder(android.R.drawable.star_on) .apply( new RequestOptions() .apply( new RequestOptions() .placeholder(new ColorDrawable(Color.RED)))) .getPlaceholderId()) .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()); } }