use of com.baseproject.image.DiskLruCache in project SimplifyReader by chentao0707.
the class PluginFullScreenPauseAD method loadImageFromUrl.
private Bitmap loadImageFromUrl(String url) {
URL u;
InputStream i = null;
Bitmap d = null;
DiskLruCache cache = null;
try {
u = new URL(url);
d = getImageFromCache(url);
if (d != null) {
return d;
}
i = (InputStream) u.getContent();
} catch (Exception e) {
}
if (mActivity != null && mActivity.mImageWorker != null && mActivity.mImageWorker.getImageCache() != null) {
cache = mActivity.mImageWorker.getImageCache().getDiskCache();
}
if (cache == null) {
return null;
}
final String fileName = Utils.urlToFileName(url);
final File cacheFile = new File(cache.createFilePath(fileName));
BufferedOutputStream out = null;
try {
BitmapDrawable bitDrawable;
bitDrawable = (BitmapDrawable) BitmapDrawable.createFromStream(i, "src");
if (bitDrawable == null) {
return null;
}
d = bitDrawable.getBitmap();
if (d != null) {
addImageToCache(url, d);
}
out = new BufferedOutputStream(new FileOutputStream(cacheFile), Utils.IO_BUFFER_SIZE);
d.compress(CompressFormat.PNG, 85, out);
out.flush();
} catch (final IOException e) {
} catch (OutOfMemoryError e) {
} finally {
if (out != null) {
try {
out.close();
} catch (final IOException e) {
Logger.e(TAG, "Error in downloadBitmap - " + e);
}
}
}
return d;
}
use of com.baseproject.image.DiskLruCache in project SimplifyReader by chentao0707.
the class PluginImageAD method loadImageFromUrl.
private Bitmap loadImageFromUrl(String url) {
URL u;
InputStream i = null;
Bitmap d = null;
DiskLruCache cache = null;
try {
u = new URL(url);
d = getImageFromCache(url);
if (d != null) {
return d;
}
i = (InputStream) u.getContent();
} catch (Exception e) {
}
if (mActivity != null && mActivity.mImageWorker != null && mActivity.mImageWorker.getImageCache() != null) {
cache = mActivity.mImageWorker.getImageCache().getDiskCache();
}
if (cache == null) {
return null;
}
final String fileName = Utils.urlToFileName(url);
final File cacheFile = new File(cache.createFilePath(fileName));
BufferedOutputStream out = null;
try {
BitmapDrawable bitDrawable;
bitDrawable = (BitmapDrawable) BitmapDrawable.createFromStream(i, "src");
if (bitDrawable == null)
return null;
d = bitDrawable.getBitmap();
if (d != null) {
addImageToCache(url, d);
}
out = new BufferedOutputStream(new FileOutputStream(cacheFile), Utils.IO_BUFFER_SIZE);
d.compress(CompressFormat.PNG, 85, out);
out.flush();
} catch (final IOException e) {
} catch (OutOfMemoryError e) {
} finally {
if (out != null) {
try {
out.close();
} catch (final IOException e) {
Logger.e(TAG, "Error in downloadBitmap - " + e);
}
}
}
return d;
}
Aggregations