一、WXEnvironment
1、static Map getConfig()
获取一些应用配置信息,如下包括:操作系统,app版本号,缓存目录,设备id等。
Map<String, String> configs = new HashMap<>();
configs.put(WXConfig.os, OS);
configs.put(WXConfig.appVersion, getAppVersionName());
configs.put(WXConfig.cacheDir, getAppCacheFile());
configs.put(WXConfig.devId, DEV_Id);
configs.put(WXConfig.sysVersion, SYS_VERSION);
configs.put(WXConfig.sysModel, SYS_MODEL);
configs.put(WXConfig.weexVersion, String.valueOf(WXSDK_VERSION));
configs.put(WXConfig.logLevel,sLogLevel.getName());
try {
if (isApkDebugable()) {
options.put(WXConfig.debugMode, "true");
}
options.put(WXConfig.scale, Float.toString(sApplication.getResources().getDisplayMetrics().density));
}catch (NullPointerException e){
//There is little chance of NullPointerException as sApplication may be null.
WXLogUtils.e("WXEnvironment scale Exception: ", e);
}
//这里讲自定义配置项放入config对象
configs.putAll(options);
if(configs!=null&&configs.get(WXConfig.appName)==null && sApplication!=null){
configs.put(WXConfig.appName, sApplication.getPackageName());
}
return configs;
2、添加和获取自定义配置项
设置的配置项都可以通过getConfig()获得值。
public static void addCustomOptions(String key, String value) {
options.put(key, value);
}
public static Map<String, String> getCustomOptions() {
return options;
}
3、检测当前硬件设备是否支持weex框架
public static boolean isSupport()
4、设置和获取apk是否可调式
public static void setApkDebugable(boolean debugable);
public static boolean isApkDebugable();
5、获取app磁盘缓存路径(短期存储,一段时间后会被删除)
public static String getDiskCacheDir(Context context)
6、设置和获取全局字体
public static void setGlobalFontFamily(String fontFamilyName, Typeface typeface)
public static String getGlobalFontFamilyName()
7、设置是否打开debug下的log输出
public static void setOpenDebugLog(boolean openDebugLog)
public static boolean isOpenDebugLog()
8、获取app文件保存目录(应用不被卸载就不会被删除)
public static String getFilesDir(Context context)
二、WXSDKInstance
1、监听界面根容器的显示和隐藏(appear、disappear)
public void addOnInstanceVisibleListener(OnInstanceVisibleListener l){
mVisibleListeners.add(l);
}
2、设置每个Component的观测器(监听),不要做任何影响界面渲染性能的事
public void setComponentObserver(ComponentObserver observer){
mComponentObserver = observer;
}
3、通过templatel渲染视图
public void render(String pageName, String template, Map<String, Object> options, String jsonInitData, WXRenderStrategy flag) {
mWXPerformance.beforeInstanceRender(mInstanceId);
if(WXEnvironment.isApkDebugable() && WXPerformance.DEFAULT.equals(pageName)){
WXLogUtils.e("WXSDKInstance", "Please set your pageName or your js bundle url !!!!!!!");
if (getUIContext() != null) {
new AlertDialog.Builder(getUIContext())
.setTitle("Error: Missing pageName")
.setMessage("We highly recommend you to set pageName. Call" +
"\nWXSDKInstance#render(String pageName, String template, Map<String, Object> options, String jsonInitData, WXRenderStrategy flag)\n" +
"to fix it.")
.show();
}
return;
}
4、通过Url渲染视图
public void renderByUrl(String pageName, final String url, Map<String, Object> options, final String jsonInitData, final WXRenderStrategy flag) {
renderByUrlInternal(pageName,url,options,jsonInitData,flag);
}
5、获取根视图
//<template>标签下的首个元素视图对象
public View getRootView() {
return mRootComp.getRealView();
}
//整个界面的容器,通常是xml布局
public View getContainerView() {
return mRenderContainer;
}
6、设置界面大小
public void setSize(int width, int height)
7、触发全局事件并传参
public void fireGlobalEventCallback(String eventName, Map<String,Object> params);
后续会持续补充。