List of usage examples for android.support.v4.util LruCache LruCache
public LruCache(int maxSize)
From source file:com.heniktechnology.hncore.dynamic_data_base.Cache.java
public static synchronized void initialize(Configuration configuration) { if (sIsInitialized) { HNLoger.info("ActiveAndroid already initialized."); return;/* w w w . j ava2 s . co 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; HNLoger.info("ActiveAndroid initialized successfully."); }
From source file:nuclei.persistence.adapter.PagedList.java
public PagedList(Context context, int maxPages, int pageSize) { mContext = context.getApplicationContext(); mMaxPages = maxPages;// ww w. ja v a 2 s .co m mPages = new LruCache<Integer, List<T>>(maxPages) { @Override protected void entryRemoved(boolean evicted, Integer key, List<T> oldValue, List<T> newValue) { if (evicted) calculatePageIndexes(); if (mListener != null) mListener.onPageEvicted(key); } }; mPageSize = pageSize; }
From source file:com.umeng.network.test.LURCacheTest.java
private void initCache() { mResponseCache = new LruCache<Request<?>, Response>(108 * 1024); }
From source file:org.tigase.messenger.phone.pro.utils.ImageHelper.java
protected static void initialize(Context context) { if (memCache == null) { // Get memory class of this device, exceeding this amount will throw // an OutOfMemory exception. final int memClass = ((android.app.ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)) .getMemoryClass();/*from w ww .j a va 2 s.c o m*/ // Use 1/8th of the available memory for this memory cache. final int cacheSize = 1024 * 1024 * memClass / 8; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) { memCache = new LruCache<String, Bitmap>(cacheSize) { @TargetApi(12) @Override protected int sizeOf(String key, Bitmap bitmap) { // The cache size will be measured in bytes rather than // number of items. Ignoring placeholder bitmap as well. return placeHolders.contains(bitmap) ? 0 : bitmap.getByteCount(); } }; } else { // below SDK 12 there is no getByteCount method memCache = new LruCache<String, Bitmap>(cacheSize) { @Override protected int sizeOf(String key, Bitmap bitmap) { // The cache size will be measured in bytes rather than // number of items. Ignoring placeholder bitmap as well. return placeHolders.contains(bitmap) ? 0 : (bitmap.getRowBytes() * bitmap.getHeight()); } }; } // maps images cache BitmapDiskLruCache diskCache = new BitmapDiskLruCache(); diskCache.initialize(context, "maps", 10 * 1024 * 1024); diskCaches.put("maps", diskCache); // images from files shared with or by us diskCache = new BitmapDiskLruCache(); diskCache.initialize(context, "images-mini", 10 * 1024 * 1024); diskCaches.put("images-mini", diskCache); } }
From source file:com.pixelpixel.pyp.SplashActivity.java
/** Called when the activity is first created. */ @Override//from www.j av a 2s . c om public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash); //Initializing the application cache final int memClass = ((ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass(); final int cacheSize = 1024 * 1024 * memClass / 4; mMemoryCache = new LruCache<String, Object>(cacheSize); /* * Setting up the animation for the logo * */ final ImageView splash_logo = (ImageView) findViewById(R.id.SplashLogo); Animation sa1 = AnimationUtils.loadAnimation(this, R.anim.splash_anim); sa1.setAnimationListener(new AnimationListener() { public void onAnimationEnd(Animation arg0) { /* * After the end of the "growing" animation, we call the "shrinking" animation. * */ Animation sa2 = AnimationUtils.loadAnimation(SplashActivity.this, R.anim.splash_anim2); sa2.setAnimationListener(new AnimationListener() { public void onAnimationEnd(Animation animation) { /* * After the end of the "shrinking" animation, we proceed to the * next screen, the start screen. * */ Handler mHandler = new Handler(); mHandler.postDelayed(new Runnable() { public void run() { startActivity(new Intent(SplashActivity.this, StartActivity.class)); SplashActivity.this.finish(); } }, 5000); } public void onAnimationRepeat(Animation animation) { } public void onAnimationStart(Animation animation) { } }); splash_logo.startAnimation(sa2); } public void onAnimationRepeat(Animation animation) { } public void onAnimationStart(Animation animation) { } }); splash_logo.startAnimation(sa1); }
From source file:com.ibuildapp.romanblack.CataloguePlugin.imageloader.Plugin.java
private Plugin() { final int CORES = Runtime.getRuntime().availableProcessors(); final int THREAD_POOL_SIZE_NETWORK = CORES + 1; final int THREAD_POOL_SIZE_NETWORK_MAX = CORES * 2 + 1; final long KEEP_ALIVE_VALUE = 1; final TimeUnit KEEP_ALIVE_VALUE_TIME_UNIT = TimeUnit.SECONDS; final int CACHE_BITMAP_SIZE = (int) (Runtime.getRuntime().maxMemory() / 8192f); cacheBitmap = new LruCache<String, Bitmap>(CACHE_BITMAP_SIZE) { @Override//from w ww . j a v a 2s . c om protected int sizeOf(String key, Bitmap bitmap) { return (int) ((bitmap.getRowBytes() * bitmap.getHeight()) / 1024f); } }; queueNetwork = new LinkedBlockingQueue<>(); queueLocal = new LinkedBlockingQueue<>(); threadPoolNetwork = new ThreadPoolExecutor(THREAD_POOL_SIZE_NETWORK, THREAD_POOL_SIZE_NETWORK_MAX, KEEP_ALIVE_VALUE, KEEP_ALIVE_VALUE_TIME_UNIT, queueNetwork); threadPoolLocal = new ThreadPoolExecutor(CORES, CORES, KEEP_ALIVE_VALUE, KEEP_ALIVE_VALUE_TIME_UNIT, queueLocal); }
From source file:org.i_chera.wolfensteineditor.document.VSwapContainer.java
/** * Gets a bitmap from a given wall texture * @param n Index of wall texture/*from w w w. j a v a 2s .co m*/ * @return Null if invalid index or not a wall texture, the bitmap otherwise */ public Bitmap getWallBitmap(int n) { if (n < 0 || n >= mSpriteStart) return null; if (mPages.get(n).length < 64 * 64) return null; if (mWallBitmapCache == null) { mWallBitmapCache = new LruCache<Integer, Bitmap>(mSpriteStart); } Bitmap bmp = mWallBitmapCache.get(n); if (bmp == null) { int[] ret = new int[64 * 64]; for (int i = 0; i < ret.length; ++i) ret[64 * (i % 64) + i / 64] = Palette.WL6[mPages.get(n)[i] & 0xff]; bmp = Bitmap.createBitmap(ret, 64, 64, Bitmap.Config.ARGB_8888); mWallBitmapCache.put(n, bmp); } return bmp; }
From source file:com.ibuildapp.ZopimChatPlugin.core.Core.java
Core() { final int CORES = Runtime.getRuntime().availableProcessors(); final int THREAD_POOL_SIZE_NETWORK = CORES + 1; final int THREAD_POOL_SIZE_NETWORK_MAX = CORES * 2 + 1; final long KEEP_ALIVE_VALUE = 1; final TimeUnit KEEP_ALIVE_VALUE_TIME_UNIT = TimeUnit.SECONDS; final int CACHE_BITMAP_SIZE = (int) (Runtime.getRuntime().maxMemory() / 8192f); cacheBitmap = new LruCache<String, Bitmap>(CACHE_BITMAP_SIZE) { @Override/*from w ww .j a v a2 s.c om*/ protected int sizeOf(String key, Bitmap bitmap) { return (int) ((bitmap.getRowBytes() * bitmap.getHeight()) / 1024f); } }; queueNetwork = new LinkedBlockingQueue<>(); queueLocal = new LinkedBlockingQueue<>(); threadPoolNetwork = new ThreadPoolExecutor(THREAD_POOL_SIZE_NETWORK, THREAD_POOL_SIZE_NETWORK_MAX, KEEP_ALIVE_VALUE, KEEP_ALIVE_VALUE_TIME_UNIT, queueNetwork); threadPoolLocal = new ThreadPoolExecutor(CORES, CORES, KEEP_ALIVE_VALUE, KEEP_ALIVE_VALUE_TIME_UNIT, queueLocal); }
From source file:inc.bait.jubilee.model.helper.util.ImgCache.java
private void init(float memCacheSizePercent) { int memCacheSize = calculateMemCacheSize(memCacheSizePercent); if (BuildConfig.DEBUG) { Log.d(TAG, "Memory cache created (size = " + memCacheSize + ")"); }//from w w w . ja v a 2s .com mMemoryCache = new LruCache<String, Bitmap>(memCacheSize) { @Override protected int sizeOf(String key, Bitmap bitmap) { final int bitmapSize = getBitmapSize(bitmap) / 1024; return bitmapSize == 0 ? 1 : bitmapSize; } }; }
From source file:com.tct.fw.ex.chips.DefaultPhotoManager.java
public DefaultPhotoManager(ContentResolver contentResolver) { mContentResolver = contentResolver; mPhotoCacheMap = new LruCache<Uri, byte[]>(PHOTO_CACHE_SIZE); }