rename hego to doric

This commit is contained in:
pengfei.zhou 2019-07-19 10:27:09 +08:00
parent 6bcc9ffe49
commit 51c8924c2a
48 changed files with 340 additions and 424 deletions

7
Android/.gitignore vendored
View File

@ -1,12 +1,7 @@
*.iml *.iml
.gradle .gradle
/local.properties /local.properties
/.idea/caches /.idea/
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store .DS_Store
/build /build
/captures /captures

View File

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
</wildcardResourcePatterns>
</component>
</project>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>

View File

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
<option value="$PROJECT_DIR$/hego" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>

View File

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectInspectionProfilesVisibleTreeState">
<entry key="Project Default">
<profile-state>
<expanded-state>
<State>
<id />
</State>
<State>
<id>Android Lint</id>
</State>
</expanded-state>
</profile-state>
</entry>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>

View File

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

View File

@ -3,7 +3,7 @@ apply plugin: 'com.android.application'
android { android {
compileSdkVersion 28 compileSdkVersion 28
defaultConfig { defaultConfig {
applicationId "com.github.pengfeizhou.hego" applicationId "com.github.pengfeizhou.doric"
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 28 targetSdkVersion 28
versionCode 1 versionCode 1
@ -27,5 +27,5 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation project(':hego') implementation project(':doric')
} }

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.github.pengfeizhou.hegodemo"> package="com.github.pengfeizhou.doricdemo">
<application <application
android:name=".MyApplication" android:name=".MyApplication"
@ -10,7 +10,7 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity android:name="com.github.pengfeizhou.hegodemo.MainActivity"> <activity android:name=".MainActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />

View File

@ -1,10 +1,10 @@
package com.github.pengfeizhou.hegodemo; package com.github.pengfeizhou.doricdemo;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import com.github.pengfeizhou.hego.HegoContext; import com.github.pengfeizhou.doric.DoricContext;
import com.github.pengfeizhou.hego.utils.HegoUtils; import com.github.pengfeizhou.doric.utils.DoricUtils;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
@ -12,7 +12,7 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
HegoContext hegoContext = HegoContext.createContext(HegoUtils.readAssetFile("demo.js"), "demo"); DoricContext doricContext = DoricContext.createContext(DoricUtils.readAssetFile("demo.js"), "demo");
hegoContext.callEntity("log"); doricContext.callEntity("log");
} }
} }

View File

@ -1,11 +1,11 @@
package com.github.pengfeizhou.hegodemo; package com.github.pengfeizhou.doricdemo;
import android.app.Application; import android.app.Application;
import com.github.pengfeizhou.hego.Hego; import com.github.pengfeizhou.doric.Doric;
/** /**
* @Description: Hego * @Description: Doric
* @Author: pengfei.zhou * @Author: pengfei.zhou
* @CreateDate: 2019-07-18 * @CreateDate: 2019-07-18
*/ */
@ -13,6 +13,6 @@ public class MyApplication extends Application {
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
Hego.init(this); Doric.init(this);
} }
} }

View File

@ -1,3 +1,3 @@
<resources> <resources>
<string name="app_name">HEGO</string> <string name="app_name">Doric</string>
</resources> </resources>

View File

@ -1,4 +1,4 @@
package com.github.pengfeizhou.hego; package com.github.pengfeizhou.doric.test;
import android.content.Context; import android.content.Context;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
@ -21,6 +21,6 @@ public class ExampleInstrumentedTest {
// Context of the app under test. // Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext(); Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.github.pengfeizhou.hego.test", appContext.getPackageName()); assertEquals("com.github.pengfeizhou.doric.test", appContext.getPackageName());
} }
} }

View File

@ -1,2 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.github.pengfeizhou.hego" /> package="com.github.pengfeizhou.doric" />

View File

