feat:use DoricPanel instead of DoricContext directly
This commit is contained in:
parent
e3813266ba
commit
a3f1e67db3
@ -18,7 +18,6 @@ package pub.doric.demo;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.FrameLayout;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
@ -30,7 +29,7 @@ import org.greenrobot.eventbus.ThreadMode;
|
|||||||
|
|
||||||
import pub.doric.DoricContext;
|
import pub.doric.DoricContext;
|
||||||
import pub.doric.DoricContextManager;
|
import pub.doric.DoricContextManager;
|
||||||
import pub.doric.devkit.DoricContextDebuggable;
|
import pub.doric.DoricPanel;
|
||||||
import pub.doric.devkit.event.EnterDebugEvent;
|
import pub.doric.devkit.event.EnterDebugEvent;
|
||||||
import pub.doric.devkit.event.QuitDebugEvent;
|
import pub.doric.devkit.event.QuitDebugEvent;
|
||||||
import pub.doric.devkit.event.ReloadEvent;
|
import pub.doric.devkit.event.ReloadEvent;
|
||||||
@ -52,14 +51,12 @@ public class DemoActivity extends AppCompatActivity {
|
|||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
String source = getIntent().getStringExtra("source");
|
String source = getIntent().getStringExtra("source");
|
||||||
FrameLayout frameLayout = new FrameLayout(this);
|
DoricPanel doricPanel = new DoricPanel(this);
|
||||||
addContentView(frameLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
addContentView(doricPanel, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT));
|
ViewGroup.LayoutParams.MATCH_PARENT));
|
||||||
doricContext = DoricContext.create(this, DoricUtils.readAssetFile("demo/" + source), source);
|
doricPanel.config(DoricUtils.readAssetFile("demo/" + source), source);
|
||||||
|
doricContext = doricPanel.getDoricContext();
|
||||||
doricContextDebuggable = new DoricContextDebuggable(doricContext);
|
doricContextDebuggable = new DoricContextDebuggable(doricContext);
|
||||||
doricContext.init(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
||||||
doricContext.getRootNode().setRootView(frameLayout);
|
|
||||||
|
|
||||||
sensorHelper = new SensorManagerHelper(this);
|
sensorHelper = new SensorManagerHelper(this);
|
||||||
sensorHelper.setOnShakeListener(new SensorManagerHelper.OnShakeListener() {
|
sensorHelper.setOnShakeListener(new SensorManagerHelper.OnShakeListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -73,17 +70,6 @@ public class DemoActivity extends AppCompatActivity {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
doricContext.onShow();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
doricContext.onHidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttachedToWindow() {
|
public void onAttachedToWindow() {
|
||||||
@ -95,7 +81,6 @@ public class DemoActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
doricContext.teardown();
|
|
||||||
EventBus.getDefault().unregister(this);
|
EventBus.getDefault().unregister(this);
|
||||||
sensorHelper.stop();
|
sensorHelper.stop();
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ public class DoricContext {
|
|||||||
return doricContext;
|
return doricContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(int width, int height) {
|
public void init(float width, float height) {
|
||||||
this.initParams = new JSONBuilder()
|
this.initParams = new JSONBuilder()
|
||||||
.put("width", width)
|
.put("width", width)
|
||||||
.put("height", height).toJSONObject();
|
.put("height", height).toJSONObject();
|
||||||
|
@ -25,6 +25,8 @@ import androidx.annotation.RequiresApi;
|
|||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
|
import pub.doric.utils.DoricUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: Doric
|
* @Description: Doric
|
||||||
* @Author: pengfei.zhou
|
* @Author: pengfei.zhou
|
||||||
@ -58,6 +60,10 @@ public class DoricPanel extends FrameLayout {
|
|||||||
|
|
||||||
public void config(DoricContext doricContext) {
|
public void config(DoricContext doricContext) {
|
||||||
mDoricContext = doricContext;
|
mDoricContext = doricContext;
|
||||||
|
mDoricContext.getRootNode().setRootView(this);
|
||||||
|
if (getMeasuredState() != 0) {
|
||||||
|
mDoricContext.init(DoricUtils.px2dp(getMeasuredWidth()), DoricUtils.px2dp(getMeasuredHeight()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -68,4 +74,14 @@ public class DoricPanel extends FrameLayout {
|
|||||||
public DoricContext getDoricContext() {
|
public DoricContext getDoricContext() {
|
||||||
return mDoricContext;
|
return mDoricContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||||
|
super.onSizeChanged(w, h, oldw, oldh);
|
||||||
|
if (oldw != w || oldh != h) {
|
||||||
|
if (mDoricContext != null) {
|
||||||
|
mDoricContext.init(DoricUtils.px2dp(w), DoricUtils.px2dp(h));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ package pub.doric;
|
|||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import pub.doric.plugin.NavigatorPlugin;
|
||||||
import pub.doric.plugin.NetworkPlugin;
|
import pub.doric.plugin.NetworkPlugin;
|
||||||
import pub.doric.plugin.ShaderPlugin;
|
import pub.doric.plugin.ShaderPlugin;
|
||||||
import pub.doric.plugin.StoragePlugin;
|
import pub.doric.plugin.StoragePlugin;
|
||||||
@ -69,6 +70,7 @@ public class DoricRegistry {
|
|||||||
this.registerNativePlugin(ModalPlugin.class);
|
this.registerNativePlugin(ModalPlugin.class);
|
||||||
this.registerNativePlugin(NetworkPlugin.class);
|
this.registerNativePlugin(NetworkPlugin.class);
|
||||||
this.registerNativePlugin(StoragePlugin.class);
|
this.registerNativePlugin(StoragePlugin.class);
|
||||||
|
this.registerNativePlugin(NavigatorPlugin.class);
|
||||||
this.registerViewNode(RootNode.class);
|
this.registerViewNode(RootNode.class);
|
||||||
this.registerViewNode(TextNode.class);
|
this.registerViewNode(TextNode.class);
|
||||||
this.registerViewNode(ImageNode.class);
|
this.registerViewNode(ImageNode.class);
|
||||||
|
@ -32,7 +32,6 @@ import pub.doric.extension.bridge.DoricPromise;
|
|||||||
import pub.doric.utils.DoricUtils;
|
import pub.doric.utils.DoricUtils;
|
||||||
import pub.doric.utils.ThreadMode;
|
import pub.doric.utils.ThreadMode;
|
||||||
|
|
||||||
import com.github.pengfeizhou.jscore.ArchiveException;
|
|
||||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||||
import com.github.pengfeizhou.jscore.JSObject;
|
import com.github.pengfeizhou.jscore.JSObject;
|
||||||
import com.github.pengfeizhou.jscore.JSValue;
|
import com.github.pengfeizhou.jscore.JSValue;
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* 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.plugin;
|
||||||
|
|
||||||
|
import pub.doric.DoricContext;
|
||||||
|
import pub.doric.extension.bridge.DoricPlugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: pub.doric.plugin
|
||||||
|
* @Author: pengfei.zhou
|
||||||
|
* @CreateDate: 2019-11-23
|
||||||
|
*/
|
||||||
|
@DoricPlugin(name = "navigator")
|
||||||
|
public class NavigatorPlugin extends DoricJavaPlugin {
|
||||||
|
public NavigatorPlugin(DoricContext doricContext) {
|
||||||
|
super(doricContext);
|
||||||
|
}
|
||||||
|
}
|
@ -56,6 +56,7 @@ export abstract class Panel {
|
|||||||
this.__data__ = data
|
this.__data__ = data
|
||||||
this.__root__.width = frame.width
|
this.__root__.width = frame.width
|
||||||
this.__root__.height = frame.height
|
this.__root__.height = frame.height
|
||||||
|
this.__root__.children.length = 0
|
||||||
this.build(this.__root__)
|
this.build(this.__root__)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user