I use Volley NetworkImageView to download images from the Internet and impressions in my listview . Now I want the Volley NetworkImageView show saved images when there is no network available. Volley already cached URL images as a key, because when I use
Entry entry = SingletonRequestQueue.getInstance(context).getRequestQueue().getCache().get(imageURL);
entry.data not null. But my problem is that the image resolutions are high and I canβt use
Bitmap b = BitmapFactory.decodeByteArray(entry.data, 0, entry.data.length);
because it creates a lot of delays, and I have to reinvent the wheel, because again I have to create asynctask to see when the listview scrolls, to cancel the decoding, processing the bitmap , creating in the memory cache, finding the best example value and ...
so better. The idea is to just do some of the tricks that Volley NetworkImageView uses to use their own DiskLRUCache to show them when there is no network.
Any idea?
My code is:
public class SingletonRequestQueue { private static SingletonRequestQueue mInstance; private RequestQueue mRequestQueue; private ImageLoader mImageLoader; private static Context mCtx; private LruBitmapCache mLruBitmapCache; private SingletonRequestQueue(Context context) { mCtx = context; mRequestQueue = getRequestQueue(); mLruBitmapCache = new LruBitmapCache(LruBitmapCache.getCacheSize(context)); mImageLoader = new ImageLoader(mRequestQueue,mLruBitmapCache); } public static synchronized SingletonRequestQueue getInstance(Context context) { if (mInstance == null) { mInstance = new SingletonRequestQueue(context); } return mInstance; } public RequestQueue getRequestQueue() { if (mRequestQueue == null) {
and in my adapter:
public IssueListAdapter(Context context, int resource, List<Issue> objects) { super(context, resource, objects); this.context = context; this.mIssueList = objects; mImageLoader = SingletonRequestQueue.getInstance(context).getImageLoader(); } public static class ViewHolder{ public NetworkImageView mNetworkImageView; public TextView mFee; public TextView mName; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if(convertView == null){ holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.gridview_issuelist_item, parent, false); holder.mNetworkImageView = (NetworkImageView)convertView.findViewById(R.id.NetworkImageView_MainActivity_issue_image); holder.mName = (TextView)convertView.findViewById(R.id.TextView_MainActivity_name); holder.mFee = (TextView)convertView.findViewById(R.id.TextView_MainActivity_fee); Utility.settingTypfaceFont(context, holder.mName); Utility.settingTypfaceFont(context, holder.mFee); convertView.setTag(holder); }else{ holder = (ViewHolder)(convertView.getTag()); } final Issue issue = mIssueList.get(position); holder.mName.setText(issue.getTitle()); holder.mFee.setText(String.valueOf(issue.getFee())); String imageURL = issue.getPublicCover(); holder.mNetworkImageView.setImageUrl(imageURL, mImageLoader); holder.mNetworkImageView.setDefaultImageResId(R.drawable.placeholder2);; return convertView; } @Override public int getCount() { if(mIssueList != null){ return mIssueList.size(); } else{ return 0; } } public List<Issue> getIssueList() { return mIssueList; } }