Java 类com.android.volley.toolbox.ImageLoader.ImageContainer 实例源码

项目:wordpress_app_android    文件:ThemeTabFragment.java   
@Override
public void onMovedToScrapHeap(View view) {
    // cancel image fetch requests if the view has been moved to recycler.

    NetworkImageView niv = (NetworkImageView) view.findViewById(R.id.theme_grid_item_image);
    if (niv != null) {
        // this tag is set in the ThemeTabAdapter class
        ScreenshotHolder tag =  (ScreenshotHolder) niv.getTag();
        if (tag != null && tag.requestURL != null) {
            // need a listener to cancel request, even if the listener does nothing
            ImageContainer container = WordPress.imageLoader.get(tag.requestURL, new ImageListener() {
                @Override
                public void onErrorResponse(VolleyError error) { }

                @Override
                public void onResponse(ImageContainer response, boolean isImmediate) { }

            });
            container.cancelRequest();
        }
    }
}
项目:android-discourse    文件:UrlImageGetter.java   
@Override
public Drawable getDrawable(String source) {
    source = checkUrl(source);
    UrlDrawable urlDrawable = new UrlDrawable();

    ImageContainer ic = mImageLoader.getForImageSpan(this, source, mTextView, new ImageCallback(mCtx.getResources(), urlDrawable));
    // TODO 当帖子滚动屏幕外的时候 如何和ImageView一样 取消前面没用的下载请求???
    if (ic != null && ic.getBitmap() != null) {
        BitmapDrawable drawable = new BitmapDrawable(mCtx.getResources(), ic.getBitmap());
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        return drawable;
    }
    if (ic != null) {
        mImageContainers.add(ic);
    }
    // get the actual source
    // ImageGetterAsyncTask asyncTask = new ImageGetterAsyncTask(urlDrawable);
    // asyncTask.execute(source);

    // return reference to URLDrawable where I will change with actual image from
    // the src tag
    return urlDrawable;
}
项目:android-promise-volley    文件:VolleyImagePromise.java   
public static Promise<ImageResult> imagePromise(ImageLoader imageLoader, final String url, int maxWidth, int maxHeight) {
    final DeferredObject<ImageResult> promise = new DeferredObject<ImageResult>();

    imageLoader.get(url, new ImageListener() {
        @Override
        public void onResponse(ImageContainer imageContainer, boolean isImmediate) {
            if (imageContainer.getBitmap() != null) {
                promise.success(new ImageResult(imageContainer, isImmediate));
            }
        }

        @Override
        public void onErrorResponse(VolleyError volleyError) {
            promise.failure(volleyError);
        }
    }, maxWidth, maxHeight);

    return promise;
}
项目:MangaJunkie-Android    文件:MangaActivity.java   
private void fetchCover() {
    fetching_cover = true;
    updateProgress();

    App.getImageLoader().get( API.getCoverUrl( manga.getCover() ),
        new ImageListener() {
            @Override
            public void onResponse( ImageContainer container, boolean something ) {
                TransitionDrawable cover_transition = new TransitionDrawable( new Drawable[]{
                cover_view.getDrawable(),
                new BitmapDrawable( getResources(), container.getBitmap() ) } );
                cover_view.setImageDrawable( cover_transition );
                cover_transition.startTransition( 200 );
                fetching_cover = false;
                updateProgress();
            }

            @Override public void onErrorResponse( VolleyError error ) {
                Log.e( "MJ", "Failed to fetch cover for " + manga.getSysName() );
                fetching_cover = false;
                updateProgress();
            }
        }
    );
}
项目:UnionListView    文件:TwoUnionView.java   
ChildViewBuffer(View v) {
    mImageView = (NetworkImageView) v.findViewById(R.id.ImageView);
    mImageView.setErrorImageResId(R.drawable.logo);
    mTitleText = (TextView) v.findViewById(R.id.Title);
    mNumText = (TextView) v.findViewById(R.id.Num);
    iImageLoader = VolleyLoader.getInstance().getImageLoader();
    iImageListener = new ImageListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d("TAG", "onErrorResponse():" + error);

        }

        @Override
        public void onResponse(ImageContainer response,
                boolean isImmediate) {
            Log.d("TAG", "onResponse():" + isImmediate);

        }
    };
}
项目:CricketBuzz    文件:MatchSquadAdapter.java   
@SuppressLint("ResourceAsColor")
@Override
public void onBindViewHolder(final ContactViewHolder contactViewHolder,
                             int i) {

    contactViewHolder.playername.setText(list.get(i).getfName());

    String player = playerimage.replace("myplayerid", list.get(i).getId());

    mImageLoader.get(player, new ImageListener() {

        @Override
        public void onErrorResponse(VolleyError error) {

        }

        @Override
        public void onResponse(ImageContainer response, boolean arg1) {
            if (response.getBitmap() != null) {
                contactViewHolder.player
                        .setImageBitmap(getRoundedCornerBitmap(
                                response.getBitmap(), 100));
            }
        }
    });

}
项目:wordpress_app_android    文件:ReaderPhotoView.java   
private void loadLoResImage() {
    if (!hasLayout() || TextUtils.isEmpty(mLoResImageUrl)) {
        return;
    }

    // skip if this same image url is already being loaded
    if (isRequestingUrl(mLoResContainer, mLoResImageUrl)) {
        AppLog.d(AppLog.T.READER, "reader photo > already requesting lo-res");
        return;
    }

    Point pt = DisplayUtils.getDisplayPixelSize(this.getContext());
    int maxSize = Math.min(pt.x, pt.y);

    showProgress();

    mLoResContainer = WordPress.imageLoader.get(mLoResImageUrl,
            new ImageLoader.ImageListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    AppLog.e(AppLog.T.READER, error);
                    hideProgress();
                    showError();
                }

                @Override
                public void onResponse(final ImageContainer response, boolean isImmediate) {
                    post(new Runnable() {
                        @Override
                        public void run() {
                            handleResponse(response.getBitmap(), true);
                        }
                    });
                }
            }, maxSize, maxSize);
}
项目:wordpress_app_android    文件:ReaderPhotoView.java   
private void loadHiResImage() {
    if (!hasLayout() || TextUtils.isEmpty(mHiResImageUrl)) {
        return;
    }

    if (isRequestingUrl(mHiResContainer, mHiResImageUrl)) {
        AppLog.d(AppLog.T.READER, "reader photo > already requesting hi-res");
        return;
    }

    Point pt = DisplayUtils.getDisplayPixelSize(this.getContext());
    int maxSize = Math.max(pt.x, pt.y);

    mHiResContainer = WordPress.imageLoader.get(mHiResImageUrl,
            new ImageLoader.ImageListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    AppLog.e(AppLog.T.READER, error);
                }

                @Override
                public void onResponse(final ImageContainer response, boolean isImmediate) {
                    post(new Runnable() {
                        @Override
                        public void run() {
                            handleResponse(response.getBitmap(), false);
                        }
                    });
                }
            }, maxSize, maxSize);
}
项目:wordpress_app_android    文件:MediaGridFragment.java   
@Override
public void onMovedToScrapHeap(View view) {
    // cancel image fetch requests if the view has been moved to recycler.

    View imageView = view.findViewById(R.id.media_grid_item_image);
    if (imageView != null) {
        // this tag is set in the MediaGridAdapter class
        String tag = (String) imageView.getTag();
        if (tag != null && tag.startsWith("http")) {
            // need a listener to cancel request, even if the listener does nothing
            ImageContainer container = WordPress.imageLoader.get(tag, new ImageListener() {
                @Override
                public void onErrorResponse(VolleyError error) { }

                @Override
                public void onResponse(ImageContainer response, boolean isImmediate) { }

            });
            container.cancelRequest();
        }
    }

    CheckableFrameLayout layout = (CheckableFrameLayout) view.findViewById(R.id.media_grid_frame_layout);
    if (layout != null) {
        layout.setOnCheckedChangeListener(null);
    }
}
项目:wordpress_app_android    文件:WPNetworkImageViewTest.java   
public void testVolleyImageLoaderGetNullHost() throws InterruptedException {
    Handler mainLooperHandler = new Handler(WordPress.getContext().getMainLooper());
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    final boolean success[] = new boolean[1];
    Runnable getImage = new Runnable() {
        @Override
        public void run() {
            try {
                // This call crash on old volley versions
                WordPress.imageLoader.get("http;///hello/null/host", new ImageListener() {
                    @Override
                    public void onResponse(ImageContainer imageContainer, boolean b) {}

                    @Override
                    public void onErrorResponse(VolleyError volleyError) {}
                }, 1, 1);
                success[0] = true;
            } catch (Exception e) {
                AppLog.e(T.TESTS, e);
                success[0] = false;
            } finally {
                countDownLatch.countDown();
            }
        }
    };
    mainLooperHandler.post(getImage);
    countDownLatch.await(1, TimeUnit.SECONDS);
    assertTrue("Invalid Volley library version", success[0]);
}
项目:GomeOnline    文件:ImageLoader.java   
@Override
public void onResponse(ImageContainer response, boolean isImmediate) {
    if(isCancel)return;
    if (response.getBitmap() != null) {
        imgView.setImageBitmap(response.getBitmap());
    } else if (defaultImageResId != 0) {
        imgView.setImageResource(defaultImageResId);
    }
    mImageMaps.remove(this);
}
项目:MangaJunkie-Android    文件:CollectionFragment.java   
@Override
public void onDestroy() {
    super.onDestroy();

    getActivity().unregisterReceiver( update_receiver );
    for ( ImageContainer request : cover_requests.values() ) request.cancelRequest();
}
项目:MangaJunkie-Android    文件:PinService.java   
private void showProgressNotification( Chapter chapter ) {
    final NotificationManager manager = (NotificationManager)getSystemService( NOTIFICATION_SERVICE );

    // Only show the chapter title if there is one
    String content_text = chapter.getManga().getTitle() + " " + chapter.toString();
    if ( chapter.hasTitle() ) content_text += ": " + chapter.getTitle();

    final Notification.Builder builder = new Notification.Builder( this )
        .setSmallIcon( R.drawable.ic_notification )
        .setContentTitle( "Saving pinned chapters" )
        .setContentText( content_text )
        .setProgress( 0, 0, true );

    App.getImageLoader().get( API.getCoverUrl( chapter.getManga().getCover() ), new ImageListener() {

        @Override
        public void onResponse( ImageContainer container, boolean immediate ) {
            if ( queue_task == null || queue_task.isCancelled() ) return;
            builder.setLargeIcon( container.getBitmap() );
            manager.notify( NOTIFICATION_ID, builder.getNotification() );
        }

        @Override public void onErrorResponse( VolleyError volleyError ) {
            if ( queue_task == null || queue_task.isCancelled() ) return;
            manager.notify( NOTIFICATION_ID, builder.getNotification() );
        }
    } );

}
项目:boohee_v5.6    文件:NetworkImageView.java   
void loadImageIfNecessary(final boolean isInLayoutPass) {
    int width = getWidth();
    int height = getHeight();
    ScaleType scaleType = getScaleType();
    boolean wrapWidth = false;
    boolean wrapHeight = false;
    if (getLayoutParams() != null) {
        if (getLayoutParams().width == -2) {
            wrapWidth = true;
        } else {
            wrapWidth = false;
        }
        if (getLayoutParams().height == -2) {
            wrapHeight = true;
        } else {
            wrapHeight = false;
        }
    }
    boolean isFullyWrapContent;
    if (wrapWidth && wrapHeight) {
        isFullyWrapContent = true;
    } else {
        isFullyWrapContent = false;
    }
    if (width != 0 || height != 0 || isFullyWrapContent) {
        if (TextUtils.isEmpty(this.mUrl)) {
            if (this.mImageContainer != null) {
                this.mImageContainer.cancelRequest();
                this.mImageContainer = null;
            }
            setDefaultImageOrNull();
            return;
        }
        int maxWidth;
        int maxHeight;
        if (!(this.mImageContainer == null || this.mImageContainer.getRequestUrl() == null)) {
            if (!this.mImageContainer.getRequestUrl().equals(this.mUrl)) {
                this.mImageContainer.cancelRequest();
                setDefaultImageOrNull();
            } else {
                return;
            }
        }
        if (wrapWidth) {
            maxWidth = 0;
        } else {
            maxWidth = width;
        }
        if (wrapHeight) {
            maxHeight = 0;
        } else {
            maxHeight = height;
        }
        this.mImageContainer = this.mImageLoader.get(this.mUrl, new ImageListener() {
            public void onErrorResponse(VolleyError error) {
                if (NetworkImageView.this.mErrorImageId != 0) {
                    NetworkImageView.this.setImageResource(NetworkImageView.this.mErrorImageId);
                }
            }

            public void onResponse(final ImageContainer response, boolean isImmediate) {
                if (isImmediate && isInLayoutPass) {
                    NetworkImageView.this.post(new Runnable() {
                        public void run() {
                            AnonymousClass1.this.onResponse(response, false);
                        }
                    });
                } else if (response.getBitmap() != null) {
                    NetworkImageView.this.setImageBitmap(response.getBitmap());
                } else if (NetworkImageView.this.mDefaultImageId != 0) {
                    NetworkImageView.this.setImageResource(NetworkImageView.this.mDefaultImageId);
                }
            }
        }, maxWidth, maxHeight, scaleType);
    }
}
项目:wordpress_app_android    文件:ReaderPhotoView.java   
private boolean isRequestingUrl(ImageContainer container, String url) {
    return (container != null
         && container.getRequestUrl() != null
         && container.getRequestUrl().equals(url));
}
项目:android-discourse    文件:UrlImageGetter.java   
@Override
public void onResponse(ImageContainer response, boolean isImmediate) {
    if (mTextView.getTag(R.id.poste_image_getter) == UrlImageGetter.this && response.getBitmap() != null) {
        BitmapDrawable drawable = new BitmapDrawable(mRes, response.getBitmap());
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        String src = response.getRequestUrl();
        // redraw the image by invalidating the container
        // 由于下面重新设置了ImageSpan,所以这里invalidate就不必要了吧
        // urlDrawable.invalidateSelf();
        // UrlImageGetter.this.mTextView.invalidate();

        // TODO 这种方式基本完美解决显示图片问题, blog?
        // 把提取到下面显示的图片在放出来? 然后点击任何图片 进入到 帖子图片浏览界面。。?
        TextView v = UrlImageGetter.this.mTextView;
        CharSequence text = v.getText();
        if (!(text instanceof Spannable)) {
            return;
        }
        Spannable spanText = (Spannable) text;
        @SuppressWarnings("unchecked") ArrayList<String> imgs = (ArrayList<String>) v.getTag(R.id.poste_image_data);
        ImageSpan[] imageSpans = spanText.getSpans(0, spanText.length(), ImageSpan.class);
        L.i("%b X Recycled %b src: %s", isImmediate, response.getBitmap().isRecycled(), src);
        for (ImageSpan imgSpan : imageSpans) {
            int start = spanText.getSpanStart(imgSpan);
            int end = spanText.getSpanEnd(imgSpan);
            L.i("%d-%d :%s", start, end, imgSpan.getSource());
            String url = imgSpan.getSource();
            url = checkUrl(url);
            if (src.equals(url)) {
                spanText.removeSpan(imgSpan);
                ImageSpan is = new ImageSpan(drawable, src, ImageSpan.ALIGN_BASELINE);
                spanText.setSpan(is, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            if (imgs != null && imgs.contains(src)) {
                ImageClickableSpan ics = new ImageClickableSpan(src);
                spanText.setSpan(ics, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }

        }
        v.setText(spanText);
    }

}
项目:android-discourse    文件:NetworkImageView.java   
/**
 * Loads the image for the view if it isn't already loaded.
 *
 * @param isInLayoutPass True if this was invoked from a layout pass, false otherwise.
 */
private void loadImageIfNecessary(final boolean isInLayoutPass) {
    int width = getWidth();
    int height = getHeight();

    boolean isFullyWrapContent = getLayoutParams() != null && getLayoutParams().height == LayoutParams.WRAP_CONTENT && getLayoutParams().width == LayoutParams.WRAP_CONTENT;
    // if the view's bounds aren't known yet, and this is not a wrap-content/wrap-content
    // view, hold off on loading the image.
    if (width == 0 && height == 0 && !isFullyWrapContent) {
        return;
    }

    // if the URL to be loaded in this view is empty, cancel any old requests and clear the
    // currently loaded image.
    if (TextUtils.isEmpty(mUrl)) {
        if (mImageContainer != null) {
            mImageContainer.cancelRequest();
            mImageContainer = null;
        }
        setImageBitmap(null);
        return;
    }

    // if there was an old request in this view, check if it needs to be canceled.
    if (mImageContainer != null && mImageContainer.getRequestUrl() != null) {
        if (mImageContainer.getRequestUrl().equals(mUrl)) {
            // if the request is from the same URL, return.
            return;
        } else {
            // if there is a pre-existing request, cancel it if it's fetching a different URL.
            mImageContainer.cancelRequest();
            setImageBitmap(null);
        }
    }

    // The pre-existing content of this view didn't match the current URL. Load the new image
    // from the network.
    ImageContainer newContainer = mImageLoader.get(mUrl, new ImageListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    if (mErrorImageId != 0) {
                        setImageResource(mErrorImageId);
                    }
                }

                @Override
                public void onResponse(final ImageContainer response, boolean isImmediate) {
                    // If this was an immediate response that was delivered inside of a layout
                    // pass do not set the image immediately as it will trigger a requestLayout
                    // inside of a layout. Instead, defer setting the image by posting back to
                    // the main thread.
                    if (isImmediate && isInLayoutPass) {
                        post(new Runnable() {
                            @Override
                            public void run() {
                                onResponse(response, false);
                            }
                        });
                        return;
                    }

                    if (response.getBitmap() != null) {
                        setImageBitmap(response.getBitmap());
                    } else if (mDefaultImageId != 0) {
                        setImageResource(mDefaultImageId);
                    }
                }
            });

    // update the ImageContainer to be the new bitmap container.
    mImageContainer = newContainer;
}
项目:Mastering-Android    文件:FeedImageView.java   
private void loadImageIfNecessary(final boolean isInLayoutPass) {
    final int width = getWidth();
    int height = getHeight();

    boolean isFullyWrapContent = getLayoutParams() != null
            && getLayoutParams().height == LayoutParams.WRAP_CONTENT
            && getLayoutParams().width == LayoutParams.WRAP_CONTENT;
    if (width == 0 && height == 0 && !isFullyWrapContent) {
        return;
    }

    if (TextUtils.isEmpty(mUrl)) {
        if (mImageContainer != null) {
            mImageContainer.cancelRequest();
            mImageContainer = null;
        }
        setDefaultImageOrNull();
        return;
    }

    if (mImageContainer != null && mImageContainer.getRequestUrl() != null) {
        if (mImageContainer.getRequestUrl().equals(mUrl)) {
            return;
        } else {
            mImageContainer.cancelRequest();
            setDefaultImageOrNull();
        }
    }

    ImageContainer newContainer = mImageLoader.get(mUrl,
            new ImageListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    if (mErrorImageId != 0) {
                        setImageResource(mErrorImageId);
                    }

                    if (mObserver != null) {
                        mObserver.onError();
                    }
                }

                @Override
                public void onResponse(final ImageContainer response,
                                       boolean isImmediate) {

                    if (isImmediate && isInLayoutPass) {
                        post(new Runnable() {
                            @Override
                            public void run() {
                                onResponse(response, false);
                            }
                        });
                        return;
                    }

                    int bWidth = 0, bHeight = 0;
                    if (response.getBitmap() != null) {

                        setImageBitmap(response.getBitmap());
                        bWidth = response.getBitmap().getWidth();
                        bHeight = response.getBitmap().getHeight();
                        adjustImageAspect(bWidth, bHeight);

                    } else if (mDefaultImageId != 0) {
                        setImageResource(mDefaultImageId);
                    }

                    if (mObserver != null) {
                        mObserver.onSuccess();

                    }
                }
            });

     mImageContainer = newContainer;

}
项目:android-promise-volley    文件:ImageResult.java   
public ImageResult(ImageContainer imageContainer, boolean fromCache) {
    this.imageContainer = imageContainer;
    this.fromCache = fromCache;
}
项目:android_tv_metro    文件:NetworkImageView.java   
/**
 * Loads the image for the view if it isn't already loaded.
 * @param isInLayoutPass True if this was invoked from a layout pass, false otherwise.
 */
