split dev kit & doric core

This commit is contained in:
王劲鹏 2019-11-22 20:43:44 +08:00
parent 3784fb964b
commit b434f61742
42 changed files with 242 additions and 110 deletions

View File

@ -22,6 +22,7 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation "com.google.android.material:material:1.0.0"
implementation project(':doric')
implementation 'com.github.bumptech.glide:glide:4.10.0'
implementation 'com.github.bumptech.glide:annotations:4.10.0'

View File

@ -28,11 +28,16 @@ import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.ArrayList;
import pub.doric.DoricContext;
import pub.doric.dev.DevPanel;
import pub.doric.dev.SensorManagerHelper;
import pub.doric.dev.event.EnterDebugEvent;
import pub.doric.dev.event.QuitDebugEvent;
import pub.doric.DoricContextManager;
import pub.doric.devkit.DataModel;
import pub.doric.devkit.event.EnterDebugEvent;
import pub.doric.devkit.event.QuitDebugEvent;
import pub.doric.devkit.event.ReloadEvent;
import pub.doric.devkit.ui.DevPanel;
import pub.doric.devkit.util.SensorManagerHelper;
import pub.doric.utils.DoricUtils;
/**
@ -63,7 +68,12 @@ public class DemoActivity extends AppCompatActivity {
if (devPanel != null && devPanel.isAdded()) {
return;
}
new DevPanel().show(getSupportFragmentManager(), "DevPanel");
ArrayList<DataModel> dataModels = new ArrayList<>();
for (DoricContext doricContext : DoricContextManager.aliveContexts()) {
dataModels.add(new DataModel(doricContext.getContextId(), doricContext.getSource()));
}
new DevPanel(dataModels).show(getSupportFragmentManager(), "DevPanel");
}
});
}
@ -100,6 +110,15 @@ public class DemoActivity extends AppCompatActivity {
doricContext.startDebug();
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onReloadEvent(ReloadEvent reloadEvent) {
for (DoricContext context : DoricContextManager.aliveContexts()) {
if (reloadEvent.source.contains(context.getSource())) {
context.reload(reloadEvent.script);
}
}
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onQuitDebugEvent(QuitDebugEvent quitDebugEvent) {
doricContext.stopDebug();
@ -108,7 +127,11 @@ public class DemoActivity extends AppCompatActivity {
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (KeyEvent.KEYCODE_MENU == event.getKeyCode()) {
new DevPanel().show(getSupportFragmentManager(), "DevPanel");
ArrayList<DataModel> dataModels = new ArrayList<>();
for (DoricContext doricContext : DoricContextManager.aliveContexts()) {
dataModels.add(new DataModel(doricContext.getContextId(), doricContext.getSource()));
}
new DevPanel(dataModels).show(getSupportFragmentManager(), "DevPanel");
}
return super.onKeyDown(keyCode, event);
}

1
Android/devkit/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/build

View File

@ -0,0 +1,51 @@
apply plugin: 'com.android.library'
def projectHome = project.rootDir.getParent() + "/demo"
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
buildConfigField "String", "PROJECT_HOME", "\"${projectHome}\""
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.github.pengfeizhou:jsc4a:0.1.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation "com.google.android.material:material:1.0.0"
implementation 'com.squareup.okhttp3:okhttp:4.2.2'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'cn.bingoogolapple:bga-qrcode-zxing:1.3.7'
implementation 'com.github.tbruyelle:rxpermissions:0.10.2'
implementation "io.reactivex.rxjava2:rxjava:2.2.14"
api 'org.greenrobot:eventbus:3.1.1'
implementation 'com.lahm.library:easy-protector-release:1.1.0'
api 'org.nanohttpd:nanohttpd:2.3.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

View File

21
Android/devkit/proguard-rules.pro vendored Normal file
View File

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View File

@ -0,0 +1,27 @@
package pub.doric.devkit;
import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("pub.doric.devkit.test", appContext.getPackageName());
}
}

View File

@ -0,0 +1,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pub.doric.devkit">
<uses-permission android:name="android.permission.CAMERA" />
<application>
<activity android:name=".ui.ScanQRCodeActivity" />
</application>
</manifest>

View File

@ -0,0 +1,11 @@
package pub.doric.devkit;
public class DataModel {
public String contextId;
public String source;
public DataModel(String contextId, String source) {
this.contextId = contextId;
this.source = source;
}
}

View File

@ -1,13 +1,13 @@
package pub.doric.dev;
package pub.doric.devkit;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import pub.doric.utils.DoricUtils;
public class DevKit implements IDevKit {
static boolean isRunningInEmulator = false;
public static boolean isRunningInEmulator = false;
public static String ip = "";
private static Gson gson = new Gson();
private static class Inner {
private static final DevKit sInstance = new DevKit();
@ -33,7 +33,7 @@ public class DevKit implements IDevKit {
JsonObject result = new JsonObject();
result.addProperty("cmd", command.toString());
result.add("data", jsonObject);
wsClient.send(DoricUtils.gson.toJson(result));
wsClient.send(gson.toJson(result));
}
@Override

View File

@ -0,0 +1,17 @@
package pub.doric.devkit;
import com.google.gson.JsonObject;
public class DoricDev {
public static void connectDevKit(String url) {
DevKit.getInstance().connectDevKit(url);
}
public static void sendDevCommand(IDevKit.Command command, JsonObject jsonObject) {
DevKit.getInstance().sendDevCommand(command, jsonObject);
}
public static void disconnectDevKit() {
DevKit.getInstance().disconnectDevKit();
}
}

View File

@ -1,9 +1,7 @@
package pub.doric.dev;
package pub.doric.devkit;
import com.google.gson.JsonObject;
import pub.doric.IDoricDriver;
public interface IDevKit {
enum Command {

View File

@ -1,4 +1,4 @@
package pub.doric.engine;
package pub.doric.devkit;
public interface IStatusCallback {
void start();

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pub.doric.dev;
package pub.doric.devkit;
import org.greenrobot.eventbus.EventBus;
import org.json.JSONException;
@ -28,12 +28,12 @@ import okhttp3.Request;
import okhttp3.Response;
import okhttp3.WebSocket;
import okhttp3.WebSocketListener;
import pub.doric.DoricContext;
import pub.doric.DoricContextManager;
import pub.doric.dev.event.ConnectExceptionEvent;
import pub.doric.dev.event.EOFExceptionEvent;
import pub.doric.dev.event.EnterDebugEvent;
import pub.doric.dev.event.OpenEvent;
import pub.doric.devkit.event.ConnectExceptionEvent;
import pub.doric.devkit.event.EOFExceptionEvent;
import pub.doric.devkit.event.EnterDebugEvent;
import pub.doric.devkit.event.OpenEvent;
import pub.doric.devkit.event.ReloadEvent;
import pub.doric.devkit.ui.DevPanel;
/**
* @Description: com.github.penfeizhou.doric.dev
@ -75,11 +75,7 @@ public class WSClient extends WebSocketListener {
case "RELOAD": {
String source = jsonObject.optString("source");
String script = jsonObject.optString("script");
for (DoricContext context : DoricContextManager.aliveContexts()) {
if (source.contains(context.getSource())) {
context.reload(script);
}
}
EventBus.getDefault().post(new ReloadEvent(source, script));
}
break;
case "SWITCH_TO_DEBUG": {

View File

@ -1,4 +1,4 @@
package pub.doric.dev.event;
package pub.doric.devkit.event;
public class ConnectExceptionEvent {
}

View File

@ -1,4 +1,4 @@
package pub.doric.dev.event;
package pub.doric.devkit.event;
public class EOFExceptionEvent {
}

View File

@ -1,4 +1,4 @@
package pub.doric.dev.event;
package pub.doric.devkit.event;
public class EnterDebugEvent {
}

View File

@ -0,0 +1,4 @@
package pub.doric.devkit.event;
public class OpenEvent {
}

View File

@ -1,4 +1,4 @@
package pub.doric.dev.event;
package pub.doric.devkit.event;
public class QuitDebugEvent {
}

View File

@ -0,0 +1,11 @@
package pub.doric.devkit.event;
public class ReloadEvent {
public String source;
public String script;
public ReloadEvent(String source, String script) {
this.source = source;
this.script = script;
}
}

View File

@ -1,4 +1,4 @@
package pub.doric.engine.remote;
package pub.doric.devkit.remote;
import com.github.pengfeizhou.jscore.JSDecoder;
import com.github.pengfeizhou.jscore.JSONBuilder;
@ -23,8 +23,8 @@ import okhttp3.Request;
import okhttp3.Response;
import okhttp3.WebSocket;
import okhttp3.WebSocketListener;
import pub.doric.dev.DevKit;
import pub.doric.dev.event.QuitDebugEvent;
import pub.doric.devkit.DevKit;
import pub.doric.devkit.event.QuitDebugEvent;
import pub.doric.engine.IStatusCallback;
public class RemoteJSExecutor {

View File

@ -1,4 +1,4 @@
package pub.doric.engine.remote;
package pub.doric.devkit.remote;
import org.json.JSONArray;
import org.json.JSONObject;

View File

@ -1,4 +1,4 @@
package pub.doric.dev;
package pub.doric.devkit.ui;
import android.app.Dialog;
import android.os.Bundle;
@ -15,11 +15,12 @@ import androidx.fragment.app.DialogFragment;
import com.google.gson.JsonObject;
import pub.doric.BuildConfig;
import pub.doric.Doric;
import pub.doric.DoricContext;
import pub.doric.DoricContextManager;
import pub.doric.R;
import pub.doric.devkit.BuildConfig;
import pub.doric.devkit.DoricDev;
import pub.doric.devkit.IDevKit;
import pub.doric.devkit.R;
public class DebugContextPanel extends DialogFragment {
@Nullable
@ -68,7 +69,7 @@ public class DebugContextPanel extends DialogFragment {
jsonObject.addProperty("contextId", doricContext.getContextId());
jsonObject.addProperty("projectHome", BuildConfig.PROJECT_HOME);
jsonObject.addProperty("source", doricContext.getSource().replace(".js", ".ts"));
Doric.sendDevCommand(IDevKit.Command.DEBUG, jsonObject);
DoricDev.sendDevCommand(IDevKit.Command.DEBUG, jsonObject);
dismissAllowingStateLoss();
}
});

View File

@ -1,4 +1,4 @@
package pub.doric.dev;
package pub.doric.devkit.ui;
import android.Manifest;
import android.content.Context;
@ -23,15 +23,16 @@ import org.greenrobot.eventbus.ThreadMode;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import pub.doric.Doric;
import pub.doric.R;
import pub.doric.dev.event.ConnectExceptionEvent;
import pub.doric.dev.event.EOFExceptionEvent;
import pub.doric.dev.event.OpenEvent;
import pub.doric.devkit.DevKit;
import pub.doric.devkit.DoricDev;
import pub.doric.devkit.R;
import pub.doric.devkit.event.ConnectExceptionEvent;
import pub.doric.devkit.event.EOFExceptionEvent;
import pub.doric.devkit.event.OpenEvent;
public class DevPanel extends BottomSheetDialogFragment {
static boolean isDevConnected = false;
public static boolean isDevConnected = false;
public DevPanel() {
@ -58,7 +59,7 @@ public class DevPanel extends BottomSheetDialogFragment {
public void onClick(View v) {
if (DevKit.isRunningInEmulator) {
DevKit.ip = "10.0.2.2";
Doric.connectDevKit("ws://" + DevKit.ip + ":7777");
DoricDev.connectDevKit("ws://" + DevKit.ip + ":7777");
} else {
final RxPermissions rxPermissions = new RxPermissions(DevPanel.this);
Disposable disposable = rxPermissions

View File

@ -1,4 +1,4 @@
package pub.doric.dev;
package pub.doric.devkit.ui;
import android.os.Bundle;
import android.widget.Toast;
@ -8,8 +8,9 @@ import androidx.appcompat.app.AppCompatActivity;
import cn.bingoogolapple.qrcode.core.QRCodeView;
import cn.bingoogolapple.qrcode.zxing.ZXingView;
import pub.doric.Doric;
import pub.doric.R;
import pub.doric.devkit.DevKit;
import pub.doric.devkit.DoricDev;
import pub.doric.devkit.R;
public class ScanQRCodeActivity extends AppCompatActivity implements QRCodeView.Delegate {
@ -51,7 +52,7 @@ public class ScanQRCodeActivity extends AppCompatActivity implements QRCodeView.
setTitle("扫描结果为:" + result);
DevKit.ip = result;
Toast.makeText(this, "dev kit connecting to " + result, Toast.LENGTH_LONG).show();
Doric.connectDevKit("ws://" + result + ":7777");
DoricDev.connectDevKit("ws://" + result + ":7777");
finish();
}

View File

@ -1,4 +1,4 @@
package pub.doric.dev;
package pub.doric.devkit.util;
import android.content.Context;
import android.hardware.Sensor;

View File

@ -0,0 +1,3 @@
<resources>
<string name="app_name">devkit</string>
</resources>

View File

@ -1,7 +1,5 @@
apply plugin: 'com.android.library'
def projectHome = project.rootDir.getParent() + "/demo"
android {
compileSdkVersion 29
buildToolsVersion '29.0.2'
@ -22,10 +20,6 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
consumerProguardFiles 'proguard-rules.pro'
}
debug {
buildConfigField "String", "PROJECT_HOME", "\"${projectHome}\""
}
}
}
@ -52,19 +46,13 @@ task buildDebugger(type: Exec) {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
api project(':devkit')
implementation 'androidx.appcompat:appcompat:1.1.0'
api 'com.github.pengfeizhou:jsc4a:0.1.0'
implementation 'com.squareup.okhttp3:okhttp:4.2.2'
implementation 'com.github.penfeizhou.android.animation:glide-plugin:1.3.1'
api 'org.nanohttpd:nanohttpd:2.3.1'
implementation 'com.google.code.gson:gson:2.8.6'
api "com.google.android.material:material:1.0.0"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'cn.bingoogolapple:bga-qrcode-zxing:1.3.7'
implementation 'com.github.tbruyelle:rxpermissions:0.10.2'
implementation "io.reactivex.rxjava2:rxjava:2.2.14"
api 'org.greenrobot:eventbus:3.1.1'
implementation 'com.lahm.library:easy-protector-release:1.1.0'
implementation "com.google.android.material:material:1.0.0"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'

View File

@ -1,9 +1 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pub.doric">
<uses-permission android:name="android.permission.CAMERA" />
<application>
<activity android:name=".dev.ScanQRCodeActivity" />
</application>
</manifest>
<manifest package="pub.doric" />

View File

@ -17,11 +17,6 @@ package pub.doric;
import android.app.Application;
import com.google.gson.JsonObject;
import pub.doric.dev.DevKit;
import pub.doric.dev.IDevKit;
/**
* @Description: Doric
* @Author: pengfei.zhou
@ -37,17 +32,4 @@ public class Doric {
public static Application application() {
return sApplication;
}
public static void connectDevKit(String url) {
DevKit.getInstance().connectDevKit(url);
}
public static void sendDevCommand(IDevKit.Command command, JsonObject jsonObject) {
DevKit.getInstance().sendDevCommand(command, jsonObject);
}
public static void disconnectDevKit() {
DevKit.getInstance().disconnectDevKit();
}
}

View File

@ -26,7 +26,7 @@ import java.util.HashMap;
import java.util.Map;
import pub.doric.async.AsyncResult;
import pub.doric.engine.IStatusCallback;
import pub.doric.devkit.IStatusCallback;
import pub.doric.plugin.DoricJavaPlugin;
import pub.doric.shader.RootNode;
import pub.doric.utils.DoricConstant;

View File

@ -26,8 +26,8 @@ import java.util.concurrent.Executors;
import pub.doric.async.AsyncCall;
import pub.doric.async.AsyncResult;
import pub.doric.devkit.IStatusCallback;
import pub.doric.engine.DoricJSEngine;
import pub.doric.engine.IStatusCallback;
import pub.doric.utils.DoricConstant;
import pub.doric.utils.DoricLog;
import pub.doric.utils.ThreadMode;

View File

@ -1,4 +0,0 @@
package pub.doric.dev.event;
public class OpenEvent {
}

View File

@ -28,6 +28,7 @@ import com.github.pengfeizhou.jscore.JavaValue;
import java.util.ArrayList;
import pub.doric.DoricRegistry;
import pub.doric.devkit.IStatusCallback;
import pub.doric.extension.bridge.DoricBridgeExtension;
import pub.doric.extension.timer.DoricTimerExtension;
import pub.doric.utils.DoricConstant;

View File

@ -20,7 +20,8 @@ import com.github.pengfeizhou.jscore.JSRuntimeException;
import com.github.pengfeizhou.jscore.JavaFunction;
import com.github.pengfeizhou.jscore.JavaValue;
import pub.doric.engine.remote.RemoteJSExecutor;
import pub.doric.devkit.IStatusCallback;
import pub.doric.devkit.remote.RemoteJSExecutor;
public class DoricRemoteJSExecutor implements IDoricJSE {

View File

@ -28,7 +28,6 @@ import com.github.pengfeizhou.jscore.JSDecoder;
import com.github.pengfeizhou.jscore.JSONBuilder;
import com.github.pengfeizhou.jscore.JSValue;
import com.github.pengfeizhou.jscore.JavaValue;
import com.google.gson.Gson;
import org.json.JSONArray;
import org.json.JSONObject;
@ -46,8 +45,6 @@ import pub.doric.Doric;
* @CreateDate: 2019-07-18
*/
public class DoricUtils {
public static Gson gson = new Gson();
public static String readAssetFile(String assetFile) {
InputStream inputStream = null;
try {

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pub.doric.dev;
package pub.doric.utils;
import android.content.Context;
import android.content.res.AssetManager;
@ -21,9 +21,6 @@ import android.net.Uri;
import android.util.Log;
import android.webkit.MimeTypeMap;
import pub.doric.DoricContext;
import pub.doric.DoricContextManager;
import com.github.pengfeizhou.jscore.JSONBuilder;
import org.json.JSONArray;
@ -42,6 +39,8 @@ import java.util.List;
import java.util.Map;
import fi.iki.elonen.NanoHTTPD;
import pub.doric.DoricContext;
import pub.doric.DoricContextManager;
/**
* @Description: com.github.penfeizhou.doricdemo
@ -171,7 +170,7 @@ public class LocalServer extends NanoHTTPD {
} catch (IOException e) {
e.printStackTrace();
}
return NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.OK, "text/html", "HelloWorld");
return NanoHTTPD.newFixedLengthResponse(Response.Status.OK, "text/html", "HelloWorld");
}
public interface APICommand {

View File

@ -1 +1 @@
include ':app', ':doric'
include ':app', ':doric', ':devkit'