Search in sources :

Example 1 with WXSDKBean

use of vip.kuaifan.weiui.ui.component.tabbar.bean.WXSDKBean in project weiui by kuaifan.

the class Tabbar method addWXSDKView.

/**
 * 添加、刷新 浏览器页面
 * @param tabName
 */
private void addWXSDKView(String tabName) {
    WXSDKBean sdkBean = WXSDKList.get(tabName);
    if (sdkBean == null || !sdkBean.getType().equals("urlView")) {
        return;
    }
    String url = String.valueOf(sdkBean.getView());
    if (url == null) {
        return;
    }
    // 
    if (sdkBean.getInstance() != null) {
        sdkBean.getInstance().registerRenderListener(null);
        sdkBean.getInstance().destroy();
    }
    // 
    sdkBean.getProgress().setVisibility(View.VISIBLE);
    sdkBean.setInstance(new WXSDKInstance(getContext()));
    sdkBean.getInstance().registerRenderListener(new IWXRenderListener() {

        @Override
        public void onViewCreated(WXSDKInstance instance, View view) {
            sdkBean.getProgress().setVisibility(View.GONE);
            sdkBean.getContainer().removeAllViews();
            sdkBean.getContainer().addView(view);
            // 
            if (getDomObject().getEvents().contains(weiuiConstants.Event.VIEW_CREATED)) {
                Map<String, Object> data = new HashMap<>();
                data.put("tabName", tabName);
                data.put("url", url);
                fireEvent(weiuiConstants.Event.VIEW_CREATED, data);
            }
        }

        @Override
        public void onRenderSuccess(WXSDKInstance instance, int width, int height) {
        }

        @Override
        public void onRefreshSuccess(WXSDKInstance instance, int width, int height) {
        }

        @Override
        public void onException(WXSDKInstance instance, String errCode, String msg) {
        }
    });
    // 
    sdkBean.getInstance().registerOnWXScrollListener(new OnWXScrollListener() {

        @Override
        public void onScrolled(View view, int x, int y) {
            if (getDomObject().getEvents().contains(weiuiConstants.Event.SCROLLED)) {
                Map<String, Object> data = new HashMap<>();
                data.put("tabName", tabName);
                data.put("x", x);
                data.put("y", y);
                fireEvent(weiuiConstants.Event.SCROLLED, data);
            }
        }

        @Override
        public void onScrollStateChanged(View view, int x, int y, int newState) {
            if (getDomObject().getEvents().contains(weiuiConstants.Event.SCROLL_STATE_CHANGED)) {
                Map<String, Object> data = new HashMap<>();
                data.put("tabName", tabName);
                data.put("x", x);
                data.put("y", y);
                data.put("newState", newState);
                fireEvent(weiuiConstants.Event.SCROLL_STATE_CHANGED, data);
            }
            if (sdkBean.getSwipeRefreshEnable()) {
                if (y == 0) {
                    sdkBean.getSwipeRefresh().setEnabled(true);
                } else {
                    sdkBean.getSwipeRefresh().setEnabled(false);
                }
            }
        }
    });
    // 
    Map<String, Object> options = new HashMap<>();
    options.put(WXSDKInstance.BUNDLE_URL, url);
    sdkBean.getInstance().renderByUrl("Tabbar:" + tabName, url, options, null, WXRenderStrategy.APPEND_ASYNC);
}
Also used : HashMap(java.util.HashMap) OnWXScrollListener(com.taobao.weex.common.OnWXScrollListener) View(android.view.View) WXSDKBean(vip.kuaifan.weiui.ui.component.tabbar.bean.WXSDKBean) WXSDKInstance(com.taobao.weex.WXSDKInstance) IWXRenderListener(com.taobao.weex.IWXRenderListener) WXDomObject(com.taobao.weex.dom.WXDomObject) JSONObject(com.alibaba.fastjson.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with WXSDKBean

use of vip.kuaifan.weiui.ui.component.tabbar.bean.WXSDKBean in project weiui by kuaifan.

the class Tabbar method addPageView.

/**
 * 添加页面
 * @param barBean
 */
private void addPageView(TabbarBean barBean) {
    View view = ((Activity) getContext()).getLayoutInflater().inflate(R.layout.layout_weiui_tabbar_page, null);
    SwipeRefreshLayout v_swipeRefresh = view.findViewById(R.id.v_swipeRefresh);
    FrameLayout v_container = view.findViewById(R.id.v_container);
    ProgressBar v_progress = view.findViewById(R.id.v_progress);
    // 
    WXSDKBean sdkBean = new WXSDKBean();
    sdkBean.setSwipeRefresh(v_swipeRefresh);
    sdkBean.setContainer(v_container);
    sdkBean.setProgress(v_progress);
    sdkBean.setView(barBean.getView());
    if (barBean.getView() instanceof String) {
        sdkBean.setType("urlView");
        WXSDKList.put(barBean.getTabName(), sdkBean);
        addWXSDKView(barBean.getTabName());
    } else if (barBean.getView() instanceof TabbarPageView) {
        sdkBean.setType("pageView");
        WXSDKList.put(barBean.getTabName(), sdkBean);
        addWXPageView(barBean.getTabName());
    }
    // 
    if (getDomObject().getEvents().contains(weiuiConstants.Event.REFRESH_LISTENER)) {
        sdkBean.getSwipeRefresh().setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_red_light, android.R.color.holo_orange_light, android.R.color.holo_green_light);
        sdkBean.getSwipeRefresh().setOnRefreshListener(() -> {
            Map<String, Object> data = new HashMap<>();
            data.put("tabName", barBean.getTabName());
            data.put("position", getTabPosition(barBean.getTabName()));
            fireEvent(weiuiConstants.Event.REFRESH_LISTENER, data);
        });
        sdkBean.setSwipeRefreshEnable(true);
    } else {
        sdkBean.setSwipeRefreshEnable(false);
        sdkBean.getSwipeRefresh().setEnabled(false);
    }
    // 
    mTabEntity.add(new TabbarEntity(barBean));
    mViewList.add(view);
    mTabPagerAdapter.setListViews(mViewList);
    mTabPagerAdapter.notifyDataSetChanged();
}
Also used : WXSDKBean(vip.kuaifan.weiui.ui.component.tabbar.bean.WXSDKBean) HashMap(java.util.HashMap) FrameLayout(android.widget.FrameLayout) WXDomObject(com.taobao.weex.dom.WXDomObject) JSONObject(com.alibaba.fastjson.JSONObject) View(android.view.View) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) ProgressBar(android.widget.ProgressBar) TabbarEntity(vip.kuaifan.weiui.ui.component.tabbar.entity.TabbarEntity)

