use of com.alibaba.fastjson.JSONObject in project weex-example by KalicyZhou.
the class WXMetaModule method setViewport.
@JSMethod(uiThread = false)
public void setViewport(String param) {
if (!TextUtils.isEmpty(param)) {
try {
param = URLDecoder.decode(param, "utf-8");
JSONObject jsObj = JSON.parseObject(param);
if (DEVICE_WIDTH.endsWith(jsObj.getString(WIDTH))) {
mWXSDKInstance.setViewPortWidth(WXViewUtils.getScreenWidth(mWXSDKInstance.getContext()));
} else {
int width = jsObj.getInteger(WIDTH);
if (width > 0) {
mWXSDKInstance.setViewPortWidth(width);
}
}
} catch (Exception e) {
WXLogUtils.e("[WXModalUIModule] alert param parse error ", e);
}
}
}
use of com.alibaba.fastjson.JSONObject in project weex-example by KalicyZhou.
the class WXModalUIModule method alert.
@JSMethod(uiThread = true)
public void alert(String param, final JSCallback callback) {
if (mWXSDKInstance.getContext() instanceof Activity) {
String message = "";
String okTitle = OK;
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);
} catch (Exception e) {
WXLogUtils.e("[WXModalUIModule] alert param parse error ", e);
}
}
if (TextUtils.isEmpty(message)) {
message = "";
}
AlertDialog.Builder builder = new AlertDialog.Builder(mWXSDKInstance.getContext());
builder.setMessage(message);
final String okTitle_f = TextUtils.isEmpty(okTitle) ? OK : okTitle;
builder.setPositiveButton(okTitle_f, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (callback != null) {
callback.invoke(okTitle_f);
}
}
});
AlertDialog alertDialog = builder.create();
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.show();
tracking(alertDialog);
} else {
WXLogUtils.e("[WXModalUIModule] when call alert mWXSDKInstance.getContext() must instanceof Activity");
}
}
use of com.alibaba.fastjson.JSONObject in project weex-example by KalicyZhou.
the class WXModalUIModule method confirm.
@JSMethod(uiThread = true)
public void confirm(String param, final JSCallback callback) {
if (mWXSDKInstance.getContext() instanceof Activity) {
String message = "";
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);
} 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 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) {
callback.invoke(okTitleFinal);
}
}
});
builder.setNegativeButton(cancelTitleFinal, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (callback != null) {
callback.invoke(cancelTitleFinal);
}
}
});
AlertDialog alertDialog = builder.create();
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.show();
tracking(alertDialog);
} else {
WXLogUtils.e("[WXModalUIModule] when call confirm mWXSDKInstance.getContext() must instanceof Activity");
}
}
use of com.alibaba.fastjson.JSONObject 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();
}
use of com.alibaba.fastjson.JSONObject in project weex-example by KalicyZhou.
the class WXSDKInstance method setSize.
public void setSize(int width, int height) {
if (width < 0 || height < 0 || isDestroy || !mRendered) {
return;
}
float realWidth = WXViewUtils.getWebPxByWidth(width, getViewPortWidth());
float realHeight = WXViewUtils.getWebPxByWidth(height, getViewPortWidth());
View godView = mRenderContainer;
if (godView != null) {
ViewGroup.LayoutParams layoutParams = godView.getLayoutParams();
if (layoutParams != null) {
if (godView.getWidth() != width || godView.getHeight() != height) {
layoutParams.width = width;
layoutParams.height = height;
godView.setLayoutParams(layoutParams);
}
JSONObject style = new JSONObject();
WXComponent rootComponent = mRootComp;
if (rootComponent == null) {
return;
}
style.put(Constants.Name.DEFAULT_WIDTH, realWidth);
style.put(Constants.Name.DEFAULT_HEIGHT, realHeight);
updateRootComponentStyle(style);
}
}
}
Aggregations