websocket dev tool
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.github.penfeizhou.doric;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.github.penfeizhou.doric.async.AsyncResult;
|
||||
import com.github.penfeizhou.doric.plugin.DoricJavaPlugin;
|
||||
@@ -8,6 +9,9 @@ import com.github.penfeizhou.doric.utils.DoricConstant;
|
||||
import com.github.penfeizhou.doric.utils.DoricMetaInfo;
|
||||
import com.github.penfeizhou.doric.shader.RootNode;
|
||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||
import com.github.pengfeizhou.jscore.JSONBuilder;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -24,6 +28,7 @@ public class DoricContext {
|
||||
private RootNode mRootNode = new RootNode(this);
|
||||
private final String source;
|
||||
private String script;
|
||||
private JSONObject initParams;
|
||||
|
||||
DoricContext(Context context, String contextId, String source) {
|
||||
this.mContext = context;
|
||||
@@ -46,6 +51,13 @@ public class DoricContext {
|
||||
return doricContext;
|
||||
}
|
||||
|
||||
public void init(int width, int height) {
|
||||
this.initParams = new JSONBuilder()
|
||||
.put("width", width)
|
||||
.put("height", height).toJSONObject();
|
||||
callEntity(DoricConstant.DORIC_ENTITY_INIT, this.initParams);
|
||||
}
|
||||
|
||||
public AsyncResult<JSDecoder> callEntity(String methodName, Object... args) {
|
||||
return getDriver().invokeContextEntityMethod(mContextId, methodName, args);
|
||||
}
|
||||
@@ -97,6 +109,7 @@ public class DoricContext {
|
||||
|
||||
public void reload(String script) {
|
||||
getDriver().createContext(mContextId, script, source);
|
||||
callEntity(DoricConstant.DORIC_ENTITY_INIT, this.initParams);
|
||||
}
|
||||
|
||||
public void onShow() {
|
||||
|
@@ -51,7 +51,7 @@ public class WSClient extends WebSocketListener {
|
||||
String source = jsonObject.optString("source");
|
||||
String script = jsonObject.optString("script");
|
||||
for (DoricContext context : DoricContextManager.aliveContexts()) {
|
||||
if (source.equals(context.getSource())) {
|
||||
if (source.contains(context.getSource())) {
|
||||
context.reload(script);
|
||||
}
|
||||
}
|
||||
|
@@ -9,7 +9,9 @@ import com.github.pengfeizhou.jscore.JSArray;
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
import com.github.pengfeizhou.jscore.JSValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -32,6 +34,7 @@ public abstract class GroupNode<F extends ViewGroup> extends ViewNode<F> {
|
||||
case "children":
|
||||
JSArray jsArray = prop.asArray();
|
||||
int i;
|
||||
List<ViewNode> tobeRemoved = new ArrayList<>();
|
||||
for (i = 0; i < jsArray.size(); i++) {
|
||||
JSValue jsValue = jsArray.get(i);
|
||||
if (!jsValue.isObject()) {
|
||||
@@ -47,11 +50,23 @@ public abstract class GroupNode<F extends ViewGroup> extends ViewNode<F> {
|
||||
child.mParent = this;
|
||||
child.mId = id;
|
||||
mChildrenNode.put(id, child);
|
||||
} else if (i != child.index) {
|
||||
mIndexInfo.remove(i);
|
||||
child.index = i;
|
||||
mView.removeView(child.getView());
|
||||
} else {
|
||||
if (i != child.index) {
|
||||
mIndexInfo.remove(i);
|
||||
child.index = i;
|
||||
mView.removeView(child.getView());
|
||||
}
|
||||
tobeRemoved.remove(child);
|
||||
}
|
||||
|
||||
ViewNode node = mIndexInfo.get(i);
|
||||
|
||||
if (node != null && node != child) {
|
||||
mView.removeViewAt(i);
|
||||
mIndexInfo.remove(i);
|
||||
tobeRemoved.add(node);
|
||||
}
|
||||
|
||||
ViewGroup.LayoutParams params = child.getLayoutParams();
|
||||
if (params == null) {
|
||||
params = generateDefaultLayoutParams();
|
||||
@@ -62,14 +77,20 @@ public abstract class GroupNode<F extends ViewGroup> extends ViewNode<F> {
|
||||
mIndexInfo.put(i, child);
|
||||
}
|
||||
}
|
||||
while (i < mView.getChildCount()) {
|
||||
mView.removeViewAt(mView.getChildCount() - 1);
|
||||
if (mIndexInfo.get(i) != null) {
|
||||
mChildrenNode.remove(mIndexInfo.get(i).getId());
|
||||
|
||||
while (i < mIndexInfo.size()) {
|
||||
ViewNode node = mIndexInfo.get(i);
|
||||
if (node != null) {
|
||||
mChildrenNode.remove(node.getId());
|
||||
mIndexInfo.remove(i);
|
||||
tobeRemoved.remove(node);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
for (ViewNode node : tobeRemoved) {
|
||||
mChildrenNode.remove(node.getId());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
super.blend(view, layoutParams, name, prop);
|
||||
|
Reference in New Issue
Block a user