12
12
import android .app .Presentation ;
13
13
import android .content .Context ;
14
14
import android .content .ContextWrapper ;
15
+ import android .content .MutableContextWrapper ;
15
16
import android .graphics .Rect ;
16
17
import android .graphics .drawable .ColorDrawable ;
17
18
import android .os .Build ;
@@ -72,8 +73,6 @@ static class PresentationState {
72
73
private FakeWindowViewGroup fakeWindowViewGroup ;
73
74
}
74
75
75
- private final PlatformViewFactory viewFactory ;
76
-
77
76
// A reference to the current accessibility bridge to which accessibility events will be
78
77
// delegated.
79
78
private final AccessibilityEventsDelegate accessibilityEventsDelegate ;
@@ -112,19 +111,19 @@ static class PresentationState {
112
111
public SingleViewPresentation (
113
112
Context outerContext ,
114
113
Display display ,
115
- PlatformViewFactory viewFactory ,
114
+ PlatformView view ,
116
115
AccessibilityEventsDelegate accessibilityEventsDelegate ,
117
116
int viewId ,
118
117
Object createParams ,
119
118
OnFocusChangeListener focusChangeListener ) {
120
119
super (new ImmContext (outerContext ), display );
121
- this .viewFactory = viewFactory ;
122
120
this .accessibilityEventsDelegate = accessibilityEventsDelegate ;
123
121
this .viewId = viewId ;
124
122
this .createParams = createParams ;
125
123
this .focusChangeListener = focusChangeListener ;
126
124
this .outerContext = outerContext ;
127
125
state = new PresentationState ();
126
+ state .platformView = view ;
128
127
getWindow ()
129
128
.setFlags (
130
129
WindowManager .LayoutParams .FLAG_NOT_FOCUSABLE ,
@@ -148,7 +147,6 @@ public SingleViewPresentation(
148
147
boolean startFocused ) {
149
148
super (new ImmContext (outerContext ), display );
150
149
this .accessibilityEventsDelegate = accessibilityEventsDelegate ;
151
- viewFactory = null ;
152
150
this .state = state ;
153
151
this .focusChangeListener = focusChangeListener ;
154
152
this .outerContext = outerContext ;
@@ -178,14 +176,18 @@ protected void onCreate(Bundle savedInstanceState) {
178
176
179
177
// Our base mContext has already been wrapped with an IMM cache at instantiation time, but
180
178
// we want to wrap it again here to also return state.windowManagerHandler.
181
- Context context =
179
+ Context baseContext =
182
180
new PresentationContext (getContext (), state .windowManagerHandler , outerContext );
183
181
184
- if (state .platformView == null ) {
185
- state .platformView = viewFactory .create (context , viewId , createParams );
182
+ View embeddedView = state .platformView .getView ();
183
+ if (embeddedView .getContext () instanceof MutableContextWrapper ) {
184
+ MutableContextWrapper currentContext = (MutableContextWrapper ) embeddedView .getContext ();
185
+ currentContext .setBaseContext (baseContext );
186
+ } else {
187
+ throw new IllegalStateException (
188
+ "embedded view context must be a MutableContextWrapper: " + viewId );
186
189
}
187
190
188
- View embeddedView = state .platformView .getView ();
189
191
container .addView (embeddedView );
190
192
rootView =
191
193
new AccessibilityDelegatingFrameLayout (
0 commit comments