Use Activity resources in DecorContext

We use the application context in DecorContext to avoid holding a reference
to the Activity. However, the resources don't match the Activity's in a multi-window
world, so we use the resources from the Activity, which  get updated as the Activity
goes between multi-window states. This avoids holding a reference to the Activity.

Bug:28096052
Change-Id: I2804f2420afad6dcecc56e5dece008c390540d72
This commit is contained in:
Adam Lesinski
2016-04-18 12:14:12 -07:00
parent 7e25024758
commit ff22a56ef8
2 changed files with 18 additions and 3 deletions

View File

@@ -17,22 +17,27 @@
package com.android.internal.policy;
import android.content.Context;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.view.ContextThemeWrapper;
import android.view.WindowManager;
import android.view.WindowManagerImpl;
/**
* Context for decor views which can be seeded with pure application context and not depend on the
* activity, but still provide some of the facilities that Activity has, e.g. themes.
* activity, but still provide some of the facilities that Activity has,
* e.g. themes, activity-based resources, etc.
*
* @hide
*/
class DecorContext extends ContextThemeWrapper {
private PhoneWindow mPhoneWindow;
private WindowManager mWindowManager;
private Resources mActivityResources;
public DecorContext(Context context) {
public DecorContext(Context context, Resources activityResources) {
super(context, null);
mActivityResources = activityResources;
}
void setPhoneWindow(PhoneWindow phoneWindow) {
@@ -52,4 +57,14 @@ class DecorContext extends ContextThemeWrapper {
}
return super.getSystemService(name);
}
@Override
public Resources getResources() {
return mActivityResources;
}
@Override
public AssetManager getAssets() {
return mActivityResources.getAssets();
}
}

View File

@@ -2297,7 +2297,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
if (applicationContext == null) {
context = getContext();
} else {
context = new DecorContext(applicationContext);
context = new DecorContext(applicationContext, getContext().getResources());
if (mTheme != -1) {
context.setTheme(mTheme);
}