Search in sources :

Example 1 with JSMethod

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

the class AbstractEditComponent method getSelectionRange.

@JSMethod
public void getSelectionRange(String callbackId) {
    EditText hostView;
    Map<String, Object> result = new HashMap<>(2);
    if ((hostView = getHostView()) != null) {
        int start = hostView.getSelectionStart();
        int end = hostView.getSelectionEnd();
        if (!hostView.hasFocus()) {
            //The default behavior, same as iOS and web
            start = 0;
            end = 0;
        }
        result.put(Constants.Name.SELECTION_START, start);
        result.put(Constants.Name.SELECTION_END, end);
    }
    WXBridgeManager.getInstance().callback(getInstanceId(), callbackId, result, false);
}
Also used : WXEditText(com.taobao.weex.ui.view.WXEditText) EditText(android.widget.EditText) HashMap(java.util.HashMap) WXDomObject(com.taobao.weex.dom.WXDomObject) JSMethod(com.taobao.weex.annotation.JSMethod)

Example 2 with JSMethod

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

the class AbstractEditComponent method setSelectionRange.

@JSMethod
public void setSelectionRange(int selectionStart, int selectionEnd) {
    EditText hostView;
    if ((hostView = getHostView()) != null) {
        focus();
        hostView.setSelection(selectionStart, selectionEnd);
    }
}
Also used : WXEditText(com.taobao.weex.ui.view.WXEditText) EditText(android.widget.EditText) JSMethod(com.taobao.weex.annotation.JSMethod)

Example 3 with JSMethod

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

the class AbstractEditComponent method focus.

@JSMethod
public void focus() {
    WXEditText host = getHostView();
    if (host != null && !host.hasFocus()) {
        if (getParent() != null) {
            getParent().ignoreFocus();
        }
        host.requestFocus();
        host.setFocusable(true);
        host.setFocusableInTouchMode(true);
        showSoftKeyboard();
    }
}
Also used : WXEditText(com.taobao.weex.ui.view.WXEditText) JSMethod(com.taobao.weex.annotation.JSMethod)

Example 4 with JSMethod

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

the class AbstractEditComponent method blur.

@JSMethod
public void blur() {
    WXEditText host = getHostView();
    if (host != null && host.hasFocus()) {
        if (getParent() != null) {
            getParent().interceptFocus();
        }
        host.clearFocus();
        hideSoftKeyboard();
    }
}
Also used : WXEditText(com.taobao.weex.ui.view.WXEditText) JSMethod(com.taobao.weex.annotation.JSMethod)

Example 5 with JSMethod

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

the class WXStreamModule method fetch.

/**
   *
   * @param optionsStr request options include:
   *  method: GET 、POST、PUT、DELETE、HEAD、PATCH
   *  headers:object,请求header
   *  url:
   *  body: "Any body that you want to add to your request"
   *  type: json、text、jsonp(native实现时等价与json)
   * @param callback finished callback,response object:
   *  status:status code
   *  ok:boolean 是否成功,等价于status200~299
   *  statusText:状态消息,用于定位具体错误原因
   *  data: 响应数据,当请求option中type为json,时data为object,否则data为string类型
   *  headers: object 响应头
   *
   * @param progressCallback in progress callback,for download progress and request state,response object:
   *  readyState: number 请求状态,1 OPENED,开始连接;2 HEADERS_RECEIVED;3 LOADING
   *  status:status code
   *  length:当前获取的字节数,总长度从headers里「Content-Length」获取
   *  statusText:状态消息,用于定位具体错误原因
   *  headers: object 响应头
   */
@JSMethod(uiThread = false)
public void fetch(String optionsStr, final JSCallback callback, JSCallback progressCallback) {
    JSONObject optionsObj = null;
    try {
        optionsObj = JSON.parseObject(optionsStr);
    } catch (JSONException e) {
        WXLogUtils.e("", e);
    }
    boolean invaildOption = optionsObj == null || optionsObj.getString("url") == null;
    if (invaildOption) {
        if (callback != null) {
            Map<String, Object> resp = new HashMap<>();
            resp.put("ok", false);
            resp.put(STATUS_TEXT, Status.ERR_INVALID_REQUEST);
            callback.invoke(resp);
        }
        return;
    }
    String method = optionsObj.getString("method");
    String url = optionsObj.getString("url");
    JSONObject headers = optionsObj.getJSONObject("headers");
    String body = optionsObj.getString("body");
    String type = optionsObj.getString("type");
    int timeout = optionsObj.getIntValue("timeout");
    if (method != null)
        method = method.toUpperCase();
    Options.Builder builder = new Options.Builder().setMethod(!"GET".equals(method) && !"POST".equals(method) && !"PUT".equals(method) && !"DELETE".equals(method) && !"HEAD".equals(method) && !"PATCH".equals(method) ? "GET" : method).setUrl(url).setBody(body).setType(type).setTimeout(timeout);
    extractHeaders(headers, builder);
    final Options options = builder.createOptions();
    sendRequest(options, new ResponseCallback() {

        @Override
        public void onResponse(WXResponse response, Map<String, String> headers) {
            if (callback != null) {
                Map<String, Object> resp = new HashMap<>();
                if (response == null || "-1".equals(response.statusCode)) {
                    resp.put(STATUS, -1);
                    resp.put(STATUS_TEXT, Status.ERR_CONNECT_FAILED);
                } else {
                    int code = Integer.parseInt(response.statusCode);
                    resp.put(STATUS, code);
                    resp.put("ok", (code >= 200 && code <= 299));
                    if (response.originalData == null) {
                        resp.put("data", null);
                    } else {
                        String respData = readAsString(response.originalData, headers != null ? getHeader(headers, "Content-Type") : "");
                        try {
                            resp.put("data", parseData(respData, options.getType()));
                        } catch (JSONException exception) {
                            WXLogUtils.e("", exception);
                            resp.put("ok", false);
                            resp.put("data", "{'err':'Data parse failed!'}");
                        }
                    }
                    resp.put(STATUS_TEXT, Status.getStatusText(response.statusCode));
                }
                resp.put("headers", headers);
                callback.invoke(resp);
            }
        }
    }, progressCallback);
}
Also used : HashMap(java.util.HashMap) JSONException(com.alibaba.fastjson.JSONException) WXResponse(com.taobao.weex.common.WXResponse) JSONObject(com.alibaba.fastjson.JSONObject) JSONObject(com.alibaba.fastjson.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map) 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