fix: inflate layout with activity instead of application context

This commit is contained in:
hyb1996
2018-01-25 13:35:13 +08:00
parent 401b8cbad0
commit 43de5913f5
4 changed files with 17 additions and 5 deletions

View File

@@ -25,6 +25,7 @@ public class ConvertLayoutInflater implements JsLayoutInflater {
try {
String androidLayoutXml = XmlConverter.convertToAndroidLayout(xml);
JsFrameLayout root = new JsFrameLayout(context);
mDynamicLayoutInflater.setContext(context);
mDynamicLayoutInflater.inflate(androidLayoutXml, root);
return root;
} catch (Exception e) {

View File

@@ -81,12 +81,19 @@ public class DynamicLayoutInflater {
private Context mContext;
private ValueParser mValueParser;
public DynamicLayoutInflater(Context context, ValueParser valueParser) {
mContext = context;
public DynamicLayoutInflater(ValueParser valueParser) {
mValueParser = valueParser;
registerViewAttrSetters();
}
public Context getContext() {
return mContext;
}
public void setContext(Context context) {
mContext = context;
}
protected void registerViewAttrSetters() {
registerViewAttrSetter(TextView.class.getName(), new TextViewAttrSetter<>(mValueParser));
registerViewAttrSetter(EditText.class.getName(), new TextViewAttrSetter<>(mValueParser));

View File

@@ -63,8 +63,8 @@ public class Floaty {
Iterator<JsFloatyWindow> iterator = mWindows.iterator();
while (iterator.hasNext()) {
JsFloatyWindow window = iterator.next();
window.close();
iterator.remove();
window.close(false);
}
}
@@ -141,7 +141,11 @@ public class Floaty {
}
public void close() {
if (mWindow == null || !mWindows.remove(this)) {
close(true);
}
void close(boolean removeFromWindows) {
if (removeFromWindows && !mWindows.remove(this)) {
return;
}
runWithWindow(() -> {

View File

@@ -35,7 +35,7 @@ public class UI extends ProxyObject {
mContext = context;
mRuntime = runtime;
mValueParser = new ValueParser(new Drawables());
DynamicLayoutInflater inflater = new DynamicLayoutInflater(context, mValueParser);
DynamicLayoutInflater inflater = new DynamicLayoutInflater(mValueParser);
inflater.registerViewAttrSetter(JsImageView.class.getName(),
new JsImageViewAttrSetter(mValueParser));
mJsLayoutInflater = new ConvertLayoutInflater(inflater);