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:org.lucasr.smoothie.samples.gallery.GalleryLoader.java

public GalleryLoader(Context context) {
    mContext = context;//from  w ww  .j  av  a  2s  . co m

    int maxSize = (int) (Runtime.getRuntime().maxMemory() * 0.4f);
    mMemCache = new LruCache<Long, Bitmap>(maxSize) {
        @Override
        protected int sizeOf(Long id, Bitmap bitmap) {
            return bitmap.getRowBytes() * bitmap.getHeight();
        }
    };
}

From source file:net.quduo.pixel.interfaces.android.common.ImageLoader.java

private ImageLoader() {

    // ???/*from  w w w . j  av a 2 s  . c  o m*/
    int maxMemory = (int) Runtime.getRuntime().maxMemory();

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

        @Override
        protected int sizeOf(String key, Bitmap bitmap) {

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
                return bitmap.getByteCount();
            } else {
                return getByteCount(bitmap);
            }
        }
    };
}

From source file:com.feedback2345sdk.cache.MemoryCache.java

public MemoryCache() {

    // ?//from  w  ww  . j  a  v a  2s .  c  om
    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);

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

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

}

From source file:com.example.chengcheng.network.cache.LruMemCache.java

public LruMemCache() {

    // ?//from  ww  w. ja  va 2 s.c  om
    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);

    // ??
    final int cacheSize = maxMemory / 8;
    mResponseCache = new LruCache<String, Response>(cacheSize) {

        @Override
        protected int sizeOf(String key, Response response) {
            return response.rawData.length / 1024;
        }
    };

}

From source file:com.ht.fyforandroid.net.simplenet.cache.LruMemCache.java

public LruMemCache() {
    // ?//from   w  w  w  .j  a v  a  2  s.  c  om
    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);

    // ??
    final int cacheSize = maxMemory / 8;
    mResponseCache = new LruCache<String, Response>(cacheSize) {

        @Override
        protected int sizeOf(String key, Response response) {
            return response.rawData.length / 1024;
        }
    };

}

From source file:com.tandong.sa.sql.Cache.java

public static synchronized void initialize(Configuration configuration) {
    if (sIsInitialized) {
        Log.v("ActiveAndroid already initialized.");
        return;//from   w w w .j a v a 2s. c  o m
    }

    sContext = configuration.getContext();
    sModelInfo = new ModelInfo(configuration);
    sDatabaseHelper = new DatabaseHelper(configuration);

    // TODO: It would be nice to override sizeOf here and calculate the
    // memory
    // actually used, however at this point it seems like the reflection
    // required would be too costly to be of any benefit. We'll just set a
    // max
    // object size instead.
    sEntities = new LruCache<String, Model>(configuration.getCacheSize());

    openDatabase();

    sIsInitialized = true;

    Log.v("ActiveAndroid initialized successfully.");
}

From source file:io.nuclei.box.adapter.PagedList.java

public PagedList(Context context, int maxPages, int pageSize) {
    mContext = context.getApplicationContext();
    mMaxPages = maxPages;/*from   w  ww .  jav  a2s .co  m*/
    mPages = new LruCache<Integer, List<T>>(maxPages) {
        @Override
        protected void entryRemoved(boolean evicted, Integer key, List<T> oldValue, List<T> newValue) {
            if (mListener != null)
                mListener.onPageEvicted(key);
        }
    };
    mPageSize = pageSize;
}

From source file:com.asuka.android.asukaandroid.orm.Cache.java

public static synchronized void initialize(Configuration configuration) {
    if (sIsInitialized) {
        LogUtil.v("AsukaOrmAndroid already initialized.");
        return;/*from www  . j a  v  a2  s.  c  om*/
    }

    sContext = configuration.getContext();
    sModelInfo = new ModelInfo(configuration);
    sDatabaseHelper = new DatabaseHelper(configuration);

    // TODO: It would be nice to override sizeOf here and calculate the memory
    // actually used, however at this point it seems like the reflection
    // required would be too costly to be of any benefit. We'll just set a max
    // object size instead.
    sEntities = new LruCache<String, Model>(configuration.getCacheSize());

    openDatabase();

    sIsInitialized = true;

    LogUtil.v("AsukaOrmAndroid initialized successfully.");
}

From source file:com.nttec.everychan.cache.DraftsCache.java

/**
 * ?/*from w ww.  j av  a2 s .  c o m*/
 * @param maxSize ?  ?  ?, ??? ?  
 * @param serizlizer ?
 */
public DraftsCache(int maxSize, Serializer serializer) {
    this.serializer = serializer;
    this.lru = new LruCache<String, SendPostModel>(maxSize);
}

From source file:com.nttec.everychan.cache.PagesCache.java

/**
 * ?//from w  w  w  .  j  a  v a2  s  .  c om
 * @param maxSize ?  ?  ? (  ?. {@link PresentationModel#getSerializablePageSize})
 * @param serizlizer ?
 */
public PagesCache(int maxSize, Serializer serializer) {
    this.serializer = serializer;
    this.lru = new LruCache<String, PresentationModel>(maxSize) {
        @Override
        protected int sizeOf(String key, PresentationModel value) {
            return value.size;
        }
    };
}