com.bumptech.glide.request.RequestListener Java Examples

The following examples show how to use com.bumptech.glide.request.RequestListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImageUtil.java    From social-app-android with Apache License 2.0 6 votes vote down vote up
public static void loadMediumImageCenterCrop(GlideRequests glideRequests,
                                             StorageReference imageStorageRefMedium,
                                             StorageReference imageStorageRefOriginal,
                                             ImageView imageView,
                                             int width,
                                             int height,
                                             RequestListener<Drawable> listener) {

    glideRequests.load(imageStorageRefMedium)
            .centerCrop()
            .override(width, height)
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .error(R.drawable.ic_stub)
            .listener(listener)
            .error(glideRequests.load(imageStorageRefOriginal))
            .into(imageView);
}
 
Example #2
Source File: ImageUtil.java    From BaseProject with Apache License 2.0 6 votes vote down vote up
public static void loadImage(Context context, String picUrl, int newWidth, int newHeight, int holderDrawableResId,
                             int errorDrawableResId, ImageView targetIv
        , RequestListener callback){
    Resources res = context.getResources();
    Drawable holderPic = null;
    if (holderDrawableResId > 0) {
        holderPic = res.getDrawable(holderDrawableResId);
    }
    Drawable errorDrawable = null;
    if (errorDrawableResId > 0) {
        errorDrawable = res.getDrawable(errorDrawableResId);
    }
    loadImage(context, picUrl, newWidth, newHeight,holderPic,
            errorDrawable,
            targetIv, callback);
}
 
Example #3
Source File: GlideHook.java    From DoraemonKit with Apache License 2.0 6 votes vote down vote up
/**
 * hook requestListeners字段
 *
 * @param singleRequest
 * @return
 */

