Java Code Examples for com.android.volley.toolbox.ImageLoader#ImageContainer

The following examples show how to use com.android.volley.toolbox.ImageLoader#ImageContainer . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NetworkMarker.java    From android-custom-markers with Apache License 2.0 5 votes vote down vote up
@Override
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {

    final Bitmap bitmap = response.getBitmap();

    // Set image and update view
    markerImage.setImageBitmap(bitmap);
    updateView();
}
 
Example 2
Source File: CheckinHolder.java    From attendee-checkin with Apache License 2.0 5 votes vote down vote up
@Override
public void bind(Checkin checkin, ImageLoader imageLoader) {
    mName.setText(checkin.getAttendeeName());
    Context context = mDescription.getContext();
    long timestamp = checkin.getTimestamp();
    if (System.currentTimeMillis() - timestamp * 1000 < 60 * 1000) {
        mDescription.setText(R.string.just_now);
    } else {
        mDescription.setText(
                DateUtils.getRelativeDateTimeString(context, timestamp * 1000,
                        DateUtils.MINUTE_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0));
    }
    // Load the icon
    ImageLoader.ImageContainer container = (ImageLoader.ImageContainer) mIcon.getTag();
    if (container != null) {
        container.cancelRequest();
    }
    String imageUrl = checkin.getAttendeeImageUrl();
    if (!TextUtils.isEmpty(imageUrl) && Patterns.WEB_URL.matcher(imageUrl).matches()) {
        mIcon.setTag(imageLoader.get(imageUrl,
                new RoundedImageListener(mIcon, R.drawable.ic_person,
                        R.drawable.ic_person)));
    } else {
        mIcon.setImageResource(R.drawable.ic_person);
    }
    if (mWillAnimate && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mCheckin.setImageResource(R.drawable.checkin_anim);
    } else {
        mCheckin.setImageResource(R.drawable.checkin);
    }
}
 
Example 3
Source File: AttendeeListFragment.java    From attendee-checkin with Apache License 2.0 5 votes vote down vote up
public void bind(Cursor cursor, ImageLoader imageLoader) {
    itemView.setBackgroundDrawable(null);
    ViewCompat.setTranslationZ(itemView, 0.f);
    mName.setText(cursor.getString(cursor.getColumnIndexOrThrow(Table.Attendee.NAME)));
    mEmail.setText(cursor.getString(cursor.getColumnIndexOrThrow(Table.Attendee.EMAIL)));
    String note = cursor.getString(cursor.getColumnIndexOrThrow(Table.Attendee.NOTE));
    mNote.setVisibility(TextUtils.isEmpty(note) ? View.GONE : View.VISIBLE);
    mNote.setText(note);
    mEventId = cursor.getString(cursor.getColumnIndexOrThrow(Table.Attendee.EVENT_ID));
    mAttendeeId = cursor.getString(cursor.getColumnIndexOrThrow(Table.Attendee.ID));
    mAttendeeCheckedIn = !cursor.isNull(cursor.getColumnIndexOrThrow(Table.Attendee.CHECKIN));
    mCheckin.setVisibility(mAttendeeCheckedIn ? View.VISIBLE : View.INVISIBLE);
    mActionCheck.setImageResource(mAttendeeCheckedIn ?
            R.drawable.ic_check_green : R.drawable.ic_check_gray);
    boolean modified = 0 != cursor.getInt(cursor.getColumnIndexOrThrow(Table.Attendee.CHECKIN_MODIFIED));
    mSyncInProcess.setVisibility(modified && BuildConfig.DEBUG ?
            View.VISIBLE : View.INVISIBLE);
    mActions.setVisibility(View.GONE);
    itemView.setOnClickListener(this);
    mActionCheck.setOnClickListener(this);
    mActionEdit.setOnClickListener(this);
    // Icon
    ImageLoader.ImageContainer container = (ImageLoader.ImageContainer)
            mIcon.getTag();
    if (container != null) {
        container.cancelRequest();
    }
    int columnIndexImageUrl = cursor.getColumnIndexOrThrow(Table.Attendee.IMAGE_URL);
    if (!cursor.isNull(columnIndexImageUrl)) {
        mIcon.setTag(imageLoader.get(cursor.getString(columnIndexImageUrl),
                new RoundedImageListener(mIcon,
                        R.drawable.ic_person, R.drawable.ic_person)));
    } else {
        mIcon.setImageResource(R.drawable.ic_person);
    }
}
 
