extract dev kit module

This commit is contained in:
王劲鹏 2019-11-13 17:36:22 +08:00
parent 0b2d447e2a
commit fd8fe277a4
7 changed files with 70 additions and 42 deletions

View File

@ -38,7 +38,8 @@ import pub.doric.utils.DoricUtils;
public class MainActivity extends AppCompatActivity {
private DevPanel mDevPanel = new DevPanel();
private DevPanel devPanel = new DevPanel();
private DoricContext doricContext;
@Override
@ -82,7 +83,7 @@ public class MainActivity extends AppCompatActivity {
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (KeyEvent.KEYCODE_MENU == event.getKeyCode()) {
mDevPanel.show(getSupportFragmentManager(), "DevPanel");
devPanel.show(getSupportFragmentManager(), "DevPanel");
}
return super.onKeyDown(keyCode, event);
}

View File

@ -19,6 +19,9 @@ import android.app.Application;
import com.google.gson.JsonObject;
import pub.doric.dev.DevKit;
import pub.doric.dev.IDevKit;
/**
* @Description: Doric
* @Author: pengfei.zhou
@ -36,15 +39,15 @@ public class Doric {
}
public static void connectDevKit(String url) {
DoricDriver.getInstance().connectDevKit(url);
DevKit.getInstance().connectDevKit(url);
}
public static void sendDevCommand(IDoricDriver.Command command, JsonObject jsonObject) {
DoricDriver.getInstance().sendDevCommand(command, jsonObject);
public static void sendDevCommand(IDevKit.Command command, JsonObject jsonObject) {
DevKit.getInstance().sendDevCommand(command, jsonObject);
}
public static void disconnectDevKit() {
DoricDriver.getInstance().disconnectDevKit();
DevKit.getInstance().disconnectDevKit();
}
}

View File

@ -19,7 +19,6 @@ import android.os.Handler;
import android.os.Looper;
import com.github.pengfeizhou.jscore.JSDecoder;
import com.google.gson.JsonObject;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
@ -27,11 +26,9 @@ import java.util.concurrent.Executors;
import pub.doric.async.AsyncCall;
import pub.doric.async.AsyncResult;
import pub.doric.dev.WSClient;
import pub.doric.engine.DoricJSEngine;
import pub.doric.utils.DoricConstant;
import pub.doric.utils.DoricLog;
import pub.doric.utils.DoricUtils;
import pub.doric.utils.ThreadMode;
/**
@ -44,7 +41,6 @@ public class DoricDriver implements IDoricDriver {
private final ExecutorService mBridgeExecutor;
private final Handler mUIHandler;
private final Handler mJSHandler;
private WSClient wsClient;
@Override
public AsyncResult<JSDecoder> invokeContextEntityMethod(final String contextId, final String method, final Object... args) {
@ -139,25 +135,6 @@ public class DoricDriver implements IDoricDriver {
return doricJSEngine.getRegistry();
}
@Override
public void connectDevKit(String url) {
wsClient = new WSClient(url);
}
@Override
public void sendDevCommand(Command command, JsonObject jsonObject) {
JsonObject result = new JsonObject();
result.addProperty("cmd", command.toString());
result.add("data", jsonObject);
wsClient.send(DoricUtils.gson.toJson(result));
}
@Override
public void disconnectDevKit() {
wsClient.close();
wsClient = null;
}
public void changeJSEngine(boolean isNative) {
doricJSEngine.changeJSEngine(isNative);
}

View File

@ -17,7 +17,6 @@ package pub.doric;
import com.github.pengfeizhou.jscore.JSDecoder;
import com.google.gson.JsonObject;
import java.util.concurrent.Callable;
@ -31,10 +30,6 @@ import pub.doric.utils.ThreadMode;
*/
public interface IDoricDriver {
enum Command {
DEBUG, HOT_RELOAD
}
AsyncResult<JSDecoder> invokeContextEntityMethod(final String contextId, final String method, final Object... args);
AsyncResult<JSDecoder> invokeDoricMethod(final String method, final Object... args);
@ -46,10 +41,4 @@ public interface IDoricDriver {
AsyncResult<Boolean> destroyContext(final String contextId);
DoricRegistry getRegistry();
void connectDevKit(String url);
void sendDevCommand(Command command, JsonObject jsonObject);
void disconnectDevKit();
}

View File

@ -0,0 +1,41 @@
package pub.doric.dev;
import com.google.gson.JsonObject;
import pub.doric.utils.DoricUtils;
public class DevKit implements IDevKit {
private static class Inner {
private static final DevKit sInstance = new DevKit();
}
private DevKit() {
}
public static DevKit getInstance() {
return Inner.sInstance;
}
private WSClient wsClient;
@Override
public void connectDevKit(String url) {
wsClient = new WSClient(url);
}
@Override
public void sendDevCommand(IDevKit.Command command, JsonObject jsonObject) {
JsonObject result = new JsonObject();
result.addProperty("cmd", command.toString());
result.add("data", jsonObject);
wsClient.send(DoricUtils.gson.toJson(result));
}
@Override
public void disconnectDevKit() {
wsClient.close();
wsClient = null;
}
}

View File

@ -27,7 +27,6 @@ import pub.doric.BuildConfig;
import pub.doric.Doric;
import pub.doric.DoricContext;
import pub.doric.DoricContextManager;
import pub.doric.IDoricDriver;
import pub.doric.R;
import pub.doric.dev.event.EOFEvent;
import pub.doric.dev.event.OpenEvent;
@ -86,7 +85,7 @@ public class DevPanel extends BottomSheetDialogFragment {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("contextId", doricContext.getContextId());
jsonObject.addProperty("projectHome", BuildConfig.PROJECT_HOME);
Doric.sendDevCommand(IDoricDriver.Command.DEBUG, jsonObject);
Doric.sendDevCommand(IDevKit.Command.DEBUG, jsonObject);
}
}
});

View File

@ -0,0 +1,18 @@
package pub.doric.dev;
import com.google.gson.JsonObject;
import pub.doric.IDoricDriver;
public interface IDevKit {
enum Command {
DEBUG, HOT_RELOAD
}
void connectDevKit(String url);
void sendDevCommand(IDevKit.Command command, JsonObject jsonObject);
void disconnectDevKit();
}