下面列出了android.content.Context#registerComponentCallbacks ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
if (null == mComponentCallback) {
mComponentCallback = new OdysseyComponentCallback();
}
// 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");
}
}
public ColorPickerDialog(Context context, int initialColor) {
super(context);
context.registerComponentCallbacks(new ComponentCallbacks() {
@Override
public void onConfigurationChanged(Configuration newConfig) {
setUp(mOldColor.getColor(), mNewColor.getColor());
setAlphaSliderVisible(mAlphaSliderEnabled);
setHexValueEnabled(mHexValueEnabled);
}
@Override
public void onLowMemory() {
}
});
init(initialColor);
}
@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) {
}
});
}
@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) {
}
});
}
/**
* Use this to create a wired-up memory manager.
*
* @param context this is used to register for system memory events.
* @param mediaSaver this used to check if the saving queue is full.
* @return A wired-up memory manager instance.
*/
public static MemoryManagerImpl create(Context context, MediaSaver mediaSaver)
{
ActivityManager activityManager = AndroidServices.instance().provideActivityManager();
int maxAllowedNativeMemory = getMaxAllowedNativeMemory(context);
MemoryQuery mMemoryQuery = new MemoryQuery(activityManager);
MemoryManagerImpl memoryManager = new MemoryManagerImpl(maxAllowedNativeMemory,
mMemoryQuery);
context.registerComponentCallbacks(memoryManager);
mediaSaver.setQueueListener(memoryManager);
return memoryManager;
}
AppLabelCache(final Context context, final Callback callback) {
mStore = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
if (CLEAR_CACHE_UPON_START) mStore.edit().clear().apply();
mCallback = callback;
mPackageManager = context.getPackageManager();
context.registerComponentCallbacks(this); // No un-registration since AppLabelCache is never released.
onConfigurationChanged(context.getResources().getConfiguration());
}
/**
* 注册系统语种变化监听
*/
static void register(Context context) {
context.registerComponentCallbacks(new LanguagesChange());
}
public Controller(Context ctx) {
ctx.registerComponentCallbacks(this);
}
public Controller(Context ctx) {
ctx.registerComponentCallbacks(this);
}
public Controller(Context ctx) {
ctx.registerComponentCallbacks(this);
}
public Controller(Context ctx) {
ctx.registerComponentCallbacks(this);
}
public Controller(Context ctx) {
ctx.registerComponentCallbacks(this);
}
public Controller(Context ctx) {
ctx.registerComponentCallbacks(this);
}