@Test public void setViewport() throws Exception { JSONObject jsonObject = new JSONObject(); jsonObject.put(WXMetaModule.WIDTH,640); mMeta.setViewport(jsonObject.toString()); assertTrue(mMeta.mWXSDKInstance.getViewPortWidth() == 640); jsonObject.put(WXMetaModule.WIDTH,320.5); mMeta.setViewport(jsonObject.toString()); assertTrue(mMeta.mWXSDKInstance.getViewPortWidth() == 320); jsonObject.put(WXMetaModule.WIDTH,"-200"); mMeta.setViewport(jsonObject.toString()); assertTrue(mMeta.mWXSDKInstance.getViewPortWidth() == 320); jsonObject.put(WXMetaModule.WIDTH,"error"); mMeta.setViewport(jsonObject.toString()); assertTrue(mMeta.mWXSDKInstance.getViewPortWidth() == 320); mMeta.setViewport("ads"); assertTrue(mMeta.mWXSDKInstance.getViewPortWidth() == 320); }
@JSMethod(uiThread = false) public void setViewport(String param) { if (!TextUtils.isEmpty(param)) { try { param = URLDecoder.decode(param, "utf-8"); JSONObject jsObj = JSON.parseObject(param); if (DEVICE_WIDTH.endsWith(jsObj.getString(WIDTH))) { mWXSDKInstance.setViewPortWidth(WXViewUtils.getScreenWidth(mWXSDKInstance.getContext())); } else { int width = jsObj.getInteger(WIDTH); if (width > 0) { mWXSDKInstance.setViewPortWidth(width); } } } catch (Exception e) { WXLogUtils.e("[WXModalUIModule] alert param parse error ", e); } } }
WXMetaModule extends WXModule { @JSMethod(uiThread = false) public void setViewport(String param) { if (!TextUtils.isEmpty(param)) { try { param = URLDecoder.decode(param, "utf-8"); JSONObject jsObj = JSON.parseObject(param); if (DEVICE_WIDTH.endsWith(jsObj.getString(WIDTH))) { mWXSDKInstance.setViewPortWidth(WXViewUtils.getScreenWidth(mWXSDKInstance.getContext())); } else { int width = jsObj.getInteger(WIDTH); if (width > 0) { mWXSDKInstance.setViewPortWidth(width); } } } catch (Exception e) { WXLogUtils.e("[WXModalUIModule] alert param parse error ", e); } } } }
WXMetaModule extends WXModule { @JSMethod(uiThread = false) public void setViewport(String param) { if (!TextUtils.isEmpty(param)) { try { param = URLDecoder.decode(param, "utf-8"); JSONObject jsObj = JSON.parseObject(param); if (DEVICE_WIDTH.endsWith(jsObj.getString(WIDTH))) { mWXSDKInstance.setViewPortWidth(WXViewUtils.getScreenWidth(mWXSDKInstance.getContext())); } else { int width = jsObj.getInteger(WIDTH); if (width > 0) { mWXSDKInstance.setViewPortWidth(width); } } } catch (Exception e) { WXLogUtils.e("[WXModalUIModule] alert param parse error ", e); } } }  }
WXMetaModule extends WXModule { @JSMethod(uiThread = false) public void setViewport(String param) { if (!TextUtils.isEmpty(param)) { try { param = URLDecoder.decode(param, "utf-8"); JSONObject jsObj = JSON.parseObject(param); if (DEVICE_WIDTH.endsWith(jsObj.getString(WIDTH))) { mWXSDKInstance.setViewPortWidth(WXViewUtils.getScreenWidth(mWXSDKInstance.getContext())); } else { int width = jsObj.getInteger(WIDTH); if (width > 0) { mWXSDKInstance.setViewPortWidth(width); } } } catch (Exception e) { WXLogUtils.e("[WXModalUIModule] alert param parse error ", e); } } }  @JSMethod(uiThread = false) void setViewport(String param); }
WXMetaModule extends WXModule { @JSMethod(uiThread = false) public void setViewport(String param) { if (!TextUtils.isEmpty(param)) { try { param = URLDecoder.decode(param, "utf-8"); JSONObject jsObj = JSON.parseObject(param); if (DEVICE_WIDTH.endsWith(jsObj.getString(WIDTH))) { mWXSDKInstance.setViewPortWidth(WXViewUtils.getScreenWidth(mWXSDKInstance.getContext())); } else { int width = jsObj.getInteger(WIDTH); if (width > 0) { mWXSDKInstance.setViewPortWidth(width); } } } catch (Exception e) { WXLogUtils.e("[WXModalUIModule] alert param parse error ", e); } } }  @JSMethod(uiThread = false) void setViewport(String param); static final String WIDTH; static final String DEVICE_WIDTH; }