use of com.taobao.weex.bridge.JSCallback in project weiui by kuaifan.
the class weiuiAdDialog method create.
/**
************************************************************************************************
*/
/**
************************************************************************************************
*/
/**
************************************************************************************************
*/
public static void create(WXSDKInstance mWXSDKInstance, JSONObject json, JSCallback callback) {
if (mWXSDKInstance == null || json == null) {
return;
}
String imgUrl = weiuiParse.parseStr(json.getString("imgUrl"), json.getString("img"));
if (imgUrl == null || imgUrl.isEmpty()) {
return;
}
Context mContext = mWXSDKInstance.getContext();
if (mContext == null) {
return;
}
String dialogName = weiuiParse.parseStr(json.getString("dialogName"), weiuiCommon.randomString(8));
int dialogWidth = weiuiParse.parseInt(json.getString("width"));
int dialogHeight = weiuiParse.parseInt(json.getString("height"));
boolean showClose = weiuiParse.parseBool(json.getString("showClose"), true);
boolean backClose = weiuiParse.parseBool(json.getString("backClose"), true);
//
if (callback != null) {
Map<String, Object> newData = new HashMap<>();
newData.put("status", "load");
newData.put("dialogName", dialogName);
newData.put("imgUrl", imgUrl);
callback.invokeAndKeepAlive(newData);
}
Glide.with(mContext).asBitmap().load(imgUrl).apply(new RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL)).into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
PageActivity.startTransparentPage(mContext, new JSCallback() {
@Override
public void invoke(Object data) {
if (callback != null) {
callback.invoke(data);
}
}
@Override
public void invokeAndKeepAlive(Object data) {
Map<String, Object> retData = weiuiMap.objectToMap(data);
String pageName = weiuiParse.parseStr(retData.get("pageName"));
String status = weiuiParse.parseStr(retData.get("status"));
PageBean mBean = weiuiPage.getPageBean(pageName);
if (mBean == null) {
return;
}
if (status.equals("create")) {
Activity mActivity = (Activity) mBean.getContext();
Animation mAnimation = AnimationUtils.loadAnimation(mActivity, R.anim.in_to_down);
//
View tmpView = LayoutInflater.from(mActivity).inflate(R.layout.dialog_ad, null);
ImageView tmpImage = tmpView.findViewById(R.id.v_activity_picture);
ImageView tmpClose = tmpView.findViewById(R.id.v_activity_close);
ViewGroup fullBox = tmpView.findViewById(R.id.float_full_box);
//
if (callback != null) {
tmpImage.setOnClickListener(view -> {
Map<String, Object> newData = (Map<String, Object>) data;
newData.put("status", "click");
newData.put("dialogName", dialogName);
newData.put("imgUrl", imgUrl);
callback.invokeAndKeepAlive(newData);
});
}
if (showClose) {
tmpClose.setVisibility(View.VISIBLE);
tmpClose.setOnClickListener(view -> close(dialogName));
}
if (mActivity instanceof PageActivity) {
((PageActivity) mActivity).setOnBackPressed(() -> !backClose || close(dialogName));
}
//
DialogBean tmpBean = new DialogBean();
tmpBean.setDialogName(dialogName);
tmpBean.setImgUrl(imgUrl);
tmpBean.setPageName(mBean.getPageName());
tmpBean.setContext(mBean.getContext());
tmpBean.setView(tmpView);
mAdDialogList.add(tmpBean);
//
ViewGroup.LayoutParams params = tmpImage.getLayoutParams();
if (dialogWidth > 0 && dialogHeight > 0) {
params.width = weiuiScreenUtils.weexPx2dp(mWXSDKInstance, dialogWidth);
params.height = weiuiScreenUtils.weexPx2dp(mWXSDKInstance, dialogHeight);
} else if (dialogWidth > 0) {
params.width = weiuiScreenUtils.weexPx2dp(mWXSDKInstance, dialogWidth);
params.height = (int) weiuiCommon.scaleHeight(params.width, resource.getWidth(), resource.getHeight());
} else if (dialogHeight > 0) {
params.height = weiuiScreenUtils.weexPx2dp(mWXSDKInstance, dialogHeight);
params.width = (int) weiuiCommon.scaleWidth(params.height, resource.getWidth(), resource.getHeight());
} else {
params.width = (int) (ScreenUtils.getScreenWidth() * 0.75);
params.height = (int) weiuiCommon.scaleHeight(params.width, resource.getWidth(), resource.getHeight());
}
tmpImage.setLayoutParams(params);
tmpImage.setImageBitmap(resource);
fullBox.startAnimation(mAnimation);
//
if (callback != null) {
Map<String, Object> newData = (Map<String, Object>) data;
newData.put("status", "show");
newData.put("dialogName", dialogName);
newData.put("imgUrl", imgUrl);
callback.invokeAndKeepAlive(newData);
}
//
((FrameLayout) mActivity.findViewById(R.id.v_body)).addView(tmpView);
}
if (callback != null) {
if (data instanceof Map) {
Map<String, Object> newData = (Map<String, Object>) data;
newData.put("dialogName", dialogName);
newData.put("imgUrl", imgUrl);
callback.invokeAndKeepAlive(newData);
} else {
callback.invokeAndKeepAlive(data);
}
}
}
});
}
});
}
use of com.taobao.weex.bridge.JSCallback in project WeexErosFramework by bmfe.
the class TableView method setNaigation.
/**
* 接通 navigator ,前端可以直接 使用 navigator 设置到 fragment
*
* @param weexEventBean 参数对象
* @return
*/
public boolean setNaigation(WeexEventBean weexEventBean) {
String params = weexEventBean.getJsParams();
JSCallback jsCallback = weexEventBean.getJscallback();
String type = weexEventBean.getKey();
int currentIndex = viewpager.getCurrentItem();
for (int i = 0; i < fragments.size(); i++) {
MainWeexFragment fragment = fragments.get(i);
if (fragment.getWxInstanseHasCode() == (int) weexEventBean.getExpand()) {
NavigatorModel navigatorModel = navigatorArray.get(i);
switch(type) {
case // setNavigationInfo
WXEventCenter.EVENT_NAVIGATIONINFO:
navigatorModel.navigatorModel = params;
if (currentIndex == i) {
DefaultNavigationAdapter.setNavigationInfo(params, jsCallback);
}
break;
case // setLeftItem
WXEventCenter.EVENT_LEFTITEM:
navigatorModel.leftNavigatorbarModel = params;
navigatorModel.leftItemJsCallback = jsCallback;
if (currentIndex == i) {
DefaultNavigationAdapter.setLeftItem(params, jsCallback);
}
break;
case // setRightItem
WXEventCenter.EVENT_RIGHTITEM:
navigatorModel.rightNavigatorbarModel = params;
navigatorModel.rightItemJsCallback = jsCallback;
if (currentIndex == i) {
DefaultNavigationAdapter.setRightItem(params, jsCallback);
}
break;
case // setCenterItem
WXEventCenter.EVENT_CENTERITEM:
navigatorModel.centerNavigatorBarModel = params;
navigatorModel.centerItemJsCallback = jsCallback;
if (currentIndex == i) {
DefaultNavigationAdapter.setCenterItem(params, jsCallback);
}
break;
}
if (currentIndex == i) {
DefaultNavigationAdapter.setTabbarNavigation(activity, navigatorModel);
}
}
}
return true;
}
use of com.taobao.weex.bridge.JSCallback in project WeexErosFramework by bmfe.
the class EventShowLoading method perform.
@Override
public void perform(Context context, WeexEventBean weexEventBean) {
String params = weexEventBean.getJsParams();
if (TextUtils.isEmpty(params))
return;
JSCallback modal_showloading_callback = weexEventBean.getJscallback();
showLoading(params, modal_showloading_callback, context);
}
use of com.taobao.weex.bridge.JSCallback in project WeexErosFramework by bmfe.
the class ModalModule method confirm.
@JSMethod(uiThread = true)
public void confirm(String options, final JSCallback cancel, final JSCallback ok) {
WeexEventBean eventBean = new WeexEventBean();
eventBean.setContext(mWXSDKInstance.getContext());
eventBean.setKey(WXEventCenter.EVENT_MODAL_CONFIRM);
eventBean.setJsParams(options);
ArrayList<JSCallback> jsCallbacks = new ArrayList<>();
jsCallbacks.add(cancel);
jsCallbacks.add(ok);
eventBean.setCallbacks(jsCallbacks);
ManagerFactory.getManagerService(DispatchEventManager.class).getBus().post(eventBean);
}
use of com.taobao.weex.bridge.JSCallback in project incubator-weex by apache.
the class WXModalUIModuleTest method testConfirm.
@Test
public void testConfirm() throws Exception {
JSCallback callback = Mockito.mock(JSCallback.class);
module.confirm(JSON.parseObject("{}"), callback);
}
Aggregations