Search in sources :

Example 1 with SimpleJSCallback

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

the class WXSDKInstance method fireModuleEvent.

/**
   * Notifies WEEX that this event has occurred
   * @param eventName WEEX register event
   * @param module Events occur in this Module
   * @param params The parameters to be notified to WEEX are required
   */
public void fireModuleEvent(String eventName, WXModule module, Map<String, Object> params) {
    if (TextUtils.isEmpty(eventName) || module == null) {
        return;
    }
    Map<String, Object> event = new HashMap<>();
    event.put("type", eventName);
    event.put("module", module.getModuleName());
    event.put("data", params);
    List<String> callbacks = module.getEventCallbacks(eventName);
    if (callbacks != null) {
        for (String callback : callbacks) {
            SimpleJSCallback jsCallback = new SimpleJSCallback(mInstanceId, callback);
            if (module.isOnce(callback)) {
                jsCallback.invoke(event);
            } else {
                jsCallback.invokeAndKeepAlive(event);
            }
        }
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) SimpleJSCallback(com.taobao.weex.bridge.SimpleJSCallback) WXDomObject(com.taobao.weex.dom.WXDomObject) JSONObject(com.alibaba.fastjson.JSONObject)

Example 2 with SimpleJSCallback

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

the class GetComponentRectAction method executeRender.

@Override
public void executeRender(RenderActionContext context) {
    WXSDKInstance instance = context.getInstance();
    JSCallback jsCallback = new SimpleJSCallback(context.getInstance().getInstanceId(), mCallback);
    if (instance == null || instance.isDestroy()) {
    // do nothing
    } else if (TextUtils.isEmpty(mRef)) {
        Map<String, Object> options = new HashMap<>();
        options.put("result", false);
        options.put("errMsg", "Illegal parameter");
        jsCallback.invoke(options);
    } else if ("viewport".equalsIgnoreCase(mRef)) {
        callbackViewport(context, jsCallback);
    } else {
        WXComponent component = context.getComponent(mRef);
        Map<String, Object> options = new HashMap<>();
        if (component != null) {
            int viewPort = instance.getInstanceViewPortWidth();
            Map<String, Float> size = new HashMap<>();
            Rect sizes = component.getComponentSize();
            size.put("width", getWebPxValue(sizes.width(), viewPort));
            size.put("height", getWebPxValue(sizes.height(), viewPort));
            size.put("bottom", getWebPxValue(sizes.bottom, viewPort));
            size.put("left", getWebPxValue(sizes.left, viewPort));
            size.put("right", getWebPxValue(sizes.right, viewPort));
            size.put("top", getWebPxValue(sizes.top, viewPort));
            options.put("size", size);
            options.put("result", true);
        } else {
            options.put("errMsg", "Component does not exist");
        }
        jsCallback.invoke(options);
    }
}
Also used : Rect(android.graphics.Rect) WXComponent(com.taobao.weex.ui.component.WXComponent) HashMap(java.util.HashMap) JSCallback(com.taobao.weex.bridge.JSCallback) SimpleJSCallback(com.taobao.weex.bridge.SimpleJSCallback) WXSDKInstance(com.taobao.weex.WXSDKInstance) SimpleJSCallback(com.taobao.weex.bridge.SimpleJSCallback) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with SimpleJSCallback

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

the class UpdateComponentDataAction method executeRender.

@Override
public void executeRender(RenderActionContext context) {
    String ref = CellDataManager.getListRef(virtualComponentId);
    if (TextUtils.isEmpty(ref)) {
        WXLogUtils.e("wrong virtualComponentId split error " + virtualComponentId);
        return;
    }
    WXComponent component = context.getComponent(ref);
    if (component instanceof WXRecyclerTemplateList) {
        WXRecyclerTemplateList templateList = (WXRecyclerTemplateList) component;
        templateList.getCellDataManager().updateVirtualComponentData(virtualComponentId, data);
        templateList.notifyUpdateList();
        SimpleJSCallback jsCallback = new SimpleJSCallback(component.getInstanceId(), callback);
        jsCallback.invoke(true);
    } else {
        WXLogUtils.e("recycler-list wrong virtualComponentId " + virtualComponentId);
    }
}
Also used : WXRecyclerTemplateList(com.taobao.weex.ui.component.list.template.WXRecyclerTemplateList) WXComponent(com.taobao.weex.ui.component.WXComponent) SimpleJSCallback(com.taobao.weex.bridge.SimpleJSCallback)

Example 4 with SimpleJSCallback

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

the class DefaultLocation method watchPosition.

@Override
public void watchPosition(final String successCallback, final String errorCallback, final String params) {
    WXLogUtils.d("into--[watchPosition] successCallback:" + successCallback + " errorCallback:" + errorCallback + "\nparams:" + params);
    if (!TextUtils.isEmpty(params)) {
        try {
            JSONObject jsObj = new JSONObject(params);
            boolean enableHighAccuracy = jsObj.optBoolean("enableHighAccuracy");
            boolean enableAddress = jsObj.optBoolean("address");
            String id = UUID.randomUUID().toString();
            WXLocationListener listener = findLocation(id, successCallback, errorCallback, enableHighAccuracy, enableAddress);
            if (listener != null) {
                mRegisterSucCallbacks.put(id, listener);
            }
            return;
        } catch (JSONException e) {
            WXLogUtils.e(TAG, e);
        }
    }
    Map<String, Object> options = new HashMap<>();
    options.put(ERROR_CODE, ErrorCode.PARAMS_ERROR);
    options.put(ERROR_MSG, ErrorMsg.PARAMS_ERROR);
    if (mWXSDKInstance != null) {
        new SimpleJSCallback(mWXSDKInstance.getInstanceId(), errorCallback).invoke(options);
    }
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) SimpleJSCallback(com.taobao.weex.bridge.SimpleJSCallback) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject)

