WXModalUIModule extends WXModule { @WXModuleAnno public void prompt(String param, final JSCallback callback) { if (mWXSDKInstance.getContext() instanceof Activity) { String message = ""; String defaultValue = ""; String okTitle = OK; String cancelTitle = CANCEL; if (!TextUtils.isEmpty(param)) { try { param = URLDecoder.decode(param, "utf-8"); JSONObject jsObj = new JSONObject(param); message = jsObj.optString("message"); okTitle = jsObj.optString("okTitle"); cancelTitle = jsObj.optString("cancelTitle"); defaultValue = jsObj.optString("default"); } catch (Exception e) { WXLogUtils.e("[WXModalUIModule] confirm param parse error ", e); } } if (TextUtils.isEmpty(message)) { message=""; } AlertDialog.Builder builder = new AlertDialog.Builder(mWXSDKInstance.getContext()); builder.setMessage(message); final EditText editText = new EditText(mWXSDKInstance.getContext()); editText.setText(defaultValue); builder.setView(editText); final String okTitle_f = TextUtils.isEmpty(okTitle) ? OK : okTitle; final String cancelTitle_f = TextUtils.isEmpty(cancelTitle) ? CANCEL : cancelTitle; builder.setPositiveButton(okTitle_f, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if(callback != null){ Map<String, Object> result = new HashMap<String, Object>(); result.put(RESULT, okTitle_f); result.put(DATA, editText.getText().toString()); callback.invoke( result); } } }); builder.setNegativeButton(cancelTitle_f, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if(callback !=null){ Map<String, Object> result = new HashMap<String, Object>(); result.put(RESULT, cancelTitle_f); result.put(DATA, editText.getText().toString()); callback.invoke( result); } } }); AlertDialog alertDialog = builder.create(); alertDialog.setCanceledOnTouchOutside(false); alertDialog.show(); } else { WXLogUtils.e("when call prompt mWXSDKInstance.getContext() must instanceof Activity"); } }  @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 testPrompt() throws Exception { JSCallback callback = Mockito.mock(JSCallback.class); module.prompt("{}",callback); }