private void loadImageIfNecessary(final boolean isInLayoutPass) {
    int width = getWidth();
    int height = getHeight();

    boolean isFullyWrapContent = getLayoutParams().height == LayoutParams.WRAP_CONTENT
            && getLayoutParams().width == LayoutParams.WRAP_CONTENT;
    // if the view's bounds aren't known yet, and this is not a wrap-content/wrap-content
    // view, hold off on loading the image.
    if (width == 0 && height == 0 && !isFullyWrapContent) {
        return;
    }

    // if the URL to be loaded in this view is empty, cancel any old requests and clear the
    // currently loaded image.
    if (TextUtils.isEmpty(mUrl)) {
        if (mImageContainer != null) {
            mImageContainer.cancelRequest();
            mImageContainer = null;
        }
        setImageBitmap(null);
        return;
    }

    // if there was an old request in this view, check if it needs to be canceled.
    if (mImageContainer != null && mImageContainer.getRequestUrl() != null) {
        if (mImageContainer.getRequestUrl().equals(mUrl)) {
            // if the request is from the same URL, return.
            return;
        } else {
            // if there is a pre-existing request, cancel it if it's fetching a different URL.
            mImageContainer.cancelRequest();
            setImageBitmap(null);
        }
    }

    // The pre-existing content of this view didn't match the current URL. Load the new image
    // from the network.
    ImageContainer newContainer = mImageLoader.get(mUrl,
            new ImageListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    if (mErrorImageId != 0) {
                        setImageResource(mErrorImageId);
                    }
                }

                @Override
                public void onResponse(final ImageContainer response, boolean isImmediate) {
                    // If this was an immediate response that was delivered inside of a layout
                    // pass do not set the image immediately as it will trigger a requestLayout
                    // inside of a layout. Instead, defer setting the image by posting back to
                    // the main thread.
                    if (isImmediate && isInLayoutPass) {
                        post(new Runnable() {
                            @Override
                            public void run() {
                                onResponse(response, false);
                            }
                        });
                        return;
                    }

                    if (response.getBitmap() != null) {
                        setImageBitmap(response.getBitmap());
                    } else if (mDefaultImageId != 0) {
                        setImageResource(mDefaultImageId);
                    }
                }
            });

    // update the ImageContainer to be the new bitmap container.
    mImageContainer = newContainer;
}
项目:barterli_android    文件:NetworkImageView.java   
/**
 * Loads the image for the view if it isn't already loaded.
 * 
 * @param isInLayoutPass
 *            True if this was invoked from a layout pass, false otherwise.
 */
