android:custimze Environment
This commit is contained in:
parent
ade6d63479
commit
b9a2065f8a
@ -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) {
|
||||
|
21
doric-js/index.d.ts
vendored
21
doric-js/index.d.ts
vendored
@ -28,12 +28,13 @@ declare module 'doric/lib/src/runtime/global' {
|
||||
libVersion: string;
|
||||
screenWidth: number;
|
||||
screenHeight: number;
|
||||
[index: string]: number | string | boolean | object | undefined;
|
||||
};
|
||||
function Entry(constructor: {
|
||||
new (...args: any[]): {};
|
||||
new(...args: any[]): {};
|
||||
}): any;
|
||||
}
|
||||
export {};
|
||||
export { };
|
||||
}
|
||||
|
||||
declare module 'doric/lib/src/ui/index.ui' {
|
||||
@ -386,7 +387,7 @@ declare module 'doric/lib/src/ui/animation' {
|
||||
delay: number | undefined;
|
||||
};
|
||||
}
|
||||
export {};
|
||||
export { };
|
||||
}
|
||||
|
||||
declare module 'doric/lib/src/widget/layouts' {
|
||||
@ -417,7 +418,7 @@ declare module 'doric/lib/src/widget/layouts' {
|
||||
export function stack(views: View[], config?: IStack): Stack;
|
||||
export function hlayout(views: View[], config?: IHLayout): HLayout;
|
||||
export function vlayout(views: View[], config?: IVLayout): VLayout;
|
||||
export {};
|
||||
export { };
|
||||
}
|
||||
|
||||
declare module 'doric/lib/src/widget/text' {
|
||||
@ -981,7 +982,7 @@ declare module 'doric/lib/src/util/types' {
|
||||
bind(binder: Binder<T>): void;
|
||||
static of<E>(v: E): Mutable<E>;
|
||||
}
|
||||
export {};
|
||||
export { };
|
||||
}
|
||||
|
||||
declare module 'doric/lib/src/util/uniqueId' {
|
||||
@ -1009,7 +1010,7 @@ declare module 'doric/lib/src/pattern/provider' {
|
||||
}
|
||||
export class Observable<M> implements IObservable<M> {
|
||||
constructor(provider: IProvider, clz: {
|
||||
new (...args: any[]): M;
|
||||
new(...args: any[]): M;
|
||||
});
|
||||
addObserver(observer: Observer<M | undefined>): void;
|
||||
removeObserver(observer: Observer<M | undefined>): void;
|
||||
@ -1018,20 +1019,20 @@ declare module 'doric/lib/src/pattern/provider' {
|
||||
export interface IProvider {
|
||||
provide(obj: Object): void;
|
||||
acquire<T>(clz: {
|
||||
new (...args: any[]): T;
|
||||
new(...args: any[]): T;
|
||||
}): T | undefined;
|
||||
remove<T>(clz: {
|
||||
new (...args: any[]): T;
|
||||
new(...args: any[]): T;
|
||||
}): void;
|
||||
clear(): void;
|
||||
observe<T>(clz: {
|
||||
new (...args: any[]): T;
|
||||
new(...args: any[]): T;
|
||||
}): Observable<T>;
|
||||
}
|
||||
export class Provider implements IProvider {
|
||||
provide(obj: Object): void;
|
||||
acquire<T>(clz: {
|
||||
new (...args: any[]): T;
|
||||
new(...args: any[]): T;
|
||||
}): T | undefined;
|
||||
remove<T>(clz: new (...args: any[]) => T): void;
|
||||
clear(): void;
|
||||
|
3
doric-js/lib/src/runtime/global.d.ts
vendored
3
doric-js/lib/src/runtime/global.d.ts
vendored
@ -7,13 +7,14 @@ export declare type BridgeContext = {
|
||||
declare global {
|
||||
const context: BridgeContext;
|
||||
const Environment: {
|
||||
platform: "Android" | "iOS" | "Qt" | "h5";
|
||||
platform: "Android" | "iOS" | "Qt" | "web";
|
||||
platformVersion: string;
|
||||
appName: string;
|
||||
appVersion: string;
|
||||
libVersion: string;
|
||||
screenWidth: number;
|
||||
screenHeight: number;
|
||||
[index: string]: number | string | boolean | object | undefined;
|
||||
};
|
||||
function Entry(constructor: {
|
||||
new (...args: any[]): {};
|
||||
|
@ -22,7 +22,7 @@ export type BridgeContext = {
|
||||
declare global {
|
||||
const context: BridgeContext
|
||||
const Environment: {
|
||||
platform: "Android" | "iOS" | "Qt" | "h5",
|
||||
platform: "Android" | "iOS" | "Qt" | "web",
|
||||
|
||||
platformVersion: string,
|
||||
|
||||
@ -36,6 +36,7 @@ declare global {
|
||||
|
||||
screenHeight: number,
|
||||
|
||||
[index: string]: number | string | boolean | object | undefined
|
||||
}
|
||||
function Entry(constructor: { new(...args: any[]): {} }): any
|
||||
}
|
||||
|
Reference in New Issue
Block a user