Search in sources :

Example 21 with LayoutHelper

use of com.alibaba.android.vlayout.LayoutHelper in project Tangram-Android by alibaba.

the class WrapperCard method convertLayoutHelper.

@Nullable
@Override
public LayoutHelper convertLayoutHelper(@Nullable LayoutHelper oldHelper) {
    LayoutHelper layoutHelper = mCard.convertLayoutHelper(oldHelper);
    if (layoutHelper != null) {
        layoutHelper.setItemCount(mCells.size());
        if (layoutHelper instanceof RangeGridLayoutHelper) {
            RangeGridLayoutHelper gridHelper = (RangeGridLayoutHelper) layoutHelper;
            gridHelper.setSpanSizeLookup(new GridCard.CellSpanSizeLookup(mCells, gridHelper.getSpanCount()));
        }
    }
    return layoutHelper;
}
Also used : GridCard(com.tmall.wireless.tangram.structure.card.GridCard) RangeGridLayoutHelper(com.alibaba.android.vlayout.layout.RangeGridLayoutHelper) GridLayoutHelper(com.alibaba.android.vlayout.layout.GridLayoutHelper) LayoutHelper(com.alibaba.android.vlayout.LayoutHelper) RangeGridLayoutHelper(com.alibaba.android.vlayout.layout.RangeGridLayoutHelper) Nullable(android.support.annotation.Nullable)

Example 22 with LayoutHelper

use of com.alibaba.android.vlayout.LayoutHelper in project Tangram-Android by alibaba.

the class TangramEngine method removeBatchBy.

/**
 * Remove all cells in a card.
 *
 * @param group
 * @since 2.1.0
 */
public void removeBatchBy(Card group) {
    VirtualLayoutManager layoutManager = getLayoutManager();
    if (group != null && mGroupBasicAdapter != null && layoutManager != null) {
        int cardIdx = mGroupBasicAdapter.findCardIdxForCard(group);
        List<LayoutHelper> layoutHelpers = layoutManager.getLayoutHelpers();
        LayoutHelper emptyLayoutHelper = null;
        int removeItemCount = 0;
        if (layoutHelpers != null && cardIdx >= 0 && cardIdx < layoutHelpers.size()) {
            for (int i = 0, size = layoutHelpers.size(); i < size; i++) {
                LayoutHelper layoutHelper = layoutHelpers.get(i);
                int start = layoutHelper.getRange().getLower();
                int end = layoutHelper.getRange().getUpper();
                if (i < cardIdx) {
                // do nothing
                } else if (i == cardIdx) {
                    removeItemCount = layoutHelper.getItemCount();
                    emptyLayoutHelper = layoutHelper;
                } else {
                    layoutHelper.setRange(start - removeItemCount, end - removeItemCount);
                }
            }
            if (emptyLayoutHelper != null) {
                final List<LayoutHelper> newLayoutHelpers = new LinkedList<>(layoutHelpers);
                newLayoutHelpers.remove(emptyLayoutHelper);
                layoutManager.setLayoutHelpers(newLayoutHelpers);
            }
            mGroupBasicAdapter.removeComponents(group);
        }
    }
}
Also used : LayoutHelper(com.alibaba.android.vlayout.LayoutHelper) VirtualLayoutManager(com.alibaba.android.vlayout.VirtualLayoutManager) LinkedList(java.util.LinkedList)

Example 23 with LayoutHelper

use of com.alibaba.android.vlayout.LayoutHelper in project Tangram-Android by alibaba.

the class TangramEngine method replace.

/**
 * Replace card one by one. New one's children size should be equal with old one's children size.
 *
 * @param oldOne
 * @param newOne
 * @since 2.1.0
 */