Example 3 with WXSDKBean

use of vip.kuaifan.weiui.ui.component.tabbar.bean.WXSDKBean in project weiui by kuaifan.

the class Tabbar method addWXPageView.

/**
 * 添加子页面
 * @param tabName
 */
private void addWXPageView(String tabName) {
    WXSDKBean sdkBean = WXSDKList.get(tabName);
    if (sdkBean == null || !sdkBean.getType().equals("pageView")) {
        return;
    }
    TabbarPageView view = (TabbarPageView) sdkBean.getView();
    if (view == null) {
        return;
    }
    // 
    ViewGroup parentViewGroup = (ViewGroup) view.getParent();
    if (parentViewGroup != null) {
        parentViewGroup.removeView(view);
    }
    sdkBean.getProgress().setVisibility(View.GONE);
    sdkBean.getContainer().removeAllViews();
    sdkBean.getContainer().addView(view);
    // 
    if (getDomObject().getEvents().contains(weiuiConstants.Event.VIEW_CREATED)) {
        Map<String, Object> data = new HashMap<>();
        data.put("tabName", tabName);
        data.put("url", null);
        fireEvent(weiuiConstants.Event.VIEW_CREATED, data);
    }
}
Also used : WXSDKBean(vip.kuaifan.weiui.ui.component.tabbar.bean.WXSDKBean) HashMap(java.util.HashMap) ViewGroup(android.view.ViewGroup) WXDomObject(com.taobao.weex.dom.WXDomObject) JSONObject(com.alibaba.fastjson.JSONObject)

Example 4 with WXSDKBean

use of vip.kuaifan.weiui.ui.component.tabbar.bean.WXSDKBean in project weiui by kuaifan.

the class Tabbar method goUrl.

/**
 * 跳转页面
 * @param tabName
 * @param url
 */
@JSMethod
public void goUrl(String tabName, String url) {
    WXSDKBean bean = WXSDKList.get(tabName);
    if (bean != null) {
        bean.setView(url);
        WXSDKList.put(tabName, bean);
        addWXSDKView(tabName);
    }
}
Also used : WXSDKBean(vip.kuaifan.weiui.ui.component.tabbar.bean.WXSDKBean) JSMethod(com.taobao.weex.annotation.JSMethod)

Aggregations

WXSDKBean (vip.kuaifan.weiui.ui.component.tabbar.bean.WXSDKBean)4 JSONObject (com.alibaba.fastjson.JSONObject)3 WXDomObject (com.taobao.weex.dom.WXDomObject)3 HashMap (java.util.HashMap)3 View (android.view.View)2 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 ViewGroup (android.view.ViewGroup)1 FrameLayout (android.widget.FrameLayout)1 ProgressBar (android.widget.ProgressBar)1 IWXRenderListener (com.taobao.weex.IWXRenderListener)1 WXSDKInstance (com.taobao.weex.WXSDKInstance)1 JSMethod (com.taobao.weex.annotation.JSMethod)1 OnWXScrollListener (com.taobao.weex.common.OnWXScrollListener)1 Map (java.util.Map)1 TabbarEntity (vip.kuaifan.weiui.ui.component.tabbar.entity.TabbarEntity)1