List of usage examples for android.content Context registerComponentCallbacks
public void registerComponentCallbacks(ComponentCallbacks callback)
From source file:org.gateshipone.odyssey.fragments.OdysseyFragment.java
@Override public void onAttach(Context context) { super.onAttach(context); if (null == mComponentCallback) { mComponentCallback = new OdysseyComponentCallback(); }// w ww. ja va 2 s .co m // Register the memory trim callback with the system. context.registerComponentCallbacks(mComponentCallback); // This makes sure that the container activity has implemented // the callback interface. If not, it throws an exception try { mToolbarAndFABCallback = (ToolbarAndFABCallback) context; } catch (ClassCastException e) { throw new ClassCastException(context.toString() + " must implement ToolbarAndFABCallback"); } }
From source file:at.diamonddogs.util.CacheManager.java
/** * Registers a component callback for cache cleaning on low memory * * @param c a {@link Context}//from ww w. ja v a 2 s . c o m */ @TargetApi(14) public void registerComponentCallback(Context c) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { c.registerComponentCallbacks(new ComponentCallbackListener()); } }
From source file:com.android.contacts.common.ContactPhotoManager.java
public static ContactPhotoManager getInstance(Context context) { if (sInstance == null) { Context applicationContext = context.getApplicationContext(); sInstance = createContactPhotoManager(applicationContext); applicationContext.registerComponentCallbacks(sInstance); if (PermissionsUtil.hasContactsPermissions(context)) { sInstance.preloadPhotosInBackground(); }//from w ww.j a v a2s .c o m } return sInstance; }
From source file:com.boko.vimusic.cache.ImageCache.java
/** * Sets up the Lru cache//w w w.j a va2s . c om * * @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 w ww . j ava 2s .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/*from w w w . j ava2 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); 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 } }); } }