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

项目: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-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;
}
项目:GomeOnline    文件:ImageLoader.java   
public void downLoadImage(String url, final ImageView imgView, final int defaultImageResId, final int errorImageResId) {
//      if (!isOk) {
//          if (imgView != null) {
//              imgView.setImageResource(R.drawable.icon_head_default);
//          }
//          return;
//      }
        if (url == null) {
            imgView.setImageResource(R.drawable.icon_head_default);
            return;
        }
        // ImageListener listener =
        // com.android.volley.toolbox.ImageLoader.getImageListener(imgView,
        // defaultImageResId, errorImageResId);

        ImageListener listener = new MyImageListener(imgView,defaultImageResId,errorImageResId) ;
        ImageListener lastL = mImageMaps.get(imgView);
        if(lastL!=null){
            ((MyImageListener)lastL).isCancel = true;
            mImageMaps.remove(lastL);
        }
        mImageMaps.put(imgView, listener);
        mImageLoader.get(url, listener);
    }
项目: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);

        }
    };
}
项目:eManga    文件:ImageCacheManager.java   
/**
 *  Executes and image load
 * @param url
 *      location of image
 * @param listener
 *      Listener for completion
 */
public void getImage(String url, final ImageView imageView, final ImageListener listener){
    mImageLoader.get(url, new ImageListener() {
        @Override
        public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
            if(response.getBitmap() != null) {
                imageView.setImageBitmap(response.getBitmap());
            }
            listener.onResponse(response,isImmediate);
        }

        @Override
        public void onErrorResponse(VolleyError error) {
            listener.onErrorResponse(error);
        }
    });
}
项目: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    文件: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]);
}
项目:lark    文件:LarkImageLoaderUtil.java   
private void getBitmap(final String url, ImageView imageView, int maxWidth,
        int maxHeight, ScaleType scaleType, int defaultLoadingBitmapResId,
        int defaultErrorBitmapResId, ImageListener listener,
        ClippingBitmapListener clippingBitmapListener) {

    LarkImageLoader imageLoader = new LarkImageLoader(mRequestQueue,
            BitmapImageCache.getInstance());
    if (clippingBitmapListener != null) {
        imageLoader.setClippingBitmapListener(clippingBitmapListener);
    }
    ImageListener imageListener = null;
    if (listener != null) {
        imageListener = listener;
    } else {
        if (imageView != null) {
            imageListener = ImageLoader.getImageListener(imageView,
                    defaultLoadingBitmapResId, defaultErrorBitmapResId);
        } else {
            Log.e(TAG,
                    "Invalid request(No ImageListener and ImageView).Url:"
                            + url);
        }
    }
    if(scaleType == null){
        scaleType = ScaleType.CENTER_INSIDE;
    }
    imageLoader.get(url, imageListener, maxWidth, maxHeight, scaleType);
}
项目:VolleyUtils    文件:VolleyUtil.java   
public static void disPlayImage(Context context, ImageView imageView,
        String url, int defaultResourceId, int errorResourceId) {
    ImageListener listener = ImageLoader.getImageListener(imageView,
            defaultResourceId, errorResourceId);
    getImageLoader(context).get(url, listener);

}
项目:VolleyUtils    文件:VolleyUtil.java   
public static void disPlayImage(Context context, ImageView imageView,
        String url, int defaultResourceId, int errorResourceId,
        int maxWidth, int maxHeight) {
    ImageListener listener = ImageLoader.getImageListener(imageView,
            defaultResourceId, errorResourceId);
    getImageLoader(context).get(url, listener, maxWidth, maxHeight);

}
项目: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() );
        }
    } );

}
项目:android-opensource-library-56    文件:RssListAdapter.java   
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        convertView = mInflator.inflate(R.layout.card_list, null);
        holder = new ViewHolder();
        holder.text = (TextView) convertView.findViewById(R.id.title);
        holder.entryImage = (ImageView) convertView
                .findViewById(R.id.entry_image);
        holder.description = (TextView) convertView
                .findViewById(R.id.description);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    Item item = getItem(position);
    holder.text.setText(item.title);
    holder.description.setText(item.description);
    if (item.imageUrl != null) {
        ImageListener listener = ImageLoader.getImageListener(
                holder.entryImage, R.drawable.ic_launcher,
                R.drawable.ic_launcher);
        if (holder.container != null) {
            holder.container.cancelRequest();
        }
        holder.container = mImageLoader.get(item.imageUrl, listener);
        holder.entryImage.setVisibility(View.VISIBLE);
    } else {
        holder.entryImage.setVisibility(View.GONE);
    }

    return convertView;
}
项目:android-opensource-library-56    文件:RssListAdapter.java   
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        convertView = mInflator.inflate(R.layout.card_list, null);
        holder = new ViewHolder();
        holder.text = (TextView) convertView.findViewById(R.id.title);
        holder.entryImage = (ImageView) convertView
                .findViewById(R.id.entry_image);
        holder.description = (TextView) convertView
                .findViewById(R.id.description);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    Item item = getItem(position);
    holder.text.setText(item.title);
    holder.description.setText(item.description);
    if (item.imageUrl != null) {
        ImageListener listener = ImageLoader.getImageListener(
                holder.entryImage, R.drawable.ic_launcher,
                R.drawable.ic_launcher);
        if (holder.container != null) {
            holder.container.cancelRequest();
        }
        holder.container = mImageLoader.get(item.imageUrl, listener);
        holder.entryImage.setVisibility(View.VISIBLE);
    } else {
        holder.entryImage.setVisibility(View.GONE);
    }

    return convertView;
}
项目: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);
    }
}
项目:BeautyGallery    文件:VolleyUtil.java   
public void displayImage(String url,ImageListener listener){
    mImageLoader.get(url, listener);
}
项目:PlexPy-Remote    文件:ImageCacheManager.java   
public void getImage(String url, ImageListener listener){
    mImageLoader.get(url, listener);
}
项目: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_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;
}
项目: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;
}
项目: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;
}
项目:lark    文件:LarkImageLoaderUtil.java   
/**
 * image dealing by yourself according to listener
 * 
 * @param url
 * @param listener
 */
