fix: inflate layout with activity instead of application context
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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(() -> {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user