Search in sources :

Example 1 with BannerCell

use of com.tmall.wireless.tangram.structure.cell.BannerCell in project Tangram-Android by alibaba.

the class BannerCard method parseWith.

@Override
public void parseWith(@NonNull JSONObject data, @NonNull MVHelper resolver) {
    if (cell == null)
        cell = new BannerCell();
    super.parseWith(data, resolver);
    JSONObject obj = new JSONObject();
    try {
        obj.put("type", TangramBuilder.TYPE_CAROUSEL_CELL);
        obj.put("bizId", id);
        resolver.parseCell(resolver, cell, obj);
        if (!super.getCells().isEmpty()) {
            cell.mCells.addAll(super.getCells());
            for (int i = 0, size = cell.mCells.size(); i < size; i++) {
                try {
                    BaseCell item = cell.mCells.get(i);
                    item.extras.put(MVResolver.KEY_INDEX, item.pos);
                } catch (JSONException e) {
                }
            }
            super.setCells(Collections.<BaseCell>singletonList(cell));
        }
    } catch (Exception e) {
        e.printStackTrace();
        setCells(null);
    }
}
Also used : JSONObject(org.json.JSONObject) BannerCell(com.tmall.wireless.tangram.structure.cell.BannerCell) BaseCell(com.tmall.wireless.tangram.structure.BaseCell) JSONException(org.json.JSONException) JSONException(org.json.JSONException)

Example 2 with BannerCell

use of com.tmall.wireless.tangram.structure.cell.BannerCell in project Tangram-Android by alibaba.

the class BannerView method onPageSelected.

@Override
public void onPageSelected(int position) {
    currentItemPos = mUltraViewPager.getCurrentItem();
    mIndicator.setCurrItem(currentItemPos);
    if (cell != null && cell.extras != null) {
        try {
            cell.extras.put(CURRENT_POS, currentItemPos);
        } catch (JSONException e) {
        }
    }
    if (bannerSupport != null) {
        for (int j = 0; j < bannerSupport.getListeners().size(); j++) {
            BannerListener listener = bannerSupport.getListeners().get(j);
            listener.onPageSelected(currentItemPos);
        }
    }
    if (cell != null && cell.serviceManager != null) {
        BusSupport busSupport = cell.serviceManager.getService(BusSupport.class);
        if (busSupport != null) {
            EventContext eventContext = new EventContext();
            if (((BannerCell) cell).mCells != null && currentItemPos >= 0 && currentItemPos < ((BannerCell) cell).mCells.size()) {
                eventContext.producer = ((BannerCell) cell).mCells.get(currentItemPos);
            }
            busSupport.post(BusSupport.obtainEvent(BusSupport.EVENT_ON_EXPOSURE, cell.id, null, eventContext));
        }
    }
}
Also used : EventContext(com.tmall.wireless.tangram.eventbus.EventContext) BannerCell(com.tmall.wireless.tangram.structure.cell.BannerCell) BannerListener(com.tmall.wireless.tangram.ext.BannerListener) BusSupport(com.tmall.wireless.tangram.eventbus.BusSupport) JSONException(org.json.JSONException)

Example 3 with BannerCell

use of com.tmall.wireless.tangram.structure.cell.BannerCell in project Tangram-Android by alibaba.

the class BannerView method postBindView.

@Override
public void postBindView(BaseCell cell) {
    getContext().registerReceiver(mScreenBroadcastReceiver, filter);
    BannerCell bannerCell = (BannerCell) cell;
    bannerCell.initAdapter();
    if (cell.style != null) {
        setPadding(cell.style.padding[3], cell.style.padding[0], cell.style.padding[1], cell.style.padding[2]);
    }
    setBackgroundColor(bannerCell.mBgColor);
    setAdapter(bannerCell.mBannerWrapper);
    mUltraViewPager.setAutoMeasureHeight(true);
    this.ratio = bannerCell.mRatio;
    this.height = bannerCell.height;
    mUltraViewPager.setRatio(this.ratio);
    setAutoScroll(bannerCell.mAutoScrollInternal, bannerCell.mSpecialInterval);
    mUltraViewPager.setPageMargin(bannerCell.hGap);
    if (bannerCell.mCells.size() <= bannerCell.mInfiniteMinCount) {
        setInfiniteLoop(false);
    } else {
        setInfiniteLoop(bannerCell.mInfinite);
    }
    setIndicatorGravity(getIndicatorGravity(bannerCell.mIndicatorGravity));
    setIndicatorPos(bannerCell.mIndicatorPos);
    int indicatorGap = bannerCell.mIndicatorGap;
    if (indicatorGap <= 0) {
        indicatorGap = mIndicatorGap;
    }
    setIndicatorGap(indicatorGap);
    int indicatorMargin = bannerCell.mIndicatorMargin;
    if (indicatorMargin <= 0) {
        indicatorMargin = mIndicatorMargin;
    }
    setIndicatorMargin(indicatorMargin);
    int indicatorHeight = bannerCell.mIndicatorHeight;
    setIndicatorHeight(indicatorHeight);
    if (bannerCell.itemMargin[0] > 0 || bannerCell.itemMargin[1] > 0) {
        setScrollMargin(bannerCell.itemMargin[0], bannerCell.itemMargin[1]);
        mUltraViewPager.setClipToPadding(false);
        mUltraViewPager.setClipChildren(false);
    } else {
        setScrollMargin(0, 0);
        mUltraViewPager.setClipToPadding(true);
        mUltraViewPager.setClipChildren(true);
    }
    VirtualLayoutManager.LayoutParams layoutParams = (VirtualLayoutManager.LayoutParams) getLayoutParams();
    layoutParams.setMargins(bannerCell.margin[3], bannerCell.margin[0], bannerCell.margin[1], bannerCell.margin[2]);
    mUltraViewPager.setItemRatio(bannerCell.itemRatio);
    currentItemPos = bannerCell.optIntParam(CURRENT_POS);
    mUltraViewPager.setCurrentItem(currentItemPos);
    updateIndicators(bannerCell.mIndicatorFocus, bannerCell.mIndicatorNor, bannerCell.mIndicatorRadius, bannerCell.mIndicatorColor, bannerCell.mIndicatorDefaultColor);
    recycleView();
    bindHeaderView(bannerCell.mHeader);
    bindFooterView(bannerCell.mFooter);
    if (cell.serviceManager != null) {
        bannerSupport = cell.serviceManager.getService(BannerSupport.class);
    }
}
Also used : BannerCell(com.tmall.wireless.tangram.structure.cell.BannerCell) BannerSupport(com.tmall.wireless.tangram.support.BannerSupport) VirtualLayoutManager(com.alibaba.android.vlayout.VirtualLayoutManager)

Aggregations

BannerCell (com.tmall.wireless.tangram.structure.cell.BannerCell)3 JSONException (org.json.JSONException)2 VirtualLayoutManager (com.alibaba.android.vlayout.VirtualLayoutManager)1 BusSupport (com.tmall.wireless.tangram.eventbus.BusSupport)1 EventContext (com.tmall.wireless.tangram.eventbus.EventContext)1 BannerListener (com.tmall.wireless.tangram.ext.BannerListener)1 BaseCell (com.tmall.wireless.tangram.structure.BaseCell)1 BannerSupport (com.tmall.wireless.tangram.support.BannerSupport)1 JSONObject (org.json.JSONObject)1