@@ -0,0 +1,1924 @@
+package com.growthbeat.message;%0A%0Aimport java.io.IOException;%0Aimport java.net.HttpURLConnection;%0Aimport java.net.URL;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0Aimport android.content.Context;%0Aimport android.graphics.Bitmap;%0Aimport android.graphics.BitmapFactory;%0Aimport android.support.v4.content.AsyncTaskLoader;%0A%0Apublic class ImageLoader %7B%0A%0A%09private final static ImageLoader instance = new ImageLoader();%0A%0A%09private Map%3CString, AsyncUrlImageLoader%3E cachedImages = new HashMap%3CString, AsyncUrlImageLoader%3E();%0A%0A%09public static ImageLoader getInstance() %7B%0A%09%09return ImageLoader.instance;%0A%09%7D%0A%0A%09public AsyncUrlImageLoader generateLoader(Context context, String url) %7B%0A%0A%09%09AsyncUrlImageLoader asyncUrlImageLoader = cachedImages.get(url);%0A%09%09if (asyncUrlImageLoader == null) %7B%0A%09%09%09asyncUrlImageLoader = new AsyncUrlImageLoader(context, url);%0A%09%09%09cachedImages.put(url, asyncUrlImageLoader);%0A%09%09%7D%0A%0A%09%09return asyncUrlImageLoader;%0A%0A%09%7D%0A%0A%09public static class AsyncUrlImageLoader extends AsyncTaskLoader%3CBitmap%3E %7B%0A%0A%09%09private String url;%0A%09%09private Bitmap bitmap;%0A%0A%09%09public AsyncUrlImageLoader(Context context, String url) %7B%0A%09%09%09super(context);%0A%09%09%09this.url = url;%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09public Bitmap loadInBackground() %7B%0A%0A%09%09%09try %7B%0A%09%09%09%09URL url = new URL(this.url);%0A%09%09%09%09HttpURLConnection connection = (HttpURLConnection) url.openConnection();%0A%09%09%09%09connection.setDoInput(true);%0A%09%09%09%09connection.connect();%0A%09%09%09%09this.bitmap = BitmapFactory.decodeStream(connection.getInputStream());%0A%09%09%09%09return bitmap;%0A%09%09%09%7D catch (IOException e) %7B%0A%09%09%09%7D%0A%0A%09%09%09return null;%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09public void onCanceled(Bitmap bitmap) %7B%0A%09%09%09if (bitmap == null)%0A%09%09%09%09return;%0A%09%09%09if (bitmap.isRecycled())%0A%09%09%09%09return;%0A%09%09%09this.bitmap = bitmap;%0A%09%09%09this.bitmap.isRecycled();%0A%09%09%09this.bitmap = null;%0A%0A%09%09%7D%0A%0A%09%09public Bitmap getBitmap() %7B%0A%09%09%09return this.bitmap;%0A%09%09%7D%0A%0A%09%09public boolean needLoad() %7B%0A%09%09%09return this.bitmap == null %7C%7C (this.bitmap != null && this.bitmap.isRecycled());%0A%09%09%7D%0A%0A%09%7D%0A%0A%7D%0A

Create async url load and cache class