public static void proxy(Object singleRequest) {
    try {
        List<RequestListener> requestListeners = null;
        if (singleRequest instanceof SingleRequest) {
            requestListeners = ReflectUtils.reflect(singleRequest).field("requestListeners").get();
        }
        //可能存在用户没有引入okhttp的情况
        if (requestListeners == null) {
            requestListeners = new ArrayList<>();
            requestListeners.add(new DokitGlideRequestListener());
        } else {
            requestListeners.add(new DokitGlideRequestListener());
        }
        if (singleRequest instanceof SingleRequest) {
            ReflectUtils.reflect(singleRequest).field("requestListeners",requestListeners);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #4
Source File: ImageLoader.java    From aptoide-client-v8 with GNU General Public License v3.0 6 votes vote down vote up
public Target<Drawable> loadWithColorPlaceholderRoundCorners(String image, int radius,
    ImageView previewImage, @AttrRes int colorResource,
    RequestListener<Drawable> requestListener) {
  Context context = weakContext.get();
  if (context != null) {
    return Glide.with(context)
        .load(image)
        .apply(getRequestOptions().centerCrop()
            .placeholder(new ColorDrawable(getAttrColor(colorResource)))
            .transforms(new CenterCrop(), new RoundedCorners(radius)))
        .listener(requestListener)
        .transition(DrawableTransitionOptions.withCrossFade())
        .into(previewImage);
  }
  return null;
}
 
Example #5
Source File: ImageUtils.java    From SendBird-Android with MIT License 6 votes vote down vote up
/**
 * Displays an image from a URL in an ImageView.
 */
public static void displayImageFromUrl(final Context context, final String url,
                                       final ImageView imageView, Drawable placeholderDrawable, RequestListener listener) {
    RequestOptions myOptions = new RequestOptions()
            .dontAnimate()
            .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
            .placeholder(placeholderDrawable);

    if (listener != null) {
        Glide.with(context)
                .load(url)
                .apply(myOptions)
                .listener(listener)
                .into(imageView);
    } else {
        Glide.with(context)
                .load(url)
                .apply(myOptions)
                .listener(listener)
                .into(imageView);
    }
}
 
Example #6
Source File: ImageUtils.java    From SendBird-Android with MIT License 6 votes vote down vote up
/**
 * Displays an image from a URL in an ImageView.
 */
public static void displayGifImageFromUrl(Context context, String url, ImageView imageView, Drawable placeholderDrawable, RequestListener listener) {
    RequestOptions myOptions = new RequestOptions()
            .dontAnimate()
            .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
            .placeholder(placeholderDrawable);

    if (listener != null) {
        Glide.with(context)
                .asGif()
                .load(url)
                .apply(myOptions)
                .listener(listener)
                .into(imageView);
    } else {
        Glide.with(context)
                .asGif()
                .load(url)
                .apply(myOptions)
                .into(imageView);
    }
}
 
Example #7
Source File: ImageUtils.java    From SendBird-Android with MIT License 6 votes vote down vote up
/**
 * Displays an image from a URL in an ImageView.
 */
public static void displayImageFromUrl(final Context context, final String url,
                                       final ImageView imageView, RequestListener listener) {
    RequestOptions myOptions = new RequestOptions()
            .dontAnimate()
            .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC);

    if (listener != null) {
        Glide.with(context)
                .load(url)
                .apply(myOptions)
                .listener(listener)
                .into(imageView);
    } else {
        Glide.with(context)
                .load(url)
                .apply(myOptions)
                .listener(listener)
                .into(imageView);
    }
}
 
Example #8
Source File: ImageUtils.java    From SendBird-Android with MIT License 6 votes vote down vote up
/**
 * Displays an image from a URL in an ImageView.
 */
public static void displayGifImageFromUrl(Context context, String url, ImageView imageView, RequestListener listener) {
    RequestOptions myOptions = new RequestOptions()
            .dontAnimate()
            .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC);

    if (listener != null) {
        Glide.with(context)
                .asGif()
                .load(url)
                .apply(myOptions)
                .listener(listener)
                .into(imageView);
    } else {
        Glide.with(context)
                .asGif()
                .load(url)
                .apply(myOptions)
                .into(imageView);
    }
}
 
Example #9
Source File: GlideUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 图片显示
 * @param uri       Image Uri
 * @param imageView ImageView
 * @param options   {@link RequestOptions}
 * @param listener  加载监听事件
 */
public void displayImageToFile(final String uri, final ImageView imageView, final RequestOptions options,
                               final RequestListener<File> listener) {
    if (mRequestManager != null && imageView != null) {
        if (options != null) {
            mRequestManager.asFile().load(uri).apply(options).listener(listener).into(imageView);
        } else {
            mRequestManager.asFile().load(uri).listener(listener).into(imageView);
        }
    }
}
 
Example #10
Source File: ImageUtil.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
public static void loadImageCenterCrop(GlideRequests glideRequests, StorageReference imageStorageRef, ImageView imageView,
                                       RequestListener<Drawable> listener) {
    glideRequests.load(imageStorageRef)
            .centerCrop()
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .error(R.drawable.ic_stub)
            .listener(listener)
            .into(imageView);
}
 
Example #11
Source File: ImageUtil.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
public static void loadImageCenterCrop(GlideRequests glideRequests, String url, ImageView imageView,
                                       int width, int height, RequestListener<Drawable> listener) {
    glideRequests.load(url)
            .centerCrop()
            .override(width, height)
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .error(R.drawable.ic_stub)
            .listener(listener)
            .into(imageView);
}
 
Example #12
Source File: ImageUtil.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
public static void loadImageCenterCrop(GlideRequests glideRequests, StorageReference imageStorageRef, ImageView imageView,
                                       int width, int height, RequestListener<Drawable> listener) {
    glideRequests.load(imageStorageRef)
            .centerCrop()
            .override(width, height)
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .error(R.drawable.ic_stub)
            .listener(listener)
            .into(imageView);
}
 
Example #13
Source File: ImageUtil.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
public static void loadImage(GlideRequests glideRequests, String url, ImageView imageView,
                             RequestListener<Drawable> listener) {
    glideRequests.load(url)
            .error(R.drawable.ic_stub)
            .listener(listener)
            .diskCacheStrategy(DiskCacheStrategy.DATA)
            .into(imageView);
}
 
Example #14
Source File: ImageUtil.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
public static void loadImageCenterCrop(GlideRequests glideRequests, String url, ImageView imageView,
                                       RequestListener<Drawable> listener) {
    glideRequests.load(url)
            .centerCrop()
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .error(R.drawable.ic_stub)
            .listener(listener)
            .into(imageView);
}
 
Example #15
Source File: ImageUtil.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
public static void loadImageCenterCrop(GlideRequests glideRequests, String url, ImageView imageView,
                                       int width, int height, RequestListener<Drawable> listener) {
    glideRequests.load(url)
            .centerCrop()
            .override(width, height)
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .error(R.drawable.ic_stub)
            .listener(listener)
            .into(imageView);
}
 
Example #16
Source File: ImageUtil.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
public static void loadImage(GlideRequests glideRequests, String url, ImageView imageView,
                             RequestListener<Drawable> listener) {
    glideRequests.load(url)
            .error(R.drawable.ic_stub)
            .listener(listener)
            .diskCacheStrategy(DiskCacheStrategy.DATA)
            .into(imageView);
}
 
Example #17
Source File: GlideUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 图片显示
 * <pre>
 *     支持显示 Gif 图片第一帧
 * </pre>
 * @param uri       Image Uri
 * @param imageView ImageView
 * @param options   {@link RequestOptions}
 * @param listener  加载监听事件
 */
public void displayImage(final String uri, final ImageView imageView, final RequestOptions options,
                         final RequestListener<Bitmap> listener) {
    if (mRequestManager != null && imageView != null) {
        if (options != null) {
            mRequestManager.asBitmap().load(uri).apply(options).listener(listener).into(imageView);
        } else {
            mRequestManager.asBitmap().load(uri).listener(listener).into(imageView);
        }
    }
}
 
Example #18
Source File: GlideUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 图片显示
 * @param uri       Image Uri
 * @param imageView ImageView
 * @param options   {@link RequestOptions}
 * @param listener  加载监听事件
 */
public void displayImageToGif(final String uri, final ImageView imageView, final RequestOptions options,
                              final RequestListener<GifDrawable> listener) {
    if (mRequestManager != null && imageView != null) {
        if (options != null) {
            mRequestManager.asGif().load(uri).apply(options).listener(listener).into(imageView);
        } else {
            mRequestManager.asGif().load(uri).listener(listener).into(imageView);
        }
    }
}
 
Example #19
Source File: ImageLoader.java    From v2ex with Apache License 2.0 5 votes vote down vote up
public BitmapRequestBuilder beginImageLoad(String url,
        RequestListener<String, Bitmap> requestListener, boolean crop) {
    return requestManager.load(url)
            .asBitmap()
            .listener(requestListener)
            .transform(crop ? mCenterCrop : mFitCenter);
}
 
Example #20
Source File: ImageUtil.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
public static void loadImageCenterCrop(GlideRequests glideRequests, String url, ImageView imageView,
                                       RequestListener<Drawable> listener) {
    glideRequests.load(url)
            .centerCrop()
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .error(R.drawable.ic_stub)
            .listener(listener)
            .into(imageView);
}
 
Example #21
Source File: ImageUtil.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
public static void loadLocalImage(GlideRequests glideRequests, Uri uri, ImageView imageView,
                                  RequestListener<Drawable> listener) {
    glideRequests.load(uri)
            .diskCacheStrategy(DiskCacheStrategy.NONE)
            .skipMemoryCache(true)
            .fitCenter()
            .listener(listener)
            .into(imageView);
}
 
Example #22
Source File: ImageLoader.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
public Target<Drawable> loadWithRoundCorners(String image, int radius, ImageView previewImage,
    @AttrRes int placeHolderDrawableId, RequestListener<Drawable> requestListener) {
  Context context = weakContext.get();
  if (context != null) {
    return Glide.with(context)
        .load(image)
        .apply(getRequestOptions().centerCrop()
            .placeholder(getAttrDrawable(placeHolderDrawableId))
            .transforms(new CenterCrop(), new RoundedCorners(radius)))
        .listener(requestListener)
        .transition(DrawableTransitionOptions.withCrossFade())
        .into(previewImage);
  }
  return null;
}
 
Example #23
Source File: MultiRequestListener.java    From glide-support with The Unlicense 5 votes vote down vote up
@Override public boolean onException(Exception e, A model, Target<B> target, boolean isFirstResource) {
	for (RequestListener<? super A, B> listener : listeners) {
		if (listener.onException(e, model, target, isFirstResource)) {
			return true;
		}
	}
	return false;
}
 
Example #24
Source File: MultiRequestListener.java    From glide-support with The Unlicense 5 votes vote down vote up
@Override public boolean onResourceReady(B resource, A model, Target<B> target, boolean isFromMemoryCache,
		boolean isFirstResource) {
	for (RequestListener<? super A, B> listener : listeners) {
		if (listener.onResourceReady(resource, model, target, isFromMemoryCache, isFirstResource)) {
			return true;
		}
	}
	return false;
}
 
Example #25
Source File: ImageLoader.java    From RetailStore with Apache License 2.0 5 votes vote down vote up
/**
 * Load an image from a url into an ImageView using the default placeholder
 * drawable if available.
 * @param url The web URL of an image.
 * @param imageView The target ImageView to load the image into.
 * @param requestListener A listener to monitor the request result.
 * @param placeholderOverride A drawable to use as a placeholder for this specific image.
 *                            If this parameter is present, {@link #mPlaceHolderResId}
 *                            if ignored for this request.
 */
public void loadImage(String url, ImageView imageView, RequestListener<String, Bitmap> requestListener,
            Drawable placeholderOverride, boolean crop) {
    BitmapRequestBuilder request = beginImageLoad(url, requestListener, crop)
            .animate(R.anim.image_fade_in);
    if (placeholderOverride != null) {
        request.placeholder(placeholderOverride);
    } else if (mPlaceHolderResId != -1) {
        request.placeholder(mPlaceHolderResId);
    }
    request.into(imageView);
}
 
Example #26
Source File: ImageLoader.java    From RetailStore with Apache License 2.0 5 votes vote down vote up
public BitmapRequestBuilder beginImageLoad(String url,
        RequestListener<String, Bitmap> requestListener, boolean crop) {
    if (crop){
        return mGlideModelRequest.load(url)
                .listener(requestListener)
                .transform(mCenterCrop);
    } else {
        return mGlideModelRequest.load(url)
                .listener(requestListener);
    }
}
 
Example #27
Source File: ImageUtil.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
public static void loadImage(Context context, String picUrl, int newWidth, int newHeight, Drawable holderDrawable,
                             Drawable errorDrawable, ImageView targetIv
        ,  RequestListener callback) {
    RequestBuilder requestBuilder = loadImageRequest(context, picUrl);
    RequestOptions options = new RequestOptions();
    if (newWidth > 0 && newHeight > 0) {
        options.override(newWidth,newHeight).centerCrop();
    }
    else{
        //            loadRequest.fit();
    }
    if (holderDrawable != null) {
        options.placeholder(holderDrawable);
    }
    else{
//        loadRequest.noPlaceholder();
    }
    if (errorDrawable != null) {
        options.error(errorDrawable);
    }
    options.dontAnimate();
    if (callback != null) {
        requestBuilder.listener(callback);
    }
    requestBuilder.apply(options)
            .into(targetIv);
}
 
Example #28
Source File: ImageLoader.java    From Toutiao with Apache License 2.0 5 votes vote down vote up
/**
 * 带监听处理
 */
public static void loadCenterCrop(Context context, String url, ImageView view, RequestListener listener) {
    GlideApp.with(context)
            .load(url)
            .transition(withCrossFade())
            .apply(new RequestOptions().centerCrop())
            .listener(listener)
            .into(view);
}
 
Example #29
Source File: ImageLoader.java    From v2ex with Apache License 2.0 5 votes vote down vote up
/**
 * Load an image from a url into an ImageView using the default placeholder
 * drawable if available.
 * @param url The web URL of an image.
 * @param imageView The target ImageView to load the image into.
 * @param requestListener A listener to monitor the request result.
 * @param placeholderOverride A drawable to use as a placeholder for this specific image.
 *                            If this parameter is present, {@link #mPlaceHolderResId}
 *                            if ignored for this request.
 */
public void loadImage(String url, ImageView imageView, RequestListener<String, Bitmap> requestListener,
            Drawable placeholderOverride, boolean crop) {
    BitmapRequestBuilder request = beginImageLoad(url, requestListener, crop)
            .animate(R.anim.image_fade_in);
    if (placeholderOverride != null) {
        request.placeholder(placeholderOverride);
    } else if (mPlaceHolderResId != -1) {
        request.placeholder(mPlaceHolderResId);
    }
    request.into(imageView);
}
 
Example #30
Source File: DrawableRequestBuilder.java    From giffun with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public DrawableRequestBuilder<ModelType> listener(
        RequestListener<? super ModelType, GlideDrawable> requestListener) {
    super.listener(requestListener);
    return this;
}