private void loadImageIfNecessary(final boolean isInLayoutPass) {

    // if the URL to be loaded in this view is empty, cancel any old
    // requests and clear the
    // currently loaded image.
    if (TextUtils.isEmpty(mUrl)) {
        if (mImageContainer != null) {
            mImageContainer.cancelRequest();
            mImageContainer = null;
        }
        setImageBitmap(null);
        return;
    }

    // if there was an old request in this view, check if it needs to be
    // canceled.
    if (mImageContainer != null && mImageContainer.getRequestUrl() != null) {
        if (mImageContainer.getRequestUrl().equals(mUrl)) {
            // if the request is from the same URL, return.
            return;
        } else {
            // if there is a pre-existing request, cancel it if it's
            // fetching a different URL.
            mImageContainer.cancelRequest();
            setImageBitmap(null);
        }
    }

    // The pre-existing content of this view didn't match the current URL.
    // Load the new image
    // from the network.
    ImageContainer newContainer = mImageLoader.get(mUrl,
            new ImageListener() {
                @Override
                public void onErrorResponse(VolleyError error, Request<?> request) {
                    if (mErrorImageId != 0) {
                        setImageResource(mErrorImageId);
                    }
                }

                @Override
                public void onResponse(final ImageContainer response, boolean isImmediate) {
                    // If this was an immediate response that was delivered
                    // inside of a layout
                    // pass do not set the image immediately as it will
                    // trigger a requestLayout
                    // inside of a layout. Instead, defer setting the image
                    // by posting back to
                    // the main thread.
                    if (isImmediate && isInLayoutPass) {
                        post(new Runnable() {
                            @Override
                            public void run() {
                                onResponse(response, false);
                            }
                        });
                        return;
                    }

                    if (response.getBitmap() != null) {
                        setImageBitmap(response.getBitmap(), !isImmediate);
                    } else if (mDefaultImageId != 0) {
                        setImageResource(mDefaultImageId);
                    }
                }
            }, getWidth(), getHeight());

    // update the ImageContainer to be the new bitmap container.
    mImageContainer = newContainer;
}
项目:upes-academics    文件:CaptchaDialogFragment.java   
/**
 * Gets the captcha image.
 */