Example 4
Source File: RoundedImageListener.java    From attendee-checkin with Apache License 2.0 5 votes vote down vote up
@Override
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
    if (response.getBitmap() != null) {
        Bitmap src = response.getBitmap();
        RoundedBitmapDrawable avatar = RoundedBitmapDrawableFactory.create(
                mImageView.getResources(), src);
        avatar.setCornerRadius(Math.max(src.getWidth(), src.getHeight()) / 2.0f);
        mImageView.setImageDrawable(avatar);
    } else if (mDefaultImageResId != 0) {
        mImageView.setImageResource(mDefaultImageResId);
    }
}
 
Example 5
Source File: HttpLoader.java    From seny-devpkg with Apache License 2.0 5 votes vote down vote up
/**
 * 发起图片网络请求
 *
 * @param requestUrl 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.
 * @return A container object that contains all of the properties of the request, as well as
 * the currently available image (default if remote is not loaded).
 */
public void display(final ImageView view, String requestUrl, final int defaultImageResId, final int errorImageResId, int maxWidth, int maxHeight, ImageView.ScaleType scaleType) {
    if (mImageContainers.containsKey(view)) {//如果已经在给该View请求一张网络图片
        mImageContainers.get(view).cancelRequest();//那么就把之前的取消掉,保证一个ImageView身上只有一个任务。
    }
    ImageLoader.ImageContainer imageContainer = mImageLoader.get(requestUrl, new ImageLoader.ImageListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (errorImageResId != 0) {
                view.setImageResource(errorImageResId);
                ObjectAnimator.ofFloat(view, "alpha", 0f, 1f).setDuration(800).start();//渐变动画
            }
            mImageContainers.remove(view);//请求失败,移除
        }

        @Override
        public void onResponse(final ImageLoader.ImageContainer response, boolean isImmediate) {
            if (response.getBitmap() != null) {
                view.setImageBitmap(response.getBitmap());
                ObjectAnimator.ofFloat(view, "alpha", 0f, 1f).setDuration(800).start();//渐变动画
                mImageContainers.remove(view);//请求成功,移除
            } else if (defaultImageResId != 0) {
                view.setImageResource(defaultImageResId);
            }
        }
    }, maxWidth, maxHeight, scaleType);
    mImageContainers.put(view, imageContainer);//将View身上的请求任务进行保存
}
 
Example 6
Source File: CrossbowImage.java    From CrossBow with Apache License 2.0 5 votes vote down vote up
/**
 * called when the network image loader returns
 */
@Override
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {

    ImageView imageView = this.imageView.get();
    if(imageView != null && response.getBitmap() != null) {
        setBitmap(response.getBitmap(), isImmediate);
    }
}
 
Example 7
Source File: FeedImageView.java    From FeedListViewDemo with MIT License 4 votes vote down vote up
private void loadImageIfNecessary(final boolean isInLayoutPass) {
    final int width = getWidth();
    int height = getHeight();

    boolean isFullyWrapContent = getLayoutParams() != null
            && getLayoutParams().height == ViewGroup.LayoutParams.WRAP_CONTENT
            && getLayoutParams().width == ViewGroup.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;
        }
        setDefaultImageOrNot();
        return;
    }

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

    // The Pre-existing content of this view didn't match the current URL. Load the new image
    // from the network
    //如果先前那个URL不等于现在需要加载的URL,那么就重新下载图片
    ImageLoader.ImageContainer newContainer = mImageLoader.get(mUrl,
            new ImageLoader.ImageListener() {
                @Override
                public void onResponse(final ImageLoader.ImageContainer response, boolean isImmediate) {
                    if (isImmediate && isInLayoutPass) {
                        post(new Runnable() {
                            @Override
                            public void run() {
                                onResponse(response, false);
                            }
                        });
                        return;
                    }
                    int bWidth = 0, bHeight = 0;
                    Bitmap bitmap = response.getBitmap();
                    if (bitmap != null) {
                        setImageBitmap(bitmap);
                        bWidth = bitmap.getWidth();
                        bHeight = bitmap.getHeight();
                        adjustImageAspect(bWidth, bHeight);
                    } else if (mDefaultImageId != 0) {
                        setImageResource(mDefaultImageId);
                    }

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

                }

                @Override
                public void onErrorResponse(VolleyError error) {
                    if (mErrorImageId != 0 ) {
                        setImageResource(mErrorImageId);
                    }
                    if (mObserver != null) {
                        mObserver.onError();
                    }
                }
            });
    mImageContainer = newContainer;
}