List of usage examples for android.support.v4.util LruCache LruCache
public LruCache(int maxSize)
From source file:com.dv.BitMap.Native.DvNativeImageLoader.java
private DvNativeImageLoader() { // ??/*from w w w . j a va2 s . c o m*/ 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.zion.adapter.CachedImageCursorAdapter.java
public CachedImageCursorAdapter(Context context, Cursor cursor, boolean autoRequery) { super(context, cursor, autoRequery); this.context = context; // Get memory class of this device, exceeding this amount will throw an OutOfMemory exception. final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); // Use 1/8th of the available memory for this memory cache. this.memoryCache = new LruCache<String, Bitmap>(maxMemory / 8) { protected int sizeOf(String key, Bitmap bitmap) { // The cache size will be measured in bytes rather than number of items. return bitmap.getRowBytes() * bitmap.getHeight(); }// ww w .j a v a2s. c o m }; }
From source file:cc.softwarefactory.lokki.android.MainApplication.java
@Override public void onCreate() { Log.e(TAG, "Lokki started component"); loadSetting();//from w w w .ja va 2s. c o m locationDisabledPromptShown = false; final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); // Use 1/8th of the available memory for this memory cache. final int cacheSize = maxMemory / 8; avatarCache = 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; } }; String iDontWantToSeeString = PreferenceUtils.getString(this, PreferenceUtils.KEY_I_DONT_WANT_TO_SEE); if (!iDontWantToSeeString.isEmpty()) { try { MainApplication.iDontWantToSee = new JSONObject(iDontWantToSeeString); } catch (JSONException e) { MainApplication.iDontWantToSee = null; Log.e(TAG, e.getMessage()); } } else { MainApplication.iDontWantToSee = new JSONObject(); } Log.e(TAG, "MainApplication.iDontWantToSee: " + MainApplication.iDontWantToSee); if (DEVELOPER_MODE) { StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects() //.detectLeakedClosableObjects() .penaltyLog().penaltyDeath().build()); } super.onCreate(); }
From source file:com.crossbow.volley.toolbox.CrossbowImageCache.java
/** * @param size - number of byes to use for the cache; *//* w ww . j a va2 s . c o m*/ protected CrossbowImageCache(int size) { imageCache = new LruCache<String, Bitmap>(size) { @Override protected int sizeOf(String key, Bitmap value) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { return value.getAllocationByteCount(); } else { return value.getRowBytes() * value.getHeight(); } } }; }
From source file:com.dp.chapter01.part1.ImageLoader.java
private void initImageCache() { // ?/*from www .ja v a 2 s .c o m*/ final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); // ?4? final int cacheSize = maxMemory / 4; mImageCache = new LruCache<String, Bitmap>(cacheSize) { @Override protected int sizeOf(String key, Bitmap bitmap) { return bitmap.getRowBytes() * bitmap.getHeight() / 1024; } }; }
From source file:com.frostwire.android.gui.PeerManager.java
private PeerManager() { this.maxPeers = Constants.PEER_MANAGER_MAX_PEERS; //this.cacheTimeout = Constants.PEER_MANAGER_CACHE_TIMEOUT; this.peerCache = new LruCache<Peer, Peer>(maxPeers); this.addressMap = new HashMap<String, Peer>(); this.peerComparator = new PeerComparator(); refreshLocalPeer();/* ww w . j a va 2s . c om*/ }
From source file:com.activeandroid.sebbia.Cache.java
public static synchronized void initialize(Configuration configuration) { if (sIsInitialized) { Log.v("ActiveAndroid already initialized."); return;/*ww w. jav a 2 s. 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()); initializeModelFillers(); openDatabase(); sIsInitialized = true; Log.v("ActiveAndroid initialized successfully."); }
From source file:com.raptureinvenice.webimageview.cache.WebImageCache.java
public WebImageCache() { mMemCache = new LruCache<String, Bitmap>(cacheSize) { @Override/* w ww. j a v a 2s . c om*/ protected int sizeOf(String key, Bitmap bitmap) { return bitmap.getRowBytes() * bitmap.getHeight(); } }; }
From source file:com.kakao.GlobalApplication.java
/** * ? ?, ? ?, ?? ./*w ww. j av a2s . com*/ */ @Override public void onCreate() { super.onCreate(); instance = 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); appKey = Utility.getMetadata(this, APP_KEY_PROPERTY); }
From source file:org.videolan.myvlc.tool.BitmapCache.java
private BitmapCache() { // Get the global context of the application Context context = MyVLCApp.getAppContext(); final int memClass = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)) .getMemoryClass();//from w w w .j a va 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(); } }; }