websocket dev tool

This commit is contained in:
pengfei.zhou
2019-08-13 17:22:56 +08:00
parent 76fe0f9044
commit f46ac2ae73
11 changed files with 97 additions and 26 deletions

View File

@@ -9,6 +9,7 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:networkSecurityConfig="@xml/network_security_config"
android:theme="@style/AppTheme">
<activity android:name="com.github.penfeizhou.doricdemo.MainActivity">
<intent-filter>

View File

@@ -20,13 +20,11 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DoricContext doricContext = DoricContext.create(this, DoricUtils.readAssetFile("demo/Snake.js"), "demo for test");
doricContext.callEntity("__init__", new JSONBuilder()
.put("width", ViewGroup.LayoutParams.MATCH_PARENT)
.put("height", ViewGroup.LayoutParams.MATCH_PARENT));
DoricContext doricContext = DoricContext.create(this, DoricUtils.readAssetFile("demo/Snake.js"), "test");
doricContext.init(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
doricContext.callEntity("log");
doricContext.getRootNode().setRootView((FrameLayout) findViewById(R.id.root));
Doric.connectDevKit("wss://192.168.11.38:7777");
Doric.connectDevKit("ws://192.168.11.38:7777");
LocalServer localServer = new LocalServer(getApplicationContext(), 8910);
try {
localServer.start();

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>

View File

@@ -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() {

View File

@@ -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);
}
}

View File

@@ -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);