Search in sources :

Example 16 with JSCallback

use of com.taobao.weex.bridge.JSCallback in project incubator-weex by apache.

the class WXClipboardModuleTest method testGetString.

@Test
public void testGetString() throws Exception {
    JSCallback mock = Mockito.mock(JSCallback.class);
    module.getString(mock);
    Mockito.verify(mock, Mockito.times(1)).invoke(Mockito.anyObject());
    testSetString();
    mock = Mockito.mock(JSCallback.class);
    module.getString(mock);
    Mockito.verify(mock, Mockito.times(1)).invoke(Mockito.anyObject());
}
Also used : JSCallback(com.taobao.weex.bridge.JSCallback) Test(org.junit.Test) WXSDKInstanceTest(com.taobao.weex.WXSDKInstanceTest)

Example 17 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.eros.framework.manager.impl.RouterManager) JSCallback(com.taobao.weex.bridge.JSCallback)

Example 18 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(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.eros.framework.model.WeexEventBean) ArrayList(java.util.ArrayList) JSCallback(com.taobao.weex.bridge.JSCallback) JSMethod(com.taobao.weex.annotation.JSMethod)

Example 19 with JSCallback

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

the class WXNavigatorModule method open.

@JSMethod(uiThread = true)
public void open(JSONObject options, JSCallback success, JSCallback failure) {
    if (options != null) {
        String url = options.getString(Constants.Value.URL);
        JSCallback callback = success;
        JSONObject result = new JSONObject();
        if (!TextUtils.isEmpty(url)) {
            Uri rawUri = Uri.parse(url);
            String scheme = rawUri.getScheme();
            if (TextUtils.isEmpty(scheme) || Constants.Scheme.HTTP.equalsIgnoreCase(scheme) || Constants.Scheme.HTTPS.equalsIgnoreCase(scheme)) {
                this.push(options.toJSONString(), success);
            } else {
                try {
                    Intent intent = new Intent(Intent.ACTION_VIEW, rawUri);
                    mWXSDKInstance.getContext().startActivity(intent);
                    result.put(CALLBACK_RESULT, MSG_SUCCESS);
                } catch (Throwable e) {
                    e.printStackTrace();
                    result.put(CALLBACK_RESULT, MSG_FAILED);
                    result.put(CALLBACK_MESSAGE, "Open page failed.");
                    callback = failure;
                }
            }
        } else {
            result.put(CALLBACK_RESULT, MSG_PARAM_ERR);
            result.put(CALLBACK_MESSAGE, "The URL parameter is empty.");
            callback = failure;
        }
        if (callback != null) {
            callback.invoke(result);
        }
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) Intent(android.content.Intent) Uri(android.net.Uri) JSCallback(com.taobao.weex.bridge.JSCallback) JSMethod(com.taobao.weex.annotation.JSMethod)

Example 20 with JSCallback

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

the class WXClipboardModuleTest method testGetString.

@Test
public void testGetString() throws Exception {
    JSCallback mock = Mockito.mock(JSCallback.class);
    module.getString(mock);
    Mockito.verify(mock, Mockito.times(1)).invoke(Mockito.anyObject());
    testSetString();
    mock = Mockito.mock(JSCallback.class);
    module.getString(mock);
    Mockito.verify(mock, Mockito.times(1)).invoke(Mockito.anyObject());
}
Also used : JSCallback(com.taobao.weex.bridge.JSCallback) Test(org.junit.Test) WXSDKInstanceTest(com.taobao.weex.WXSDKInstanceTest)

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