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.mythdroid.cache.ImageCache.java

/**
 * Constructor/*www.  jav a2 s. co m*/
 * @param name name of the cache
 * @param memCapacity maximum capacity of MemCache in bytes
 * @param memMaxSize maximum size of image to cache in memory in bytes
 * @param diskMaxSize maximum size of disk backed cache in bytes
 */
public ImageCache(String name, long memCapacity, long memMaxSize, int diskMaxSize) {
    try {
        diskCache = new ImageDiskCache(name, diskMaxSize);
    } catch (IOException e) {
        LogUtil.debug("Disk cache disabled: " + e.getMessage()); //$NON-NLS-1$
    }

    if (diskCache != null && diskCacheThread == null)
        newDiskCacheThread();

    memCache = new LruCache<String, Bitmap>((int) memCapacity) {
        @Override
        protected int sizeOf(String key, Bitmap value) {
            return value.getRowBytes() * value.getHeight();
        }
    };

    memMax = memMaxSize;

}

From source file:org.fuusio.api.graphics.BitmapManagerImpl.java

public LruCache<String, Bitmap> addCache(final String cacheName, final int cacheSize) {
    LruCache<String, Bitmap> cache = mBitmacaches.get(cacheName);

    assert (cache == null);

    cache = new LruCache<>(cacheSize);
    mBitmacaches.put(cacheName, cache);/*from w  w  w .  j av  a2s . c om*/
    return cache;
}

From source file:com.rk.lib.view.SVGView.java

/**
 * Loads the initial resource for the View.
 * /*from w  w w  .jav  a2  s .c  o m*/
 * @param context
 *            - The Context associated with the view.
 * @param attrs
 *            - The AttributeSet associated with the view.
 * @param defStyle
 *            - The style associated with the view.
 */
public void init(Context context, AttributeSet attrs, int defStyle) {
    if (!isInEditMode()) {
        setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        mContext = context;
        final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
        final int cacheSize = maxMemory / 8;
        memoryCache = new LruCache<Integer, Drawable>(cacheSize);
        TypedArray typedArray = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.SVGView,
                defStyle, 0);
        resourceId = typedArray.getResourceId(R.styleable.SVGView_source, -1);
        isSvgResource = typedArray.getBoolean(R.styleable.SVGView_isSvg, false);
        if (resourceId != -1) {
            if (isSvgResource) {
                setCacheImageDrawable(resourceId, true);
            } else {
                setCacheImageDrawable(resourceId, false);
            }
        }
    }
}

From source file:com.easibeacon.examples.shop.util.OffersArrayAdapter.java

public OffersArrayAdapter(Context context, ArrayList<Offer> commandsList) {
    // TODO Auto-generated constructor stub
    super(context, R.layout.offer_list_item, commandsList);
    this.context = context;
    values = new ArrayList<Offer>();
    values.addAll(commandsList);//from   www .  j  av  a 2  s  . c om
    inflater = LayoutInflater.from(this.context);
    if (_bitmapCache == null)
        _bitmapCache = new LruCache<String, Bitmap>(5);
}

From source file:com.blogspot.codigogoogle.listloadingsamples.ImageLoaderListAdapter.java

public ImageLoaderListAdapter(Activity context, ArrayList<Map<String, String>> listItems) {
    this.context = context;
    this.listItems = listItems;

    mPlaceHolderBitmap = decodeSampledBitmapFromResource(context.getResources(), R.drawable.img_placeholder, 20,
            20);/*from  w  w  w.  j av  a 2  s.c  om*/

    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
    final int cacheSize = maxMemory / 8;
    mMemoryCache = new LruCache<String, Bitmap>(cacheSize) {
        @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
        @Override
        protected int sizeOf(String key, Bitmap bitmap) {
            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB_MR1) {
                return bitmap.getByteCount() / 1024;
            } else {
                return bitmap.getRowBytes() * bitmap.getHeight() / 1024;
            }
        }
    };
}

From source file:com.example.android.uamp.AlbumArtCache.java

