zoukankan      html  css  js  c++  java
  • enjoy the code ImageLoader.ImageCache of Volley

    it is so concise.

    /**
    * Simple cache adapter interface. If provided to the ImageLoader, it
    * will be used as an L1 cache before dispatch to Volley. Implementations
    * must not block. Implementation with an LruCache is recommended.
    */
    public interface ImageCache {
    public Bitmap getBitmap(String url);
    public void putBitmap(String url, Bitmap bitmap);
    }

    /**
    * 使用LruCache来缓存图片
    */
    public class BitmapCache implements ImageLoader.ImageCache {

    private LruCache<String, Bitmap> mCache;

    public BitmapCache() {
    // 获取应用程序最大可用内存
    int maxMemory = (int) Runtime.getRuntime().maxMemory();
    int cacheSize = maxMemory / 8;
    mCache = new LruCache<String, Bitmap>(cacheSize) {
    @Override
    protected int sizeOf(String key, Bitmap bitmap) {
    return bitmap.getRowBytes() * bitmap.getHeight();
    }
    };
    }

    @Override
    public Bitmap getBitmap(String url) {
    return mCache.get(url);
    }

    @Override
    public void putBitmap(String url, Bitmap bitmap) {
    mCache.put(url, bitmap);
    }

    }
  • 相关阅读:
    hdu3874
    spoj D-query
    hdu4348
    hdu4417
    hdu2665
    [LUOGU] P1057 传球游戏
    [CODEVS] 2193 数字三角形WW
    [CODEVS] 2189 数字三角形W
    [模板] 线段树
    [模板] 树状数组
  • 原文地址:https://www.cnblogs.com/jianglijs/p/7458900.html
Copyright © 2011-2022 走看看