Search in sources :

Example 26 with JSCallback

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);
                        }
                    }
                }
            });
        }
    });
}
Also used : Context(android.content.Context) PageActivity(vip.kuaifan.weiui.PageActivity) HashMap(java.util.HashMap) RequestOptions(vip.kuaifan.weiui.extend.integration.glide.request.RequestOptions) ViewGroup(android.view.ViewGroup) PageActivity(vip.kuaifan.weiui.PageActivity) Activity(android.app.Activity) ImageView(android.widget.ImageView) View(android.view.View) JSCallback(com.taobao.weex.bridge.JSCallback) Bitmap(android.graphics.Bitmap) PageBean(vip.kuaifan.weiui.extend.bean.PageBean) FrameLayout(android.widget.FrameLayout) Animation(android.view.animation.Animation) JSONObject(com.alibaba.fastjson.JSONObject) ImageView(android.widget.ImageView) HashMap(java.util.HashMap) Map(java.util.Map)

Example 27 with JSCallback

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;
}
Also used : MainWeexFragment(com.eros.framework.fragment.MainWeexFragment) NavigatorModel(com.eros.framework.model.NavigatorModel) JSCallback(com.taobao.weex.bridge.JSCallback)

Example 28 with JSCallback

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);
}
Also used : JSCallback(com.taobao.weex.bridge.JSCallback)

Example 29 with JSCallback

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);
}
Also used : WeexEventBean(com.eros.framework.model.WeexEventBean) ArrayList(java.util.ArrayList) JSCallback(com.taobao.weex.bridge.JSCallback) JSMethod(com.taobao.weex.annotation.JSMethod)

Example 30 with JSCallback

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);
}
Also used : JSCallback(com.taobao.weex.bridge.JSCallback) Test(org.junit.Test) WXSDKInstanceTest(com.taobao.weex.WXSDKInstanceTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

JSCallback (com.taobao.weex.bridge.JSCallback)33 JSMethod (com.taobao.weex.annotation.JSMethod)12 WXSDKInstanceTest (com.taobao.weex.WXSDKInstanceTest)10 Test (org.junit.Test)10 JSONObject (com.alibaba.fastjson.JSONObject)9 ArrayList (java.util.ArrayList)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 HashMap (java.util.HashMap)6 Map (java.util.Map)5 Activity (android.app.Activity)4 Context (android.content.Context)4 WeexEventBean (com.benmu.framework.model.WeexEventBean)4 DialogInterface (android.content.DialogInterface)2 Intent (android.content.Intent)2 Color (android.graphics.Color)2 Uri (android.net.Uri)2 AppCompatActivity (android.support.v7.app.AppCompatActivity)2 View (android.view.View)2 FrameLayout (android.widget.FrameLayout)2 JSONArray (com.alibaba.fastjson.JSONArray)2