private AlbumArtCache() {
    // Holds no more than MAX_ALBUM_ART_CACHE_SIZE bytes, bounded by maxmemory/4 and
    // Integer.MAX_VALUE:
    int maxSize = Math.min(MAX_ALBUM_ART_CACHE_SIZE,
            (int) (Math.min(Integer.MAX_VALUE, Runtime.getRuntime().maxMemory() / 4)));
    mCache = new LruCache<String, Bitmap[]>(maxSize) {
        @Override/* www . jav  a2s.c  om*/
        protected int sizeOf(String key, Bitmap[] value) {
            return getSizeInBytes(value[BIG_BITMAP_INDEX]) + getSizeInBytes(value[ICON_BITMAP_INDEX]);
        }
    };
}

From source file:com.zhongyun.viewer.utils.VideoListImage.java

public VideoListImage(Context context, int serverType) {
    this.context = context;
    this.media = Viewer.getViewer().getMedia();
    cacheDir = FileUtils.createFile(Constants.LOCAL_ICON_PATH);
    options.inJustDecodeBounds = false;/*from   www.  j a  v a2s .  c  o  m*/
    options.inPurgeable = true;

    int MAXMEMONRY = (int) (Runtime.getRuntime().maxMemory() / 1024);
    if (filesCache == null) {
        filesCache = new LruCache<String, Bitmap>(MAXMEMONRY / 8) {
            @Override
            protected int sizeOf(String key, Bitmap bitmap) {
                return bitmap.getRowBytes() * bitmap.getHeight() / 1024;
            }

            @Override
            protected void entryRemoved(boolean evicted, String key, Bitmap oldValue, Bitmap newValue) {
                if (oldValue != null && !oldValue.isRecycled()) {
                    oldValue.recycle();
                    oldValue = null;
                }
            }
        };
    }
}

From source file:com.yamin.kk.vlc.BitmapCache.java

private BitmapCache() {

    // Get the global context of the application
    Context context = VLCApplication.getAppContext();

    // Get memory class of this device, exceeding this amount will throw an
    // OutOfMemory exception.
    final int memClass = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE))
            .getMemoryClass();// w  w  w  .j  ava 2  s.  c  om

    // Use 1/5th of the available memory for this memory cache.
    final int cacheSize = 1024 * 1024 * memClass / 5;

    Log.d(TAG, "LRUCache size sets to " + cacheSize);

    mMemCache = new LruCache<String, Bitmap>(cacheSize) {

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

    };
}

From source file:monotalk.db.DatabaseConnectionSource.java

DatabaseConnectionSource(Context context, DatabaseConfigration config) {
    this.version = config.getVersion();
    this.dataBaseName = config.getDataBaseName();
    this.entityClasses = config.getEntityList();
    this.dbHelper = new DatabaseOpenHelper(context, config.getDataBaseName(), config.getVersion(),
            config.getEntityList(), config.getMigrations());

    /* NodeCache */
    this.nodeCache = new LruCache<String, Node>(config.getNodeCacheSize());

    this.tableStatements = new HashMap<Class<? extends Entity>, TableStatement>();
    for (Class<? extends Entity> entity : config.getEntityList()) {
        TableStatement tableStatement = new TableStatement(entity);
        tableStatements.put(entity, tableStatement);
    }/* w  w  w  . j  a  va  2s  .c  om*/
}

From source file:org.couchtatertot.helper.PosterCache.java

private PosterCache(Context c) {
    this.cacheDir = new File(c.getExternalCacheDir(), cacheFolder);
    this.cacheDir.mkdirs();
    int memClass = ((ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
    // use half of the memory unless we have less then 32MB
    int cacheSize = memClass * 1024 * 1024 / 2;
    if (memClass < 32)
        cacheSize = memClass * 1024 * 1024 / 4;
    this.memCache = new LruCache<String, Bitmap>(cacheSize) {
        @Override/*w  ww  .j  ava 2s  . c  om*/
        protected int sizeOf(String key, Bitmap value) {
            return value.getRowBytes() * value.getHeight();
        }
    };
}