fix sublime plugin issue with ui mode, object prototype pollution, try for ui api
This commit is contained in:
@@ -29,6 +29,7 @@ dependencies {
|
||||
})
|
||||
testCompile 'junit:junit:4.12'
|
||||
compile 'com.github.hyb1996:node-android-lib:1.0.14'
|
||||
compile 'com.github.hyb1996:DynamicLayoutInflator:0.1'
|
||||
compile 'org.greenrobot:eventbus:3.0.0'
|
||||
compile project(path: ':common')
|
||||
compile project(path: ':automator')
|
||||
|
||||
@@ -13,12 +13,13 @@ if(__engine_name__ == "rhino"){
|
||||
}
|
||||
}
|
||||
|
||||
var __that__ = this;
|
||||
|
||||
var __asGlobal__ = function(obj, functions){
|
||||
var len = functions.length;
|
||||
for(var i = 0; i < len; i++) {
|
||||
var funcName = functions[i];
|
||||
this[funcName] = obj[funcName].bind(obj);
|
||||
__that__[funcName] = obj[funcName].bind(obj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,4 +33,4 @@ require("__general__")(__runtime__, this);
|
||||
var m = modules[i];
|
||||
scope[m] = require('__' + m + '__')(scope.__runtime__, scope);
|
||||
}
|
||||
})(this);
|
||||
})(__that__);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
module.exports = function(__runtime__, scope){
|
||||
var app = new Object(__runtime__.app);
|
||||
var app = Object.create(__runtime__.app);
|
||||
var context = scope.context;
|
||||
|
||||
app.intent = function(i) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
module.exports = function(__runtime__, scope){
|
||||
var console = new Object(__runtime__.console);
|
||||
var console = Object.create(__runtime__.console);
|
||||
|
||||
console.assert = function(value, message){
|
||||
message = message || "";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module.exports = function(__runtime__, scope){
|
||||
var ui = Object(__runtime__.ui);
|
||||
ui.layout = function(xml){
|
||||
view = ui.inflate(xml);
|
||||
view = ui.inflate(activity, xml);
|
||||
ui.setView(view);
|
||||
}
|
||||
|
||||
|
||||
@@ -120,6 +120,12 @@ public class ScriptEngineService {
|
||||
task.setExecutionListener(mScriptExecutionObserver);
|
||||
}
|
||||
if (isUiMode(task)) {
|
||||
mUiHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
}
|
||||
});
|
||||
return ScriptExecuteActivity.execute(mContext, this, task);
|
||||
} else {
|
||||
RunnableScriptExecution scriptExecution = new RunnableScriptExecution(this, task);
|
||||
|
||||
@@ -83,20 +83,26 @@ public class ScriptExecuteActivity extends Activity {
|
||||
|
||||
private ScriptEngine mScriptEngine;
|
||||
private ScriptRuntime mScriptRuntime;
|
||||
private ScriptEngineService mScriptEngineService;
|
||||
|
||||
ActivityScriptExecution(ScriptEngineService service, ScriptExecutionTask task) {
|
||||
super(task);
|
||||
mScriptEngine = service.createScriptEngine();
|
||||
mScriptRuntime = service.createScriptRuntime();
|
||||
mScriptEngineService = service;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScriptEngine getEngine() {
|
||||
if (mScriptEngine == null) {
|
||||
mScriptEngine = mScriptEngineService.createScriptEngine();
|
||||
}
|
||||
return mScriptEngine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScriptRuntime getRuntime() {
|
||||
if (mScriptRuntime == null) {
|
||||
mScriptRuntime = mScriptEngineService.createScriptRuntime();
|
||||
}
|
||||
return mScriptRuntime;
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ public interface AttributeHandler {
|
||||
|
||||
@Override
|
||||
public boolean handle(String nodeName, Node attr, StringBuilder layoutXml) {
|
||||
String dimen = convertToAndroidDimen(attr.getNodeName());
|
||||
String dimen = convertToAndroidDimen(attr.getNodeValue());
|
||||
layoutXml.append("android:").append(mAttrName).append("=\"").append(dimen).append("\"\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ import android.content.Context;
|
||||
import android.util.Xml;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.nickandjerry.dynamiclayoutinflator.lib.DynamicLayoutInflator;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
@@ -16,22 +19,14 @@ import java.io.StringReader;
|
||||
|
||||
public class ConvertLayoutInflater implements JsLayoutInflater {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
public ConvertLayoutInflater(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View inflate(String xml) {
|
||||
public View inflate(Context context, String xml) {
|
||||
try {
|
||||
// 我靠%>_<% 弄完了xml转换以后发现android并不能动态inflate非resources的xml啊啊啊啊啊啊
|
||||
String androidLayoutXml = XmlConverter.convertToAndroidLayout(xml);
|
||||
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
|
||||
XmlPullParser parser = factory.newPullParser();
|
||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
parser.setInput(new StringReader(androidLayoutXml));
|
||||
return inflater.inflate(parser, null);
|
||||
FrameLayout root = new FrameLayout(context);
|
||||
DynamicLayoutInflator.inflate(context, androidLayoutXml, root);
|
||||
return root;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -9,5 +9,5 @@ import android.view.View;
|
||||
|
||||
public interface JsLayoutInflater {
|
||||
|
||||
View inflate(String xml);
|
||||
View inflate(Context context, String xml);
|
||||
}
|
||||
|
||||
@@ -20,14 +20,14 @@ public class UI {
|
||||
|
||||
|
||||
public UI(Context context) {
|
||||
this(context, new ConvertLayoutInflater(context));
|
||||
this(context, new ConvertLayoutInflater());
|
||||
}
|
||||
|
||||
public JsLayoutInflater getLayoutInflater() {
|
||||
return mJsLayoutInflater;
|
||||
}
|
||||
|
||||
public View inflate(String xml) {
|
||||
return mJsLayoutInflater.inflate(xml);
|
||||
public View inflate(Context context, String xml) {
|
||||
return mJsLayoutInflater.inflate(context, xml);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user