From 51c8924c2a29683a520e0310b27069c8432c99f1 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Fri, 19 Jul 2019 10:27:09 +0800 Subject: [PATCH] rename hego to doric --- Android/.gitignore | 7 +- Android/.idea/compiler.xml | 15 --- Android/.idea/encodings.xml | 6 -- Android/.idea/gradle.xml | 19 ---- Android/.idea/misc.xml | 23 ----- Android/.idea/runConfigurations.xml | 12 --- Android/.idea/vcs.xml | 6 -- Android/app/build.gradle | 4 +- Android/app/src/main/AndroidManifest.xml | 4 +- .../{hegodemo => doricdemo}/MainActivity.java | 10 +- .../MyApplication.java | 8 +- Android/app/src/main/res/values/strings.xml | 2 +- Android/{hego => doric}/.gitignore | 0 Android/{hego => doric}/build.gradle | 0 Android/{hego => doric}/proguard-rules.pro | 0 .../doric/test}/ExampleInstrumentedTest.java | 4 +- .../src/main/AndroidManifest.xml | 2 +- .../com/github/pengfeizhou/doric/Doric.java} | 10 +- .../pengfeizhou/doric/DoricContext.java | 34 +++++++ .../github/pengfeizhou/doric/DoricDriver.java | 40 ++++++++ .../github/pengfeizhou/doric/DoricPanel.java | 54 +++++++++++ .../pengfeizhou/doric/bridge/BaseModule.java | 18 ++++ .../pengfeizhou/doric/bridge/ModalModule.java | 26 ++++++ .../doric/engine/DoricJSEngine.java} | 92 +++++++++---------- .../doric/engine/DoricJSExecutor.java} | 8 +- .../pengfeizhou/doric/engine/IDoricJSE.java} | 6 +- .../extension/DoricBridgeExtension.java} | 8 +- .../doric/extension/DoricMethod.java} | 6 +- .../doric/extension/DoricModule.java} | 6 +- .../doric/extension/DoricTimerExtension.java} | 8 +- .../doric}/extension/ModuleClassInfo.java | 16 ++-- .../doric/utils/DoricConstant.java | 45 +++++++++ .../pengfeizhou/doric/utils/DoricLog.java} | 10 +- .../doric/utils/DoricSettableFuture.java} | 6 +- .../pengfeizhou/doric/utils/DoricUtils.java} | 10 +- Android/doric/src/main/res/values/strings.xml | 3 + .../doric/test}/ExampleUnitTest.java | 2 +- .../github/pengfeizhou/hego/HegoContext.java | 34 ------- .../github/pengfeizhou/hego/HegoDriver.java | 40 -------- .../github/pengfeizhou/hego/HegoPanel.java | 54 ----------- .../pengfeizhou/hego/bridge/BaseModule.java | 18 ---- .../pengfeizhou/hego/bridge/ModalModule.java | 26 ------ .../pengfeizhou/hego/utils/HegoConstant.java | 39 -------- Android/hego/src/main/res/values/strings.xml | 3 - Android/settings.gradle | 2 +- README.md | 2 +- js-framework/package.json | 10 +- js-framework/rollup.config.js | 6 +- 48 files changed, 340 insertions(+), 424 deletions(-) delete mode 100644 Android/.idea/compiler.xml delete mode 100644 Android/.idea/encodings.xml delete mode 100644 Android/.idea/gradle.xml delete mode 100644 Android/.idea/misc.xml delete mode 100644 Android/.idea/runConfigurations.xml delete mode 100644 Android/.idea/vcs.xml rename Android/app/src/main/java/com/github/pengfeizhou/{hegodemo => doricdemo}/MainActivity.java (50%) rename Android/app/src/main/java/com/github/pengfeizhou/{hegodemo => doricdemo}/MyApplication.java (62%) rename Android/{hego => doric}/.gitignore (100%) rename Android/{hego => doric}/build.gradle (100%) rename Android/{hego => doric}/proguard-rules.pro (100%) rename Android/{hego/src/androidTest/java/com/github/pengfeizhou/hego => doric/src/androidTest/java/com/github/pengfeizhou/doric/test}/ExampleInstrumentedTest.java (82%) rename Android/{hego => doric}/src/main/AndroidManifest.xml (60%) rename Android/{hego/src/main/java/com/github/pengfeizhou/hego/Hego.java => doric/src/main/java/com/github/pengfeizhou/doric/Doric.java} (71%) create mode 100644 Android/doric/src/main/java/com/github/pengfeizhou/doric/DoricContext.java create mode 100644 Android/doric/src/main/java/com/github/pengfeizhou/doric/DoricDriver.java create mode 100644 Android/doric/src/main/java/com/github/pengfeizhou/doric/DoricPanel.java create mode 100644 Android/doric/src/main/java/com/github/pengfeizhou/doric/bridge/BaseModule.java create mode 100644 Android/doric/src/main/java/com/github/pengfeizhou/doric/bridge/ModalModule.java rename Android/{hego/src/main/java/com/github/pengfeizhou/hego/engine/HegoJSEngine.java => doric/src/main/java/com/github/pengfeizhou/doric/engine/DoricJSEngine.java} (65%) rename Android/{hego/src/main/java/com/github/pengfeizhou/hego/engine/HegoJSExecutor.java => doric/src/main/java/com/github/pengfeizhou/doric/engine/DoricJSExecutor.java} (90%) rename Android/{hego/src/main/java/com/github/pengfeizhou/hego/engine/IHegoJSE.java => doric/src/main/java/com/github/pengfeizhou/doric/engine/IDoricJSE.java} (96%) rename Android/{hego/src/main/java/com/github/pengfeizhou/hego/extension/HegoBridgeExtension.java => doric/src/main/java/com/github/pengfeizhou/doric/extension/DoricBridgeExtension.java} (68%) rename Android/{hego/src/main/java/com/github/pengfeizhou/hego/extension/HegoMethod.java => doric/src/main/java/com/github/pengfeizhou/doric/extension/DoricMethod.java} (78%) rename Android/{hego/src/main/java/com/github/pengfeizhou/hego/extension/HegoModule.java => doric/src/main/java/com/github/pengfeizhou/doric/extension/DoricModule.java} (78%) rename Android/{hego/src/main/java/com/github/pengfeizhou/hego/extension/HegoTimerExtension.java => doric/src/main/java/com/github/pengfeizhou/doric/extension/DoricTimerExtension.java} (89%) rename Android/{hego/src/main/java/com/github/pengfeizhou/hego => doric/src/main/java/com/github/pengfeizhou/doric}/extension/ModuleClassInfo.java (67%) create mode 100644 Android/doric/src/main/java/com/github/pengfeizhou/doric/utils/DoricConstant.java rename Android/{hego/src/main/java/com/github/pengfeizhou/hego/utils/HegoLog.java => doric/src/main/java/com/github/pengfeizhou/doric/utils/DoricLog.java} (81%) rename Android/{hego/src/main/java/com/github/pengfeizhou/hego/utils/HegoSettableFuture.java => doric/src/main/java/com/github/pengfeizhou/doric/utils/DoricSettableFuture.java} (93%) rename Android/{hego/src/main/java/com/github/pengfeizhou/hego/utils/HegoUtils.java => doric/src/main/java/com/github/pengfeizhou/doric/utils/DoricUtils.java} (80%) create mode 100644 Android/doric/src/main/res/values/strings.xml rename Android/{hego/src/test/java/com/github/pengfeizhou/hego => doric/src/test/java/com/github/pengfeizhou/doric/test}/ExampleUnitTest.java (88%) delete mode 100644 Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoContext.java delete mode 100644 Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoDriver.java delete mode 100644 Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoPanel.java delete mode 100644 Android/hego/src/main/java/com/github/pengfeizhou/hego/bridge/BaseModule.java delete mode 100644 Android/hego/src/main/java/com/github/pengfeizhou/hego/bridge/ModalModule.java delete mode 100644 Android/hego/src/main/java/com/github/pengfeizhou/hego/utils/HegoConstant.java delete mode 100644 Android/hego/src/main/res/values/strings.xml diff --git a/Android/.gitignore b/Android/.gitignore index 2b75303a..0df7064d 100644 --- a/Android/.gitignore +++ b/Android/.gitignore @@ -1,12 +1,7 @@ *.iml .gradle /local.properties -/.idea/caches -/.idea/libraries -/.idea/modules.xml -/.idea/workspace.xml -/.idea/navEditor.xml -/.idea/assetWizardSettings.xml +/.idea/ .DS_Store /build /captures diff --git a/Android/.idea/compiler.xml b/Android/.idea/compiler.xml deleted file mode 100644 index 40ed9378..00000000 --- a/Android/.idea/compiler.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Android/.idea/encodings.xml b/Android/.idea/encodings.xml deleted file mode 100644 index ada92a5e..00000000 --- a/Android/.idea/encodings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Android/.idea/gradle.xml b/Android/.idea/gradle.xml deleted file mode 100644 index 4b13e0fb..00000000 --- a/Android/.idea/gradle.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Android/.idea/misc.xml b/Android/.idea/misc.xml deleted file mode 100644 index 8397a565..00000000 --- a/Android/.idea/misc.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - Android Lint - - - - - - - - - - - \ No newline at end of file diff --git a/Android/.idea/runConfigurations.xml b/Android/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460d..00000000 --- a/Android/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Android/.idea/vcs.xml b/Android/.idea/vcs.xml deleted file mode 100644 index 6c0b8635..00000000 --- a/Android/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Android/app/build.gradle b/Android/app/build.gradle index f67521cd..d17cfdde 100644 --- a/Android/app/build.gradle +++ b/Android/app/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'com.android.application' android { compileSdkVersion 28 defaultConfig { - applicationId "com.github.pengfeizhou.hego" + applicationId "com.github.pengfeizhou.doric" minSdkVersion 16 targetSdkVersion 28 versionCode 1 @@ -27,5 +27,5 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' - implementation project(':hego') + implementation project(':doric') } diff --git a/Android/app/src/main/AndroidManifest.xml b/Android/app/src/main/AndroidManifest.xml index 7b2449c4..9291365d 100644 --- a/Android/app/src/main/AndroidManifest.xml +++ b/Android/app/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ + package="com.github.pengfeizhou.doricdemo"> - + diff --git a/Android/app/src/main/java/com/github/pengfeizhou/hegodemo/MainActivity.java b/Android/app/src/main/java/com/github/pengfeizhou/doricdemo/MainActivity.java similarity index 50% rename from Android/app/src/main/java/com/github/pengfeizhou/hegodemo/MainActivity.java rename to Android/app/src/main/java/com/github/pengfeizhou/doricdemo/MainActivity.java index d84da1b9..320e122c 100644 --- a/Android/app/src/main/java/com/github/pengfeizhou/hegodemo/MainActivity.java +++ b/Android/app/src/main/java/com/github/pengfeizhou/doricdemo/MainActivity.java @@ -1,10 +1,10 @@ -package com.github.pengfeizhou.hegodemo; +package com.github.pengfeizhou.doricdemo; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; -import com.github.pengfeizhou.hego.HegoContext; -import com.github.pengfeizhou.hego.utils.HegoUtils; +import com.github.pengfeizhou.doric.DoricContext; +import com.github.pengfeizhou.doric.utils.DoricUtils; public class MainActivity extends AppCompatActivity { @@ -12,7 +12,7 @@ public class MainActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - HegoContext hegoContext = HegoContext.createContext(HegoUtils.readAssetFile("demo.js"), "demo"); - hegoContext.callEntity("log"); + DoricContext doricContext = DoricContext.createContext(DoricUtils.readAssetFile("demo.js"), "demo"); + doricContext.callEntity("log"); } } diff --git a/Android/app/src/main/java/com/github/pengfeizhou/hegodemo/MyApplication.java b/Android/app/src/main/java/com/github/pengfeizhou/doricdemo/MyApplication.java similarity index 62% rename from Android/app/src/main/java/com/github/pengfeizhou/hegodemo/MyApplication.java rename to Android/app/src/main/java/com/github/pengfeizhou/doricdemo/MyApplication.java index 17aa3ead..ecb50d34 100644 --- a/Android/app/src/main/java/com/github/pengfeizhou/hegodemo/MyApplication.java +++ b/Android/app/src/main/java/com/github/pengfeizhou/doricdemo/MyApplication.java @@ -1,11 +1,11 @@ -package com.github.pengfeizhou.hegodemo; +package com.github.pengfeizhou.doricdemo; import android.app.Application; -import com.github.pengfeizhou.hego.Hego; +import com.github.pengfeizhou.doric.Doric; /** - * @Description: Hego + * @Description: Doric * @Author: pengfei.zhou * @CreateDate: 2019-07-18 */ @@ -13,6 +13,6 @@ public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); - Hego.init(this); + Doric.init(this); } } diff --git a/Android/app/src/main/res/values/strings.xml b/Android/app/src/main/res/values/strings.xml index b5461315..8a3bad8d 100644 --- a/Android/app/src/main/res/values/strings.xml +++ b/Android/app/src/main/res/values/strings.xml @@ -1,3 +1,3 @@ - HEGO + Doric diff --git a/Android/hego/.gitignore b/Android/doric/.gitignore similarity index 100% rename from Android/hego/.gitignore rename to Android/doric/.gitignore diff --git a/Android/hego/build.gradle b/Android/doric/build.gradle similarity index 100% rename from Android/hego/build.gradle rename to Android/doric/build.gradle diff --git a/Android/hego/proguard-rules.pro b/Android/doric/proguard-rules.pro similarity index 100% rename from Android/hego/proguard-rules.pro rename to Android/doric/proguard-rules.pro diff --git a/Android/hego/src/androidTest/java/com/github/pengfeizhou/hego/ExampleInstrumentedTest.java b/Android/doric/src/androidTest/java/com/github/pengfeizhou/doric/test/ExampleInstrumentedTest.java similarity index 82% rename from Android/hego/src/androidTest/java/com/github/pengfeizhou/hego/ExampleInstrumentedTest.java rename to Android/doric/src/androidTest/java/com/github/pengfeizhou/doric/test/ExampleInstrumentedTest.java index 137e2d53..29d807fc 100644 --- a/Android/hego/src/androidTest/java/com/github/pengfeizhou/hego/ExampleInstrumentedTest.java +++ b/Android/doric/src/androidTest/java/com/github/pengfeizhou/doric/test/ExampleInstrumentedTest.java @@ -1,4 +1,4 @@ -package com.github.pengfeizhou.hego; +package com.github.pengfeizhou.doric.test; import android.content.Context; import android.support.test.InstrumentationRegistry; @@ -21,6 +21,6 @@ public class ExampleInstrumentedTest { // Context of the app under test. Context appContext = InstrumentationRegistry.getTargetContext(); - assertEquals("com.github.pengfeizhou.hego.test", appContext.getPackageName()); + assertEquals("com.github.pengfeizhou.doric.test", appContext.getPackageName()); } } diff --git a/Android/hego/src/main/AndroidManifest.xml b/Android/doric/src/main/AndroidManifest.xml similarity index 60% rename from Android/hego/src/main/AndroidManifest.xml rename to Android/doric/src/main/AndroidManifest.xml index 1ff40fa2..e9f535ae 100644 --- a/Android/hego/src/main/AndroidManifest.xml +++ b/Android/doric/src/main/AndroidManifest.xml @@ -1,2 +1,2 @@ + package="com.github.pengfeizhou.doric" /> diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/Hego.java b/Android/doric/src/main/java/com/github/pengfeizhou/doric/Doric.java similarity index 71% rename from Android/hego/src/main/java/com/github/pengfeizhou/hego/Hego.java rename to Android/doric/src/main/java/com/github/pengfeizhou/doric/Doric.java index 76216108..836d5fc7 100644 --- a/Android/hego/src/main/java/com/github/pengfeizhou/hego/Hego.java +++ b/Android/doric/src/main/java/com/github/pengfeizhou/doric/Doric.java @@ -1,4 +1,4 @@ -package com.github.pengfeizhou.hego; +package com.github.pengfeizhou.doric; import android.app.Application; @@ -6,11 +6,11 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; /** - * @Description: Hego + * @Description: Doric * @Author: pengfei.zhou * @CreateDate: 2019-07-18 */ -public class Hego { +public class Doric { private static Application sApplication; public static void init(Application application) { @@ -23,11 +23,11 @@ public class Hego { private static Map bundles = new ConcurrentHashMap<>(); - public static void registerJSModuleContent(String name, String bundle) { + public static void registerJSBundle(String name, String bundle) { bundles.put(name, bundle); } - public static String getJSModuleContent(String name) { + public static String getJSBundle(String name) { return bundles.get(name); } } diff --git a/Android/doric/src/main/java/com/github/pengfeizhou/doric/DoricContext.java b/Android/doric/src/main/java/com/github/pengfeizhou/doric/DoricContext.java new file mode 100644 index 00000000..30e2ed92 --- /dev/null +++ b/Android/doric/src/main/java/com/github/pengfeizhou/doric/DoricContext.java @@ -0,0 +1,34 @@ +package com.github.pengfeizhou.doric; + +import com.github.pengfeizhou.doric.utils.DoricSettableFuture; +import com.github.pengfeizhou.jscore.JSDecoder; + +import java.util.concurrent.atomic.AtomicInteger; + +/** + * @Description: Doric + * @Author: pengfei.zhou + * @CreateDate: 2019-07-18 + */ +public class DoricContext { + private static AtomicInteger sCounter = new AtomicInteger(); + private final String mContextId; + + private DoricContext(String contextId) { + this.mContextId = contextId; + } + + public static DoricContext createContext(String script, String alias) { + String contextId = String.valueOf(sCounter.incrementAndGet()); + DoricDriver.getInstance().createPage(contextId, script, alias); + return new DoricContext(contextId); + } + + public DoricSettableFuture callEntity(String methodName, Object... args) { + return DoricDriver.getInstance().invokeContextMethod(mContextId, methodName, args); + } + + public void teardown() { + DoricDriver.getInstance().destoryContext(mContextId); + } +} diff --git a/Android/doric/src/main/java/com/github/pengfeizhou/doric/DoricDriver.java b/Android/doric/src/main/java/com/github/pengfeizhou/doric/DoricDriver.java new file mode 100644 index 00000000..ca113b74 --- /dev/null +++ b/Android/doric/src/main/java/com/github/pengfeizhou/doric/DoricDriver.java @@ -0,0 +1,40 @@ +package com.github.pengfeizhou.doric; + +import com.github.pengfeizhou.doric.engine.DoricJSEngine; +import com.github.pengfeizhou.doric.utils.DoricSettableFuture; +import com.github.pengfeizhou.jscore.JSDecoder; + +/** + * @Description: Doric + * @Author: pengfei.zhou + * @CreateDate: 2019-07-18 + */ +public class DoricDriver { + private final DoricJSEngine doricJSEngine; + + public DoricSettableFuture invokeContextMethod(final String contextId, final String method, final Object... args) { + return doricJSEngine.invokeContextEntityMethod(contextId, method, args); + } + + private static class Inner { + private static final DoricDriver sInstance = new DoricDriver(); + } + + private DoricDriver() { + doricJSEngine = new DoricJSEngine(); + } + + public static DoricDriver getInstance() { + return Inner.sInstance; + } + + public void createPage(final String contextId, final String script, final String source) { + doricJSEngine.prepareContext(contextId, script, source); + } + + public void destoryContext(String contextId) { + doricJSEngine.destroyContext(contextId); + } + + +} diff --git a/Android/doric/src/main/java/com/github/pengfeizhou/doric/DoricPanel.java b/Android/doric/src/main/java/com/github/pengfeizhou/doric/DoricPanel.java new file mode 100644 index 00000000..cda83018 --- /dev/null +++ b/Android/doric/src/main/java/com/github/pengfeizhou/doric/DoricPanel.java @@ -0,0 +1,54 @@ +package com.github.pengfeizhou.doric; + +import android.content.Context; +import android.os.Build; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.annotation.RequiresApi; +import android.util.AttributeSet; +import android.widget.FrameLayout; + +/** + * @Description: Doric + * @Author: pengfei.zhou + * @CreateDate: 2019-07-18 + */ +public class DoricPanel extends FrameLayout { + + private DoricContext mDoricContext; + + public DoricPanel(@NonNull Context context) { + super(context); + } + + public DoricPanel(@NonNull Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + } + + public DoricPanel(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) + public DoricPanel(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + public void config(String script, String alias) { + DoricContext doricContext = DoricContext.createContext(script, alias); + config(doricContext); + } + + public void config(DoricContext doricContext) { + mDoricContext = doricContext; + } + + @Override + protected void onFinishInflate() { + super.onFinishInflate(); + } + + public DoricContext getDoricContext() { + return mDoricContext; + } +} diff --git a/Android/doric/src/main/java/com/github/pengfeizhou/doric/bridge/BaseModule.java b/Android/doric/src/main/java/com/github/pengfeizhou/doric/bridge/BaseModule.java new file mode 100644 index 00000000..cfcbe9e8 --- /dev/null +++ b/Android/doric/src/main/java/com/github/pengfeizhou/doric/bridge/BaseModule.java @@ -0,0 +1,18 @@ +package com.github.pengfeizhou.doric.bridge; + +import com.github.pengfeizhou.doric.DoricContext; + +/** + * @Description: Doric + * @Author: pengfei.zhou + * @CreateDate: 2019-07-18 + */ +public abstract class BaseModule { + private final DoricContext doricContext; + + protected BaseModule(DoricContext doricContext) { + this.doricContext = doricContext; + } + + public abstract String moduleName(); +} diff --git a/Android/doric/src/main/java/com/github/pengfeizhou/doric/bridge/ModalModule.java b/Android/doric/src/main/java/com/github/pengfeizhou/doric/bridge/ModalModule.java new file mode 100644 index 00000000..092faa75 --- /dev/null +++ b/Android/doric/src/main/java/com/github/pengfeizhou/doric/bridge/ModalModule.java @@ -0,0 +1,26 @@ +package com.github.pengfeizhou.doric.bridge; + +import com.github.pengfeizhou.doric.DoricContext; +import com.github.pengfeizhou.doric.extension.DoricMethod; + +/** + * @Description: Doric + * @Author: pengfei.zhou + * @CreateDate: 2019-07-18 + */ +public class ModalModule extends BaseModule { + + protected ModalModule(DoricContext doricContext) { + super(doricContext); + } + + @Override + public String moduleName() { + return "modal"; + } + + @DoricMethod(name = "toast") + public void toast() { + + } +} diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/engine/HegoJSEngine.java b/Android/doric/src/main/java/com/github/pengfeizhou/doric/engine/DoricJSEngine.java similarity index 65% rename from Android/hego/src/main/java/com/github/pengfeizhou/hego/engine/HegoJSEngine.java rename to Android/doric/src/main/java/com/github/pengfeizhou/doric/engine/DoricJSEngine.java index 308802b2..2417eae6 100644 --- a/Android/hego/src/main/java/com/github/pengfeizhou/hego/engine/HegoJSEngine.java +++ b/Android/doric/src/main/java/com/github/pengfeizhou/doric/engine/DoricJSEngine.java @@ -1,4 +1,4 @@ -package com.github.pengfeizhou.hego.engine; +package com.github.pengfeizhou.doric.engine; import android.os.Handler; import android.os.HandlerThread; @@ -6,13 +6,13 @@ import android.os.Looper; import android.os.Message; import android.text.TextUtils; -import com.github.pengfeizhou.hego.Hego; -import com.github.pengfeizhou.hego.extension.HegoBridgeExtension; -import com.github.pengfeizhou.hego.utils.HegoConstant; -import com.github.pengfeizhou.hego.utils.HegoLog; -import com.github.pengfeizhou.hego.utils.HegoSettableFuture; -import com.github.pengfeizhou.hego.extension.HegoTimerExtension; -import com.github.pengfeizhou.hego.utils.HegoUtils; +import com.github.pengfeizhou.doric.Doric; +import com.github.pengfeizhou.doric.extension.DoricBridgeExtension; +import com.github.pengfeizhou.doric.utils.DoricConstant; +import com.github.pengfeizhou.doric.utils.DoricLog; +import com.github.pengfeizhou.doric.utils.DoricSettableFuture; +import com.github.pengfeizhou.doric.extension.DoricTimerExtension; +import com.github.pengfeizhou.doric.utils.DoricUtils; import com.github.pengfeizhou.jscore.JSDecoder; import com.github.pengfeizhou.jscore.JavaFunction; import com.github.pengfeizhou.jscore.JavaValue; @@ -22,17 +22,17 @@ import org.json.JSONObject; import java.util.ArrayList; /** - * @Description: Hego + * @Description: Doric * @Author: pengfei.zhou * @CreateDate: 2019-07-18 */ -public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerCallback { +public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.TimerCallback { private final Handler mJSHandler; - private final HegoBridgeExtension mHegoBridgeExtensio; - private IHegoJSE mHegoJSE; - private HegoTimerExtension mTimerExtension; + private final DoricBridgeExtension mDoricBridgeExtension; + private IDoricJSE mDoricJSE; + private DoricTimerExtension mTimerExtension; - public HegoJSEngine() { + public DoricJSEngine() { HandlerThread handlerThread = new HandlerThread(this.getClass().getSimpleName()); handlerThread.start(); Looper looper = handlerThread.getLooper(); @@ -44,14 +44,14 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC initHugoRuntime(); } }); - mTimerExtension = new HegoTimerExtension(looper, this); - mHegoBridgeExtensio = new HegoBridgeExtension(); + mTimerExtension = new DoricTimerExtension(looper, this); + mDoricBridgeExtension = new DoricBridgeExtension(); } private void initJSExecutor() { - mHegoJSE = new HegoJSExecutor(); - mHegoJSE.injectGlobalJSFunction(HegoConstant.INJECT_LOG, new JavaFunction() { + mDoricJSE = new DoricJSExecutor(); + mDoricJSE.injectGlobalJSFunction(DoricConstant.INJECT_LOG, new JavaFunction() { @Override public JavaValue exec(JSDecoder[] args) { try { @@ -59,13 +59,13 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC String message = args[1].string(); switch (type) { case "w": - HegoLog.w(message, "_js"); + DoricLog.w(message, "_js"); break; case "e": - HegoLog.e(message, "_js"); + DoricLog.e(message, "_js"); break; default: - HegoLog.d(message, "_js"); + DoricLog.d(message, "_js"); break; } } catch (Exception e) { @@ -74,17 +74,17 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC return null; } }); - mHegoJSE.injectGlobalJSFunction(HegoConstant.INJECT_REQUIRE, new JavaFunction() { + mDoricJSE.injectGlobalJSFunction(DoricConstant.INJECT_REQUIRE, new JavaFunction() { @Override public JavaValue exec(JSDecoder[] args) { try { String name = args[0].string(); - String content = Hego.getJSModuleContent(name); + String content = Doric.getJSBundle(name); if (TextUtils.isEmpty(content)) { - HegoLog.e("error"); + DoricLog.e("error"); return new JavaValue(false); } - mHegoJSE.loadJS(packageModuleScript(name, content), "Module://" + name); + mDoricJSE.loadJS(packageModuleScript(name, content), "Module://" + name); return new JavaValue(true); } catch (Exception e) { e.printStackTrace(); @@ -92,7 +92,7 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC } } }); - mHegoJSE.injectGlobalJSFunction(HegoConstant.INJECT_TIMER_SET, new JavaFunction() { + mDoricJSE.injectGlobalJSFunction(DoricConstant.INJECT_TIMER_SET, new JavaFunction() { @Override public JavaValue exec(JSDecoder[] args) { try { @@ -106,7 +106,7 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC return null; } }); - mHegoJSE.injectGlobalJSFunction(HegoConstant.INJECT_TIMER_CLEAR, new JavaFunction() { + mDoricJSE.injectGlobalJSFunction(DoricConstant.INJECT_TIMER_CLEAR, new JavaFunction() { @Override public JavaValue exec(JSDecoder[] args) { try { @@ -117,7 +117,7 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC return null; } }); - mHegoJSE.injectGlobalJSFunction(HegoConstant.INJECT_BRIDGE, new JavaFunction() { + mDoricJSE.injectGlobalJSFunction(DoricConstant.INJECT_BRIDGE, new JavaFunction() { @Override public JavaValue exec(JSDecoder[] args) { try { @@ -126,7 +126,7 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC String method = args[2].string(); String callbackId = args[3].string(); JSDecoder jsDecoder = args[4]; - return mHegoBridgeExtensio.callNative(contextId, module, method, callbackId, jsDecoder); + return mDoricBridgeExtension.callNative(contextId, module, method, callbackId, jsDecoder); } catch (Exception e) { e.printStackTrace(); } @@ -136,10 +136,10 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC } private void initHugoRuntime() { - loadBuiltinJS("hego-sandbox.js"); - String libName = "./index"; - String libJS = HegoUtils.readAssetFile("hego-lib.js"); - mHegoJSE.loadJS(packageModuleScript(libName, libJS), "Module://" + libName); + loadBuiltinJS(DoricConstant.DORIC_BUNDLE_SANDBOX); + String libName = DoricConstant.DORIC_MODULE_LIB; + String libJS = DoricUtils.readAssetFile(DoricConstant.DORIC_BUNDLE_LIB); + mDoricJSE.loadJS(packageModuleScript(libName, libJS), "Module://" + libName); } @Override @@ -148,19 +148,19 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC } public void teardown() { - mHegoJSE.teardown(); + mDoricJSE.teardown(); } private void loadBuiltinJS(String assetName) { - String script = HegoUtils.readAssetFile(assetName); - mHegoJSE.loadJS(script, "Assets://" + assetName); + String script = DoricUtils.readAssetFile(assetName); + mDoricJSE.loadJS(script, "Assets://" + assetName); } public void prepareContext(final String contextId, final String script, final String source) { Runnable runnable = new Runnable() { @Override public void run() { - mHegoJSE.loadJS(packageContextScript(contextId, script), "Context://" + source); + mDoricJSE.loadJS(packageContextScript(contextId, script), "Context://" + source); } }; doOnJSThread(runnable); @@ -178,37 +178,37 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC Runnable runnable = new Runnable() { @Override public void run() { - mHegoJSE.loadJS(String.format(HegoConstant.TEMPLATE_CONTEXT_DESTORY, contextId), "_Context://" + contextId); + mDoricJSE.loadJS(String.format(DoricConstant.TEMPLATE_CONTEXT_DESTROY, contextId), "_Context://" + contextId); } }; doOnJSThread(runnable); } private String packageContextScript(String contextId, String content) { - return String.format(HegoConstant.TEMPLATE_CONTEXT_CREATE, content, contextId, contextId); + return String.format(DoricConstant.TEMPLATE_CONTEXT_CREATE, content, contextId, contextId); } private String packageModuleScript(String moduleName, String content) { - return String.format(HegoConstant.TEMPLATE_MODULE, moduleName, content); + return String.format(DoricConstant.TEMPLATE_MODULE, moduleName, content); } public boolean isJSThread() { return Looper.myLooper() == mJSHandler.getLooper(); } - public HegoSettableFuture invokeContextEntityMethod(final String contextId, final String method, final Object... args) { + public DoricSettableFuture invokeContextEntityMethod(final String contextId, final String method, final Object... args) { final Object[] nArgs = new Object[args.length + 2]; nArgs[0] = contextId; nArgs[1] = method; if (args.length > 0) { System.arraycopy(args, 0, nArgs, 2, args.length); } - return invokeHegoMethod(HegoConstant.HEGO_CONTEXT_INVOKE, nArgs); + return invokeDoricMethod(DoricConstant.DORIC_CONTEXT_INVOKE, nArgs); } - public HegoSettableFuture invokeHegoMethod(final String method, final Object... args) { - final HegoSettableFuture settableFuture = new HegoSettableFuture<>(); + public DoricSettableFuture invokeDoricMethod(final String method, final Object... args) { + final DoricSettableFuture settableFuture = new DoricSettableFuture<>(); Runnable runnable = new Runnable() { @Override public void run() { @@ -234,7 +234,7 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC values.add(new JavaValue(String.valueOf(arg))); } } - settableFuture.set(mHegoJSE.invokeMethod(HegoConstant.GLOBAL_HEGO, method, + settableFuture.set(mDoricJSE.invokeMethod(DoricConstant.GLOBAL_DORIC, method, values.toArray(new JavaValue[values.size()]), true)); } }; @@ -244,6 +244,6 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC @Override public void callback(long timerId) { - invokeHegoMethod(HegoConstant.HEGO_TIMER_CALLBACK, timerId); + invokeDoricMethod(DoricConstant.DORIC_TIMER_CALLBACK, timerId); } } diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/engine/HegoJSExecutor.java b/Android/doric/src/main/java/com/github/pengfeizhou/doric/engine/DoricJSExecutor.java similarity index 90% rename from Android/hego/src/main/java/com/github/pengfeizhou/hego/engine/HegoJSExecutor.java rename to Android/doric/src/main/java/com/github/pengfeizhou/doric/engine/DoricJSExecutor.java index d5548cda..d44a1cc6 100644 --- a/Android/hego/src/main/java/com/github/pengfeizhou/hego/engine/HegoJSExecutor.java +++ b/Android/doric/src/main/java/com/github/pengfeizhou/doric/engine/DoricJSExecutor.java @@ -1,4 +1,4 @@ -package com.github.pengfeizhou.hego.engine; +package com.github.pengfeizhou.doric.engine; import com.github.pengfeizhou.jscore.JSDecoder; import com.github.pengfeizhou.jscore.JSExecutor; @@ -7,15 +7,15 @@ import com.github.pengfeizhou.jscore.JavaFunction; import com.github.pengfeizhou.jscore.JavaValue; /** - * @Description: Hego + * @Description: Doric * @Author: pengfei.zhou * @CreateDate: 2019-07-18 */ -public class HegoJSExecutor implements IHegoJSE { +public class DoricJSExecutor implements IDoricJSE { private final JSExecutor mJSExecutor; - public HegoJSExecutor() { + public DoricJSExecutor() { this.mJSExecutor = JSExecutor.create(); } diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/engine/IHegoJSE.java b/Android/doric/src/main/java/com/github/pengfeizhou/doric/engine/IDoricJSE.java similarity index 96% rename from Android/hego/src/main/java/com/github/pengfeizhou/hego/engine/IHegoJSE.java rename to Android/doric/src/main/java/com/github/pengfeizhou/doric/engine/IDoricJSE.java index fd6f43ec..5ea58c18 100644 --- a/Android/hego/src/main/java/com/github/pengfeizhou/hego/engine/IHegoJSE.java +++ b/Android/doric/src/main/java/com/github/pengfeizhou/doric/engine/IDoricJSE.java @@ -1,4 +1,4 @@ -package com.github.pengfeizhou.hego.engine; +package com.github.pengfeizhou.doric.engine; import com.github.pengfeizhou.jscore.JSDecoder; import com.github.pengfeizhou.jscore.JSRuntimeException; @@ -6,11 +6,11 @@ import com.github.pengfeizhou.jscore.JavaFunction; import com.github.pengfeizhou.jscore.JavaValue; /** - * @Description: Hego + * @Description: Doric * @Author: pengfei.zhou * @CreateDate: 2019-07-18 */ -public interface IHegoJSE { +public interface IDoricJSE { /** * 执行JS语句 * diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/extension/HegoBridgeExtension.java b/Android/doric/src/main/java/com/github/pengfeizhou/doric/extension/DoricBridgeExtension.java similarity index 68% rename from Android/hego/src/main/java/com/github/pengfeizhou/hego/extension/HegoBridgeExtension.java rename to Android/doric/src/main/java/com/github/pengfeizhou/doric/extension/DoricBridgeExtension.java index 297e284b..af7bccb7 100644 --- a/Android/hego/src/main/java/com/github/pengfeizhou/hego/extension/HegoBridgeExtension.java +++ b/Android/doric/src/main/java/com/github/pengfeizhou/doric/extension/DoricBridgeExtension.java @@ -1,15 +1,15 @@ -package com.github.pengfeizhou.hego.extension; +package com.github.pengfeizhou.doric.extension; import com.github.pengfeizhou.jscore.JSDecoder; import com.github.pengfeizhou.jscore.JavaValue; /** - * @Description: Android + * @Description: Doric * @Author: pengfei.zhou * @CreateDate: 2019-07-18 */ -public class HegoBridgeExtension { - public HegoBridgeExtension() { +public class DoricBridgeExtension { + public DoricBridgeExtension() { } diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/extension/HegoMethod.java b/Android/doric/src/main/java/com/github/pengfeizhou/doric/extension/DoricMethod.java similarity index 78% rename from Android/hego/src/main/java/com/github/pengfeizhou/hego/extension/HegoMethod.java rename to Android/doric/src/main/java/com/github/pengfeizhou/doric/extension/DoricMethod.java index 22e40c87..f32fe1c5 100644 --- a/Android/hego/src/main/java/com/github/pengfeizhou/hego/extension/HegoMethod.java +++ b/Android/doric/src/main/java/com/github/pengfeizhou/doric/extension/DoricMethod.java @@ -1,4 +1,4 @@ -package com.github.pengfeizhou.hego.extension; +package com.github.pengfeizhou.doric.extension; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; @@ -7,13 +7,13 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** - * @Description: Android + * @Description: Doric * @Author: pengfei.zhou * @CreateDate: 2019-07-18 */ @Documented @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) -public @interface HegoMethod { +public @interface DoricMethod { String name() default ""; } diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/extension/HegoModule.java b/Android/doric/src/main/java/com/github/pengfeizhou/doric/extension/DoricModule.java similarity index 78% rename from Android/hego/src/main/java/com/github/pengfeizhou/hego/extension/HegoModule.java rename to Android/doric/src/main/java/com/github/pengfeizhou/doric/extension/DoricModule.java index be0d0cc4..1350cfd7 100644 --- a/Android/hego/src/main/java/com/github/pengfeizhou/hego/extension/HegoModule.java +++ b/Android/doric/src/main/java/com/github/pengfeizhou/doric/extension/DoricModule.java @@ -1,4 +1,4 @@ -package com.github.pengfeizhou.hego.extension; +package com.github.pengfeizhou.doric.extension; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; @@ -7,13 +7,13 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** - * @Description: Hego + * @Description: Doric * @Author: pengfei.zhou * @CreateDate: 2019-07-18 */ @Documented @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) -public @interface HegoModule { +public @interface DoricModule { String name() default ""; } diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/extension/HegoTimerExtension.java b/Android/doric/src/main/java/com/github/pengfeizhou/doric/extension/DoricTimerExtension.java similarity index 89% rename from Android/hego/src/main/java/com/github/pengfeizhou/hego/extension/HegoTimerExtension.java rename to Android/doric/src/main/java/com/github/pengfeizhou/doric/extension/DoricTimerExtension.java index 7a39847a..0078df0a 100644 --- a/Android/hego/src/main/java/com/github/pengfeizhou/hego/extension/HegoTimerExtension.java +++ b/Android/doric/src/main/java/com/github/pengfeizhou/doric/extension/DoricTimerExtension.java @@ -1,4 +1,4 @@ -package com.github.pengfeizhou.hego.extension; +package com.github.pengfeizhou.doric.extension; import android.os.Handler; import android.os.Looper; @@ -8,18 +8,18 @@ import java.util.HashSet; import java.util.Set; /** - * @Description: Android + * @Description: Doric * @Author: pengfei.zhou * @CreateDate: 2019-07-18 */ -public class HegoTimerExtension implements Handler.Callback { +public class DoricTimerExtension implements Handler.Callback { private static final int MSG_TIMER = 0; private final Handler mTimerHandler; private final TimerCallback mTimerCallback; private Set mDeletedTimerIds = new HashSet<>(); - public HegoTimerExtension(Looper looper, TimerCallback timerCallback) { + public DoricTimerExtension(Looper looper, TimerCallback timerCallback) { mTimerHandler = new Handler(looper, this); mTimerCallback = timerCallback; } diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/extension/ModuleClassInfo.java b/Android/doric/src/main/java/com/github/pengfeizhou/doric/extension/ModuleClassInfo.java similarity index 67% rename from Android/hego/src/main/java/com/github/pengfeizhou/hego/extension/ModuleClassInfo.java rename to Android/doric/src/main/java/com/github/pengfeizhou/doric/extension/ModuleClassInfo.java index 53a8f0f6..8a70df26 100644 --- a/Android/hego/src/main/java/com/github/pengfeizhou/hego/extension/ModuleClassInfo.java +++ b/Android/doric/src/main/java/com/github/pengfeizhou/doric/extension/ModuleClassInfo.java @@ -1,17 +1,13 @@ -package com.github.pengfeizhou.hego.extension; +package com.github.pengfeizhou.doric.extension; import android.text.TextUtils; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; /** - * @Description: Android + * @Description: Doric * @Author: pengfei.zhou * @CreateDate: 2019-07-18 */ @@ -34,12 +30,12 @@ public class ModuleClassInfo { Method[] methods = clz.getMethods(); if (methods != null) { for (Method method : methods) { - HegoMethod hegoMethod = method.getAnnotation(HegoMethod.class); - if (hegoMethod != null) { - if (TextUtils.isEmpty(hegoMethod.name())) { + DoricMethod doricMethod = method.getAnnotation(DoricMethod.class); + if (doricMethod != null) { + if (TextUtils.isEmpty(doricMethod.name())) { methodMap.put(method.getName(), method); } else { - methodMap.put(hegoMethod.name(), method); + methodMap.put(doricMethod.name(), method); } } } diff --git a/Android/doric/src/main/java/com/github/pengfeizhou/doric/utils/DoricConstant.java b/Android/doric/src/main/java/com/github/pengfeizhou/doric/utils/DoricConstant.java new file mode 100644 index 00000000..1038d921 --- /dev/null +++ b/Android/doric/src/main/java/com/github/pengfeizhou/doric/utils/DoricConstant.java @@ -0,0 +1,45 @@ +package com.github.pengfeizhou.doric.utils; + +/** + * @Description: Doric + * @Author: pengfei.zhou + * @CreateDate: 2019-07-18 + */ +public class DoricConstant { + public static final String DORIC_BUNDLE_SANDBOX = "doric-sandbox.js"; + public static final String DORIC_BUNDLE_LIB = "doric-lib.js"; + public static final String DORIC_MODULE_LIB = "./index"; + + + + public static final String INJECT_LOG = "nativeLog"; + public static final String INJECT_REQUIRE = "nativeRequire"; + public static final String INJECT_TIMER_SET = "nativeSetTimer"; + public static final String INJECT_TIMER_CLEAR = "nativeClearTimer"; + public static final String INJECT_BRIDGE = "nativeBridge"; + + public static final String TEMPLATE_CONTEXT_CREATE = "Reflect.apply(" + + "function(doric,context,require,exports){" + "\n" + + "%s" + "\n" + + "},doric.jsObtainContext(\"%s\"),[" + + "undefined," + + "doric.jsObtainContext(\"%s\")," + + "doric.__require__" + + ",{}" + + "])"; + + public static final String TEMPLATE_MODULE = "Reflect.apply(doric.jsRegisterModule,this,[" + + "\"%s\"," + + "Reflect.apply(function(__module){" + + "(function(module,exports,require){" + "\n" + + "%s" + "\n" + + "})(__module,__module.exports,doric.__require__);" + + "\nreturn __module.exports;" + + "},this,[{exports:{}}])" + + "])"; + public static final String TEMPLATE_CONTEXT_DESTROY = "doric.jsRelease(%s)"; + public static final String GLOBAL_DORIC = "doric"; + public static final String DORIC_CONTEXT_RELEASE = "jsReleaseContext"; + public static final String DORIC_CONTEXT_INVOKE = "jsCallEntityMethod"; + public static final String DORIC_TIMER_CALLBACK = "jsCallbackTimer"; +} diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/utils/HegoLog.java b/Android/doric/src/main/java/com/github/pengfeizhou/doric/utils/DoricLog.java similarity index 81% rename from Android/hego/src/main/java/com/github/pengfeizhou/hego/utils/HegoLog.java rename to Android/doric/src/main/java/com/github/pengfeizhou/doric/utils/DoricLog.java index e0f95939..4998ab24 100644 --- a/Android/hego/src/main/java/com/github/pengfeizhou/hego/utils/HegoLog.java +++ b/Android/doric/src/main/java/com/github/pengfeizhou/doric/utils/DoricLog.java @@ -1,16 +1,16 @@ -package com.github.pengfeizhou.hego.utils; +package com.github.pengfeizhou.doric.utils; import android.util.Log; -import com.github.pengfeizhou.hego.Hego; +import com.github.pengfeizhou.doric.Doric; /** - * @Description: Hego + * @Description: Doric * @Author: pengfei.zhou * @CreateDate: 2019-07-18 */ -public class HegoLog { - private static String TAG = Hego.class.getSimpleName(); +public class DoricLog { + private static String TAG = Doric.class.getSimpleName(); public static void d(String message, String... suffix) { StringBuilder stringBuilder = new StringBuilder(TAG); diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/utils/HegoSettableFuture.java b/Android/doric/src/main/java/com/github/pengfeizhou/doric/utils/DoricSettableFuture.java similarity index 93% rename from Android/hego/src/main/java/com/github/pengfeizhou/hego/utils/HegoSettableFuture.java rename to Android/doric/src/main/java/com/github/pengfeizhou/doric/utils/DoricSettableFuture.java index 805bf8ae..8ac927cd 100644 --- a/Android/hego/src/main/java/com/github/pengfeizhou/hego/utils/HegoSettableFuture.java +++ b/Android/doric/src/main/java/com/github/pengfeizhou/doric/utils/DoricSettableFuture.java @@ -1,7 +1,7 @@ -package com.github.pengfeizhou.hego.utils; +package com.github.pengfeizhou.doric.utils; /** - * @Description: Hego + * @Description: Doric * @Author: pengfei.zhou * @CreateDate: 2019-07-18 */ @@ -13,7 +13,7 @@ import java.util.concurrent.TimeUnit; * A super simple Future-like class that can safely notify another Thread when a value is ready. * Does not support setting errors or canceling. */ -public class HegoSettableFuture { +public class DoricSettableFuture { private final CountDownLatch mReadyLatch = new CountDownLatch(1); private volatile diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/utils/HegoUtils.java b/Android/doric/src/main/java/com/github/pengfeizhou/doric/utils/DoricUtils.java similarity index 80% rename from Android/hego/src/main/java/com/github/pengfeizhou/hego/utils/HegoUtils.java rename to Android/doric/src/main/java/com/github/pengfeizhou/doric/utils/DoricUtils.java index ee5a068f..dd0e2e5d 100644 --- a/Android/hego/src/main/java/com/github/pengfeizhou/hego/utils/HegoUtils.java +++ b/Android/doric/src/main/java/com/github/pengfeizhou/doric/utils/DoricUtils.java @@ -1,22 +1,22 @@ -package com.github.pengfeizhou.hego.utils; +package com.github.pengfeizhou.doric.utils; import android.content.res.AssetManager; -import com.github.pengfeizhou.hego.Hego; +import com.github.pengfeizhou.doric.Doric; import java.io.IOException; import java.io.InputStream; /** - * @Description: Hego + * @Description: Doric * @Author: pengfei.zhou * @CreateDate: 2019-07-18 */ -public class HegoUtils { +public class DoricUtils { public static String readAssetFile(String assetFile) { InputStream inputStream = null; try { - AssetManager assetManager = Hego.application().getAssets(); + AssetManager assetManager = Doric.application().getAssets(); inputStream = assetManager.open(assetFile); int length = inputStream.available(); byte[] buffer = new byte[length]; diff --git a/Android/doric/src/main/res/values/strings.xml b/Android/doric/src/main/res/values/strings.xml new file mode 100644 index 00000000..8a3bad8d --- /dev/null +++ b/Android/doric/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + Doric + diff --git a/Android/hego/src/test/java/com/github/pengfeizhou/hego/ExampleUnitTest.java b/Android/doric/src/test/java/com/github/pengfeizhou/doric/test/ExampleUnitTest.java similarity index 88% rename from Android/hego/src/test/java/com/github/pengfeizhou/hego/ExampleUnitTest.java rename to Android/doric/src/test/java/com/github/pengfeizhou/doric/test/ExampleUnitTest.java index 43e7ee4a..12620b8f 100644 --- a/Android/hego/src/test/java/com/github/pengfeizhou/hego/ExampleUnitTest.java +++ b/Android/doric/src/test/java/com/github/pengfeizhou/doric/test/ExampleUnitTest.java @@ -1,4 +1,4 @@ -package com.github.pengfeizhou.hego; +package com.github.pengfeizhou.doric.test; import org.junit.Test; diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoContext.java b/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoContext.java deleted file mode 100644 index 4331c7d2..00000000 --- a/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoContext.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.github.pengfeizhou.hego; - -import com.github.pengfeizhou.hego.utils.HegoSettableFuture; -import com.github.pengfeizhou.jscore.JSDecoder; - -import java.util.concurrent.atomic.AtomicInteger; - -/** - * @Description: Hego - * @Author: pengfei.zhou - * @CreateDate: 2019-07-18 - */ -public class HegoContext { - private static AtomicInteger sCounter = new AtomicInteger(); - private final String mContextId; - - private HegoContext(String contextId) { - this.mContextId = contextId; - } - - public static HegoContext createContext(String script, String alias) { - String contextId = String.valueOf(sCounter.incrementAndGet()); - HegoDriver.getInstance().createPage(contextId, script, alias); - return new HegoContext(contextId); - } - - public HegoSettableFuture callEntity(String methodName, Object... args) { - return HegoDriver.getInstance().invokeContextMethod(mContextId, methodName, args); - } - - public void teardown() { - HegoDriver.getInstance().destoryContext(mContextId); - } -} diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoDriver.java b/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoDriver.java deleted file mode 100644 index 451cb41f..00000000 --- a/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoDriver.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.github.pengfeizhou.hego; - -import com.github.pengfeizhou.hego.engine.HegoJSEngine; -import com.github.pengfeizhou.hego.utils.HegoSettableFuture; -import com.github.pengfeizhou.jscore.JSDecoder; - -/** - * @Description: Hego - * @Author: pengfei.zhou - * @CreateDate: 2019-07-18 - */ -public class HegoDriver { - private final HegoJSEngine hegoJSEngine; - - public HegoSettableFuture invokeContextMethod(final String contextId, final String method, final Object... args) { - return hegoJSEngine.invokeContextEntityMethod(contextId, method, args); - } - - private static class Inner { - private static final HegoDriver sInstance = new HegoDriver(); - } - - private HegoDriver() { - hegoJSEngine = new HegoJSEngine(); - } - - public static HegoDriver getInstance() { - return Inner.sInstance; - } - - public void createPage(final String contextId, final String script, final String source) { - hegoJSEngine.prepareContext(contextId, script, source); - } - - public void destoryContext(String contextId) { - hegoJSEngine.destroyContext(contextId); - } - - -} diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoPanel.java b/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoPanel.java deleted file mode 100644 index 3490ab17..00000000 --- a/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoPanel.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.github.pengfeizhou.hego; - -import android.content.Context; -import android.os.Build; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.annotation.RequiresApi; -import android.util.AttributeSet; -import android.widget.FrameLayout; - -/** - * @Description: Hego - * @Author: pengfei.zhou - * @CreateDate: 2019-07-18 - */ -public class HegoPanel extends FrameLayout { - - private HegoContext mHegoContext; - - public HegoPanel(@NonNull Context context) { - super(context); - } - - public HegoPanel(@NonNull Context context, @Nullable AttributeSet attrs) { - super(context, attrs); - } - - public HegoPanel(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) - public HegoPanel(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } - - public void config(String script, String alias) { - HegoContext hegoContext = HegoContext.createContext(script, alias); - config(hegoContext); - } - - public void config(HegoContext hegoContext) { - mHegoContext = hegoContext; - } - - @Override - protected void onFinishInflate() { - super.onFinishInflate(); - } - - public HegoContext getHegoContext() { - return mHegoContext; - } -} diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/bridge/BaseModule.java b/Android/hego/src/main/java/com/github/pengfeizhou/hego/bridge/BaseModule.java deleted file mode 100644 index 0bfdd6a5..00000000 --- a/Android/hego/src/main/java/com/github/pengfeizhou/hego/bridge/BaseModule.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.github.pengfeizhou.hego.bridge; - -import com.github.pengfeizhou.hego.HegoContext; - -/** - * @Description: Android - * @Author: pengfei.zhou - * @CreateDate: 2019-07-18 - */ -public abstract class BaseModule { - private final HegoContext hegoContext; - - protected BaseModule(HegoContext hegoContext) { - this.hegoContext = hegoContext; - } - - public abstract String moduleName(); -} diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/bridge/ModalModule.java b/Android/hego/src/main/java/com/github/pengfeizhou/hego/bridge/ModalModule.java deleted file mode 100644 index 6bdefb36..00000000 --- a/Android/hego/src/main/java/com/github/pengfeizhou/hego/bridge/ModalModule.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.github.pengfeizhou.hego.bridge; - -import com.github.pengfeizhou.hego.HegoContext; -import com.github.pengfeizhou.hego.extension.HegoMethod; - -/** - * @Description: Hego - * @Author: pengfei.zhou - * @CreateDate: 2019-07-18 - */ -public class ModalModule extends BaseModule { - - protected ModalModule(HegoContext hegoContext) { - super(hegoContext); - } - - @Override - public String moduleName() { - return "modal"; - } - - @HegoMethod(name = "toast") - public void toast() { - - } -} diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/utils/HegoConstant.java b/Android/hego/src/main/java/com/github/pengfeizhou/hego/utils/HegoConstant.java deleted file mode 100644 index 0f432fcf..00000000 --- a/Android/hego/src/main/java/com/github/pengfeizhou/hego/utils/HegoConstant.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.github.pengfeizhou.hego.utils; - -/** - * @Description: Hego - * @Author: pengfei.zhou - * @CreateDate: 2019-07-18 - */ -public class HegoConstant { - public static final String INJECT_LOG = "nativeLog"; - public static final String INJECT_REQUIRE = "nativeRequire"; - public static final String INJECT_TIMER_SET = "nativeSetTimer"; - public static final String INJECT_TIMER_CLEAR = "nativeClearTimer"; - public static final String INJECT_BRIDGE = "nativeBridge"; - - public static final String TEMPLATE_CONTEXT_CREATE = "Reflect.apply(" + - "function(hego,context,require,exports){" + "\n" + - "%s" + "\n" + - "},hego.jsObtainContext(\"%s\"),[" + - "undefined," + - "hego.jsObtainContext(\"%s\")," + - "hego.__require__" + - ",{}" + - "])"; - - public static final String TEMPLATE_MODULE = "Reflect.apply(hego.jsRegisterModule,this,[" + - "\"%s\"," + - "Reflect.apply(function(__module){" + - "(function(module,exports,require){" + "\n" + - "%s" + "\n" + - "})(__module,__module.exports,hego.__require__);" + - "\nreturn __module.exports;" + - "},this,[{exports:{}}])" + - "])"; - public static final String TEMPLATE_CONTEXT_DESTORY = "hego.jsRelease(%s)"; - public static final String GLOBAL_HEGO = "hego"; - public static final String HEGO_CONTEXT_RELEASE = "jsReleaseContext"; - public static final String HEGO_CONTEXT_INVOKE = "jsCallEntityMethod"; - public static final String HEGO_TIMER_CALLBACK = "jsCallbackTimer"; -} diff --git a/Android/hego/src/main/res/values/strings.xml b/Android/hego/src/main/res/values/strings.xml deleted file mode 100644 index b5461315..00000000 --- a/Android/hego/src/main/res/values/strings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - HEGO - diff --git a/Android/settings.gradle b/Android/settings.gradle index d0723e1a..c6f1ccee 100644 --- a/Android/settings.gradle +++ b/Android/settings.gradle @@ -1 +1 @@ -include ':app', ':hego' +include ':app', ':doric' diff --git a/README.md b/README.md index 253dc8e9..39f692db 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# hego +# Doric A cross-platform development framework for Android & iOS diff --git a/js-framework/package.json b/js-framework/package.json index 0ff0621d..c1465a51 100644 --- a/js-framework/package.json +++ b/js-framework/package.json @@ -1,7 +1,7 @@ { - "name": "hego-js-framework", + "name": "doric-js-framework", "version": "0.1.0", - "description": "The JS Framework of Hego", + "description": "The JS Framework of Doric", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", @@ -11,14 +11,14 @@ }, "repository": { "type": "https", - "url": "https://github.com/penfeizhou/hego.git" + "url": "https://github.com/penfeizhou/doric.git" }, "author": "pengfeizhou", "license": "Apache-2.0", "bugs": { - "url": "https://github.com/penfeizhou/hego/issues" + "url": "https://github.com/penfeizhou/doric/issues" }, - "homepage": "https://github.com/penfeizhou/hego#readme", + "homepage": "https://github.com/penfeizhou/doric#readme", "dependencies": { "reflect-metadata": "^0.1.13", "rollup": "^1.17.0", diff --git a/js-framework/rollup.config.js b/js-framework/rollup.config.js index 8c1c3a38..2e848923 100644 --- a/js-framework/rollup.config.js +++ b/js-framework/rollup.config.js @@ -7,9 +7,9 @@ export default [ { input: "build/index.runtime.js", output: { - name: "hego", + name: "doric", format: "iife", - file: "bundle/hego-sandbox.js", + file: "bundle/doric-sandbox.js", }, sourceMap: true, plugins: [ @@ -21,7 +21,7 @@ export default [ input: "build/index.js", output: { format: "cjs", - file: "bundle/hego-lib.js", + file: "bundle/doric-lib.js", }, sourceMap: true, plugins: [