Example 5 with SimpleJSCallback

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

the class WXDomModule method getComponentRect.

/**
   * By ref the width and height of the component.
   *
   * @param ref      the refer of component
   * @param callback function id
   */
public void getComponentRect(String ref, String callback) {
    if (mWXSDKInstance == null) {
        return;
    }
    SimpleJSCallback jsCallback = new SimpleJSCallback(mWXSDKInstance.getInstanceId(), callback);
    if (TextUtils.isEmpty(ref)) {
        Map<String, Object> options = new HashMap<>();
        options.put("result", false);
        options.put("errMsg", "Illegal parameter");
        jsCallback.invoke(options);
        return;
    } else if ("viewport".equalsIgnoreCase(ref)) {
        if (mWXSDKInstance.getContainerView() != null) {
            Map<String, Object> options = new HashMap<>();
            Map<String, String> sizes = new HashMap<>();
            int[] location = new int[2];
            mWXSDKInstance.getContainerView().getLocationOnScreen(location);
            sizes.put("left", "0");
            sizes.put("top", "0");
            sizes.put("right", getWebPxValue(mWXSDKInstance.getContainerView().getWidth()));
            sizes.put("bottom", getWebPxValue(mWXSDKInstance.getContainerView().getHeight()));
            sizes.put("width", getWebPxValue(mWXSDKInstance.getContainerView().getWidth()));
            sizes.put("height", getWebPxValue(mWXSDKInstance.getContainerView().getHeight()));
            options.put("size", sizes);
            options.put("result", true);
            jsCallback.invoke(options);
        } else {
            Map<String, Object> options = new HashMap<>();
            options.put("result", false);
            options.put("errMsg", "Component does not exist");
            jsCallback.invoke(options);
        }
    } else {
        Message msg = Message.obtain();
        WXDomTask task = new WXDomTask();
        task.instanceId = mWXSDKInstance.getInstanceId();
        task.args = new ArrayList<>();
        task.args.add(ref);
        task.args.add(jsCallback);
        msg.what = WXDomHandler.MsgType.WX_COMPONENT_SIZE;
        msg.obj = task;
        WXSDKManager.getInstance().getWXDomManager().sendMessage(msg);
    }
}
Also used : Message(android.os.Message) HashMap(java.util.HashMap) SimpleJSCallback(com.taobao.weex.bridge.SimpleJSCallback) ArrayList(java.util.ArrayList) JSONObject(com.alibaba.fastjson.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

SimpleJSCallback (com.taobao.weex.bridge.SimpleJSCallback)8 HashMap (java.util.HashMap)7 JSONObject (com.alibaba.fastjson.JSONObject)3 JSONObject (org.json.JSONObject)3 WXDomObject (com.taobao.weex.dom.WXDomObject)2 WXComponent (com.taobao.weex.ui.component.WXComponent)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 JSONException (org.json.JSONException)2 Rect (android.graphics.Rect)1 Criteria (android.location.Criteria)1 Message (android.os.Message)1 WXSDKInstance (com.taobao.weex.WXSDKInstance)1 JSCallback (com.taobao.weex.bridge.JSCallback)1 WXRecyclerTemplateList (com.taobao.weex.ui.component.list.template.WXRecyclerTemplateList)1 ArrayList (java.util.ArrayList)1