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.serloman.imagecachedownloader.cache.LRUImageCache.java

public LRUImageCache(int maxMemory) {
    int cacheSize = maxMemory / 4;

    listeners = new ArrayList<EvictListener>();

    mMemoryCache = new LruCache<String, Bitmap>(cacheSize) {
        @Override//from  www. ja va2s .  c om
        protected int sizeOf(String key, Bitmap bitmap) {
            // The cache size will be measured in kilobytes rather than number of items.
            return bitmap.getByteCount() / 1024;
        }

        @Override
        protected void entryRemoved(boolean evicted, String key, Bitmap oldValue, Bitmap newValue) {
            super.entryRemoved(evicted, key, oldValue, newValue);

            for (EvictListener listener : listeners)
                listener.imageEvicted(evicted, key, oldValue, newValue);
        }
    };
}

From source file:com.gsma.rcs.ri.utils.BitmapCache.java

private BitmapCache() {
    /*/*from   w  w w  .j a va 2s .c om*/
     * Get max available VM memory, exceeding this amount will throw an OutOfMemory exception.
     * Stored in kilobytes as LruCache takes an int in its constructor.
     */
    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);

    /* Use 1/8th of the available memory for this memory cache. */
    final int cacheSize = maxMemory / 8;

    mMemoryCache = new LruCache<String, BitmapLoader.BitmapCacheInfo>(cacheSize) {

        /**
         * Measure item size in kilobytes rather than units which is more practical for a bitmap
         * cache
         */
        @Override
        protected int sizeOf(String key, BitmapLoader.BitmapCacheInfo bitmapCacheInfo) {
            /*
             * The cache size will be measured in kilobytes rather than number of items.
             */
            return bitmapCacheInfo.getBitmap().getByteCount() / 1024;
        }
    };
}

From source file:com.facebook.litho.reference.DrawableResourcesCache.java

DrawableResourcesCache() {
    mDrawableCache = new LruCache<Integer, SimplePoolWithCount<Drawable>>(DRAWABLES_MAX_ENTRIES) {
        @Override//from w w  w.  j  ava  2  s. com
        protected int sizeOf(Integer key, SimplePoolWithCount<Drawable> value) {
            return value.getPoolSize();
        }
    };
}

From source file:com.frostwire.android.gui.httpserver.SessionManager.java

public SessionManager() {
    this.durCache = new LruCache<String, DesktopUploadRequest>(MAX_DESKTOP_UPLOAD_REQUESTS);
}

From source file:me.vijayjaybhay.galleryview.cache.MemoryImageCache.java

/**
 * Initializes memory cache/*from   ww w.  ja  v  a2 s.c om*/
 * @param context Application context
 */
private MemoryImageCache(Context context) {
    mContext = context;
    mMemoryCache = new LruCache<String, Bitmap>(getCacheSize()) {
        @Override
        protected int sizeOf(String key, Bitmap bitmap) {
            // The cache size will be measured in kilobytes rather than
            // number of items.
            return byteSizeOf(bitmap) / 1024;
        }
    };
}

From source file:binh.app.englishidiom.ImageCache.java

private void init(float memCacheSizePercent) {
    int memCacheSize = calculateMemCacheSize(memCacheSizePercent);
    // Set up memory cache
    if (BuildConfig.DEBUG)
        Log.d(TAG, "Memory cache created (size = " + memCacheSize + ")");
    mMemoryCache = new LruCache<String, Bitmap>(memCacheSize) {
        @Override/*w ww .j ava2 s  . co m*/
        protected int sizeOf(String key, Bitmap bitmap) {
            final int bitmapSize = getBitmapSize(bitmap) / 1024;
            return bitmapSize == 0 ? 1 : bitmapSize;
        }
    };
}

From source file:net.evecom.androidecssp.activity.pub.imagescan.NativeImageLoader.java

/**
 * /*ww w .ja va 2  s . c o  m*/
 * 
 * 
 * @author Mars zhang
 * @created 2015-11-25 12:06:01
 */
private NativeImageLoader() {
    // 
    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);

    // 1/4
    final int cacheSize = maxMemory / 4;
    mMemoryCache = new LruCache<String, Bitmap>(cacheSize) {

        // 
        @Override
        protected int sizeOf(String key, Bitmap bitmap) {
            return bitmap.getRowBytes() * bitmap.getHeight() / 1024;
        }
    };
}

From source file:com.wj.android.wjframe.bitmap.BitmapMemoryCache.java

/**
 * @param maxSize ???kb/*from  w w  w .ja v  a  2s  . c  om*/
 */
@SuppressLint("NewApi")
private void init(int maxSize) {
    this.maxSize = maxSize;
    cache = new LruCache<String, Bitmap>(maxSize) {
        @Override
        protected int sizeOf(String key, Bitmap value) {
            super.sizeOf(key, value);
            if (SystemTool.getSDKVersion() >= 12) {
                return value.getByteCount();
            } else {
                return value.getRowBytes() * value.getHeight();
            }
        }
    };
}

From source file:com.aniruddhfichadia.presentable.CachingAndroidResourceProvider.java

public CachingAndroidResourceProvider(@NonNull Context context, int cacheSize) {
    super(context);

    stringLookupCache = new LruCache<>(cacheSize);
}

From source file:com.micabytes.gfx.ImageHandler.java

private static void initCache() {
    int memoryClass = ((ActivityManager) GameApplication.getInstance()
            .getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
    int memoryCacheSize = MEGABYTE * MEGABYTE * memoryClass / 8;
    memoryCache = new LruCache<Integer, Bitmap>(memoryCacheSize) {
        @Override// w  w w. j  a  va 2 s  . c  o m
        protected int sizeOf(Integer key, Bitmap value) {
            return value.getRowBytes() * value.getHeight();
        }
    };
}