extract dev kit module
This commit is contained in:
parent
0b2d447e2a
commit
fd8fe277a4
@ -38,7 +38,8 @@ import pub.doric.utils.DoricUtils;
|
|||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private DevPanel mDevPanel = new DevPanel();
|
private DevPanel devPanel = new DevPanel();
|
||||||
|
|
||||||
private DoricContext doricContext;
|
private DoricContext doricContext;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -82,7 +83,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
if (KeyEvent.KEYCODE_MENU == event.getKeyCode()) {
|
if (KeyEvent.KEYCODE_MENU == event.getKeyCode()) {
|
||||||
mDevPanel.show(getSupportFragmentManager(), "DevPanel");
|
devPanel.show(getSupportFragmentManager(), "DevPanel");
|
||||||
}
|
}
|
||||||
return super.onKeyDown(keyCode, event);
|
return super.onKeyDown(keyCode, event);
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,9 @@ import android.app.Application;
|
|||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
|
import pub.doric.dev.DevKit;
|
||||||
|
import pub.doric.dev.IDevKit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: Doric
|
* @Description: Doric
|
||||||
* @Author: pengfei.zhou
|
* @Author: pengfei.zhou
|
||||||
@ -36,15 +39,15 @@ public class Doric {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void connectDevKit(String url) {
|
public static void connectDevKit(String url) {
|
||||||
DoricDriver.getInstance().connectDevKit(url);
|
DevKit.getInstance().connectDevKit(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendDevCommand(IDoricDriver.Command command, JsonObject jsonObject) {
|
public static void sendDevCommand(IDevKit.Command command, JsonObject jsonObject) {
|
||||||
DoricDriver.getInstance().sendDevCommand(command, jsonObject);
|
DevKit.getInstance().sendDevCommand(command, jsonObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void disconnectDevKit() {
|
public static void disconnectDevKit() {
|
||||||
DoricDriver.getInstance().disconnectDevKit();
|
DevKit.getInstance().disconnectDevKit();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ import android.os.Handler;
|
|||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
|
||||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
@ -27,11 +26,9 @@ import java.util.concurrent.Executors;
|
|||||||
|
|
||||||
import pub.doric.async.AsyncCall;
|
import pub.doric.async.AsyncCall;
|
||||||
import pub.doric.async.AsyncResult;
|
import pub.doric.async.AsyncResult;
|
||||||
import pub.doric.dev.WSClient;
|
|
||||||
import pub.doric.engine.DoricJSEngine;
|
import pub.doric.engine.DoricJSEngine;
|
||||||
import pub.doric.utils.DoricConstant;
|
import pub.doric.utils.DoricConstant;
|
||||||
import pub.doric.utils.DoricLog;
|
import pub.doric.utils.DoricLog;
|
||||||
import pub.doric.utils.DoricUtils;
|
|
||||||
import pub.doric.utils.ThreadMode;
|
import pub.doric.utils.ThreadMode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,7 +41,6 @@ public class DoricDriver implements IDoricDriver {
|
|||||||
private final ExecutorService mBridgeExecutor;
|
private final ExecutorService mBridgeExecutor;
|
||||||
private final Handler mUIHandler;
|
private final Handler mUIHandler;
|
||||||
private final Handler mJSHandler;
|
private final Handler mJSHandler;
|
||||||
private WSClient wsClient;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AsyncResult<JSDecoder> invokeContextEntityMethod(final String contextId, final String method, final Object... args) {
|
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();
|
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) {
|
public void changeJSEngine(boolean isNative) {
|
||||||
doricJSEngine.changeJSEngine(isNative);
|
doricJSEngine.changeJSEngine(isNative);
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ package pub.doric;
|
|||||||
|
|
||||||
|
|
||||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
@ -31,10 +30,6 @@ import pub.doric.utils.ThreadMode;
|
|||||||
*/
|
*/
|
||||||
public interface IDoricDriver {
|
public interface IDoricDriver {
|
||||||
|
|
||||||
enum Command {
|
|
||||||
DEBUG, HOT_RELOAD
|
|
||||||
}
|
|
||||||
|
|
||||||
AsyncResult<JSDecoder> invokeContextEntityMethod(final String contextId, final String method, final Object... args);
|
AsyncResult<JSDecoder> invokeContextEntityMethod(final String contextId, final String method, final Object... args);
|
||||||
|
|
||||||
AsyncResult<JSDecoder> invokeDoricMethod(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);
|
AsyncResult<Boolean> destroyContext(final String contextId);
|
||||||
|
|
||||||
DoricRegistry getRegistry();
|
DoricRegistry getRegistry();
|
||||||
|
|
||||||
void connectDevKit(String url);
|
|
||||||
|
|
||||||
void sendDevCommand(Command command, JsonObject jsonObject);
|
|
||||||
|
|
||||||
void disconnectDevKit();
|
|
||||||
}
|
}
|
||||||
|
41
Android/doric/src/main/java/pub/doric/dev/DevKit.java
Normal file
41
Android/doric/src/main/java/pub/doric/dev/DevKit.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -27,7 +27,6 @@ import pub.doric.BuildConfig;
|
|||||||
import pub.doric.Doric;
|
import pub.doric.Doric;
|
||||||
import pub.doric.DoricContext;
|
import pub.doric.DoricContext;
|
||||||
import pub.doric.DoricContextManager;
|
import pub.doric.DoricContextManager;
|
||||||
import pub.doric.IDoricDriver;
|
|
||||||
import pub.doric.R;
|
import pub.doric.R;
|
||||||
import pub.doric.dev.event.EOFEvent;
|
import pub.doric.dev.event.EOFEvent;
|
||||||
import pub.doric.dev.event.OpenEvent;
|
import pub.doric.dev.event.OpenEvent;
|
||||||
@ -86,7 +85,7 @@ public class DevPanel extends BottomSheetDialogFragment {
|
|||||||
JsonObject jsonObject = new JsonObject();
|
JsonObject jsonObject = new JsonObject();
|
||||||
jsonObject.addProperty("contextId", doricContext.getContextId());
|
jsonObject.addProperty("contextId", doricContext.getContextId());
|
||||||
jsonObject.addProperty("projectHome", BuildConfig.PROJECT_HOME);
|
jsonObject.addProperty("projectHome", BuildConfig.PROJECT_HOME);
|
||||||
Doric.sendDevCommand(IDoricDriver.Command.DEBUG, jsonObject);
|
Doric.sendDevCommand(IDevKit.Command.DEBUG, jsonObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
18
Android/doric/src/main/java/pub/doric/dev/IDevKit.java
Normal file
18
Android/doric/src/main/java/pub/doric/dev/IDevKit.java
Normal 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();
|
||||||
|
}
|
Reference in New Issue
Block a user