WXModalUIModule extends WXModule { @WXModuleAnno public void toast(String param) { String message = ""; int duration = Toast.LENGTH_SHORT; if (!TextUtils.isEmpty(param)) { try { param = URLDecoder.decode(param, "utf-8"); JSONObject jsObj = new JSONObject(param); message = jsObj.optString(MESSAGE); duration = jsObj.optInt(DURATION); } catch (Exception e) { WXLogUtils.e("[WXModalUIModule] alert param parse error ", e); } } if (TextUtils.isEmpty(message)) { WXLogUtils.e("[WXModalUIModule] toast param parse is null "); return; } if (duration > 3) { duration = Toast.LENGTH_LONG; } else { duration = Toast.LENGTH_SHORT; } if(toast== null){ toast =Toast.makeText(mWXSDKInstance.getContext(), message, duration); } else { toast.setDuration(duration); toast.setText(message); } toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); }  @WXModuleAnno void toast(String param); @WXModuleAnno void alert(String param, final JSCallback callback); @WXModuleAnno void confirm(String param, final JSCallback callback); @WXModuleAnno void prompt(String param, final JSCallback callback); static final String OK; static final String CANCEL; static final String RESULT; static final String DATA; static final String MESSAGE; static final String DURATION; static final String OK_TITLE; static final String CANCEL_TITLE; }
@Test public void testToast() throws Exception { module.toast("{}"); }