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);
}
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);
}
}
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();
}
}
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();
}
}
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);
}
Aggregations