Example usage for android.support.v4.util LruCache LruCache

List of usage examples for android.support.v4.util LruCache LruCache

Introduction

In this page you can find the example usage for android.support.v4.util LruCache LruCache.

Prototype

public LruCache(int maxSize) 

Source Link

Usage

From source file:com.aidigame.hisun.imengstar.huanxin.ImageCache1.java

private ImageCache1() {
    // use 1/8 of available heap size
    cache = new LruCache<String, Bitmap>((int) (Runtime.getRuntime().maxMemory() / 8)) {
        @Override//  ww w. jav a  2 s  . co m
        protected int sizeOf(String key, Bitmap value) {
            return value.getRowBytes() * value.getHeight();
        }
    };
}

From source file:com.bellman.bible.android.control.navigation.DocumentBibleBooksFactory.java

public DocumentBibleBooksFactory() {
    // initialise the DocumentBibleBooks factory
    cache = new LruCache<AbstractPassageBook, DocumentBibleBooks>(CACHE_SIZE) {

        /** If entry for this Book not found in cache then create one
         *///  ww w  . ja  v a 2 s. c  o  m
        @Override
        protected DocumentBibleBooks create(AbstractPassageBook document) {
            return new DocumentBibleBooks(document);
        }
    };
}

From source file:org.akita.cache.MemCacheLruImpl.java

protected MemCacheLruImpl(int maxSize) {
    mCache = new LruCache<K, V>(maxSize);

}

From source file:MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    NetworkImageView networkImageView = (NetworkImageView) findViewById(R.id.networkImageView);
    String url = "http://www.android.com/static/img/logos-2x/android-wordmark-8EC047.png";
    RequestQueue queue = Volley.newRequestQueue(this);
    ImageLoader imageLoader = new ImageLoader(queue, new ImageLoader.ImageCache() {
        private final LruCache<String, Bitmap> cache = new LruCache<String, Bitmap>(20);

        @Override/*from   ww w  .j a  va2 s  .c o m*/
        public Bitmap getBitmap(String url) {
            return cache.get(url);
        }

        @Override
        public void putBitmap(String url, Bitmap bitmap) {
            cache.put(url, bitmap);
        }
    });
    networkImageView.setImageUrl(url, imageLoader);
}

From source file:com.apptentive.android.sdk.util.cache.ImageMemoryCache.java

public ImageMemoryCache() {
    bufferCache = new LruCache<String, Object>(MAX_CACHE_COUNT) {
        /**//from w  ww  .j a  v  a2  s  . c om
         * recycle the removed bitmap from memory
         */
        @Override
        protected void entryRemoved(boolean evicted, String key, Object oldValue, Object newValue) {
            if (oldValue != null) {
                if (oldValue instanceof Bitmap) {
                    ((Bitmap) oldValue).recycle();
                } else if (oldValue instanceof BitmapDrawable) {
                    ((BitmapDrawable) oldValue).getBitmap().recycle();
                }
                oldValue = null;
            }
        }
    };
}

From source file:com.sudaotech.chatlibrary.utils.ChatImageCache.java

private ChatImageCache() {
    // use 1/8 of available heap size
    cache = new LruCache<String, Bitmap>((int) (Runtime.getRuntime().maxMemory() / 8)) {
        @Override/*from  ww  w .  ja va 2  s . c  om*/
        protected int sizeOf(String key, Bitmap value) {
            return value.getRowBytes() * value.getHeight();
        }
    };
}

From source file:org.akita.cache.MemCacheLruBitmapImpl.java

protected MemCacheLruBitmapImpl(int maxMByteSize) {
    mCache = new LruCache<K, V>(maxMByteSize) {
        @Override/*from   w w  w  .j av a 2  s .  c o  m*/
        protected int sizeOf(K key, V value) {
            return super.sizeOf(key, value);
        }

        @Override
        protected void entryRemoved(boolean evicted, K key, V oldValue, V newValue) {
            super.entryRemoved(evicted, key, oldValue, newValue);
        }
    };

}

From source file:org.jboss.aerogear.android.impl.offline.MemoryCache.java

@Override
public void init(Callback callback) {
    cache = new LruCache<String, T>(DISK_CACHE_SIZE);
    callback.onSuccess(this);
}

From source file:com.yahoo.mobile.client.android.yodel.utils.MemoryCache.java

public MemoryCache() {
    int cacheSize = 10 * 1024 * 1024 / 1024; // 10 mB
    Log.i(LOG_TAG, "Image cache size: " + cacheSize + "kB");

    mCache = new LruCache<String, Bitmap>(cacheSize) {
        @Override/*from   www  .  j  a  va 2  s.  co  m*/
        protected int sizeOf(String key, Bitmap value) {
            return value.getByteCount() / 1024;
        }
    };
}

From source file:com.almalence.util.MemoryImageCache.java

public MemoryImageCache(int maxCount) {
    lruCache = new LruCache<String, Bitmap>(maxCount);
}