本文整理匯總了Java中android.content.ComponentCallbacks2類的典型用法代碼示例。如果您正苦於以下問題:Java ComponentCallbacks2類的具體用法?Java ComponentCallbacks2怎麽用?Java ComponentCallbacks2使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ComponentCallbacks2類屬於android.content包,在下文中一共展示了ComponentCallbacks2類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: registerSystemCallback
import android.content.ComponentCallbacks2; //導入依賴的package包/類
@CalledByNative
private static void registerSystemCallback(Context context) {
context.registerComponentCallbacks(
new ComponentCallbacks2() {
@Override
public void onTrimMemory(int level) {
maybeNotifyMemoryPresure(level);
}
@Override
public void onLowMemory() {
nativeOnMemoryPressure(MemoryPressureLevel.CRITICAL);
}
@Override
public void onConfigurationChanged(Configuration configuration) {
}
});
}
示例2: testComponentCallbacksForTargetContext
import android.content.ComponentCallbacks2; //導入依賴的package包/類
@SmallTest
public void testComponentCallbacksForTargetContext() {
Context targetContext = getInstrumentation().getTargetContext();
Application targetApplication = (Application) targetContext.getApplicationContext();
AdvancedMockContext context = new AdvancedMockContext(targetContext);
Callback1 callback1 = new Callback1();
Callback2 callback2 = new Callback2();
context.registerComponentCallbacks(callback1);
context.registerComponentCallbacks(callback2);
targetApplication.onLowMemory();
assertTrue("onLowMemory should have been called.", callback1.mOnLowMemoryCalled);
assertTrue("onLowMemory should have been called.", callback2.mOnLowMemoryCalled);
Configuration configuration = new Configuration();
targetApplication.onConfigurationChanged(configuration);
assertEquals("onConfigurationChanged should have been called.", configuration,
callback1.mConfiguration);
assertEquals("onConfigurationChanged should have been called.", configuration,
callback2.mConfiguration);
targetApplication.onTrimMemory(ComponentCallbacks2.TRIM_MEMORY_MODERATE);
assertEquals("onTrimMemory should have been called.", ComponentCallbacks2
.TRIM_MEMORY_MODERATE, callback2.mLevel);
}
示例3: handleDebugIntent
import android.content.ComponentCallbacks2; //導入依賴的package包/類
/**
* Used by applications to simulate a memory pressure signal. By throwing certain intent
* actions.
*/
public static boolean handleDebugIntent(Activity activity, String action) {
if (ACTION_LOW_MEMORY.equals(action)) {
simulateLowMemoryPressureSignal(activity);
} else if (ACTION_TRIM_MEMORY.equals(action)) {
simulateTrimMemoryPressureSignal(activity, ComponentCallbacks2.TRIM_MEMORY_COMPLETE);
} else if (ACTION_TRIM_MEMORY_RUNNING_CRITICAL.equals(action)) {
simulateTrimMemoryPressureSignal(activity,
ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL);
} else if (ACTION_TRIM_MEMORY_MODERATE.equals(action)) {
simulateTrimMemoryPressureSignal(activity, ComponentCallbacks2.TRIM_MEMORY_MODERATE);
} else {
return false;
}
return true;
}
示例4: onTrimMemory
import android.content.ComponentCallbacks2; //導入依賴的package包/類
@Override
public void onTrimMemory(int level) {
switch (level) {
case ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE:
case ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW:
case ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL:
Log.d(TAG, "Memory trimmed");
FragmentManager fragmentManager = getFragmentManager();
BookListFragment lf = (BookListFragment) fragmentManager.findFragmentById(R.id.book_list);
lf.adapter.getModel().lowMemory();
default:
break;
}
}
示例5: handleDebugIntent
import android.content.ComponentCallbacks2; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static boolean handleDebugIntent(Application application, String action) {
switch (action) {
case ACTION_TRIM_MEMORY_UI_HIDDEN:
simulateTrimMemory(application, ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN);
break;
case ACTION_TRIM_MEMORY_MODERATE:
simulateTrimMemory(application, TRIM_MEMORY_MODERATE);
break;
case ACTION_TRIM_MEMORY_CRITICAL:
simulateTrimMemory(application, TRIM_MEMORY_COMPLETE);
default:
return false;
}
return true;
}
示例6: onTrimMemory
import android.content.ComponentCallbacks2; //導入依賴的package包/類
@Override
public void onTrimMemory(int level) {
ImageLoader imageLoader = SubsonicActivity.getStaticImageLoader(this);
if(imageLoader != null) {
Log.i(TAG, "Memory Trim Level: " + level);
if (level < ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
if (level >= ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL) {
imageLoader.onLowMemory(0.75f);
} else if (level >= ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW) {
imageLoader.onLowMemory(0.50f);
} else if(level >= ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE) {
imageLoader.onLowMemory(0.25f);
}
} else if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
imageLoader.onLowMemory(0.25f);
} else if(level >= ComponentCallbacks2.TRIM_MEMORY_COMPLETE) {
imageLoader.onLowMemory(0.75f);
}
}
}
示例7: onTrimMemory
import android.content.ComponentCallbacks2; //導入依賴的package包/類
@Override
public void onTrimMemory(int level) {
switch(level) {
// Trims memory when it reaches a moderate level and the session is inactive
case ComponentCallbacks2.TRIM_MEMORY_MODERATE:
case ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE:
if(session.isActive()) break;
// Trims memory when it reaches a critical level
case ComponentCallbacks2.TRIM_MEMORY_COMPLETE:
case ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL:
Log.w("MusicControl", "Control resources are being removed due to system's low memory (Level: " + level + ")");
destroy();
break;
}
}
示例8: start
import android.content.ComponentCallbacks2; //導入依賴的package包/類
public void start() {
//自動回收內存
imageView.getContext().registerComponentCallbacks(new ComponentCallbacks2() {
@Override
public void onTrimMemory(int level) {
LogUtils.log().addMsg("內存較低,自動回收內存緩存,Level:" + level).build().execute();
clearMemCache(level);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
}
@Override
public void onLowMemory() {
LogUtils.log().addMsg("內存不足,自動清空內存緩存").build().execute();
clearMemCache();
}
});
new ImageLoader(this).start();
}
示例9: registerSystemCallback
import android.content.ComponentCallbacks2; //導入依賴的package包/類
@CalledByNative
private static void registerSystemCallback() {
ContextUtils.getApplicationContext().registerComponentCallbacks(
new ComponentCallbacks2() {
@Override
public void onTrimMemory(int level) {
maybeNotifyMemoryPresure(level);
}
@Override
public void onLowMemory() {
nativeOnMemoryPressure(MemoryPressureLevel.CRITICAL);
}
@Override
public void onConfigurationChanged(Configuration configuration) {
}
});
}
示例10: registerComponentCallbacks
import android.content.ComponentCallbacks2; //導入依賴的package包/類
/**
* Register ComponentCallbacks2 to receive memory pressure signals.
*
*/
@CalledByNative
private static void registerComponentCallbacks() {
sCallbacks = new ComponentCallbacks2() {
@Override
public void onTrimMemory(int level) {
if (level != ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
nativeOnTrimMemory(level);
}
}
@Override
public void onLowMemory() {
// Don't support old onLowMemory().
}
@Override
public void onConfigurationChanged(Configuration config) {
}
};
ContextUtils.getApplicationContext().registerComponentCallbacks(sCallbacks);
}
示例11: onTrimMemory
import android.content.ComponentCallbacks2; //導入依賴的package包/類
@Override
public void onTrimMemory(int level) {
ImageLoader imageLoader = SubsonicActivity.getStaticImageLoader(this);
if(imageLoader != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
Log.i(TAG, "Memory Trim Level: " + level);
if (level < ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
if (level >= ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL) {
imageLoader.onLowMemory(0.75f);
} else if (level >= ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW) {
imageLoader.onLowMemory(0.50f);
} else if(level >= ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE) {
imageLoader.onLowMemory(0.25f);
}
} else if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
imageLoader.onLowMemory(0.25f);
} else if(level >= ComponentCallbacks2.TRIM_MEMORY_COMPLETE) {
imageLoader.onLowMemory(0.75f);
}
}
}
示例12: onTrimMemory
import android.content.ComponentCallbacks2; //導入依賴的package包/類
@Override
public void onTrimMemory(int level) {
switch (level) {
case ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN:
releaseUnUsedBitmaps(3);
break;
case ComponentCallbacks2.TRIM_MEMORY_BACKGROUND:
releaseUnUsedBitmaps(1);
break;
case ComponentCallbacks2.TRIM_MEMORY_MODERATE:
case ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE:
case ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW:
case ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL:
case ComponentCallbacks2.TRIM_MEMORY_COMPLETE:
releaseUnUsedBitmaps(0);
break;
}
}
示例13: handleLowMemory
import android.content.ComponentCallbacks2; //導入依賴的package包/類
final void handleLowMemory() {
ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null);
final int N = callbacks.size();
for (int i=0; i<N; i++) {
callbacks.get(i).onLowMemory();
}
// Ask SQLite to free up as much memory as it can, mostly from its page caches.
if (Process.myUid() != Process.SYSTEM_UID) {
int sqliteReleased = SQLiteDatabase.releaseMemory();
EventLog.writeEvent(SQLITE_MEM_RELEASED_EVENT_LOG_TAG, sqliteReleased);
}
// Ask graphics to free up as much as possible (font/image caches)
Canvas.freeCaches();
// Ask text layout engine to free also as much as possible
Canvas.freeTextLayoutCaches();
BinderInternal.forceGc("mem");
}
示例14: trimMemory
import android.content.ComponentCallbacks2; //導入依賴的package包/類
/**
* @inheritDoc
*/
@Override
public void trimMemory(int level) {
if(level >= ComponentCallbacks2.TRIM_MEMORY_COMPLETE) {
emptyCache(); //dump the cache
}
else if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE){
trimCache(0.5f); // trim to half the max size
}
else if (level >= ComponentCallbacks2.TRIM_MEMORY_BACKGROUND){
trimCache(0.7f); // trim to one seventh max size
}
else if (level >= ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL){
trimCache(0.2f); // trim to one fifth max size
}
}
示例15: registerSystemCallback
import android.content.ComponentCallbacks2; //導入依賴的package包/類
@CalledByNative
private static void registerSystemCallback(Context context) {
context.registerComponentCallbacks(
new ComponentCallbacks2() {
@Override
public void onTrimMemory(int level) {
maybeNotifyMemoryPresure(level);
}
@Override
public void onLowMemory() {
nativeOnMemoryPressure(MemoryPressureLevelList.MEMORY_PRESSURE_CRITICAL);
}
@Override
public void onConfigurationChanged(Configuration configuration) {
}
});
}