1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
downloadThread = new Thread() {
public void run() {
try {
if(cache != null) {
downloadedImage = cache.getDrawableForURL(imageURL); // here
if(downloadedImage != null) {
animate = false;
imageProgressHandler.sendEmptyMessage(COMPLETE);
return ;
}
}
animate = true;
imageProgressHandler.sendEmptyMessage(DOWNLOADING);
try {
downloadedImage = Drawable.createFromStream(((java.io.InputStream) new java.net.URL(imageURL).getContent()), "image");
} catch (OutOfMemoryError e) {
Log.e(TAG,"Out of memory when downloading image : " + imageURL);
imageProgressHandler.sendEmptyMessage(FAILED);
}
if(Thread.currentThread() == downloadThread) {
if(cache != null) {
cache.setDrawableForURL(imageURL, downloadedImage);
}
imageProgressHandler.sendEmptyMessage(COMPLETE);
} else {
return;
}
} catch (MalformedURLException e) {
Log.e(TAG,"Malformed Image URL : " + imageURL);
imageProgressHandler.sendEmptyMessage(FAILED);
} catch (IOException e) {
Log.e(TAG,"IOException while downloading image : " + imageURL);
imageProgressHandler.sendEmptyMessage(FAILED);
}
};
}; |
Partager