Merge "Register to receive onTrimMemory callbacks"

This commit is contained in:
John Reck
2011-09-07 15:47:30 -07:00
committed by Android (Google) Code Review

View File

@@ -383,6 +383,39 @@ public class WebView extends AbsoluteLayout
} }
} }
private static class OnTrimMemoryListener implements ComponentCallbacks2 {
private static OnTrimMemoryListener sInstance = null;
static void init(Context c) {
if (sInstance == null) {
sInstance = new OnTrimMemoryListener(c.getApplicationContext());
}
}
private OnTrimMemoryListener(Context c) {
c.registerComponentCallbacks(this);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
// Ignore
}
@Override
public void onLowMemory() {
// Ignore
}
@Override
public void onTrimMemory(int level) {
if (DebugFlags.WEB_VIEW) {
Log.d("WebView", "onTrimMemory: " + level);
}
WebView.nativeOnTrimMemory(level);
}
}
// A final CallbackProxy shared by WebViewCore and BrowserFrame. // A final CallbackProxy shared by WebViewCore and BrowserFrame.
private final CallbackProxy mCallbackProxy; private final CallbackProxy mCallbackProxy;
@@ -1195,6 +1228,8 @@ public class WebView extends AbsoluteLayout
} }
private void init() { private void init() {
OnTrimMemoryListener.init(getContext());
setWillNotDraw(false); setWillNotDraw(false);
setFocusable(true); setFocusable(true);
setFocusableInTouchMode(true); setFocusableInTouchMode(true);