Code example for ImageView

Methods: getContextgetResources

0
     * @param url The URL of the image that should be loaded. 
     * @param defaultResource The Android resid of the {@link Drawable} that 
     *            should be displayed while the image is being downloaded. 
     */ 
    public static void setUrlDrawable(final ImageView imageView, final String url, final int defaultResource) {
        setUrlDrawable(imageView.getContext(), imageView, url, defaultResource, CACHE_DURATION_THREE_DAYS);
    } 
 
    /** 
     * Download and shrink an Image located at a specified URL, and display it 
     * in the provided {@link ImageView} once it finishes loading. 
     * 
     * @param imageView The {@link ImageView} to display the image to after it 
     *            is loaded. 
     * @param url The URL of the image that should be loaded. 
     */ 
    public static void setUrlDrawable(final ImageView imageView, final String url) {
        setUrlDrawable(imageView.getContext(), imageView, url, null, CACHE_DURATION_THREE_DAYS, null);
    } 
 
    public static void loadUrlDrawable(final Context context, final String url) {
        setUrlDrawable(context, null, url, null, CACHE_DURATION_THREE_DAYS, null);
    } 
 
    /** 
     * Download and shrink an Image located at a specified URL, and display it 
     * in the provided {@link ImageView}. 
     * 
     * @param imageView The {@link ImageView} to display the image to after it 
     *            is loaded. 
     * @param url The URL of the image that should be loaded. 
     * @param defaultDrawable A {@link Drawable} that should be displayed in 
     *            {@code imageView} while the image has not been loaded. This 
     *            image will also be displayed if the image fails to load. This 
     *            can be set to {@code null}. 
     */ 
    public static void setUrlDrawable(final ImageView imageView, final String url, final Drawable defaultDrawable) {
        setUrlDrawable(imageView.getContext(), imageView, url, defaultDrawable, CACHE_DURATION_THREE_DAYS, null);
    } 
 
    /** 
     * Download and shrink an Image located at a specified URL, and display it 
     * in the provided {@link ImageView}. 
     * 
     * @param imageView The {@link ImageView} to display the image to after it 
     *            is loaded. 
     * @param url The URL of the image that should be loaded. 
     * @param defaultResource The Android resid of the {@link Drawable} that 
     *            should be displayed while the image is being downloaded. 
     * @param cacheDurationMs The length of time, in milliseconds, that this 
     *            image should be cached locally. 
     */ 
    public static void setUrlDrawable(final ImageView imageView, final String url, final int defaultResource, final long cacheDurationMs) {
        setUrlDrawable(imageView.getContext(), imageView, url, defaultResource, cacheDurationMs);
    } 
 
    public static void loadUrlDrawable(final Context context, final String url, final long cacheDurationMs) {
        setUrlDrawable(context, null, url, null, cacheDurationMs, null);
    } 
 
    /** 
     * Download and shrink an Image located at a specified URL, and display it 
     * in the provided {@link ImageView}. 
     * 
     * @param imageView The {@link ImageView} to display the image to after it 
     *            is loaded. 
     * @param url The URL of the image that should be loaded. 
     * @param defaultDrawable A {@link Drawable} that should be displayed in 
     *            {@code imageView} while the image has not been loaded. This 
     *            image will also be displayed if the image fails to load. This 
     *            can be set to {@code null}. 
     * @param cacheDurationMs The length of time, in milliseconds, that this 
     *            image should be cached locally. 
     */ 
    public static void setUrlDrawable(final ImageView imageView, final String url, final Drawable defaultDrawable, final long cacheDurationMs) {
        setUrlDrawable(imageView.getContext(), imageView, url, defaultDrawable, cacheDurationMs, null);
    } 
 
    /** 
     * Download and shrink an Image located at a specified URL, and display it 
     * in the provided {@link ImageView}. 
     * 
     * @param context A {@link Context} to allow setUrlDrawable to load and save 
     *            files. 
     * @param imageView The {@link ImageView} to display the image to after it 
     *            is loaded. 
     * @param url The URL of the image that should be loaded. 
     * @param defaultResource The Android resid of the {@link Drawable} that 
     *            should be displayed while the image is being downloaded. 
     * @param cacheDurationMs The length of time, in milliseconds, that this 
     *            image should be cached locally. 
     */ 
    private static void setUrlDrawable(final Context context, final ImageView imageView, final String url, final int defaultResource, final long cacheDurationMs) {
        Drawable d = null;
        if (defaultResource != 0) {
            d = imageView.getResources().getDrawable(defaultResource);
        } 
        setUrlDrawable(context, imageView, url, d, cacheDurationMs, null);
    } 
 
    /**