當前位置: 首頁>>代碼示例>>Java>>正文


Java ComponentCallbacks2類代碼示例

本文整理匯總了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) {
                }
            });
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:20,代碼來源:MemoryPressureListener.java

示例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);
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:26,代碼來源:AdvancedMockContextTest.java

示例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;
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:21,代碼來源:MemoryPressureListener.java

示例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;
  }
}
 
開發者ID:andviane,項目名稱:google-books-android-viewer,代碼行數:17,代碼來源:BookListActivity.java

示例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;
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:18,代碼來源:MemoryPressureRouter.java

示例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);
        }
    }
}
 
開發者ID:nvllsvm,項目名稱:Audinaut,代碼行數:21,代碼來源:DownloadService.java

示例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;
    }
}
 
開發者ID:tanguyantoine,項目名稱:react-native-music-control,代碼行數:18,代碼來源:MusicControlModule.java

示例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();
        }
 
開發者ID:maxwell-nc,項目名稱:ExhibitionCenter,代碼行數:24,代碼來源:ImageLoader.java

示例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) {
                }
            });
}
 
開發者ID:mogoweb,項目名稱:365browser,代碼行數:20,代碼來源:MemoryPressureListener.java

示例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);
}
 
開發者ID:mogoweb,項目名稱:365browser,代碼行數:24,代碼來源:MemoryMonitorAndroid.java

示例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);
		}
	}
}
 
開發者ID:popeen,項目名稱:Popeens-DSub,代碼行數:21,代碼來源:DownloadService.java

示例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;
    }
}
 
開發者ID:ArthurHub,項目名稱:Android-Fast-Image-Loader,代碼行數:19,代碼來源:MemoryPoolImpl.java

示例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");
}
 
開發者ID:cuplv,項目名稱:droidel,代碼行數:23,代碼來源:ActivityThread.java

示例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
    }
}
 
開發者ID:patrick-doyle,項目名稱:CrossBow,代碼行數:20,代碼來源:DefaultImageCache.java

示例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) {
              }
        });
}
 
開發者ID:openresearch,項目名稱:android-chromium-view,代碼行數:20,代碼來源:MemoryPressureListener.java


注:本文中的android.content.ComponentCallbacks2類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。