private void getImg() 
{
    // TODO Set priority and timeout
    Log.i(LoginActivity.class.getName(), "Loading captcha image...");
    ImageLoader imageLoader = MyVolley.getInstance().getImageLoader();
    imageLoader.setBatchedResponseDelay(0);
    imageLoader.get("https://academics.ddn.upes.ac.in/upes/modules/create_image.php",
            new ImageLoader.ImageListener() {

        final ImageView view = ivCapImg;
        final int defaultImageResId = 5;
        final int errorImageResId = R.drawable.ic_menu_report_image;
        @Override
        public void onErrorResponse(VolleyError error) {
            if (errorImageResId != 0) {
                pbar.setVisibility(View.INVISIBLE);
                view.setVisibility(View.VISIBLE);
                view.setScaleType(ImageView.ScaleType.CENTER);
                view.setImageResource(errorImageResId);
                String msg = MyVolleyErrorHelper.getMessage(error, mContext);
                Toast.makeText(mContext, msg, Toast.LENGTH_SHORT).show();
                Log.e(getActivity().getClass().getName(), msg);
            }
        }

        @Override
        public void onResponse(ImageContainer response, boolean isImmediate) {
            if (response.getBitmap() != null) {
                pbar.setVisibility(View.INVISIBLE);
                view.setVisibility(View.VISIBLE);
                view.setImageBitmap(response.getBitmap());
                view.setScaleType(ImageView.ScaleType.FIT_XY);
                Log.i(LoginActivity.class.getName(), "Loaded captcha image.");
            } else if (defaultImageResId != 0) {
                pbar.setVisibility(ProgressBar.VISIBLE);
                view.setVisibility(View.INVISIBLE);
            }
        }
    });
}
项目:MovableImageView    文件:TestActivity.java   
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final MovableBitmapView iv1 = (MovableBitmapView)findViewById(R.id.image_1);
    final MovableBitmapView iv2 = (MovableBitmapView)findViewById(R.id.image_2);
    final MovableBitmapView iv3 = (MovableBitmapView)findViewById(R.id.image_3);
    final MovableBitmapView iv4 = (MovableBitmapView)findViewById(R.id.image_4);
    final MovableBitmapView iv5 = (MovableBitmapView)findViewById(R.id.image_5);
    final MovableBitmapView iv6 = (MovableBitmapView)findViewById(R.id.image_6);

    iv1.setImageResource(R.drawable.sample1);
    iv2.setImageResource(R.drawable.sample2);
    iv3.setImageResource(R.drawable.sample3);
    iv4.setImageResource(R.drawable.sample4);

    RequestQueue queue = Volley.newRequestQueue(getApplicationContext());

    ImageLoader loader = new ImageLoader(queue, new BitmapLruCache());

    String url = "http://cinephilefix.files.wordpress.com/2010/11/mooon.jpg";

    loader.get(url, new ImageLoader.ImageListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.v(TAG, "onError:"+error.toString());
        }

        @Override
        public void onResponse(ImageContainer response, boolean isImmediate) {
            if (response == null) {
                Log.v(TAG, "onResponse null");
                return;
            }
            if (response.getBitmap() == null) {
                Log.v(TAG, "onResponse bitmap null");
                return;
            }
            iv5.setBitmap(response.getBitmap());
            iv6.setBitmap(response.getBitmap());
        }
    });
}
项目:MangaJunkie-Android    文件:SearchFragment.java   
public void cancelAll() {
    for ( ImageContainer request : cover_requests.values() ) request.cancelRequest();
}
项目:MangaJunkie-Android    文件:SearchFragment.java   
@Override
public View getView( int index, View view, ViewGroup parent ) {
    if ( view == null ) { view = getActivity().getLayoutInflater().inflate( R.layout.listitem_search, parent, false ); }

    String sys_name, title, author, tags;
    try {
        sys_name = query_results.getJSONArray( "sys_name" ).getString( index );
        title    = query_results.getJSONArray( "title"    ).getString( index );
        author   = query_results.getJSONArray( "author"   ).getString( index );
        tags     = query_results.getJSONArray( "tags"     ).getString( index );

        author = author == null || author.equals( "null" ) ? "" : "by " + author;

    } catch ( JSONException e ) {
        sys_name = "";
        title    = "error";
        author   = "contact developer";
        tags     = null;
    }

    final Cover cover = new Manga( sys_name ).getCover();
    final ImageView cover_view = (ImageView)view.findViewById( R.id.cover );
    cover_view.setTag( cover );
    cover_view.setImageDrawable( null );


    ( (TextView)view.findViewById( R.id.title  )).setText( title );
    ( (TextView)view.findViewById( R.id.author )).setText( author );
    ( (TextView)view.findViewById( R.id.tags   )).setText( tags   );


    // Queue and store image request for cover
    if ( cover_requests.containsKey( view )) cover_requests.get( view ).cancelRequest();

    ImageContainer request = App.getImageLoader().get(
        API.getCoverUrl( new Manga( sys_name ).getCover() ),
        new ImageListener() {
            @Override public void onResponse( ImageContainer container, boolean instant ) {
                if ( !cover.equals( cover_view.getTag() )) return;
                if ( instant ) cover_view.setImageBitmap( container.getBitmap() );
                else {
                    TransitionDrawable cover_transition = new TransitionDrawable( new Drawable[]{
                        new ColorDrawable(),
                        new BitmapDrawable( getResources(), container.getBitmap() ) } );
                    cover_view.setImageDrawable( cover_transition );
                    cover_transition.startTransition( 200 );
                }
            }

            @Override public void onErrorResponse( VolleyError volleyError ) {
                if ( !cover.equals( cover_view.getTag() )) return;
                cover_view.setImageDrawable( null );
            }
        },
        COVER_SIZE, COVER_SIZE );

    cover_requests.put( view, request );

    return view;
}
项目:android-blog    文件:NetworkImageView.java   
/**
 * Loads the image for the view if it isn't already loaded.
 * @param isInLayoutPass True if this was invoked from a layout pass, false otherwise.
 */
