List of usage examples for android.support.v4.util LruCache LruCache
public LruCache(int maxSize)
From source file:com.uzmap.pkg.uzmodules.UIMediaScanner.UzImgsAdapterForFileList.java
public UzImgsAdapterForFileList(Context context, ArrayList<FileInfo> data, OnItemClickClass onItemClickClass) { this.mContext = context; this.mAllImgFiles = data; this.mOnItemClickClass = onItemClickClass; long maxMem = Runtime.getRuntime().maxMemory() / 1024L; this.mCachedMap = new LruCache<String, SoftReference<Bitmap>>((int) (maxMem / 8L)); for (int i = 0; i < data.size(); i++) { this.mCachedMap.put(((FileInfo) data.get(i)).path, new SoftReference<Bitmap>(null)); }/*from w w w . ja v a 2 s . c om*/ this.mUtil = new Util(context); this.mHolderlist = new ArrayList<View>(); }
From source file:com.uzmap.pkg.uzmodules.UIMediaScanner.UzImgsAdapter.java
public UzImgsAdapter(Context context, ArrayList<FileInfo> data, OnItemClickClass onItemClickClass) { this.mContext = context; this.mAllImgFiles = data; this.onItemClickClass = onItemClickClass; long maxMem = Runtime.getRuntime().maxMemory() / 1024L; this.cacheMap = new LruCache<String, SoftReference<Bitmap>>((int) (maxMem / 8L)); for (int i = 0; i < data.size(); i++) { this.cacheMap.put(((FileInfo) data.get(i)).path, new SoftReference<Bitmap>(null)); }//from w w w . j a v a 2 s.c om this.mUtil = new Util(context); this.mHolderlist = new ArrayList<View>(); }
From source file:org.videolan.libvlc.BitmapCache.java
private BitmapCache() { // Get the global context of the application Context context = KsApplication.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();//from w w w.ja v a 2 s .c o m // 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:com.kakao.template.loginbase.GlobalApplication.java
/** * ? ?, ? ?, ?? .//from w w w. jav a2 s . c o m */ @Override public void onCreate() { super.onCreate(); instance = this; // ? . ?? ? Session.initializeSession(this, AuthType.KAKAO_TALK) Session.initialize(this); SystemInfo.initialize(); final RequestQueue requestQueue = Volley.newRequestQueue(this); ImageLoader.ImageCache imageCache = new ImageLoader.ImageCache() { final LruCache<String, Bitmap> imageCache = new LruCache<String, Bitmap>(3); @Override public void putBitmap(String key, Bitmap value) { imageCache.put(key, value); } @Override public Bitmap getBitmap(String key) { return imageCache.get(key); } }; imageLoader = new ImageLoader(requestQueue, imageCache); }
From source file:com.isaacrf.epicbitmaprenderer.core.EpicBitmapCache.java
/** * Basic constructor, builds the memory cache automatically. *///from w w w . j a v a 2 s . c o m public EpicBitmapCache() { // 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; //Initialize the memory cache mMemoryCache = new LruCache<String, Bitmap>(cacheSize) { @Override protected int sizeOf(String key, Bitmap bitmap) { // The cache size will be measured in kilobytes rather than // number of items. return (bitmap.getRowBytes() * bitmap.getHeight()) / 1024; } }; }
From source file:com.robopupu.api.component.BitmapManagerImpl.java
public LruCache<String, Bitmap> addCache(final String cacheName, final int cacheSize) { LruCache<String, Bitmap> cache = bitmapCaches.get(cacheName); assert (cache == null); cache = new LruCache<>(cacheSize); bitmapCaches.put(cacheName, cache);//from w w w. j a v a 2 s . c o m return cache; }
From source file:com.ttoview.nakayosi.ttoview.util.picker.image.ImageCache.java
/** * Create a new ImageCache object using the specified parameters. This should not be * called directly by other classes, instead use * {@link ImageCache#getInstance(android.support.v4.app.FragmentManager, ImageCacheParams)} to fetch an ImageCache * instance./*ww w . j av a 2 s . c o m*/ * * @param cacheParams The cache parameters to use to initialize the cache */ public ImageCache(float memPercent) { int cacheSize = Math.round(memPercent * Runtime.getRuntime().maxMemory() / 1024); mMemoryCache = new LruCache<String, RecyclingBitmapWrapper>(cacheSize) { /** * Notify the removed entry that is no longer being cached */ @Override protected void entryRemoved(boolean evicted, String key, RecyclingBitmapWrapper oldValue, RecyclingBitmapWrapper newValue) { oldValue.setIsCached(false); } /** * Measure item size in kilobytes rather than units which is more practical * for a bitmap cache */ @Override protected int sizeOf(String key, RecyclingBitmapWrapper value) { final int bitmapSize = getBitmapSize(value) / 1024; return bitmapSize == 0 ? 1 : bitmapSize; } }; }
From source file:org.sickstache.helper.BannerCache.java
private BannerCache(Context c) { c = c.getApplicationContext();//from ww w . jav a 2s . co m this.cacheDir = new File(c.getExternalCacheDir(), cacheFolder); if (this.cacheDir.exists() == false) 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 protected int sizeOf(String key, Bitmap value) { return value.getRowBytes() * value.getHeight(); } }; }
From source file:com.yanzhenjie.album.task.ImageLocalLoader.java
private ImageLocalLoader() { mExecutorService = Executors.newFixedThreadPool(5); int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 8); mLruCache = new LruCache<String, Bitmap>(maxMemory) { @Override/* www . ja va 2 s. c o m*/ protected int sizeOf(String key, Bitmap value) { return value.getRowBytes() * value.getHeight(); } }; }
From source file:com.example.android.supportv4.media.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//w ww .j a v a 2s . c om protected int sizeOf(String key, Bitmap[] value) { return BitmapCompat.getAllocationByteCount(value[BIG_BITMAP_INDEX]) + BitmapCompat.getAllocationByteCount(value[ICON_BITMAP_INDEX]); } }; }