public void replace(Card oldOne, Card newOne) {
    VirtualLayoutManager layoutManager = getLayoutManager();
    if (oldOne != null && newOne != null && mGroupBasicAdapter != null && layoutManager != null) {
        List<LayoutHelper> layoutHelpers = layoutManager.getLayoutHelpers();
        int cardIdx = mGroupBasicAdapter.findCardIdxForCard(oldOne);
        if (layoutHelpers != null && cardIdx >= 0 && cardIdx < layoutHelpers.size()) {
            final List<LayoutHelper> newLayoutHelpers = new LinkedList<>();
            for (int i = 0, size = layoutHelpers.size(); i < size; i++) {
                LayoutHelper layoutHelper = layoutHelpers.get(i);
                if (i == cardIdx) {
                    layoutHelper = newOne.getLayoutHelper();
                }
                newLayoutHelpers.add(layoutHelper);
            }
            layoutManager.setLayoutHelpers(newLayoutHelpers);
            mGroupBasicAdapter.replaceComponent(oldOne, newOne);
        }
    }
}
Also used : LayoutHelper(com.alibaba.android.vlayout.LayoutHelper) VirtualLayoutManager(com.alibaba.android.vlayout.VirtualLayoutManager) LinkedList(java.util.LinkedList)

Example 24 with LayoutHelper

use of com.alibaba.android.vlayout.LayoutHelper 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 25 with LayoutHelper

use of com.alibaba.android.vlayout.LayoutHelper in project Tangram-Android by alibaba.

the class WrapperCard method convertLayoutHelper.

@Nullable
@Override
public LayoutHelper convertLayoutHelper(@Nullable LayoutHelper oldHelper) {
    LayoutHelper layoutHelper = mCard.convertLayoutHelper(oldHelper);
    if (layoutHelper != null) {
        layoutHelper.setItemCount(mCells.size());
        if (layoutHelper instanceof RangeGridLayoutHelper) {
            RangeGridLayoutHelper gridHelper = (RangeGridLayoutHelper) layoutHelper;
            gridHelper.setSpanSizeLookup(new GridCard.CellSpanSizeLookup(mCells, gridHelper.getSpanCount()));
        }
    }
    return layoutHelper;
}
Also used : GridCard(com.tmall.wireless.tangram3.structure.card.GridCard) RangeGridLayoutHelper(com.alibaba.android.vlayout.layout.RangeGridLayoutHelper) LayoutHelper(com.alibaba.android.vlayout.LayoutHelper) RangeGridLayoutHelper(com.alibaba.android.vlayout.layout.RangeGridLayoutHelper) Nullable(android.support.annotation.Nullable)

Aggregations

LayoutHelper (com.alibaba.android.vlayout.LayoutHelper)26 VirtualLayoutManager (com.alibaba.android.vlayout.VirtualLayoutManager)13 LinkedList (java.util.LinkedList)9 View (android.view.View)7 Nullable (android.support.annotation.Nullable)6 ArrayList (java.util.ArrayList)6 RecyclerView (android.support.v7.widget.RecyclerView)5 FixLayoutHelper (com.alibaba.android.vlayout.layout.FixLayoutHelper)3 Card (com.tmall.wireless.tangram.dataparser.concrete.Card)3 Card (com.tmall.wireless.tangram3.dataparser.concrete.Card)3 NonNull (android.support.annotation.NonNull)2 ViewPropertyAnimator (android.view.ViewPropertyAnimator)2 ImageView (android.widget.ImageView)2 BaseLayoutHelper (com.alibaba.android.vlayout.layout.BaseLayoutHelper)2 FixAreaLayoutHelper (com.alibaba.android.vlayout.layout.FixAreaLayoutHelper)2 GridLayoutHelper (com.alibaba.android.vlayout.layout.GridLayoutHelper)2 MarginLayoutHelper (com.alibaba.android.vlayout.layout.MarginLayoutHelper)2 RangeGridLayoutHelper (com.alibaba.android.vlayout.layout.RangeGridLayoutHelper)2 BaseCell (com.tmall.wireless.tangram.structure.BaseCell)2 BaseCell (com.tmall.wireless.tangram3.structure.BaseCell)2