private void loadImageIfNecessary(final boolean isInLayoutPass) {
    int width = getWidth();
    int height = getHeight();

    boolean isFullyWrapContent = getLayoutParams() != null
            && getLayoutParams().height == LayoutParams.WRAP_CONTENT
            && getLayoutParams().width == LayoutParams.WRAP_CONTENT;
    // if the view's bounds aren't known yet, and this is not a wrap-content/wrap-content
    // view, hold off on loading the image.
    if (width == 0 && height == 0 && !isFullyWrapContent) {
        return;
    }

    // if the URL to be loaded in this view is empty, cancel any old requests and clear the
    // currently loaded image.
    if (TextUtils.isEmpty(mUrl)) {
        if (mImageContainer != null) {
            mImageContainer.cancelRequest();
            mImageContainer = null;
        }
        setImageBitmap(null);
        return;
    }

    // if there was an old request in this view, check if it needs to be canceled.
    if (mImageContainer != null && mImageContainer.getRequestUrl() != null) {
        if (mImageContainer.getRequestUrl().equals(mUrl)) {
            // if the request is from the same URL, return.
            return;
        } else {
            // if there is a pre-existing request, cancel it if it's fetching a different URL.
            mImageContainer.cancelRequest();
            setImageBitmap(null);
        }
    }

    // The pre-existing content of this view didn't match the current URL. Load the new image
    // from the network.
    ImageContainer newContainer = mImageLoader.get(mUrl,
            new ImageListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    if (mErrorImageId != 0) {
                        setImageResource(mErrorImageId);
                    }
                }

                @Override
                public void onResponse(final ImageContainer response, boolean isImmediate) {
                    // If this was an immediate response that was delivered inside of a layout
                    // pass do not set the image immediately as it will trigger a requestLayout
                    // inside of a layout. Instead, defer setting the image by posting back to
                    // the main thread.
                    if (isImmediate && isInLayoutPass) {
                        post(new Runnable() {
                            @Override
                            public void run() {
                                onResponse(response, false);
                            }
                        });
                        return;
                    }

                    if (response.getBitmap() != null) {
                        setImageBitmap(response.getBitmap());
                    } else if (mDefaultImageId != 0) {
                        setImageResource(mDefaultImageId);
                    }
                }
            });

    // update the ImageContainer to be the new bitmap container.
    mImageContainer = newContainer;
}
项目:wmc    文件:NetworkImageView.java   
/**
 * Loads the image for the view if it isn't already loaded.
 * @param isInLayoutPass True if this was invoked from a layout pass, false otherwise.
 */