public void get(final String url, ImageListener listener) {
    if (listener != null) {
        getBitmap(url, null, 0, 0, ScaleType.CENTER_INSIDE, 0, 0, listener,null);
    }
}
项目:lark    文件:LarkImageLoaderUtil.java   
/**
 * Issues a bitmap request with the given URL if that image is not available
 * in the cache, and returns a bitmap container that contains all of the
 * data relating to the request (as well as the default image if the
 * requested image is not available).
 * 
 * @param url
 *            The url of the remote image
 * @param maxWidth
 *            The maximum width of the returned image.
 * @param maxHeight
 *            The maximum height of the returned image.
 * @param scaleType
 *            The ImageViews ScaleType used to calculate the needed image
 *            size.
 * @param listener
 *            The listener to call when the remote image is loaded
 */
public void get(final String url, int maxWidth, int maxHeight,
        ScaleType scaleType, ImageListener listener) {
    getBitmap(url, null, maxWidth, maxHeight, scaleType, 0, 0, listener,null);
}
项目:AndroidLinkup    文件:VolleyHelper.java   
/**
 * 加载网络图片到ImageView
 * 
 * @param iv
 *            ImageView实例
 * @param url
 *            url地址
 */
public void loadImage(ImageView iv, String url) {
    ImageLoader imageLoader = new ImageLoader(requestQueue, new BitmapCache());
    ImageListener listener = ImageLoader.getImageListener(iv, R.drawable.icon_default, R.drawable.icon_default);
    imageLoader.get(url, listener);
}
项目:eManga    文件:ImageCacheManager.java   
/**
 *  Executes and image load
 * @param url
 *      location of image
 * @param listener
 *      Listener for completion
 */
public void getImage(String url, ImageListener listener){
    mImageLoader.get(url, listener);
}
项目:Qmusic    文件:QMusicRequestManager.java   
/**
 * Executes and image load
 * 
 * @param url
 *            location of image
 * @param listener
 *            Listener for completion
 */
public void getImage(String url, ImageListener listener) {
    mImageLoader.get(url, listener);
}