Java Code Examples for com.android.volley.toolbox.ImageLoader#get()

The following examples show how to use com.android.volley.toolbox.ImageLoader#get() . 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: ProfilePictureActivity.java    From kute with Apache License 2.0 6 votes vote down vote up
/******************** Custom Functions *************************/
private void setupProfileImage()
{

    String Base64=pref.getString("Profile_Image",null);
    if(!(pref.getString("Profile_Image",null).equals("null"))){
        //Get the Image from base64 string stored in the prefs
        //This is the case when the user has a custom profile image
        Log.d(TAG,"User has custom profile image");
        base64ToBitmap(Base64);
    }
    else {
        String img_url = String.format("https://graph.facebook.com/%s/picture?type=large", pref.getString("Id", "null"));
        Log.d(TAG,"Image Url for ImageLoader is"+img_url);
        ImageLoader mImageLoader = VolleySingleton.getInstance(getApplicationContext()).getImageLoader();
        mImageLoader.get(img_url, ImageLoader.getImageListener(profile_image,
                R.drawable.ic_person_black_36dp, R.drawable.ic_person_black_36dp));
    }
}
 
Example 2
Source File: MainActivity.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
public void btnClick5(View view){
    ImageLoader loader = new ImageLoader(queue,new BitmapCache(this));

    /**
     * 参数2:默认图片
     * 参数3:错误图片
     */
    ImageLoader.ImageListener imageListener = ImageLoader.getImageListener(iv,
            R.mipmap.ic_launcher,
            R.mipmap.ic_launcher);

    loader.get("http://cdn8.staztic.com/app/a/5993/5993203/volley-17-l-280x280.png",imageListener);
}
 
Example 3
Source File: VolleyDataSource.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
public VolleyDataSource(
    final ImageLoader imageLoader,
    final Uri imageRequest,
    final boolean bitmapCacheOnly) {

  // TODO: add VolleyImageRequest {uri, resizeOptions, bitmapCacheOnly, ...}
  String uriString = imageRequest.toString();
  int maxWidth = 0;
  int maxHeight = 0;

  if (bitmapCacheOnly) {
    if (!imageLoader.isCached(uriString, maxWidth, maxHeight)) {
      mImageContainer = null;
      setFailure(new NullPointerException("Image not found in bitmap-cache."));
      return;
    }
  }

  mImageContainer = imageLoader.get(
      uriString,
      new ImageLoader.ImageListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
          setFailure(error.getCause());
        }
        @Override
        public void onResponse(final ImageLoader.ImageContainer response, boolean isImmediate) {
          if (response.getBitmap() != null) {
            setResult(response.getBitmap(), true);
          }
        }
      },
      maxWidth,
      maxHeight);
}
 
Example 4
Source File: ImagesActivity.java    From volley_demo with Apache License 2.0 5 votes vote down vote up
private void get_imageloader()
{
    textview.setText("获取图片开始了");
    networkImageView.setImageBitmap(null);
    imageView.setImageBitmap(null);
    String url = "http://g.hiphotos.baidu.com/image/pic/item/21a4462309f790521631d9e908f3d7ca7bcbd53f.jpg";

    ImageLoader loader = new ImageLoader(MyApplication.getHttpQueues(), new BitmapCache());
    ImageLoader.ImageListener listener = ImageLoader.getImageListener(imageView, R.drawable.default_icon , R.drawable.error );

    loader.get(url, listener);

}
 
Example 5
Source File: MainActivity.java    From android-advanced-light with MIT License 4 votes vote down vote up
private void UseImageLoader() {
    ImageLoader imageLoader = new ImageLoader(mQueue, new BitmapCache());
    ImageLoader.ImageListener listener = ImageLoader.getImageListener(iv_image, R.drawable.ico_default, R.drawable.ico_default);
    imageLoader.get("http://img.my.csdn.net/uploads/201603/26/1458988468_5804.jpg", listener);
}
 
