Search in sources :

Example 1 with CardSupport

use of com.tmall.wireless.tangram3.support.CardSupport in project Tangram-Android by alibaba.

the class Card method getLayoutHelper.

@Nullable
public final LayoutHelper getLayoutHelper() {
    LayoutHelper helper = convertLayoutHelper(mLayoutHelper);
    // bind style to helper
    if (style != null && helper != null) {
        helper.setZIndex(style.zIndex);
        if (helper instanceof BaseLayoutHelper) {
            BaseLayoutHelper baseHelper = (BaseLayoutHelper) helper;
            baseHelper.setBgColor(style.bgColor);
            if (!TextUtils.isEmpty(style.bgImgUrl)) {
                if (serviceManager != null && serviceManager.getService(CardSupport.class) != null) {
                    final CardSupport support = serviceManager.getService(CardSupport.class);
                    baseHelper.setLayoutViewBindListener(new BindListener(style) {

                        @Override
                        public void onBind(View layoutView, BaseLayoutHelper baseLayoutHelper) {
                            support.onBindBackgroundView(layoutView, Card.this);
                        }
                    });
                    baseHelper.setLayoutViewUnBindListener(new UnbindListener(style) {

                        @Override
                        public void onUnbind(View layoutView, BaseLayoutHelper baseLayoutHelper) {
                            support.onUnbindBackgroundView(layoutView, Card.this);
                        }
                    });
                } else {
                    baseHelper.setLayoutViewBindListener(new BindListener(style));
                    baseHelper.setLayoutViewUnBindListener(new UnbindListener(style));
                }
            } else {
                baseHelper.setLayoutViewBindListener(null);
                baseHelper.setLayoutViewUnBindListener(null);
            }
            if (!Float.isNaN(style.aspectRatio)) {
            // ((BaseLayoutHelper) helper).setAspectRatio(style.aspectRatio);
            }
        }
        if (helper instanceof FixAreaLayoutHelper) {
            FixAreaLayoutHelper fixHelper = (FixAreaLayoutHelper) helper;
            boolean hasCustomAnimatorHelper = false;
            if (serviceManager != null && serviceManager.getService(CardSupport.class) != null) {
                CardSupport support = serviceManager.getService(CardSupport.class);
                FixAreaLayoutHelper.FixViewAnimatorHelper viewAnimatorHelper = support.onGetFixViewAppearAnimator(Card.this);
                if (viewAnimatorHelper != null) {
                    hasCustomAnimatorHelper = true;
                    fixHelper.setFixViewAnimatorHelper(viewAnimatorHelper);
                }
            }
            if (!hasCustomAnimatorHelper) {
                final int duration = style.extras != null ? style.extras.getIntValue(Style.KEY_ANIMATION_DURATION) : 0;
                if (duration > 0) {
                    fixHelper.setFixViewAnimatorHelper(new FixAreaLayoutHelper.FixViewAnimatorHelper() {

                        @Override
                        public ViewPropertyAnimator onGetFixViewAppearAnimator(View fixView) {
                            int height = fixView.getMeasuredHeight();
                            fixView.setTranslationY(-height);
                            return fixView.animate().translationYBy(height).setDuration(duration);
                        }

                        @Override
                        public ViewPropertyAnimator onGetFixViewDisappearAnimator(View fixView) {
                            int height = fixView.getMeasuredHeight();
                            return fixView.animate().translationYBy(-height).setDuration(duration);
                        }
                    });
                }
            }
        }
        if (helper instanceof MarginLayoutHelper) {
            ((MarginLayoutHelper) helper).setMargin(style.margin[Style.MARGIN_LEFT_INDEX], style.margin[Style.MARGIN_TOP_INDEX], style.margin[Style.MARGIN_RIGHT_INDEX], style.margin[Style.MARGIN_BOTTOM_INDEX]);
            ((MarginLayoutHelper) helper).setPadding(style.padding[Style.MARGIN_LEFT_INDEX], style.padding[Style.MARGIN_TOP_INDEX], style.padding[Style.MARGIN_RIGHT_INDEX], style.padding[Style.MARGIN_BOTTOM_INDEX]);
        }
    }
    if (mRetainLayout) {
        mLayoutHelper = helper;
    }
    return helper;
}
Also used : MarginLayoutHelper(com.alibaba.android.vlayout.layout.MarginLayoutHelper) FixAreaLayoutHelper(com.alibaba.android.vlayout.layout.FixAreaLayoutHelper) ImageView(android.widget.ImageView) View(android.view.View) ViewPropertyAnimator(android.view.ViewPropertyAnimator) CardSupport(com.tmall.wireless.tangram3.support.CardSupport) BaseLayoutHelper(com.alibaba.android.vlayout.layout.BaseLayoutHelper) LayoutHelper(com.alibaba.android.vlayout.LayoutHelper) MarginLayoutHelper(com.alibaba.android.vlayout.layout.MarginLayoutHelper) FixAreaLayoutHelper(com.alibaba.android.vlayout.layout.FixAreaLayoutHelper) BaseLayoutHelper(com.alibaba.android.vlayout.layout.BaseLayoutHelper) Nullable(android.support.annotation.Nullable)

Example 2 with CardSupport

