use of com.taobao.weex.annotation.JSMethod 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);
}
}
}
use of com.taobao.weex.annotation.JSMethod in project weex-example by KalicyZhou.
the class WXNavigatorModule method setNavBarHidden.
@JSMethod
public void setNavBarHidden(String param, final String callback) {
String message = MSG_FAILED;
try {
JSONObject jsObj = JSON.parseObject(param);
int visibility = jsObj.getInteger(Constants.Name.NAV_BAR_VISIBILITY);
boolean success = changeVisibilityOfActionBar(mWXSDKInstance.getContext(), visibility);
if (success) {
message = MSG_SUCCESS;
}
} catch (JSONException e) {
WXLogUtils.e(TAG, WXLogUtils.getStackTrace(e));
}
WXBridgeManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callback, message);
}
use of com.taobao.weex.annotation.JSMethod in project weex-example by KalicyZhou.
the class WXClipboardModule method setString.
@Override
@JSMethod
public void setString(String text) {
if (null == text) {
return;
}
Context context = mWXSDKInstance.getContext();
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText(CLIP_KEY, text);
clipboard.setPrimaryClip(clip);
}
use of com.taobao.weex.annotation.JSMethod in project weex-example by KalicyZhou.
the class WXModalUIModule method prompt.
@JSMethod(uiThread = true)
public void prompt(String param, final JSCallback callback) {
if (mWXSDKInstance.getContext() instanceof Activity) {
String message = "";
String defaultValue = "";
String okTitle = OK;
String cancelTitle = CANCEL;
if (!TextUtils.isEmpty(param)) {
try {
param = URLDecoder.decode(param, "utf-8");
JSONObject jsObj = JSON.parseObject(param);
message = jsObj.getString(MESSAGE);
okTitle = jsObj.getString(OK_TITLE);
cancelTitle = jsObj.getString(CANCEL_TITLE);
defaultValue = jsObj.getString(DEFAULT);
} catch (Exception e) {
WXLogUtils.e("[WXModalUIModule] confirm param parse error ", e);
}
}
if (TextUtils.isEmpty(message)) {
message = "";
}
AlertDialog.Builder builder = new AlertDialog.Builder(mWXSDKInstance.getContext());
builder.setMessage(message);
final EditText editText = new EditText(mWXSDKInstance.getContext());
editText.setText(defaultValue);
builder.setView(editText);
final String okTitleFinal = TextUtils.isEmpty(okTitle) ? OK : okTitle;
final String cancelTitleFinal = TextUtils.isEmpty(cancelTitle) ? CANCEL : cancelTitle;
builder.setPositiveButton(okTitleFinal, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (callback != null) {
Map<String, Object> result = new HashMap<String, Object>();
result.put(RESULT, okTitleFinal);
result.put(DATA, editText.getText().toString());
callback.invoke(result);
}
}
}).setNegativeButton(cancelTitleFinal, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (callback != null) {
Map<String, Object> result = new HashMap<String, Object>();
result.put(RESULT, cancelTitleFinal);
result.put(DATA, editText.getText().toString());
callback.invoke(result);
}
}
});
AlertDialog alertDialog = builder.create();
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.show();
tracking(alertDialog);
} else {
WXLogUtils.e("when call prompt mWXSDKInstance.getContext() must instanceof Activity");
}
}
use of com.taobao.weex.annotation.JSMethod in project weex-example by KalicyZhou.
the class SimpleComponentHolder method getMethods.
static Pair<Map<String, Invoker>, Map<String, Invoker>> getMethods(Class clz) {
Map<String, Invoker> methods = new HashMap<>();
Map<String, Invoker> mInvokers = new HashMap<>();
Annotation[] annotations;
Annotation anno;
try {
for (Method method : clz.getMethods()) {
try {
annotations = method.getDeclaredAnnotations();
for (int i = 0, annotationsCount = annotations.length; i < annotationsCount; ++i) {
anno = annotations[i];
if (anno == null) {
continue;
}
if (anno instanceof WXComponentProp) {
String name = ((WXComponentProp) anno).name();
methods.put(name, new MethodInvoker(method, true));
break;
} else if (anno instanceof JSMethod) {
JSMethod methodAnno = (JSMethod) anno;
String name = methodAnno.alias();
if (JSMethod.NOT_SET.equals(name)) {
name = method.getName();
}
mInvokers.put(name, new MethodInvoker(method, methodAnno.uiThread()));
break;
}
}
} catch (ArrayIndexOutOfBoundsException | IncompatibleClassChangeError e) {
//ignore: getDeclaredAnnotations may throw this
}
}
} catch (IndexOutOfBoundsException e) {
e.printStackTrace();
//ignore: getMethods may throw this
}
return new Pair<>(methods, mInvokers);
}
Aggregations