List of usage examples for android.content ComponentCallbacks2 ComponentCallbacks2
ComponentCallbacks2
From source file:com.boko.vimusic.cache.ImageCache.java
/** * Sets up the Lru cache/* w ww .j av a 2 s . c o m*/ * * @param context * The {@link Context} to use */ @SuppressLint("NewApi") public void initLruCache(final Context context) { final ActivityManager activityManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); final int lruCacheSize = Math.round(MEM_CACHE_DIVIDER * activityManager.getMemoryClass() * 1024 * 1024); mLruCache = new MemoryCache(lruCacheSize); // Release some memory as needed context.registerComponentCallbacks(new ComponentCallbacks2() { /** * {@inheritDoc} */ @Override public void onTrimMemory(final int level) { if (level >= TRIM_MEMORY_MODERATE) { evictAll(); } else if (level >= TRIM_MEMORY_BACKGROUND) { mLruCache.trimToSize(mLruCache.size() / 2); } } /** * {@inheritDoc} */ @Override public void onLowMemory() { // Nothing to do } /** * {@inheritDoc} */ @Override public void onConfigurationChanged(final Configuration newConfig) { // Nothing to do } }); }
From source file:com.andrew.apollo.cache.ImageCache.java
/** * Sets up the Lru cache//from ww w .j av a 2 s.c o m * * @param context The {@link Context} to use */ @SuppressLint("NewApi") public void initLruCache(final Context context) { final ActivityManager activityManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); final int lruCacheSize = Math.round(MEM_CACHE_DIVIDER * activityManager.getMemoryClass() * 1024 * 1024); mLruCache = new MemoryCache(lruCacheSize); // Release some memory as needed if (ApolloUtils.hasICS()) { context.registerComponentCallbacks(new ComponentCallbacks2() { /** * {@inheritDoc} */ @Override public void onTrimMemory(final int level) { if (level >= TRIM_MEMORY_MODERATE) { evictAll(); } else if (level >= TRIM_MEMORY_BACKGROUND) { mLruCache.trimToSize(mLruCache.size() / 2); } } /** * {@inheritDoc} */ @Override public void onLowMemory() { // Nothing to do } /** * {@inheritDoc} */ @Override public void onConfigurationChanged(final Configuration newConfig) { // Nothing to do } }); } }
From source file:com.utils.image.cache.ImageCache.java
/** * Sets up the Lru cache// w w w .j a v a 2s . co m * * @param context The {@link Context} to use */ @SuppressLint("NewApi") public void initLruCache(final Context context) { final ActivityManager activityManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); final int lruCacheSize = Math.round(MEM_CACHE_DIVIDER * activityManager.getMemoryClass() * 1024 * 1024); KeelLog.d("lruCacheSize:" + lruCacheSize); mLruCache = new MemoryCache(lruCacheSize / 2); // Release some memory as needed if (ApolloUtils.hasICS()) { context.registerComponentCallbacks(new ComponentCallbacks2() { /** * {@inheritDoc} */ @Override public void onTrimMemory(final int level) { if (level >= TRIM_MEMORY_MODERATE) { evictAll(); } else if (level >= TRIM_MEMORY_BACKGROUND) { mLruCache.trimToSize(mLruCache.size() / 2); } } /** * {@inheritDoc} */ @Override public void onLowMemory() { // Nothing to do } /** * {@inheritDoc} */ @Override public void onConfigurationChanged(final Configuration newConfig) { // Nothing to do } }); } }