Search in sources :

Example 1 with DiskLruCache

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;
}
Also used : Bitmap(android.graphics.Bitmap) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) DiskLruCache(com.baseproject.image.DiskLruCache) BitmapDrawable(android.graphics.drawable.BitmapDrawable) IOException(java.io.IOException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) URL(java.net.URL) GoplayException(com.youku.player.base.GoplayException) PBException(com.punchbox.exception.PBException) IOException(java.io.IOException)

Example 2 with DiskLruCache

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;
}
Also used : Bitmap(android.graphics.Bitmap) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) DiskLruCache(com.baseproject.image.DiskLruCache) BitmapDrawable(android.graphics.drawable.BitmapDrawable) IOException(java.io.IOException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) URL(java.net.URL) GoplayException(com.youku.player.base.GoplayException) PBException(com.punchbox.exception.PBException) IOException(java.io.IOException)

Aggregations

Bitmap (android.graphics.Bitmap)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 DiskLruCache (com.baseproject.image.DiskLruCache)2 PBException (com.punchbox.exception.PBException)2 GoplayException (com.youku.player.base.GoplayException)2 BufferedOutputStream (java.io.BufferedOutputStream)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 URL (java.net.URL)2