diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3988de39..d35dadc4 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -21,15 +21,6 @@ - - - - - - - \ No newline at end of file diff --git a/app/src/main/java/pub/doric/demo/DemoActivity.java b/app/src/main/java/pub/doric/demo/DemoActivity.java deleted file mode 100644 index 9f54980b..00000000 --- a/app/src/main/java/pub/doric/demo/DemoActivity.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright [2019] [Doric.Pub] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package pub.doric.demo; - -import android.os.Bundle; -import android.view.ViewGroup; - -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; - -import pub.doric.DoricContext; -import pub.doric.DoricPanel; -import pub.doric.utils.DoricUtils; - -/** - * @Description: pub.doric.demo - * @Author: pengfei.zhou - * @CreateDate: 2019-11-19 - */ -public class DemoActivity extends AppCompatActivity { - private DoricContext doricContext; - - @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(); - } -} diff --git a/devkit/src/main/java/pub/doric/devkit/DoricContextDebuggable.java b/devkit/src/main/java/pub/doric/devkit/DoricContextDebuggable.java index 1ff0b20a..dca526c0 100644 --- a/devkit/src/main/java/pub/doric/devkit/DoricContextDebuggable.java +++ b/devkit/src/main/java/pub/doric/devkit/DoricContextDebuggable.java @@ -1,14 +1,15 @@ 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 DoricContextDebuggable(DoricContext doricContext) { - this.doricContext = doricContext; + public DoricContextDebuggable(String contextId) { + this.doricContext = DoricContextManager.getContext(contextId); } public void startDebug() { diff --git a/devkit/src/main/java/pub/doric/devkit/WSClient.java b/devkit/src/main/java/pub/doric/devkit/WSClient.java index dd81e587..80e659be 100644 --- a/devkit/src/main/java/pub/doric/devkit/WSClient.java +++ b/devkit/src/main/java/pub/doric/devkit/WSClient.java @@ -79,7 +79,8 @@ public class WSClient extends WebSocketListener { } break; case "SWITCH_TO_DEBUG": { - EventBus.getDefault().post(new EnterDebugEvent()); + String contextId = jsonObject.optString("contextId"); + EventBus.getDefault().post(new EnterDebugEvent(contextId)); } break; } diff --git a/devkit/src/main/java/pub/doric/devkit/event/EnterDebugEvent.java b/devkit/src/main/java/pub/doric/devkit/event/EnterDebugEvent.java index 5e02b0d0..84d666f8 100644 --- a/devkit/src/main/java/pub/doric/devkit/event/EnterDebugEvent.java +++ b/devkit/src/main/java/pub/doric/devkit/event/EnterDebugEvent.java @@ -1,4 +1,14 @@ package pub.doric.devkit.event; public class EnterDebugEvent { + + private String contextId; + + public EnterDebugEvent(String contextId) { + this.contextId = contextId; + } + + public String getContextId() { + return contextId; + } } diff --git a/devkit/src/main/java/pub/doric/devkit/ui/DemoDebugActivity.java b/devkit/src/main/java/pub/doric/devkit/ui/DemoDebugActivity.java index 135e4cf0..2a085654 100644 --- a/devkit/src/main/java/pub/doric/devkit/ui/DemoDebugActivity.java +++ b/devkit/src/main/java/pub/doric/devkit/ui/DemoDebugActivity.java @@ -17,46 +17,35 @@ 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.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,19 +62,24 @@ 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 onEnterDebugEvent(EnterDebugEvent enterDebugEvent) { + doricContextDebuggable = new DoricContextDebuggable(enterDebugEvent.getContextId()); doricContextDebuggable.startDebug(); }