@ -1,4 +1,4 @@
package com.github.pengfeizhou.hego; package com.github.pengfeizhou.doric;
import android.app.Application; import android.app.Application;
@ -6,11 +6,11 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
/** /**
* @Description: Hego * @Description: Doric
* @Author: pengfei.zhou * @Author: pengfei.zhou
* @CreateDate: 2019-07-18 * @CreateDate: 2019-07-18
*/ */
public class Hego { public class Doric {
private static Application sApplication; private static Application sApplication;
public static void init(Application application) { public static void init(Application application) {
@ -23,11 +23,11 @@ public class Hego {
private static Map<String, String> bundles = new ConcurrentHashMap<>(); private static Map<String, String> bundles = new ConcurrentHashMap<>();
public static void registerJSModuleContent(String name, String bundle) { public static void registerJSBundle(String name, String bundle) {
bundles.put(name, bundle); bundles.put(name, bundle);
} }
public static String getJSModuleContent(String name) { public static String getJSBundle(String name) {
return bundles.get(name); return bundles.get(name);
} }
} }

View File

@ -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<JSDecoder> callEntity(String methodName, Object... args) {
return DoricDriver.getInstance().invokeContextMethod(mContextId, methodName, args);
}
public void teardown() {
DoricDriver.getInstance().destoryContext(mContextId);
}
}

View File

@ -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<JSDecoder> 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);
}
}

View File

@ -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;
}
}

View File

@ -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();
}

View File

@ -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() {
}
}

View File