use of com.tmall.wireless.tangram3.support.CardSupport in project Tangram-Android by alibaba.

the class GridCard method convertChildLayoutHelper.

private void convertChildLayoutHelper(@Nullable RangeGridLayoutHelper gridHelper, GridCard parentCard) {
    for (int i = 0, size = parentCard.getChildren().size(); i < size; i++) {
        Range<Integer> range = parentCard.getChildren().keyAt(i);
        Card child = parentCard.getChildren().valueAt(i);
        Style style = child.style;
        if (style instanceof GridStyle && child instanceof GridCard) {
            final GridStyle gridStyle = (GridStyle) style;
            final GridCard gridCard = (GridCard) child;
            if (!gridCard.getChildren().isEmpty()) {
                convertChildLayoutHelper(gridHelper, gridCard);
            }
            GridRangeStyle rangeStyle = new GridRangeStyle();
            int totalColumn = gridCard.mColumn;
            if (gridStyle.column > 0) {
                totalColumn = gridStyle.column;
                rangeStyle.setSpanCount(gridStyle.column);
            } else {
                rangeStyle.setSpanCount(totalColumn);
            }
            rangeStyle.setSpanSizeLookup(new CellSpanSizeLookup(gridCard.getCells(), totalColumn));
            rangeStyle.setVGap(gridStyle.vGap);
            rangeStyle.setHGap(gridStyle.hGap);
            rangeStyle.setAutoExpand(gridStyle.autoExpand);
            if (gridStyle.cols != null && gridStyle.cols.length > 0) {
                rangeStyle.setWeights(gridStyle.cols);
            }
            if (!Float.isNaN(gridStyle.aspectRatio)) {
                rangeStyle.setAspectRatio(gridStyle.aspectRatio);
            }
            rangeStyle.setBgColor(style.bgColor);
            rangeStyle.setMargin(style.margin[Style.MARGIN_LEFT_INDEX], style.margin[Style.MARGIN_TOP_INDEX], style.margin[Style.MARGIN_RIGHT_INDEX], style.margin[Style.MARGIN_BOTTOM_INDEX]);
            rangeStyle.setPadding(style.padding[Style.MARGIN_LEFT_INDEX], style.padding[Style.MARGIN_TOP_INDEX], style.padding[Style.MARGIN_RIGHT_INDEX], style.padding[Style.MARGIN_BOTTOM_INDEX]);
            if (!TextUtils.isEmpty(style.bgImgUrl)) {
                if (serviceManager != null && serviceManager.getService(CardSupport.class) != null) {
                    final CardSupport support = serviceManager.getService(CardSupport.class);
                    rangeStyle.setLayoutViewBindListener(new BindListener(style) {

                        @Override
                        public void onBind(View layoutView, BaseLayoutHelper baseLayoutHelper) {
                            support.onBindBackgroundView(layoutView, gridCard);
                        }
                    });
                    rangeStyle.setLayoutViewUnBindListener(new UnbindListener(style) {

                        @Override
                        public void onUnbind(View layoutView, BaseLayoutHelper baseLayoutHelper) {
                            support.onUnbindBackgroundView(layoutView, gridCard);
                        }
                    });
                } else {
                    rangeStyle.setLayoutViewBindListener(new BindListener(style));
                    rangeStyle.setLayoutViewUnBindListener(new UnbindListener(style));
                }
            } else {
                rangeStyle.setLayoutViewBindListener(null);
                rangeStyle.setLayoutViewUnBindListener(null);
            }
            gridHelper.addRangeStyle(range.getLower().intValue(), range.getUpper().intValue(), rangeStyle);
        }
    }
}
Also used : View(android.view.View) Card(com.tmall.wireless.tangram3.dataparser.concrete.Card) CardSupport(com.tmall.wireless.tangram3.support.CardSupport) Style(com.tmall.wireless.tangram3.dataparser.concrete.Style) GridRangeStyle(com.alibaba.android.vlayout.layout.RangeGridLayoutHelper.GridRangeStyle) GridRangeStyle(com.alibaba.android.vlayout.layout.RangeGridLayoutHelper.GridRangeStyle) BaseLayoutHelper(com.alibaba.android.vlayout.layout.BaseLayoutHelper)

Aggregations

View (android.view.View)2 BaseLayoutHelper (com.alibaba.android.vlayout.layout.BaseLayoutHelper)2 CardSupport (com.tmall.wireless.tangram3.support.CardSupport)2 Nullable (android.support.annotation.Nullable)1 ViewPropertyAnimator (android.view.ViewPropertyAnimator)1 ImageView (android.widget.ImageView)1 LayoutHelper (com.alibaba.android.vlayout.LayoutHelper)1 FixAreaLayoutHelper (com.alibaba.android.vlayout.layout.FixAreaLayoutHelper)1 MarginLayoutHelper (com.alibaba.android.vlayout.layout.MarginLayoutHelper)1 GridRangeStyle (com.alibaba.android.vlayout.layout.RangeGridLayoutHelper.GridRangeStyle)1 Card (com.tmall.wireless.tangram3.dataparser.concrete.Card)1 Style (com.tmall.wireless.tangram3.dataparser.concrete.Style)1