private void loadImageIfNecessary(final boolean isInLayoutPass) {
    int width = getWidth();
    int height = getHeight();

    boolean isFullyWrapContent = getLayoutParams() != null
            && getLayoutParams().height == LayoutParams.WRAP_CONTENT
            && getLayoutParams().width == LayoutParams.WRAP_CONTENT;
    // if the view's bounds aren't known yet, and this is not a wrap-content/wrap-content
    // view, hold off on loading the image.
    if (width == 0 && height == 0 && !isFullyWrapContent) {
        return;
    }

    // if the URL to be loaded in this view is empty, cancel any old requests and clear the
    // currently loaded image.
    if (TextUtils.isEmpty(mUrl)) {
        if (mImageContainer != null) {
            mImageContainer.cancelRequest();
            mImageContainer = null;
        }
        setImageBitmap(null);
        return;
    }

    // if there was an old request in this view, check if it needs to be canceled.
    if (mImageContainer != null && mImageContainer.getRequestUrl() != null) {
        if (mImageContainer.getRequestUrl().equals(mUrl)) {
            // if the request is from the same URL, return.
            return;
        } else {
            // if there is a pre-existing request, cancel it if it's fetching a different URL.
            mImageContainer.cancelRequest();
            setImageBitmap(null);
        }
    }

    // The pre-existing content of this view didn't match the current URL. Load the new image
    // from the network.
    ImageContainer newContainer = mImageLoader.get(mUrl,
            new ImageListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    if (mErrorImageId != 0) {
                        setImageResource(mErrorImageId);
                    }
                }

                @Override
                public void onResponse(final ImageContainer response, boolean isImmediate) {
                    // If this was an immediate response that was delivered inside of a layout
                    // pass do not set the image immediately as it will trigger a requestLayout
                    // inside of a layout. Instead, defer setting the image by posting back to
                    // the main thread.
                    if (isImmediate && isInLayoutPass) {
                        post(new Runnable() {
                            @Override
                            public void run() {
                                onResponse(response, false);
                            }
                        });
                        return;
                    }

                    if (response.getBitmap() != null) {
                        setImageBitmap(response.getBitmap());
                    } else if (mDefaultImageId != 0) {
                        setImageResource(mDefaultImageId);
                    }
                }
            });

    // update the ImageContainer to be the new bitmap container.
    mImageContainer = newContainer;
}
项目:skip-android    文件:NetworkImageView.java   
/**
 * Loads the image for the view if it isn't already loaded.
 * @param isInLayoutPass True if this was invoked from a layout pass, false otherwise.
 */
private void loadImageIfNecessary(final boolean isInLayoutPass) {
    int width = getWidth();
    int height = getHeight();

    boolean isFullyWrapContent = getLayoutParams() != null
            && getLayoutParams().height == LayoutParams.WRAP_CONTENT
            && getLayoutParams().width == LayoutParams.WRAP_CONTENT;
    // if the view's bounds aren't known yet, and this is not a wrap-content/wrap-content
    // view, hold off on loading the image.
    if (width == 0 && height == 0 && !isFullyWrapContent) {
        return;
    }

    // if the URL to be loaded in this view is empty, cancel any old requests and clear the
    // currently loaded image.
    if (TextUtils.isEmpty(mUrl)) {
        if (mImageContainer != null) {
            mImageContainer.cancelRequest();
            mImageContainer = null;
        }
        setImageBitmap(null);
        return;
    }

    // if there was an old request in this view, check if it needs to be canceled.
    if (mImageContainer != null && mImageContainer.getRequestUrl() != null) {
        if (mImageContainer.getRequestUrl().equals(mUrl)) {
            // if the request is from the same URL, return.
            return;
        } else {
            // if there is a pre-existing request, cancel it if it's fetching a different URL.
            mImageContainer.cancelRequest();
            setImageBitmap(null);
        }
    }

    // The pre-existing content of this view didn't match the current URL. Load the new image
    // from the network.
    ImageContainer newContainer = mImageLoader.get(mUrl,
            new ImageListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    if (mErrorImageId != 0) {
                        setImageResource(mErrorImageId);
                    }
                }

                @Override
                public void onResponse(final ImageContainer response, boolean isImmediate) {
                    // If this was an immediate response that was delivered inside of a layout
                    // pass do not set the image immediately as it will trigger a requestLayout
                    // inside of a layout. Instead, defer setting the image by posting back to
                    // the main thread.
                    if (isImmediate && isInLayoutPass) {
                        post(new Runnable() {
                            @Override
                            public void run() {
                                onResponse(response, false);
                            }
                        });
                        return;
                    }

                    if (response.getBitmap() != null) {
                        setImageBitmap(response.getBitmap());
                    } else if (mDefaultImageId != 0) {
                        setImageResource(mDefaultImageId);
                    }
                }
            });

    // update the ImageContainer to be the new bitmap container.
    mImageContainer = newContainer;
}
项目:acfun-new    文件:NetworkImageView.java   
/**
 * Loads the image for the view if it isn't already loaded.
 * @param isInLayoutPass True if this was invoked from a layout pass, false otherwise.
 */