@ -1,4 +1,4 @@
package com.github.pengfeizhou.hego.engine; package com.github.pengfeizhou.doric.engine;
import android.os.Handler; import android.os.Handler;
import android.os.HandlerThread; import android.os.HandlerThread;
@ -6,13 +6,13 @@ import android.os.Looper;
import android.os.Message; import android.os.Message;
import android.text.TextUtils; import android.text.TextUtils;
import com.github.pengfeizhou.hego.Hego; import com.github.pengfeizhou.doric.Doric;
import com.github.pengfeizhou.hego.extension.HegoBridgeExtension; import com.github.pengfeizhou.doric.extension.DoricBridgeExtension;
import com.github.pengfeizhou.hego.utils.HegoConstant; import com.github.pengfeizhou.doric.utils.DoricConstant;
import com.github.pengfeizhou.hego.utils.HegoLog; import com.github.pengfeizhou.doric.utils.DoricLog;
import com.github.pengfeizhou.hego.utils.HegoSettableFuture; import com.github.pengfeizhou.doric.utils.DoricSettableFuture;
import com.github.pengfeizhou.hego.extension.HegoTimerExtension; import com.github.pengfeizhou.doric.extension.DoricTimerExtension;
import com.github.pengfeizhou.hego.utils.HegoUtils; import com.github.pengfeizhou.doric.utils.DoricUtils;
import com.github.pengfeizhou.jscore.JSDecoder; import com.github.pengfeizhou.jscore.JSDecoder;
import com.github.pengfeizhou.jscore.JavaFunction; import com.github.pengfeizhou.jscore.JavaFunction;
import com.github.pengfeizhou.jscore.JavaValue; import com.github.pengfeizhou.jscore.JavaValue;
@ -22,17 +22,17 @@ import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
* @Description: Hego * @Description: Doric
* @Author: pengfei.zhou * @Author: pengfei.zhou
* @CreateDate: 2019-07-18 * @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 Handler mJSHandler;
private final HegoBridgeExtension mHegoBridgeExtensio; private final DoricBridgeExtension mDoricBridgeExtension;
private IHegoJSE mHegoJSE; private IDoricJSE mDoricJSE;
private HegoTimerExtension mTimerExtension; private DoricTimerExtension mTimerExtension;
public HegoJSEngine() { public DoricJSEngine() {
HandlerThread handlerThread = new HandlerThread(this.getClass().getSimpleName()); HandlerThread handlerThread = new HandlerThread(this.getClass().getSimpleName());
handlerThread.start(); handlerThread.start();
Looper looper = handlerThread.getLooper(); Looper looper = handlerThread.getLooper();
@ -44,14 +44,14 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC
initHugoRuntime(); initHugoRuntime();
} }
}); });
mTimerExtension = new HegoTimerExtension(looper, this); mTimerExtension = new DoricTimerExtension(looper, this);
mHegoBridgeExtensio = new HegoBridgeExtension(); mDoricBridgeExtension = new DoricBridgeExtension();
} }
private void initJSExecutor() { private void initJSExecutor() {
mHegoJSE = new HegoJSExecutor(); mDoricJSE = new DoricJSExecutor();
mHegoJSE.injectGlobalJSFunction(HegoConstant.INJECT_LOG, new JavaFunction() { mDoricJSE.injectGlobalJSFunction(DoricConstant.INJECT_LOG, new JavaFunction() {
@Override @Override
public JavaValue exec(JSDecoder[] args) { public JavaValue exec(JSDecoder[] args) {
try { try {
@ -59,13 +59,13 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC
String message = args[1].string(); String message = args[1].string();
switch (type) { switch (type) {
case "w": case "w":
HegoLog.w(message, "_js"); DoricLog.w(message, "_js");
break; break;
case "e": case "e":
HegoLog.e(message, "_js"); DoricLog.e(message, "_js");
break; break;
default: default:
HegoLog.d(message, "_js"); DoricLog.d(message, "_js");
break; break;
} }
} catch (Exception e) { } catch (Exception e) {
@ -74,17 +74,17 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC
return null; return null;
} }
}); });
mHegoJSE.injectGlobalJSFunction(HegoConstant.INJECT_REQUIRE, new JavaFunction() { mDoricJSE.injectGlobalJSFunction(DoricConstant.INJECT_REQUIRE, new JavaFunction() {
@Override @Override
public JavaValue exec(JSDecoder[] args) { public JavaValue exec(JSDecoder[] args) {
try { try {
String name = args[0].string(); String name = args[0].string();
String content = Hego.getJSModuleContent(name); String content = Doric.getJSBundle(name);
if (TextUtils.isEmpty(content)) { if (TextUtils.isEmpty(content)) {
HegoLog.e("error"); DoricLog.e("error");
return new JavaValue(false); return new JavaValue(false);
} }
mHegoJSE.loadJS(packageModuleScript(name, content), "Module://" + name); mDoricJSE.loadJS(packageModuleScript(name, content), "Module://" + name);
return new JavaValue(true); return new JavaValue(true);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); 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 @Override
public JavaValue exec(JSDecoder[] args) { public JavaValue exec(JSDecoder[] args) {
try { try {
@ -106,7 +106,7 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC
return null; return null;
} }
}); });
mHegoJSE.injectGlobalJSFunction(HegoConstant.INJECT_TIMER_CLEAR, new JavaFunction() { mDoricJSE.injectGlobalJSFunction(DoricConstant.INJECT_TIMER_CLEAR, new JavaFunction() {
@Override @Override
public JavaValue exec(JSDecoder[] args) { public JavaValue exec(JSDecoder[] args) {
try { try {
@ -117,7 +117,7 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC
return null; return null;
} }
}); });
mHegoJSE.injectGlobalJSFunction(HegoConstant.INJECT_BRIDGE, new JavaFunction() { mDoricJSE.injectGlobalJSFunction(DoricConstant.INJECT_BRIDGE, new JavaFunction() {
@Override @Override
public JavaValue exec(JSDecoder[] args) { public JavaValue exec(JSDecoder[] args) {
try { try {
@ -126,7 +126,7 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC
String method = args[2].string(); String method = args[2].string();
String callbackId = args[3].string(); String callbackId = args[3].string();
JSDecoder jsDecoder = args[4]; JSDecoder jsDecoder = args[4];
return mHegoBridgeExtensio.callNative(contextId, module, method, callbackId, jsDecoder); return mDoricBridgeExtension.callNative(contextId, module, method, callbackId, jsDecoder);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -136,10 +136,10 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC
} }
private void initHugoRuntime() { private void initHugoRuntime() {
loadBuiltinJS("hego-sandbox.js"); loadBuiltinJS(DoricConstant.DORIC_BUNDLE_SANDBOX);
String libName = "./index"; String libName = DoricConstant.DORIC_MODULE_LIB;
String libJS = HegoUtils.readAssetFile("hego-lib.js"); String libJS = DoricUtils.readAssetFile(DoricConstant.DORIC_BUNDLE_LIB);
mHegoJSE.loadJS(packageModuleScript(libName, libJS), "Module://" + libName); mDoricJSE.loadJS(packageModuleScript(libName, libJS), "Module://" + libName);
} }
@Override @Override
@ -148,19 +148,19 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC
} }
public void teardown() { public void teardown() {
mHegoJSE.teardown(); mDoricJSE.teardown();
} }
private void loadBuiltinJS(String assetName) { private void loadBuiltinJS(String assetName) {
String script = HegoUtils.readAssetFile(assetName); String script = DoricUtils.readAssetFile(assetName);
mHegoJSE.loadJS(script, "Assets://" + assetName); mDoricJSE.loadJS(script, "Assets://" + assetName);
} }
public void prepareContext(final String contextId, final String script, final String source) { public void prepareContext(final String contextId, final String script, final String source) {
Runnable runnable = new Runnable() { Runnable runnable = new Runnable() {
@Override @Override
public void run() { public void run() {
mHegoJSE.loadJS(packageContextScript(contextId, script), "Context://" + source); mDoricJSE.loadJS(packageContextScript(contextId, script), "Context://" + source);
} }
}; };
doOnJSThread(runnable); doOnJSThread(runnable);
@ -178,37 +178,37 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC
Runnable runnable = new Runnable() { Runnable runnable = new Runnable() {
@Override @Override
public void run() { 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); doOnJSThread(runnable);
} }
private String packageContextScript(String contextId, String content) { 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) { 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() { public boolean isJSThread() {
return Looper.myLooper() == mJSHandler.getLooper(); return Looper.myLooper() == mJSHandler.getLooper();
} }
public HegoSettableFuture<JSDecoder> invokeContextEntityMethod(final String contextId, final String method, final Object... args) { public DoricSettableFuture<JSDecoder> invokeContextEntityMethod(final String contextId, final String method, final Object... args) {
final Object[] nArgs = new Object[args.length + 2]; final Object[] nArgs = new Object[args.length + 2];
nArgs[0] = contextId; nArgs[0] = contextId;
nArgs[1] = method; nArgs[1] = method;
if (args.length > 0) { if (args.length > 0) {
System.arraycopy(args, 0, nArgs, 2, args.length); System.arraycopy(args, 0, nArgs, 2, args.length);
} }
return invokeHegoMethod(HegoConstant.HEGO_CONTEXT_INVOKE, nArgs); return invokeDoricMethod(DoricConstant.DORIC_CONTEXT_INVOKE, nArgs);
} }
public HegoSettableFuture<JSDecoder> invokeHegoMethod(final String method, final Object... args) { public DoricSettableFuture<JSDecoder> invokeDoricMethod(final String method, final Object... args) {
final HegoSettableFuture<JSDecoder> settableFuture = new HegoSettableFuture<>(); final DoricSettableFuture<JSDecoder> settableFuture = new DoricSettableFuture<>();
Runnable runnable = new Runnable() { Runnable runnable = new Runnable() {
@Override @Override
public void run() { public void run() {
@ -234,7 +234,7 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC
values.add(new JavaValue(String.valueOf(arg))); 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)); values.toArray(new JavaValue[values.size()]), true));
} }
}; };
@ -244,6 +244,6 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC
@Override @Override
public void callback(long timerId) { public void callback(long timerId) {
invokeHegoMethod(HegoConstant.HEGO_TIMER_CALLBACK, timerId); invokeDoricMethod(DoricConstant.DORIC_TIMER_CALLBACK, timerId);
} }
} }

View File

@ -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.JSDecoder;
import com.github.pengfeizhou.jscore.JSExecutor; import com.github.pengfeizhou.jscore.JSExecutor;
@ -7,15 +7,15 @@ import com.github.pengfeizhou.jscore.JavaFunction;
import com.github.pengfeizhou.jscore.JavaValue; import com.github.pengfeizhou.jscore.JavaValue;
/** /**
* @Description: Hego * @Description: Doric
* @Author: pengfei.zhou * @Author: pengfei.zhou
* @CreateDate: 2019-07-18 * @CreateDate: 2019-07-18
*/ */
public class HegoJSExecutor implements IHegoJSE { public class DoricJSExecutor implements IDoricJSE {
private final JSExecutor mJSExecutor; private final JSExecutor mJSExecutor;
public HegoJSExecutor() { public DoricJSExecutor() {
this.mJSExecutor = JSExecutor.create(); this.mJSExecutor = JSExecutor.create();
} }

View File

@ -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.JSDecoder;
import com.github.pengfeizhou.jscore.JSRuntimeException; import com.github.pengfeizhou.jscore.JSRuntimeException;
@ -6,11 +6,11 @@ import com.github.pengfeizhou.jscore.JavaFunction;
import com.github.pengfeizhou.jscore.JavaValue; import com.github.pengfeizhou.jscore.JavaValue;
/** /**
* @Description: Hego * @Description: Doric
* @Author: pengfei.zhou * @Author: pengfei.zhou
* @CreateDate: 2019-07-18 * @CreateDate: 2019-07-18
*/ */
public interface IHegoJSE { public interface IDoricJSE {
/** /**
* 执行JS语句 * 执行JS语句
* *

View File

@ -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.JSDecoder;
import com.github.pengfeizhou.jscore.JavaValue; import com.github.pengfeizhou.jscore.JavaValue;
/** /**
* @Description: Android * @Description: Doric
* @Author: pengfei.zhou * @Author: pengfei.zhou
* @CreateDate: 2019-07-18 * @CreateDate: 2019-07-18
*/ */
public class HegoBridgeExtension { public class DoricBridgeExtension {
public HegoBridgeExtension() { public DoricBridgeExtension() {
} }

View File

@ -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.Documented;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
@ -7,13 +7,13 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
/** /**
* @Description: Android * @Description: Doric
* @Author: pengfei.zhou * @Author: pengfei.zhou
* @CreateDate: 2019-07-18 * @CreateDate: 2019-07-18
*/ */
@Documented @Documented
@Target(ElementType.METHOD) @Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface HegoMethod { public @interface DoricMethod {
String name() default ""; String name() default "";
} }

View File

@ -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.Documented;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
@ -7,13 +7,13 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
/** /**
* @Description: Hego * @Description: Doric
* @Author: pengfei.zhou * @Author: pengfei.zhou
* @CreateDate: 2019-07-18 * @CreateDate: 2019-07-18
*/ */
@Documented @Documented
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface HegoModule { public @interface DoricModule {
String name() default ""; String name() default "";
} }

View File

@ -1,4 +1,4 @@
package com.github.pengfeizhou.hego.extension; package com.github.pengfeizhou.doric.extension;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
@ -8,18 +8,18 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
/** /**
* @Description: Android * @Description: Doric
* @Author: pengfei.zhou * @Author: pengfei.zhou
* @CreateDate: 2019-07-18 * @CreateDate: 2019-07-18
*/ */
public class HegoTimerExtension implements Handler.Callback { public class DoricTimerExtension implements Handler.Callback {
private static final int MSG_TIMER = 0; private static final int MSG_TIMER = 0;
private final Handler mTimerHandler; private final Handler mTimerHandler;
private final TimerCallback mTimerCallback; private final TimerCallback mTimerCallback;
private Set<Long> mDeletedTimerIds = new HashSet<>(); private Set<Long> mDeletedTimerIds = new HashSet<>();
public HegoTimerExtension(Looper looper, TimerCallback timerCallback) { public DoricTimerExtension(Looper looper, TimerCallback timerCallback) {
mTimerHandler = new Handler(looper, this); mTimerHandler = new Handler(looper, this);
mTimerCallback = timerCallback; mTimerCallback = timerCallback;
} }

View File

@ -1,17 +1,13 @@
package com.github.pengfeizhou.hego.extension; package com.github.pengfeizhou.doric.extension;
import android.text.TextUtils; import android.text.TextUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* @Description: Android * @Description: Doric
* @Author: pengfei.zhou * @Author: pengfei.zhou
* @CreateDate: 2019-07-18 * @CreateDate: 2019-07-18
*/ */
@ -34,12 +30,12 @@ public class ModuleClassInfo {
Method[] methods = clz.getMethods(); Method[] methods = clz.getMethods();
if (methods != null) { if (methods != null) {
for (Method method : methods) { for (Method method : methods) {
HegoMethod hegoMethod = method.getAnnotation(HegoMethod.class); DoricMethod doricMethod = method.getAnnotation(DoricMethod.class);
if (hegoMethod != null) { if (doricMethod != null) {
if (TextUtils.isEmpty(hegoMethod.name())) { if (TextUtils.isEmpty(doricMethod.name())) {
methodMap.put(method.getName(), method); methodMap.put(method.getName(), method);
} else { } else {
methodMap.put(hegoMethod.name(), method); methodMap.put(doricMethod.name(), method);
} }
} }
} }

View File

@ -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";
}

View File

@ -1,16 +1,16 @@
package com.github.pengfeizhou.hego.utils; package com.github.pengfeizhou.doric.utils;
import android.util.Log; import android.util.Log;
import com.github.pengfeizhou.hego.Hego; import com.github.pengfeizhou.doric.Doric;
/** /**
* @Description: Hego * @Description: Doric
* @Author: pengfei.zhou * @Author: pengfei.zhou
* @CreateDate: 2019-07-18 * @CreateDate: 2019-07-18
*/ */
public class HegoLog { public class DoricLog {
private static String TAG = Hego.class.getSimpleName(); private static String TAG = Doric.class.getSimpleName();
public static void d(String message, String... suffix) { public static void d(String message, String... suffix) {
StringBuilder stringBuilder = new StringBuilder(TAG); StringBuilder stringBuilder = new StringBuilder(TAG);

View File

@ -1,7 +1,7 @@
package com.github.pengfeizhou.hego.utils; package com.github.pengfeizhou.doric.utils;
/** /**
* @Description: Hego * @Description: Doric
* @Author: pengfei.zhou * @Author: pengfei.zhou
* @CreateDate: 2019-07-18 * @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. * A super simple Future-like class that can safely notify another Thread when a value is ready.
* Does not support setting errors or canceling. * Does not support setting errors or canceling.
*/ */
public class HegoSettableFuture<T> { public class DoricSettableFuture<T> {
private final CountDownLatch mReadyLatch = new CountDownLatch(1); private final CountDownLatch mReadyLatch = new CountDownLatch(1);
private volatile private volatile

View File

@ -1,22 +1,22 @@
package com.github.pengfeizhou.hego.utils; package com.github.pengfeizhou.doric.utils;
import android.content.res.AssetManager; import android.content.res.AssetManager;
import com.github.pengfeizhou.hego.Hego; import com.github.pengfeizhou.doric.Doric;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
/** /**
* @Description: Hego * @Description: Doric
* @Author: pengfei.zhou * @Author: pengfei.zhou
* @CreateDate: 2019-07-18 * @CreateDate: 2019-07-18
*/ */
public class HegoUtils { public class DoricUtils {
public static String readAssetFile(String assetFile) { public static String readAssetFile(String assetFile) {
InputStream inputStream = null; InputStream inputStream = null;
try { try {
AssetManager assetManager = Hego.application().getAssets(); AssetManager assetManager = Doric.application().getAssets();
inputStream = assetManager.open(assetFile); inputStream = assetManager.open(assetFile);
int length = inputStream.available(); int length = inputStream.available();
byte[] buffer = new byte[length]; byte[] buffer = new byte[length];

View File

@ -0,0 +1,3 @@
<resources>
<string name="app_name">Doric</string>
</resources>

View File

@ -1,4 +1,4 @@
package com.github.pengfeizhou.hego; package com.github.pengfeizhou.doric.test;
import org.junit.Test; import org.junit.Test;

View File

@ -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<JSDecoder> callEntity(String methodName, Object... args) {
return HegoDriver.getInstance().invokeContextMethod(mContextId, methodName, args);
}
public void teardown() {
HegoDriver.getInstance().destoryContext(mContextId);
}
}

View File

@ -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<JSDecoder> 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);
}
}

View File

@ -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;
}
}

View File

@ -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();
}

View File

@ -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() {
}
}

View File

@ -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";
}

View File

@ -1,3 +0,0 @@
<resources>
<string name="app_name">HEGO</string>
</resources>

View File

@ -1 +1 @@
include ':app', ':hego' include ':app', ':doric'

View File

@ -1,2 +1,2 @@
# hego # Doric
A cross-platform development framework for Android &amp; iOS A cross-platform development framework for Android &amp; iOS

View File

@ -1,7 +1,7 @@
{ {
"name": "hego-js-framework", "name": "doric-js-framework",
"version": "0.1.0", "version": "0.1.0",
"description": "The JS Framework of Hego", "description": "The JS Framework of Doric",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
@ -11,14 +11,14 @@
}, },
"repository": { "repository": {
"type": "https", "type": "https",
"url": "https://github.com/penfeizhou/hego.git" "url": "https://github.com/penfeizhou/doric.git"
}, },
"author": "pengfeizhou", "author": "pengfeizhou",
"license": "Apache-2.0", "license": "Apache-2.0",
"bugs": { "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": { "dependencies": {
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"rollup": "^1.17.0", "rollup": "^1.17.0",

View File

@ -7,9 +7,9 @@ export default [
{ {
input: "build/index.runtime.js", input: "build/index.runtime.js",
output: { output: {
name: "hego", name: "doric",
format: "iife", format: "iife",
file: "bundle/hego-sandbox.js", file: "bundle/doric-sandbox.js",
}, },
sourceMap: true, sourceMap: true,
plugins: [ plugins: [
@ -21,7 +21,7 @@ export default [
input: "build/index.js", input: "build/index.js",
output: { output: {
format: "cjs", format: "cjs",
file: "bundle/hego-lib.js", file: "bundle/doric-lib.js",
}, },
sourceMap: true, sourceMap: true,
plugins: [ plugins: [