Search in sources :

Example 11 with JSMethod

use of com.taobao.weex.annotation.JSMethod in project weex-example by KalicyZhou.

the class WXModalUIModule method toast.

@JSMethod(uiThread = true)
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 = JSON.parseObject(param);
            message = jsObj.getString(MESSAGE);
            duration = jsObj.getInteger(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();
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSMethod(com.taobao.weex.annotation.JSMethod)

Example 12 with JSMethod

use of com.taobao.weex.annotation.JSMethod in project weex-example by KalicyZhou.

the class WXClipboardModule method getString.

@Override
@JSMethod
public void getString(@Nullable JSCallback callback) {
    Context context = mWXSDKInstance.getContext();
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    Map<String, Object> map = new HashMap<>(2);
    ClipData clip = clipboard.getPrimaryClip();
    if (clip != null && clip.getItemCount() > 0) {
        ClipData.Item item = clip.getItemAt(0);
        CharSequence text = coerceToText(context, item);
        map.put(RESULT, text != null ? RESULT_OK : RESULT_FAILED);
        map.put(DATA, text != null ? text : "");
    } else {
        map.put(RESULT, RESULT_FAILED);
        map.put(DATA, "");
    }
    if (null != callback) {
        callback.invoke(map);
    }
}
Also used : Context(android.content.Context) ClipboardManager(android.content.ClipboardManager) HashMap(java.util.HashMap) ClipData(android.content.ClipData) JSMethod(com.taobao.weex.annotation.JSMethod)

Example 13 with JSMethod

use of com.taobao.weex.annotation.JSMethod in project WeexErosFramework by bmfe.

the class AxiosModule method fetch.

@JSMethod(uiThread = false)
public void fetch(String params, final JSCallback jsCallback) {
    WeexEventBean eventBean = new WeexEventBean();
    eventBean.setContext(mWXSDKInstance.getContext());
    eventBean.setKey(WXConstant.WXEventCenter.EVENT_FETCH);
    eventBean.setJsParams(params);
    eventBean.setJscallback(jsCallback);
    ManagerFactory.getManagerService(DispatchEventManager.class).getBus().post(eventBean);
}
Also used : WeexEventBean(com.benmu.framework.model.WeexEventBean) JSMethod(com.taobao.weex.annotation.JSMethod)

Example 14 with JSMethod

use of com.taobao.weex.annotation.JSMethod in project WeexErosFramework by bmfe.

the class BrowserImgModule method open.

@JSMethod(uiThread = true)
public void open(String json) {
    WeexEventBean eventBean = new WeexEventBean();
    eventBean.setContext(mWXSDKInstance.getContext());
    eventBean.setKey(WXConstant.WXEventCenter.EVENT_BROWSERIMG);
    eventBean.setJsParams(json);
    ManagerFactory.getManagerService(DispatchEventManager.class).getBus().post(eventBean);
}
Also used : WeexEventBean(com.benmu.framework.model.WeexEventBean) JSMethod(com.taobao.weex.annotation.JSMethod)

Example 15 with JSMethod

use of com.taobao.weex.annotation.JSMethod in project WeexErosFramework by bmfe.

the class CameraModule method uploadScreenshot.

@JSMethod(uiThread = true)
public void uploadScreenshot(JSCallback callback) {
    WeexEventBean eventBean = new WeexEventBean();
    eventBean.setContext(mWXSDKInstance.getContext());
    eventBean.setKey(WXConstant.WXEventCenter.EVENT_CAMERA_UPLOADSCREENSHOT);
    eventBean.setJscallback(callback);
    ManagerFactory.getManagerService(DispatchEventManager.class).getBus().post(eventBean);
}
Also used : WeexEventBean(com.benmu.framework.model.WeexEventBean) JSMethod(com.taobao.weex.annotation.JSMethod)

Aggregations

JSMethod (com.taobao.weex.annotation.JSMethod)198 WeexEventBean (com.eros.framework.model.WeexEventBean)53 WeexEventBean (com.benmu.framework.model.WeexEventBean)50 JSONObject (com.alibaba.fastjson.JSONObject)32 ArrayList (java.util.ArrayList)25 HashMap (java.util.HashMap)20 Intent (android.content.Intent)19 JSCallback (com.taobao.weex.bridge.JSCallback)12 Activity (android.app.Activity)11 WXEditText (com.taobao.weex.ui.view.WXEditText)8 Map (java.util.Map)8 Uri (android.net.Uri)7 AlertDialog (android.app.AlertDialog)6 Context (android.content.Context)6 DialogInterface (android.content.DialogInterface)6 OnClickListener (android.content.DialogInterface.OnClickListener)6 EditText (android.widget.EditText)6 JSONException (com.alibaba.fastjson.JSONException)6 Invoker (com.taobao.weex.bridge.Invoker)5 MethodInvoker (com.taobao.weex.bridge.MethodInvoker)5