private void loadImageIfNecessary(final boolean isInLayoutPass) {
    int width = getWidth();
    int height = getHeight();

    boolean isFullyWrapContent = getLayoutParams() != null
            && getLayoutParams().height == LayoutParams.WRAP_CONTENT
            && getLayoutParams().width == LayoutParams.WRAP_CONTENT;
    // if the view's bounds aren't known yet, and this is not a wrap-content/wrap-content
    // view, hold off on loading the image.
    if (width == 0 && height == 0 && !isFullyWrapContent) {
        return;
    }

    // if the URL to be loaded in this view is empty, cancel any old requests and clear the
    // currently loaded image.
    if (TextUtils.isEmpty(mUrl)) {
        if (mImageContainer != null) {
            mImageContainer.cancelRequest();
            mImageContainer = null;
        }
        setImageBitmap(null);
        return;
    }

    // if there was an old request in this view, check if it needs to be canceled.
    if (mImageContainer != null && mImageContainer.getRequestUrl() != null) {
        if (mImageContainer.getRequestUrl().equals(mUrl)) {
            // if the request is from the same URL, return.
            return;
        } else {
            // if there is a pre-existing request, cancel it if it's fetching a different URL.
            mImageContainer.cancelRequest();
            setImageBitmap(null);
        }
    }

    // The pre-existing content of this view didn't match the current URL. Load the new image
    // from the network.
    ImageContainer newContainer = mImageLoader.get(mUrl,
            new ImageListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    if (mErrorImageId != 0) {
                        setImageResource(mErrorImageId);
                    }
                }

                @Override
                public void onResponse(final ImageContainer response, boolean isImmediate) {
                    // If this was an immediate response that was delivered inside of a layout
                    // pass do not set the image immediately as it will trigger a requestLayout
                    // inside of a layout. Instead, defer setting the image by posting back to
                    // the main thread.
                    if (isImmediate && isInLayoutPass) {
                        post(new Runnable() {
                            @Override
                            public void run() {
                                onResponse(response, false);
                            }
                        });
                        return;
                    }

                    if (response.getBitmap() != null) {
                        setImageBitmap(response.getBitmap());
                    } else if (mDefaultImageId != 0) {
                        setImageResource(mDefaultImageId);
                    }
                }
            });

    // update the ImageContainer to be the new bitmap container.
    mImageContainer = newContainer;
}
项目:500px    文件:NetworkImageView.java   
/**
 * Loads the image for the view if it isn't already loaded.
 * @param isInLayoutPass True if this was invoked from a layout pass, false otherwise.
 */
private void loadImageIfNecessary(final boolean isInLayoutPass) {
    int width = getWidth();
    int height = getHeight();

    boolean isFullyWrapContent = getLayoutParams() != null
            && getLayoutParams().height == LayoutParams.WRAP_CONTENT
            && getLayoutParams().width == LayoutParams.WRAP_CONTENT;
    // if the view's bounds aren't known yet, and this is not a wrap-content/wrap-content
    // view, hold off on loading the image.
    if (width == 0 && height == 0 && !isFullyWrapContent) {
        return;
    }

    // if the URL to be loaded in this view is empty, cancel any old requests and clear the
    // currently loaded image.
    if (TextUtils.isEmpty(mUrl)) {
        if (mImageContainer != null) {
            mImageContainer.cancelRequest();
            mImageContainer = null;
        }
        setImageBitmap(null);
        return;
    }

    // if there was an old request in this view, check if it needs to be canceled.
    if (mImageContainer != null && mImageContainer.getRequestUrl() != null) {
        if (mImageContainer.getRequestUrl().equals(mUrl)) {
            // if the request is from the same URL, return.
            return;
        } else {
            // if there is a pre-existing request, cancel it if it's fetching a different URL.
            mImageContainer.cancelRequest();
            setImageBitmap(null);
        }
    }

    // The pre-existing content of this view didn't match the current URL. Load the new image
    // from the network.
    ImageContainer newContainer = mImageLoader.get(mUrl,
            new ImageListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    if (mErrorImageId != 0) {
                        setImageResource(mErrorImageId);
                    }
                }

                @Override
                public void onResponse(final ImageContainer response, boolean isImmediate) {
                    // If this was an immediate response that was delivered inside of a layout
                    // pass do not set the image immediately as it will trigger a requestLayout
                    // inside of a layout. Instead, defer setting the image by posting back to
                    // the main thread.
                    if (isImmediate && isInLayoutPass) {
                        post(new Runnable() {
                            @Override
                            public void run() {
                                onResponse(response, false);
                            }
                        });
                        return;
                    }

                    if (response.getBitmap() != null) {
                        setImageBitmap(response.getBitmap());
                    } else if (mDefaultImageId != 0) {
                        setImageResource(mDefaultImageId);
                    }
                }
            });

    // update the ImageContainer to be the new bitmap container.
    mImageContainer = newContainer;
}
项目:CS492-FA13    文件:NetworkImageView.java   
/**
 * Loads the image for the view if it isn't already loaded.
 * @param isInLayoutPass True if this was invoked from a layout pass, false otherwise.
 */
