refactor: devkit depends on doric
This commit is contained in:
parent
72e59ffb86
commit
10f343a95b
@ -23,7 +23,7 @@ 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 project(':devkit')
|
||||
implementation 'com.github.bumptech.glide:glide:4.10.0'
|
||||
implementation 'com.github.bumptech.glide:annotations:4.10.0'
|
||||
implementation 'com.github.penfeizhou.android.animation:glide-plugin:1.3.1'
|
||||
|
@ -28,11 +28,9 @@ 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.DoricContextManager;
|
||||
import pub.doric.devkit.DataModel;
|
||||
import pub.doric.devkit.DoricContextDebuggable;
|
||||
import pub.doric.devkit.event.EnterDebugEvent;
|
||||
import pub.doric.devkit.event.QuitDebugEvent;
|
||||
import pub.doric.devkit.event.ReloadEvent;
|
||||
@ -48,6 +46,7 @@ import pub.doric.utils.DoricUtils;
|
||||
public class DemoActivity extends AppCompatActivity {
|
||||
private DoricContext doricContext;
|
||||
private SensorManagerHelper sensorHelper;
|
||||
private DoricContextDebuggable doricContextDebuggable;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@ -57,6 +56,7 @@ public class DemoActivity extends AppCompatActivity {
|
||||
addContentView(frameLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
doricContext = DoricContext.create(this, DoricUtils.readAssetFile("demo/" + source), source);
|
||||
doricContextDebuggable = new DoricContextDebuggable(doricContext);
|
||||
doricContext.init(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
doricContext.getRootNode().setRootView(frameLayout);
|
||||
|
||||
@ -68,12 +68,7 @@ public class DemoActivity extends AppCompatActivity {
|
||||
if (devPanel != null && devPanel.isAdded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<DataModel> dataModels = new ArrayList<>();
|
||||
for (DoricContext doricContext : DoricContextManager.aliveContexts()) {
|
||||
dataModels.add(new DataModel(doricContext.getContextId(), doricContext.getSource()));
|
||||
}
|
||||
new DevPanel(dataModels).show(getSupportFragmentManager(), "DevPanel");
|
||||
new DevPanel().show(getSupportFragmentManager(), "DevPanel");
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -107,7 +102,7 @@ public class DemoActivity extends AppCompatActivity {
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEnterDebugEvent(EnterDebugEvent enterDebugEvent) {
|
||||
doricContext.startDebug();
|
||||
doricContextDebuggable.startDebug();
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
@ -121,17 +116,13 @@ public class DemoActivity extends AppCompatActivity {
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onQuitDebugEvent(QuitDebugEvent quitDebugEvent) {
|
||||
doricContext.stopDebug();
|
||||
doricContextDebuggable.stopDebug();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (KeyEvent.KEYCODE_MENU == event.getKeyCode()) {
|
||||
ArrayList<DataModel> dataModels = new ArrayList<>();
|
||||
for (DoricContext doricContext : DoricContextManager.aliveContexts()) {
|
||||
dataModels.add(new DataModel(doricContext.getContextId(), doricContext.getSource()));
|
||||
}
|
||||
new DevPanel(dataModels).show(getSupportFragmentManager(), "DevPanel");
|
||||
new DevPanel().show(getSupportFragmentManager(), "DevPanel");
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
@ -17,6 +17,8 @@ package pub.doric.demo;
|
||||
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.github.pengfeizhou.jscore.JavaValue;
|
||||
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.extension.bridge.DoricMethod;
|
||||
import pub.doric.extension.bridge.DoricPlugin;
|
||||
@ -24,8 +26,6 @@ import pub.doric.extension.bridge.DoricPromise;
|
||||
import pub.doric.plugin.DoricJavaPlugin;
|
||||
import pub.doric.utils.ThreadMode;
|
||||
|
||||
import com.github.pengfeizhou.jscore.JavaValue;
|
||||
|
||||
@DoricPlugin(name = "demo")
|
||||
public class DemoPlugin extends DoricJavaPlugin {
|
||||
public DemoPlugin(DoricContext doricContext) {
|
||||
|
@ -44,6 +44,7 @@ dependencies {
|
||||
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')
|
||||
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
|
@ -1,11 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package pub.doric.devkit;
|
||||
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.DoricNativeDriver;
|
||||
import pub.doric.engine.IStatusCallback;
|
||||
|
||||
public class DoricContextDebuggable {
|
||||
private DoricContext doricContext;
|
||||
private DoricDebugDriver doricDebugDriver;
|
||||
|
||||
public DoricContextDebuggable(DoricContext doricContext) {
|
||||
this.doricContext = doricContext;
|
||||
}
|
||||
|
||||
public void startDebug() {
|
||||
doricDebugDriver = new DoricDebugDriver(new IStatusCallback() {
|
||||
@Override
|
||||
public void start() {
|
||||
doricContext.setDriver(doricDebugDriver);
|
||||
doricContext.reInit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void stopDebug() {
|
||||
doricDebugDriver.destroy();
|
||||
doricContext.setDriver(DoricNativeDriver.getInstance());
|
||||
doricContext.reInit();
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package pub.doric;
|
||||
package pub.doric.devkit;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
@ -24,10 +24,12 @@ import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import pub.doric.DoricRegistry;
|
||||
import pub.doric.IDoricDriver;
|
||||
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;
|
||||
@ -45,7 +47,7 @@ public class DoricDebugDriver implements IDoricDriver {
|
||||
|
||||
|
||||
public DoricDebugDriver(IStatusCallback statusCallback) {
|
||||
doricJSEngine = new DoricJSEngine(false, statusCallback);
|
||||
doricJSEngine = new DoricDebugJSEngine(statusCallback);
|
||||
mBridgeExecutor = Executors.newCachedThreadPool();
|
||||
mUIHandler = new Handler(Looper.getMainLooper());
|
||||
mJSHandler = doricJSEngine.getJSHandler();
|
@ -0,0 +1,20 @@
|
||||
package pub.doric.devkit;
|
||||
|
||||
import pub.doric.devkit.remote.DoricRemoteJSExecutor;
|
||||
import pub.doric.engine.DoricJSEngine;
|
||||
import pub.doric.engine.IStatusCallback;
|
||||
|
||||
public class DoricDebugJSEngine extends DoricJSEngine {
|
||||
|
||||
private IStatusCallback statusCallback;
|
||||
|
||||
public DoricDebugJSEngine(IStatusCallback statusCallback) {
|
||||
super();
|
||||
this.statusCallback = statusCallback;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initJSEngine() {
|
||||
mDoricJSE = new DoricRemoteJSExecutor(statusCallback);
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package pub.doric.utils;
|
||||
package pub.doric.devkit;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetManager;
|
@ -13,15 +13,15 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package pub.doric.engine;
|
||||
package pub.doric.devkit.remote;
|
||||
|
||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||
import com.github.pengfeizhou.jscore.JSRuntimeException;
|
||||
import com.github.pengfeizhou.jscore.JavaFunction;
|
||||
import com.github.pengfeizhou.jscore.JavaValue;
|
||||
|
||||
import pub.doric.devkit.IStatusCallback;
|
||||
import pub.doric.devkit.remote.RemoteJSExecutor;
|
||||
import pub.doric.engine.IDoricJSE;
|
||||
import pub.doric.engine.IStatusCallback;
|
||||
|
||||
public class DoricRemoteJSExecutor implements IDoricJSE {
|
||||
|
@ -25,7 +25,7 @@ import okhttp3.WebSocket;
|
||||
import okhttp3.WebSocketListener;
|
||||
import pub.doric.devkit.DevKit;
|
||||
import pub.doric.devkit.event.QuitDebugEvent;
|
||||
import pub.doric.devkit.IStatusCallback;
|
||||
import pub.doric.engine.IStatusCallback;
|
||||
|
||||
public class RemoteJSExecutor {
|
||||
private final WebSocket webSocket;
|
||||
|
@ -15,20 +15,16 @@ import androidx.fragment.app.DialogFragment;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.DoricContextManager;
|
||||
import pub.doric.devkit.BuildConfig;
|
||||
import pub.doric.devkit.DataModel;
|
||||
import pub.doric.devkit.DoricDev;
|
||||
import pub.doric.devkit.IDevKit;
|
||||
import pub.doric.devkit.R;
|
||||
|
||||
public class DebugContextPanel extends DialogFragment {
|
||||
|
||||
private ArrayList<DataModel> dataModels;
|
||||
|
||||
public DebugContextPanel(ArrayList<DataModel> dataModels) {
|
||||
this.dataModels = dataModels;
|
||||
public DebugContextPanel() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -61,22 +57,22 @@ public class DebugContextPanel extends DialogFragment {
|
||||
LinearLayout container = getView().findViewById(R.id.container);
|
||||
LayoutInflater inflater = LayoutInflater.from(getContext());
|
||||
|
||||
for (final DataModel dataModel : dataModels) {
|
||||
for (final DoricContext doricContext : DoricContextManager.aliveContexts()) {
|
||||
View cell = inflater.inflate(R.layout.layout_debug_context_cell, container, false);
|
||||
|
||||
TextView contextIdTextView = cell.findViewById(R.id.context_id_text_view);
|
||||
contextIdTextView.setText(dataModel.contextId);
|
||||
contextIdTextView.setText(doricContext.getContextId());
|
||||
|
||||
TextView sourceTextView = cell.findViewById(R.id.source_text_view);
|
||||
sourceTextView.setText(dataModel.source);
|
||||
sourceTextView.setText(doricContext.getSource());
|
||||
|
||||
cell.findViewById(R.id.debug_text_view).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("contextId", dataModel.contextId);
|
||||
jsonObject.addProperty("contextId", doricContext.getContextId());
|
||||
jsonObject.addProperty("projectHome", BuildConfig.PROJECT_HOME);
|
||||
jsonObject.addProperty("source", dataModel.source.replace(".js", ".ts"));
|
||||
jsonObject.addProperty("source", doricContext.getSource().replace(".js", ".ts"));
|
||||
DoricDev.sendDevCommand(IDevKit.Command.DEBUG, jsonObject);
|
||||
dismissAllowingStateLoss();
|
||||
}
|
||||
|
@ -21,11 +21,8 @@ import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.functions.Consumer;
|
||||
import pub.doric.devkit.DataModel;
|
||||
import pub.doric.devkit.DevKit;
|
||||
import pub.doric.devkit.DoricDev;
|
||||
import pub.doric.devkit.R;
|
||||
@ -37,10 +34,7 @@ public class DevPanel extends BottomSheetDialogFragment {
|
||||
|
||||
public static boolean isDevConnected = false;
|
||||
|
||||
ArrayList<DataModel> dataModels;
|
||||
|
||||
public DevPanel(ArrayList<DataModel> dataModels) {
|
||||
this.dataModels = dataModels;
|
||||
public DevPanel() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -85,7 +79,7 @@ public class DevPanel extends BottomSheetDialogFragment {
|
||||
getView().findViewById(R.id.debug_text_view).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
DebugContextPanel debugContextPanel = new DebugContextPanel(dataModels);
|
||||
DebugContextPanel debugContextPanel = new DebugContextPanel();
|
||||
debugContextPanel.show(getActivity().getSupportFragmentManager(), "DebugContextPanel");
|
||||
dismissAllowingStateLoss();
|
||||
}
|
||||
|
@ -46,7 +46,6 @@ 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'
|
||||
|
@ -26,7 +26,6 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import pub.doric.async.AsyncResult;
|
||||
import pub.doric.devkit.IStatusCallback;
|
||||
import pub.doric.plugin.DoricJavaPlugin;
|
||||
import pub.doric.shader.RootNode;
|
||||
import pub.doric.utils.DoricConstant;
|
||||
@ -45,10 +44,9 @@ public class DoricContext {
|
||||
private final String source;
|
||||
private String script;
|
||||
private JSONObject initParams;
|
||||
public boolean isDebugging = false;
|
||||
private DoricDebugDriver doricDebugDriver;
|
||||
private IDoricDriver doricDriver;
|
||||
|
||||
DoricContext(Context context, String contextId, String source) {
|
||||
protected DoricContext(Context context, String contextId, String source) {
|
||||
this.mContext = context;
|
||||
this.mContextId = contextId;
|
||||
this.source = source;
|
||||
@ -73,7 +71,11 @@ public class DoricContext {
|
||||
.put("width", width)
|
||||
.put("height", height).toJSONObject();
|
||||
callEntity(DoricConstant.DORIC_ENTITY_INIT, this.initParams);
|
||||
callEntity(DoricConstant.DORIC_ENTITY_CREATE);
|
||||
}
|
||||
|
||||
public void reInit() {
|
||||
callEntity(DoricConstant.DORIC_ENTITY_INIT, this.initParams);
|
||||
callEntity(DoricConstant.DORIC_ENTITY_CREATE);
|
||||
}
|
||||
|
||||
@ -82,11 +84,14 @@ public class DoricContext {
|
||||
}
|
||||
|
||||
public IDoricDriver getDriver() {
|
||||
if (isDebugging) {
|
||||
return doricDebugDriver;
|
||||
} else {
|
||||
return DoricNativeDriver.getInstance();
|
||||
if (doricDriver == null) {
|
||||
doricDriver = DoricNativeDriver.getInstance();
|
||||
}
|
||||
return doricDriver;
|
||||
}
|
||||
|
||||
public void setDriver(IDoricDriver doricDriver) {
|
||||
this.doricDriver = doricDriver;
|
||||
}
|
||||
|
||||
public RootNode getRootNode() {
|
||||
@ -143,22 +148,4 @@ public class DoricContext {
|
||||
public void onHidden() {
|
||||
callEntity(DoricConstant.DORIC_ENTITY_HIDDEN);
|
||||
}
|
||||
|
||||
public void startDebug() {
|
||||
doricDebugDriver = new DoricDebugDriver(new IStatusCallback() {
|
||||
@Override
|
||||
public void start() {
|
||||
isDebugging = true;
|
||||
callEntity(DoricConstant.DORIC_ENTITY_INIT, initParams);
|
||||
callEntity(DoricConstant.DORIC_ENTITY_CREATE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void stopDebug() {
|
||||
doricDebugDriver.destroy();
|
||||
isDebugging = false;
|
||||
callEntity(DoricConstant.DORIC_ENTITY_INIT, initParams);
|
||||
callEntity(DoricConstant.DORIC_ENTITY_CREATE);
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public class DoricNativeDriver implements IDoricDriver {
|
||||
}
|
||||
|
||||
private DoricNativeDriver() {
|
||||
doricJSEngine = new DoricJSEngine(true, null);
|
||||
doricJSEngine = new DoricJSEngine();
|
||||
mBridgeExecutor = Executors.newCachedThreadPool();
|
||||
mUIHandler = new Handler(Looper.getMainLooper());
|
||||
mJSHandler = doricJSEngine.getJSHandler();
|
||||
|
@ -28,7 +28,6 @@ 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;
|
||||
@ -45,11 +44,11 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
private HandlerThread handlerThread;
|
||||
private final Handler mJSHandler;
|
||||
private final DoricBridgeExtension mDoricBridgeExtension = new DoricBridgeExtension();
|
||||
private IDoricJSE mDoricJSE;
|
||||
protected IDoricJSE mDoricJSE;
|
||||
private final DoricTimerExtension mTimerExtension;
|
||||
private final DoricRegistry mDoricRegistry = new DoricRegistry();
|
||||
|
||||
public DoricJSEngine(final boolean isNative, final IStatusCallback statusCallback) {
|
||||
public DoricJSEngine() {
|
||||
handlerThread = new HandlerThread(this.getClass().getSimpleName());
|
||||
handlerThread.start();
|
||||
Looper looper = handlerThread.getLooper();
|
||||
@ -57,12 +56,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
mJSHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (isNative) {
|
||||
mDoricJSE = new DoricNativeJSExecutor();
|
||||
} else {
|
||||
mDoricJSE = new DoricRemoteJSExecutor(statusCallback);
|
||||
}
|
||||
|
||||
initJSEngine();
|
||||
injectGlobal();
|
||||
initDoricRuntime();
|
||||
}
|
||||
@ -74,6 +68,10 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
return mJSHandler;
|
||||
}
|
||||
|
||||
protected void initJSEngine() {
|
||||
mDoricJSE = new DoricNativeJSExecutor();
|
||||
}
|
||||
|
||||
private void injectGlobal() {
|
||||
mDoricJSE.injectGlobalJSFunction(DoricConstant.INJECT_LOG, new JavaFunction() {
|
||||
@Override
|
||||
|
@ -1,4 +1,4 @@
|
||||
package pub.doric.devkit;
|
||||
package pub.doric.engine;
|
||||
|
||||
public interface IStatusCallback {
|
||||
void start();
|
Reference in New Issue
Block a user