/** * DrawableRequestBuilder 的通行配置 * @param ctx 上下文 * @param img ImageLoader封装器 * @param typeRequest url or resource * @param <T> String or Integer * @return DrawableRequestBuilder<T> */ private <T> BitmapRequestBuilder<T, Bitmap> getBitmapRequestBuilder(Context ctx, ImageLoader img, BitmapTypeRequest<T> typeRequest) { BitmapRequestBuilder<T, Bitmap> builder = typeRequest.diskCacheStrategy(DiskCacheStrategy.ALL); // transform image type if (img.transType == LoaderConfig.TRANS_CIRCLE) { builder = builder.transform(new GlideCircleTransform(ctx)); } else if (img.transType == LoaderConfig.TRANS_ROUND) { builder = builder.transform(new GlideRoundTransform(ctx)); } // SCALE type if (img.scaleType == LoaderConfig.SCALE_CENTER_CROP) { builder = builder.centerCrop(); } else if (img.scaleType == LoaderConfig.SCALE_FIT_CENTER) { builder = builder.fitCenter(); } return builder; }
/** * 加载圆角图片 * * @param * @param */ public static void loadCircleImage(BitmapTypeRequest bitmapTypeRequest, final Object object) { bitmapTypeRequest.into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { Drawable circleDrawable = DrawableUtils.roundedBitmap(resource); if (object instanceof ImageView) { ((ImageView) object).setImageDrawable(circleDrawable); return; } if (object instanceof Preference) { ((Preference) object).setIcon(circleDrawable); } } }); }
public void setUrl(String url, boolean loading) { mUrl = url; if (mUrl.isEmpty()) { return; } Log.d("url", mUrl); GlideUrl glideUrl = new GlideUrl(mUrl, new LazyHeaders.Builder() .addHeader("User-Agent", Const.HTTP_USER_AGENT) .build()); BitmapTypeRequest req = Glide.with(Application.getApplication()).load(glideUrl).asBitmap(); if (loading) { req.placeholder(R.mipmap.ic_photo_black); } req.error(R.mipmap.ic_broken_image_black) .fitCenter() .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) .into(this); }
/** * 加载带V效果 * * @param imageView */ public static void loadBadgeImage(int vIcon, BitmapTypeRequest bitmapTypeRequest, final BGABadgeImageView imageView) { final Bitmap avatorBadgeBitmap = BitmapFactory.decodeResource(App.getInstance().getResources(), vIcon); bitmapTypeRequest.into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { Drawable circleDrawable = DrawableUtils.roundedBitmap(resource); imageView.setImageDrawable(circleDrawable); imageView.showDrawableBadge(avatorBadgeBitmap); } }); }
private static void loadImage(Activity activity, int v, SimpleUserEntity entity, BGABadgeImageView imageView) { if (TextUtils.isEmpty(entity.getAvatar())) return; BitmapTypeRequest builder = Glide.with(activity).load(entity.getAvatar()).asBitmap(); if (entity.getVerified()) { GlideUtils.loadBadgeImage(v, builder, imageView); } else { GlideUtils.loadCircleImage(builder, imageView); } }
private Builder(BitmapTypeRequest<Uri> request, Uri uri) { this.request = request; this.uri = uri; }
public BitmapTypeRequest<Uri> childBuilder() { return request; }
@Override public Drawable getDrawable(ImageHolder holder, final RichTextConfig config, TextView textView) { final ImageTarget target; final GenericRequestBuilder load; DrawableTypeRequest dtr; DrawableWrapper drawableWrapper = new DrawableWrapper(); byte[] src = Base64.decode(holder.getSource()); if (src != null) { dtr = Glide.with(textView.getContext()).load(src); } else { dtr = Glide.with(textView.getContext()).load(holder.getSource()); } Rect rect = null; if (config.cacheType >= CacheType.LAYOUT) { rect = loadCache(holder.getSource()); if (rect != null) { drawableWrapper.setBounds(rect); } } else { drawableWrapper.setBounds(0, 0, holder.getWidth(), holder.getHeight()); } if (holder.isGif()) { target = new ImageTargetGif(textView, drawableWrapper, holder, config, this, rect); load = dtr.asGif(); } else { target = new ImageTargetBitmap(textView, drawableWrapper, holder, config, this, rect); load = dtr.asBitmap().atMost(); } checkTag(textView); targets.add(target); if (!config.resetSize && holder.isInvalidateSize()) { load.override(holder.getWidth(), holder.getHeight()); } if (holder.getScaleType() == ImageHolder.ScaleType.CENTER_CROP) { if (holder.isGif()) { //noinspection ConstantConditions ((GifTypeRequest) load).centerCrop(); } else { //noinspection ConstantConditions ((BitmapTypeRequest) load).centerCrop(); } } else if (holder.getScaleType() == ImageHolder.ScaleType.FIT_CENTER) { if (holder.isGif()) { //noinspection ConstantConditions ((GifTypeRequest) load).fitCenter(); } else { //noinspection ConstantConditions ((BitmapTypeRequest) load).fitCenter(); } } textView.post(new Runnable() { @Override public void run() { load.placeholder(config.placeHolder).error(config.errorImage).into(target); } }); drawableWrapper.setCallback(textView); return drawableWrapper; }