private void loadImageIfNecessary(final boolean isInLayoutPass) {
    int width = getWidth();
    int height = getHeight();

    boolean isFullyWrapContent = getLayoutParams() != null
            && getLayoutParams().height == LayoutParams.WRAP_CONTENT
            && getLayoutParams().width == LayoutParams.WRAP_CONTENT;
    // if the view's bounds aren't known yet, and this is not a wrap-content/wrap-content
    // view, hold off on loading the image.
    if (width == 0 && height == 0 && !isFullyWrapContent) {
        return;
    }

    // if the URL to be loaded in this view is empty, cancel any old requests and clear the
    // currently loaded image.
    if (TextUtils.isEmpty(mUrl)) {
        if (mImageContainer != null) {
            mImageContainer.cancelRequest();
            mImageContainer = null;
        }
        setDefaultImageOrNull();
        return;
    }

    // if there was an old request in this view, check if it needs to be canceled.
    if (mImageContainer != null && mImageContainer.getRequestUrl() != null) {
        if (mImageContainer.getRequestUrl().equals(mUrl)) {
            // if the request is from the same URL, return.
            return;
        } else {
            // if there is a pre-existing request, cancel it if it's fetching a different URL.
            mImageContainer.cancelRequest();
            setDefaultImageOrNull();
        }
    }

    // The pre-existing content of this view didn't match the current URL. Load the new image
    // from the network.
    ImageContainer newContainer = mImageLoader.get(mUrl,
            new ImageListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    if (mErrorImageId != 0) {
                        setImageResource(mErrorImageId);
                    }
                }

                @Override
                public void onResponse(final ImageContainer response, boolean isImmediate) {
                    // If this was an immediate response that was delivered inside of a layout
                    // pass do not set the image immediately as it will trigger a requestLayout
                    // inside of a layout. Instead, defer setting the image by posting back to
                    // the main thread.
                    if (isImmediate && isInLayoutPass) {
                        post(new Runnable() {
                            @Override
                            public void run() {
                                onResponse(response, false);
                            }
                        });
                        return;
                    }

                    if (response.getBitmap() != null) {
                        setImageBitmap(response.getBitmap());
                    } else if (mDefaultImageId != 0) {
                        setImageResource(mDefaultImageId);
                    }
                }
            });

    // update the ImageContainer to be the new bitmap container.
    mImageContainer = newContainer;
}
项目:icareyou    文件:NetworkImageView.java   
/**
 * Loads the image for the view if it isn't already loaded.
 */
private void loadImageIfNecessary() {
    int width = getWidth();
    int height = getHeight();

    // if the view's bounds aren't known yet, hold off on loading the image.
    if (width == 0 && height == 0) {
        return;
    }

    // if the URL to be loaded in this view is empty, cancel any old requests and clear the
    // currently loaded image.
    if (TextUtils.isEmpty(mUrl)) {
        if (mImageContainer != null) {
            mImageContainer.cancelRequest();
            mImageContainer = null;
        }
        setImageBitmap(null);
        return;
    }

    // if there was an old request in this view, check if it needs to be canceled.
    if (mImageContainer != null && mImageContainer.getRequestUrl() != null) {
        if (mImageContainer.getRequestUrl().equals(mUrl)) {
            // if the request is from the same URL, return.
            return;
        } else {
            // if there is a pre-existing request, cancel it if it's fetching a different URL.
            mImageContainer.cancelRequest();
            setImageBitmap(null);
        }
    }

    // The pre-existing content of this view didn't match the current URL. Load the new image
    // from the network.
    ImageContainer newContainer = mImageLoader.get(mUrl,
            ImageLoader.getImageListener(this, mDefaultImageId, mErrorImageId));

    // update the ImageContainer to be the new bitmap container.
    mImageContainer = newContainer;
}
项目:turtle-server    文件:NetworkImageView.java   
/**
 * Loads the image for the view if it isn't already loaded.
 * @param isInLayoutPass True if this was invoked from a layout pass, false otherwise.
 */
private void loadImageIfNecessary(final boolean isInLayoutPass) {
    int width = getWidth();
    int height = getHeight();

    boolean isFullyWrapContent = getLayoutParams() != null
            && getLayoutParams().height == LayoutParams.WRAP_CONTENT
            && getLayoutParams().width == LayoutParams.WRAP_CONTENT;
    // if the view's bounds aren't known yet, and this is not a wrap-content/wrap-content
    // view, hold off on loading the image.
    if (width == 0 && height == 0 && !isFullyWrapContent) {
        return;
    }

    // if the URL to be loaded in this view is empty, cancel any old requests and clear the
    // currently loaded image.
    if (TextUtils.isEmpty(mUrl)) {
        if (mImageContainer != null) {
            mImageContainer.cancelRequest();
            mImageContainer = null;
        }
        setImageBitmap(null);
        return;
    }

    // if there was an old request in this view, check if it needs to be canceled.
    if (mImageContainer != null && mImageContainer.getRequestUrl() != null) {
        if (mImageContainer.getRequestUrl().equals(mUrl)) {
            // if the request is from the same URL, return.
            return;
        } else {
            // if there is a pre-existing request, cancel it if it's fetching a different URL.
            mImageContainer.cancelRequest();
            setImageBitmap(null);
        }
    }

    // The pre-existing content of this view didn't match the current URL. Load the new image
    // from the network.
    ImageContainer newContainer = mImageLoader.get(mUrl,
            new ImageListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    if (mErrorImageId != 0) {
                        setImageResource(mErrorImageId);
                    }
                }

                @Override
                public void onResponse(final ImageContainer response, boolean isImmediate) {
                    // If this was an immediate response that was delivered inside of a layout
                    // pass do not set the image immediately as it will trigger a requestLayout
                    // inside of a layout. Instead, defer setting the image by posting back to
                    // the main thread.
                    if (isImmediate && isInLayoutPass) {
                        post(new Runnable() {
                            @Override
                            public void run() {
                                onResponse(response, false);
                            }
                        });
                        return;
                    }

                    if (response.getBitmap() != null) {
                        setImageBitmap(response.getBitmap());
                    } else if (mDefaultImageId != 0) {
                        setImageResource(mDefaultImageId);
                    }
                }
            });

    // update the ImageContainer to be the new bitmap container.
    mImageContainer = newContainer;
}