android:custimze Environment
This commit is contained in:
@@ -66,6 +66,7 @@ public class DoricRegistry {
|
||||
private static Map<String, String> bundles = new ConcurrentHashMap<>();
|
||||
private static Set<DoricLibrary> doricLibraries = new HashSet<>();
|
||||
private static Set<IDoricJSLoader> jsLoaders = new HashSet<>();
|
||||
private Map<String, Object> extendedEnvValues = new HashMap<>();
|
||||
|
||||
static {
|
||||
addJSLoader(new DoricAssetJSLoader());
|
||||
@@ -154,4 +155,12 @@ public class DoricRegistry {
|
||||
public static Collection<IDoricJSLoader> getJSLoaders() {
|
||||
return jsLoaders;
|
||||
}
|
||||
|
||||
public void setEnvironmentVariabel(String key, Object val) {
|
||||
extendedEnvValues.put(key, val);
|
||||
}
|
||||
|
||||
public Map<String, Object> getEnvironmentVariables() {
|
||||
return extendedEnvValues;
|
||||
}
|
||||
}
|
||||
|
@@ -30,6 +30,7 @@ import com.github.pengfeizhou.jscore.JavaFunction;
|
||||
import com.github.pengfeizhou.jscore.JavaValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import pub.doric.Doric;
|
||||
import pub.doric.DoricRegistry;
|
||||
@@ -91,14 +92,22 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
mDoricJSE.injectGlobalJSObject(DoricConstant.INJECT_ENVIRONMENT, new JavaValue(new JSONBuilder()
|
||||
JSONBuilder envObject = new JSONBuilder()
|
||||
.put("platform", "Android")
|
||||
.put("platformVersion", String.valueOf(android.os.Build.VERSION.SDK_INT))
|
||||
.put("appName", appName)
|
||||
.put("appVersion", appVersion)
|
||||
.put("screenWidth", DoricUtils.px2dp(DoricUtils.getScreenWidth()))
|
||||
.put("screenHeight", DoricUtils.px2dp(DoricUtils.getScreenHeight()))
|
||||
.toJSONObject()));
|
||||
.put("screenHeight", DoricUtils.px2dp(DoricUtils.getScreenHeight()));
|
||||
|
||||
Map<String, Object> extend = mDoricRegistry.getEnvironmentVariables();
|
||||
for (String key : extend.keySet()) {
|
||||
envObject.put(key, extend.get(key));
|
||||
}
|
||||
|
||||
mDoricJSE.injectGlobalJSObject(DoricConstant.INJECT_ENVIRONMENT,
|
||||
new JavaValue(envObject.toJSONObject()));
|
||||
|
||||
mDoricJSE.injectGlobalJSFunction(DoricConstant.INJECT_LOG, new JavaFunction() {
|
||||
@Override
|
||||
public JavaValue exec(JSDecoder[] args) {
|
||||
|
Reference in New Issue
Block a user