Search in sources :

Example 1 with JSCallback

use of com.taobao.weex.bridge.JSCallback in project weex-example by KalicyZhou.

the class WXStreamModuleTest method testFetchRequestHttpbinCallback.

@Test
public void testFetchRequestHttpbinCallback() throws Exception {
    WXStreamModule streamModule = createModule(new DefaultWXHttpAdapter());
    JSCallback progress = mock(JSCallback.class);
    JSCallback finish = mock(JSCallback.class);
    System.out.print("request start " + System.currentTimeMillis());
    streamModule.fetch("{method: 'POST',url: 'http://httpbin.org/post',type:'json'}", finish, progress);
    verify(progress, timeout(10 * 1000).atLeastOnce()).invokeAndKeepAlive(anyMapOf(String.class, Object.class));
    verify(finish, timeout(10 * 1000).times(1)).invoke(anyMapOf(String.class, Object.class));
    System.out.print("\nrequest finish" + System.currentTimeMillis());
}
Also used : DefaultWXHttpAdapter(com.taobao.weex.adapter.DefaultWXHttpAdapter) JSCallback(com.taobao.weex.bridge.JSCallback) Test(org.junit.Test) WXSDKInstanceTest(com.taobao.weex.WXSDKInstanceTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with JSCallback

use of com.taobao.weex.bridge.JSCallback in project weex-example by KalicyZhou.

the class WXModalUIModuleTest method testPrompt.

@Test
public void testPrompt() throws Exception {
    JSCallback callback = Mockito.mock(JSCallback.class);
    module.prompt("{}", callback);
}
Also used : JSCallback(com.taobao.weex.bridge.JSCallback) Test(org.junit.Test) WXSDKInstanceTest(com.taobao.weex.WXSDKInstanceTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with JSCallback

use of com.taobao.weex.bridge.JSCallback in project WeexErosFramework by bmfe.

the class EventOpen method open.

public void open(String params, Context context, List<JSCallback> callbacks) {
    JSCallback backCallback = null;
    JSCallback resultCallback = null;
    if (callbacks.size() > 1) {
        backCallback = callbacks.get(0);
        resultCallback = callbacks.get(1);
    } else if (callbacks.size() > 0) {
        backCallback = callbacks.get(0);
    }
    RouterManager routerManager = ManagerFactory.getManagerService(RouterManager.class);
    boolean result = routerManager.open(context, params, backCallback);
    if (resultCallback != null) {
        resultCallback.invoke(result ? WXConstant.OPEN_PAGE_SUCCESS : WXConstant.OPNE_PAGE_FAILED);
    }
}
Also used : RouterManager(com.benmu.framework.manager.impl.RouterManager) JSCallback(com.taobao.weex.bridge.JSCallback)

Example 4 with JSCallback

use of com.taobao.weex.bridge.JSCallback in project WeexErosFramework by bmfe.

the class ModalModule method confirm.

@JSMethod(uiThread = true)
public void confirm(String options, final JSCallback cancel, final JSCallback ok) {
    WeexEventBean eventBean = new WeexEventBean();
    eventBean.setContext(mWXSDKInstance.getContext());
    eventBean.setKey(WXConstant.WXEventCenter.EVENT_MODAL_CONFIRM);
    eventBean.setJsParams(options);
    ArrayList<JSCallback> jsCallbacks = new ArrayList<>();
    jsCallbacks.add(cancel);
    jsCallbacks.add(ok);
    eventBean.setCallbacks(jsCallbacks);
    ManagerFactory.getManagerService(DispatchEventManager.class).getBus().post(eventBean);
}
Also used : WeexEventBean(com.benmu.framework.model.WeexEventBean) ArrayList(java.util.ArrayList) JSCallback(com.taobao.weex.bridge.JSCallback) JSMethod(com.taobao.weex.annotation.JSMethod)

Example 5 with JSCallback

use of com.taobao.weex.bridge.JSCallback in project WeexErosFramework by bmfe.

the class RouterModule method open.

@JSMethod(uiThread = true)
public void open(String params, JSCallback backCallback, JSCallback resultCallback) {
    WeexEventBean eventBean = new WeexEventBean();
    eventBean.setKey(WXConstant.WXEventCenter.EVENT_OPEN);
    eventBean.setJsParams(params);
    ArrayList<JSCallback> callBacks = new ArrayList<>();
    callBacks.add(backCallback);
    callBacks.add(resultCallback);
    eventBean.setCallbacks(callBacks);
    eventBean.setContext(mWXSDKInstance.getContext());
    ManagerFactory.getManagerService(DispatchEventManager.class).getBus().post(eventBean);
}
Also used : WeexEventBean(com.benmu.framework.model.WeexEventBean) ArrayList(java.util.ArrayList) JSCallback(com.taobao.weex.bridge.JSCallback) JSMethod(com.taobao.weex.annotation.JSMethod)

Aggregations

JSCallback (com.taobao.weex.bridge.JSCallback)33 JSMethod (com.taobao.weex.annotation.JSMethod)12 WXSDKInstanceTest (com.taobao.weex.WXSDKInstanceTest)10 Test (org.junit.Test)10 JSONObject (com.alibaba.fastjson.JSONObject)9 ArrayList (java.util.ArrayList)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 HashMap (java.util.HashMap)6 Map (java.util.Map)5 Activity (android.app.Activity)4 Context (android.content.Context)4 WeexEventBean (com.benmu.framework.model.WeexEventBean)4 DialogInterface (android.content.DialogInterface)2 Intent (android.content.Intent)2 Color (android.graphics.Color)2 Uri (android.net.Uri)2 AppCompatActivity (android.support.v7.app.AppCompatActivity)2 View (android.view.View)2 FrameLayout (android.widget.FrameLayout)2 JSONArray (com.alibaba.fastjson.JSONArray)2