From fd8fe277a4b0b63b637c2b5d425262ef21e172a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Wed, 13 Nov 2019 17:36:22 +0800 Subject: [PATCH] extract dev kit module --- .../java/pub/doric/demo/MainActivity.java | 5 ++- .../doric/src/main/java/pub/doric/Doric.java | 11 +++-- .../src/main/java/pub/doric/DoricDriver.java | 23 ----------- .../src/main/java/pub/doric/IDoricDriver.java | 11 ----- .../src/main/java/pub/doric/dev/DevKit.java | 41 +++++++++++++++++++ .../src/main/java/pub/doric/dev/DevPanel.java | 3 +- .../src/main/java/pub/doric/dev/IDevKit.java | 18 ++++++++ 7 files changed, 70 insertions(+), 42 deletions(-) create mode 100644 Android/doric/src/main/java/pub/doric/dev/DevKit.java create mode 100644 Android/doric/src/main/java/pub/doric/dev/IDevKit.java diff --git a/Android/app/src/main/java/pub/doric/demo/MainActivity.java b/Android/app/src/main/java/pub/doric/demo/MainActivity.java index 26ba1856..ece1b1a1 100644 --- a/Android/app/src/main/java/pub/doric/demo/MainActivity.java +++ b/Android/app/src/main/java/pub/doric/demo/MainActivity.java @@ -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); } diff --git a/Android/doric/src/main/java/pub/doric/Doric.java b/Android/doric/src/main/java/pub/doric/Doric.java index 6acdd4fb..f2ac8561 100644 --- a/Android/doric/src/main/java/pub/doric/Doric.java +++ b/Android/doric/src/main/java/pub/doric/Doric.java @@ -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(); } } diff --git a/Android/doric/src/main/java/pub/doric/DoricDriver.java b/Android/doric/src/main/java/pub/doric/DoricDriver.java index b831d5e4..d4d562b8 100644 --- a/Android/doric/src/main/java/pub/doric/DoricDriver.java +++ b/Android/doric/src/main/java/pub/doric/DoricDriver.java @@ -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 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); } diff --git a/Android/doric/src/main/java/pub/doric/IDoricDriver.java b/Android/doric/src/main/java/pub/doric/IDoricDriver.java index b3cba549..afaf8625 100644 --- a/Android/doric/src/main/java/pub/doric/IDoricDriver.java +++ b/Android/doric/src/main/java/pub/doric/IDoricDriver.java @@ -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 invokeContextEntityMethod(final String contextId, final String method, final Object... args); AsyncResult invokeDoricMethod(final String method, final Object... args); @@ -46,10 +41,4 @@ public interface IDoricDriver { AsyncResult destroyContext(final String contextId); DoricRegistry getRegistry(); - - void connectDevKit(String url); - - void sendDevCommand(Command command, JsonObject jsonObject); - - void disconnectDevKit(); } diff --git a/Android/doric/src/main/java/pub/doric/dev/DevKit.java b/Android/doric/src/main/java/pub/doric/dev/DevKit.java new file mode 100644 index 00000000..66e2e56d --- /dev/null +++ b/Android/doric/src/main/java/pub/doric/dev/DevKit.java @@ -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; + } +} diff --git a/Android/doric/src/main/java/pub/doric/dev/DevPanel.java b/Android/doric/src/main/java/pub/doric/dev/DevPanel.java index 1a0efc44..1037b715 100644 --- a/Android/doric/src/main/java/pub/doric/dev/DevPanel.java +++ b/Android/doric/src/main/java/pub/doric/dev/DevPanel.java @@ -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); } } }); diff --git a/Android/doric/src/main/java/pub/doric/dev/IDevKit.java b/Android/doric/src/main/java/pub/doric/dev/IDevKit.java new file mode 100644 index 00000000..767c0ceb --- /dev/null +++ b/Android/doric/src/main/java/pub/doric/dev/IDevKit.java @@ -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(); +}