Merge branch 'android_master' into combine
This commit is contained in:
@@ -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 {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
|
||||
debug {
|
||||
buildConfigField "String", "PROJECT_HOME", "\"${projectHome}\""
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,7 +27,7 @@ android {
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
|
||||
implementation 'com.github.pengfeizhou:jsc4a:0.1.0'
|
||||
implementation "pub.doric:core:${rootProject.ext.Version}"
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||
implementation "com.google.android.material:material:1.0.0"
|
||||
implementation 'com.squareup.okhttp3:okhttp:4.2.2'
|
||||
@@ -42,11 +36,10 @@ dependencies {
|
||||
implementation 'com.github.tbruyelle:rxpermissions:0.10.2'
|
||||
implementation "io.reactivex.rxjava2:rxjava:2.2.15"
|
||||
api 'org.greenrobot:eventbus:3.1.1'
|
||||
implementation 'com.lahm.library:easy-protector-release:1.1.0'
|
||||
api 'org.nanohttpd:nanohttpd:2.3.1'
|
||||
api project(':doric')
|
||||
|
||||
implementation 'com.lahm.library:easy-protector-release:1.1.1'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
}
|
||||
|
||||
apply from: rootProject.file('scripts/upload.gradle')
|
3
doric-android/devkit/pom.properties
Normal file
3
doric-android/devkit/pom.properties
Normal file
@@ -0,0 +1,3 @@
|
||||
name=DoricDevKit
|
||||
groupId=pub.doric
|
||||
artifactId=devkit
|
@@ -2,9 +2,12 @@
|
||||
package="pub.doric.devkit">
|
||||
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<application>
|
||||
<activity android:name=".ui.ScanQRCodeActivity" />
|
||||
<activity android:name=".ui.DemoDebugActivity" />
|
||||
<activity
|
||||
android:name=".ui.DemoDebugActivity"
|
||||
android:theme="@style/Theme.Design.Light.NoActionBar" />
|
||||
</application>
|
||||
</manifest>
|
||||
|
@@ -1,14 +1,17 @@
|
||||
package pub.doric.devkit;
|
||||
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.DoricContextManager;
|
||||
import pub.doric.DoricNativeDriver;
|
||||
|
||||
public class DoricContextDebuggable {
|
||||
private DoricContext doricContext;
|
||||
private DoricDebugDriver doricDebugDriver;
|
||||
public boolean isDebugging = false;
|
||||
|
||||
public DoricContextDebuggable(DoricContext doricContext) {
|
||||
this.doricContext = doricContext;
|
||||
public DoricContextDebuggable(String contextId) {
|
||||
this.doricContext = DoricContextManager.getContext(contextId);
|
||||
isDebugging = true;
|
||||
}
|
||||
|
||||
public void startDebug() {
|
||||
@@ -22,8 +25,13 @@ public class DoricContextDebuggable {
|
||||
}
|
||||
|
||||
public void stopDebug() {
|
||||
isDebugging = false;
|
||||
doricDebugDriver.destroy();
|
||||
doricContext.setDriver(DoricNativeDriver.getInstance());
|
||||
doricContext.reInit();
|
||||
}
|
||||
|
||||
public DoricContext getContext() {
|
||||
return doricContext;
|
||||
}
|
||||
}
|
||||
|
@@ -79,6 +79,7 @@ public class WSClient extends WebSocketListener {
|
||||
}
|
||||
break;
|
||||
case "SWITCH_TO_DEBUG": {
|
||||
String contextId = jsonObject.optString("contextId");
|
||||
EventBus.getDefault().post(new EnterDebugEvent());
|
||||
}
|
||||
break;
|
||||
|
@@ -1,4 +1,5 @@
|
||||
package pub.doric.devkit.event;
|
||||
|
||||
public class EnterDebugEvent {
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,13 @@
|
||||
package pub.doric.devkit.event;
|
||||
|
||||
public class StartDebugEvent {
|
||||
private String contextId;
|
||||
|
||||
public StartDebugEvent(String contextId) {
|
||||
this.contextId = contextId;
|
||||
}
|
||||
|
||||
public String getContextId() {
|
||||
return contextId;
|
||||
}
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
package pub.doric.devkit.event;
|
||||
|
||||
public class StopDebugEvent {
|
||||
|
||||
}
|
@@ -25,7 +25,7 @@ import okhttp3.WebSocket;
|
||||
import okhttp3.WebSocketListener;
|
||||
import pub.doric.devkit.DevKit;
|
||||
import pub.doric.devkit.IStatusCallback;
|
||||
import pub.doric.devkit.event.QuitDebugEvent;
|
||||
import pub.doric.devkit.event.StopDebugEvent;
|
||||
|
||||
public class RemoteJSExecutor {
|
||||
private final WebSocket webSocket;
|
||||
@@ -59,7 +59,7 @@ public class RemoteJSExecutor {
|
||||
System.out.println("remote js executor eof");
|
||||
|
||||
LockSupport.unpark(current);
|
||||
EventBus.getDefault().post(new QuitDebugEvent());
|
||||
EventBus.getDefault().post(new StopDebugEvent());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -15,12 +15,14 @@ import androidx.fragment.app.DialogFragment;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.DoricContextManager;
|
||||
import pub.doric.devkit.BuildConfig;
|
||||
import pub.doric.devkit.DoricDev;
|
||||
import pub.doric.devkit.IDevKit;
|
||||
import pub.doric.devkit.R;
|
||||
import pub.doric.devkit.event.StartDebugEvent;
|
||||
|
||||
public class DebugContextPanel extends DialogFragment {
|
||||
|
||||
@@ -69,9 +71,9 @@ public class DebugContextPanel extends DialogFragment {
|
||||
cell.findViewById(R.id.debug_text_view).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
EventBus.getDefault().post(new StartDebugEvent(doricContext.getContextId()));
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("contextId", doricContext.getContextId());
|
||||
jsonObject.addProperty("projectHome", BuildConfig.PROJECT_HOME);
|
||||
jsonObject.addProperty("source", doricContext.getSource().replace(".js", ".ts"));
|
||||
DoricDev.sendDevCommand(IDevKit.Command.DEBUG, jsonObject);
|
||||
dismissAllowingStateLoss();
|
||||
|
@@ -17,46 +17,36 @@ package pub.doric.devkit.ui;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import pub.doric.DoricActivity;
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.DoricContextManager;
|
||||
import pub.doric.DoricPanel;
|
||||
import pub.doric.devkit.DoricContextDebuggable;
|
||||
import pub.doric.devkit.event.EnterDebugEvent;
|
||||
import pub.doric.devkit.event.QuitDebugEvent;
|
||||
import pub.doric.devkit.event.ReloadEvent;
|
||||
import pub.doric.devkit.event.StartDebugEvent;
|
||||
import pub.doric.devkit.event.StopDebugEvent;
|
||||
import pub.doric.devkit.util.SensorManagerHelper;
|
||||
import pub.doric.utils.DoricUtils;
|
||||
|
||||
/**
|
||||
* @Description: pub.doric.demo
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2019-11-19
|
||||
*/
|
||||
public class DemoDebugActivity extends AppCompatActivity {
|
||||
private DoricContext doricContext;
|
||||
public class DemoDebugActivity extends DoricActivity {
|
||||
private SensorManagerHelper sensorHelper;
|
||||
private DoricContextDebuggable doricContextDebuggable;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
String source = getIntent().getStringExtra("source");
|
||||
DoricPanel doricPanel = new DoricPanel(this);
|
||||
addContentView(doricPanel, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
doricPanel.config(DoricUtils.readAssetFile("demo/" + source), source);
|
||||
doricContext = doricPanel.getDoricContext();
|
||||
doricContextDebuggable = new DoricContextDebuggable(doricContext);
|
||||
sensorHelper = new SensorManagerHelper(this);
|
||||
sensorHelper.setOnShakeListener(new SensorManagerHelper.OnShakeListener() {
|
||||
@Override
|
||||
@@ -73,34 +63,49 @@ public class DemoDebugActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
EventBus.getDefault().unregister(this);
|
||||
sensorHelper.stop();
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onStartDebugEvent(StartDebugEvent startDebugEvent) {
|
||||
doricContextDebuggable = new DoricContextDebuggable(startDebugEvent.getContextId());
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEnterDebugEvent(EnterDebugEvent enterDebugEvent) {
|
||||
doricContextDebuggable.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);
|
||||
}
|
||||
}
|
||||
public void onQuitDebugEvent(StopDebugEvent quitDebugEvent) {
|
||||
doricContextDebuggable.stopDebug();
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onQuitDebugEvent(QuitDebugEvent quitDebugEvent) {
|
||||
doricContextDebuggable.stopDebug();
|
||||
public void onReloadEvent(ReloadEvent reloadEvent) {
|
||||
for (DoricContext context : DoricContextManager.aliveContexts()) {
|
||||
if (reloadEvent.source.contains(context.getSource())) {
|
||||
if (doricContextDebuggable != null &&
|
||||
doricContextDebuggable.isDebugging &&
|
||||
doricContextDebuggable.getContext().getContextId().equals(context.getContextId())) {
|
||||
System.out.println("is debugging context id: " + context.getContextId());
|
||||
} else {
|
||||
context.reload(reloadEvent.script);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user