Example 6
Source File: NewsAdapter.java    From QuickNews with MIT License 4 votes vote down vote up
public void getImage(ImageView imageView, String url) {
    ImageLoader imageLoader = new ImageLoader(mRequestQueue, new BitmapCache());
    ImageLoader.ImageListener listener = ImageLoader.getImageListener(imageView,
            R.drawable.default_picture, R.drawable.default_picture);
    imageLoader.get(url, listener);
}
 
Example 7
Source File: CommentsAdapter.java    From QuickNews with MIT License 4 votes vote down vote up
public void getImage(ImageView imageView, String url) {
    ImageLoader imageLoader = new ImageLoader(mRequestQueue, new BitmapCache());
    ImageLoader.ImageListener listener = ImageLoader.getImageListener(imageView,
            R.drawable.default_picture, R.drawable.default_picture);
    imageLoader.get(url, listener);
}
 
Example 8
Source File: MainActivity.java    From BlogDemo with Apache License 2.0 4 votes vote down vote up
@Override
        public Drawable getDrawable(final String source) {
            final DrawableWrapper imgDrawable = new DrawableWrapper();

            // 设置默认图
            Drawable dfDrawable = getResources().getDrawable(R.mipmap.ic_launcher);
            Rect dfRect = new Rect(0, 0, tv.getMeasuredWidth(), (int) getResources().getDimension(R.dimen.imhH));
            dfDrawable.setBounds(dfRect);
            imgDrawable.setBounds(dfRect);
            imgDrawable.setDrawable(dfDrawable);

            // 加载图片,
            // 如果是使用ImageLoader加载图片,那么请不要使用单例方式实现的ImageLoader.ImageCache,否则回出现bitmap释放不了,重新进入界面,图片不显示的问题
            RequestQueue queue = Volley.newRequestQueue(MainActivity.this);
            ImageLoader loader = new ImageLoader(queue, new BitmapCache());
            loader.get(source, new ImageLoader.ImageListener() {
                @Override
                public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
                    Bitmap bm = response.getBitmap();
                    if (bm != null) {
                        Log.d("TAG", "bitmapH = " + bm.getWidth() + "/" + bm.getHeight());
                        int tvWidth = tv.getMeasuredWidth();

                        Drawable bd = new BitmapDrawable(bm);
                        Rect rect = new Rect(0, 0, tvWidth, tvWidth * bm.getHeight() / bm.getWidth());
//                        Rect rect = new Rect(0, 0, bm.getWidth(), bm.getHeight());
                        bd.setBounds(rect);
                        imgDrawable.setBounds(rect);
                        imgDrawable.setDrawable(bd);
                        Log.d("TAG", "tvH = " + tv.getMeasuredHeight() + ", hashCode = " + tv.hashCode());
//                        int tvH = tv.getHeight() + bm.getHeight();
                        int tvH = tv.getHeight() + rect.bottom;
                        ViewGroup.LayoutParams lp = tv.getLayoutParams();
                        lp.height = tvH;
                        tv.setLayoutParams(lp);
                        tv.setMaxHeight(tvH);  // 更新textview高度
//                        Log.d("TAG", "TVH = " + tvH);
                        tv.postInvalidate();    // 刷新view
                    } else {
//                        Drawable drawable = getResources().getDrawable(Resource.drawable.dgcs_ic_default);
//                        imgDrawable.setDrawable(drawable);
//                        tv.postInvalidate();    // 刷新view
                    }
                }

                @Override
                public void onErrorResponse(VolleyError error) {
//                    Drawable drawable = getResources().getDrawable(Resource.drawable.dgcs_ic_default);
//                    imgDrawable.setDrawable(drawable);
//                    tv.postInvalidate();    // 刷新view
                }
            });


            return imgDrawable;
        }
 
Example 9
Source File: VolleyHelper.java    From AndroidLinkup with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 加载网络图片到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);
}