Search in sources :

Example 1 with Style

use of com.tmall.wireless.tangram3.dataparser.concrete.Style in project Tangram-Android by alibaba.

the class PojoDataParser method parseSingleGroup.

@NonNull
@Override
public Card parseSingleGroup(@Nullable JSONObject data, @NonNull final ServiceManager serviceManager) {
    if (TangramBuilder.isPrintLog() && serviceManager == null) {
        throw new RuntimeException("serviceManager is null when parsing card!");
    }
    if (data == null) {
        return Card.NaN;
    }
    checkCardResolverAndMVHelper(serviceManager);
    String cardType = parseCardType(data);
    if (!TextUtils.isEmpty(cardType)) {
        Card card = cardResolver.create(cardType);
        if (card == null) {
            card = new WrapCellCard();
            cardType = TangramBuilder.TYPE_CONTAINER_1C_FLOW;
            JSONObject wrapCardJson = new JSONObject();
            wrapCardJson.put("type", TangramBuilder.TYPE_CONTAINER_1C_FLOW);
            JSONArray itemArray = new JSONArray();
            itemArray.add(data);
            wrapCardJson.put("items", itemArray);
            data = wrapCardJson;
        }
        card.dataParser = this;
        card.serviceManager = serviceManager;
        card.extras = data;
        card.stringType = cardType;
        card.loadParams = data.getJSONObject(KEY_API_LOAD_PARAMS);
        Map<String, ComponentInfo> infoMap = parseComponentInfo(data);
        parseCard(card, data, serviceManager, infoMap);
        JSONObject styleJson = data.getJSONObject(KEY_STYLE);
        // parse specific style
        if (card instanceof GridCard) {
            GridCard gridCard = (GridCard) card;
            GridCard.GridStyle style = new GridCard.GridStyle();
            if (styleJson != null) {
                parseStyle(style, styleJson);
                style.column = styleJson.getIntValue(KEY_COLUMN);
                style.autoExpand = styleJson.getBooleanValue(KEY_AUTO_EXPAND);
                JSONArray jsonCols = styleJson.getJSONArray(KEY_COLS);
                if (jsonCols != null) {
                    style.cols = new float[jsonCols.size()];
                    for (int i = 0; i < style.cols.length; i++) {
                        style.cols[i] = (float) jsonCols.getDoubleValue(i);
                    }
                } else {
                    style.cols = new float[0];
                }
                style.hGap = Style.parseSize(styleJson.getString(KEY_H_GAP), 0);
                style.vGap = Style.parseSize(styleJson.getString(KEY_V_GAP), 0);
                if (style.column > 0) {
                    gridCard.mColumn = style.column;
                }
                for (BaseCell cell : card.mCells) {
                    if (cell.style.extras != null) {
                        int colSpan = cell.style.extras.getIntValue("colspan");
                        if (colSpan == 0) {
                            colSpan = 1;
                        }
                        cell.colSpan = colSpan;
                    }
                }
            }
            card = gridCard;
            card.style = style;
        } else if (card instanceof BannerCard) {
            BannerCard bannerCard = (BannerCard) card;
            if (bannerCard.cell == null) {
                bannerCard.cell = new BannerCell();
                bannerCard.cell.serviceManager = serviceManager;
            }
            try {
                bannerCard.cell.stringType = TYPE_CAROUSEL_CELL_COMPACT;
                if (!bannerCard.getCells().isEmpty()) {
                    bannerCard.cell.mCells.addAll(bannerCard.getCells());
                    bannerCard.setCells(bannerCard.getCells());
                }
            } catch (Exception e) {
                if (errorSupport == null) {
                    errorSupport = serviceManager.getService(InternalErrorSupport.class);
                }
                HashMap<String, Object> params = new HashMap<>();
                params.put("exception", Log.getStackTraceString(e));
                errorSupport.onError(InternalErrorSupport.ERROR_PARSE_CARDS_ERROR, "Parse banner card error.", params);
                e.printStackTrace();
                bannerCard.setCells(null);
            }
            Style style = new Style();
            if (styleJson != null) {
                bannerCard.cell.setIndicatorRadius(Style.parseSize(styleJson.getString(ATTR_INDICATOR_RADIUS), 0));
                bannerCard.cell.setIndicatorColor(Style.parseColor(styleJson.getString(ATTR_INDICATOR_COLOR), Color.TRANSPARENT));
                bannerCard.cell.setIndicatorDefaultColor(Style.parseColor(styleJson.getString(ATTR_INDICATOR_DEFAULT_INDICATOR_COLOR), Color.TRANSPARENT));
                bannerCard.cell.setAutoScrollInternal(styleJson.getIntValue(ATTR_AUTOSCROLL));
                bannerCard.cell.setSpecialInterval(styleJson.getJSONObject(ATTR_SPECIAL_INTERVAL));
                bannerCard.cell.setInfinite(styleJson.getBooleanValue(ATTR_INFINITE));
                bannerCard.cell.setInfiniteMinCount(styleJson.getIntValue(ATTR_INFINITE_MIN_COUNT));
                bannerCard.cell.setIndicatorFocus(styleJson.getString(ATTR_INDICATOR_FOCUS));
                bannerCard.cell.setIndicatorNor(styleJson.getString(ATTR_INDICATOR_NORMAL));
                bannerCard.cell.setIndicatorGravity(styleJson.getString(ATTR_INDICATOR_GRA));
                bannerCard.cell.setIndicatorPos(styleJson.getString(ATTR_INDICATOR_POS));
                bannerCard.cell.setIndicatorGap(Style.parseSize(styleJson.getString(ATTR_INDICATOR_GAP), Style.dp2px(6)));
                bannerCard.cell.setIndicatorMargin(Style.parseSize(styleJson.getString(ATTR_INDICATOR_MARGIN), 0));
                bannerCard.cell.setIndicatorHeight(Style.parseSize(styleJson.getString(ATTR_INDICATOR_HEIGHT), 0));
                bannerCard.cell.setPageWidth(Utils.getJsonFloatValue(styleJson, ATTR_PAGE_WIDTH));
                bannerCard.cell.sethGap(Style.parseSize(styleJson.getString(ATTR_HGAP), 0));
                bannerCard.cell.itemRatio = Utils.getJsonDoubleValue(styleJson, ATTR_ITEM_RATIO);
                bannerCard.cell.itemMargin[0] = Style.parseSize(styleJson.getString(ATTR_ITEM_MARGIN_LEFT), 0);
                bannerCard.cell.itemMargin[1] = Style.parseSize(styleJson.getString(ATTR_ITEM_MARGIN_RIGHT), 0);
                parseStyle(style, styleJson);
            }
            card.style = style;
            bannerCard.cell.setRatio(style.aspectRatio);
            bannerCard.cell.margin = style.margin;
            bannerCard.cell.height = style.height;
        } else if (card instanceof OnePlusNCard) {
            ColumnStyle style = new ColumnStyle();
            if (styleJson != null) {
                parseStyle(style, styleJson);
                JSONArray jsonCols = styleJson.getJSONArray(KEY_COLS);
                if (jsonCols != null) {
                    style.cols = new float[jsonCols.size()];
                    for (int i = 0; i < style.cols.length; i++) {
                        style.cols[i] = (float) jsonCols.getDoubleValue(i);
                    }
                } else {
                    style.cols = new float[0];
                }
                JSONArray jsonRows = styleJson.getJSONArray(KEY_ROWS);
                if (jsonRows != null) {
                    style.rows = new float[jsonRows.size()];
                    for (int i = 0; i < style.rows.length; i++) {
                        style.rows[i] = (float) jsonRows.getDoubleValue(i);
                    }
                } else {
                    style.rows = new float[0];
                }
            }
            card.style = style;
        } else if (card instanceof FixLinearScrollCard) {
            FixLinearScrollCard fixLinearScrollCard = (FixLinearScrollCard) card;
            FixCard.FixStyle fixStyle = new FixCard.FixStyle();
            if (styleJson != null) {
                parseStyle(fixStyle, styleJson);
                String showTypeStr = styleJson.getString(KEY_SHOW_TYPE);
                if (TextUtils.isEmpty(showTypeStr)) {
                    showTypeStr = "top_left";
                } else {
                    showTypeStr = showTypeStr.toLowerCase();
                }
                String align = styleJson.getString(KEY_ALIGN);
                if (TextUtils.isEmpty(align)) {
                    align = "always";
                } else {
                    align = align.toLowerCase();
                }
                Boolean sketchMeasure = styleJson.getBoolean(KEY_SKETCH_MEASURE);
                if (sketchMeasure == null) {
                    fixStyle.sketchMeasure = true;
                } else {
                    fixStyle.sketchMeasure = sketchMeasure;
                }
                if ("showonenter".equals(showTypeStr)) {
                    fixStyle.showType = SHOW_ON_ENTER;
                } else if ("showonleave".equals(showTypeStr)) {
                    fixStyle.showType = SHOW_ON_LEAVE;
                } else if ("always".equals(showTypeStr)) {
                    fixStyle.showType = SHOW_ALWAYS;
                }
                if ("top_left".equals(align)) {
                    fixStyle.alignType = TOP_LEFT;
                } else if ("top_right".equals(align)) {
                    fixStyle.alignType = TOP_RIGHT;
                } else if ("bottom_left".equals(align)) {
                    fixStyle.alignType = BOTTOM_LEFT;
                } else if ("bottom_right".equals(align)) {
                    fixStyle.alignType = BOTTOM_RIGHT;
                }
                fixStyle.x = Style.parseSize(styleJson.getString(KEY_X), 0);
                fixStyle.y = Style.parseSize(styleJson.getString(KEY_Y), 0);
            }
            fixLinearScrollCard.mFixStyle = fixStyle;
        } else if (card instanceof StickyEndCard) {
            StickyCard.StickyStyle stickyStyle = new StickyCard.StickyStyle(false);
            if (styleJson != null) {
                stickyStyle.offset = Style.parseSize(styleJson.getString("offset"), 0);
            }
            card.style = stickyStyle;
        } else if (card instanceof StickyCard) {
            StickyCard.StickyStyle stickyStyle = new StickyCard.StickyStyle(true);
            if (styleJson != null) {
                String sticky = styleJson.getString(KEY_STICKY);
                if (TextUtils.isEmpty(sticky)) {
                    sticky = stickyStyle.stickyStart ? STICKY_START : STICKY_END;
                }
                stickyStyle.stickyStart = STICKY_START.equalsIgnoreCase(sticky);
                stickyStyle.offset = Style.parseSize(styleJson.getString("offset"), 0);
            }
            card.style = stickyStyle;
        } else if (card instanceof FixCard) {
            FixCard.FixStyle fixStyle = new FixCard.FixStyle();
            if (styleJson != null) {
                parseStyle(fixStyle, styleJson);
                String showTypeStr = styleJson.getString(KEY_SHOW_TYPE);
                if (TextUtils.isEmpty(showTypeStr)) {
                    showTypeStr = "top_left";
                } else {
                    showTypeStr = showTypeStr.toLowerCase();
                }
                String align = styleJson.getString(KEY_ALIGN);
                if (TextUtils.isEmpty(align)) {
                    align = "always";
                } else {
                    align = align.toLowerCase();
                }
                Boolean sketchMeasure = styleJson.getBoolean(KEY_SKETCH_MEASURE);
                if (sketchMeasure == null) {
                    fixStyle.sketchMeasure = true;
                } else {
                    fixStyle.sketchMeasure = sketchMeasure;
                }
                if ("showonenter".equals(showTypeStr)) {
                    fixStyle.showType = SHOW_ON_ENTER;
                } else if ("showonleave".equals(showTypeStr)) {
                    fixStyle.showType = SHOW_ON_LEAVE;
                } else if ("always".equals(showTypeStr)) {
                    fixStyle.showType = SHOW_ALWAYS;
                }
                if ("top_left".equals(align)) {
                    fixStyle.alignType = TOP_LEFT;
                } else if ("top_right".equals(align)) {
                    fixStyle.alignType = TOP_RIGHT;
                } else if ("bottom_left".equals(align)) {
                    fixStyle.alignType = BOTTOM_LEFT;
                } else if ("bottom_right".equals(align)) {
                    fixStyle.alignType = BOTTOM_RIGHT;
                }
                fixStyle.x = Style.parseSize(styleJson.getString(KEY_X), 0);
                fixStyle.y = Style.parseSize(styleJson.getString(KEY_Y), 0);
            }
            card.style = fixStyle;
        } else if (card instanceof LinearScrollCard) {
            LinearScrollCard linearScrollCard = (LinearScrollCard) card;
            try {
                linearScrollCard.cell.stringType = TangramBuilder.TYPE_LINEAR_SCROLL_CELL_COMPACT;
                linearScrollCard.cell.serviceManager = serviceManager;
                if (!linearScrollCard.getCells().isEmpty()) {
                    linearScrollCard.cell.cells.addAll(linearScrollCard.getCells());
                    linearScrollCard.setCells(linearScrollCard.getCells());
                }
            } catch (Exception e) {
                if (errorSupport == null) {
                    errorSupport = serviceManager.getService(InternalErrorSupport.class);
                }
                HashMap<String, Object> params = new HashMap<>();
                params.put("exception", Log.getStackTraceString(e));
                errorSupport.onError(InternalErrorSupport.ERROR_PARSE_CARDS_ERROR, "Parse linear scroll card error.", params);
                e.printStackTrace();
                linearScrollCard.setCells(null);
            }
            Style style = new Style();
            if (styleJson != null) {
                linearScrollCard.cell.pageWidth = Style.parseSize(styleJson.getString(LinearScrollCell.KEY_PAGE_WIDTH), 0);
                linearScrollCard.cell.pageHeight = Style.parseSize(styleJson.getString(LinearScrollCell.KEY_PAGE_HEIGHT), 0);
                linearScrollCard.cell.defaultIndicatorColor = Style.parseColor(styleJson.getString(LinearScrollCell.KEY_DEFAULT_INDICATOR_COLOR), LinearScrollCell.DEFAULT_DEFAULT_INDICATOR_COLOR);
                linearScrollCard.cell.indicatorColor = Style.parseColor(styleJson.getString(LinearScrollCell.KEY_INDICATOR_COLOR), LinearScrollCell.DEFAULT_INDICATOR_COLOR);
                if (styleJson.containsKey(LinearScrollCell.KEY_HAS_INDICATOR)) {
                    linearScrollCard.cell.hasIndicator = styleJson.getBooleanValue(LinearScrollCell.KEY_HAS_INDICATOR);
                }
                linearScrollCard.cell.indicatorHeight = Style.parseSize(styleJson.getString(LinearScrollCell.KEY_INDICATOR_HEIGHT), LinearScrollCell.DEFAULT_INDICATOR_HEIGHT);
                linearScrollCard.cell.indicatorWidth = Style.parseSize(styleJson.getString(LinearScrollCell.KEY_INDICATOR_WIDTH), LinearScrollCell.DEFAULT_INDICATOR_WIDTH);
                linearScrollCard.cell.defaultIndicatorWidth = Style.parseSize(styleJson.getString(LinearScrollCell.KEY_DEFAULT_INDICATOR_WIDTH), LinearScrollCell.DEFAULT_DEFAULT_INDICATOR_WIDTH);
                linearScrollCard.cell.indicatorMargin = Style.parseSize(styleJson.getString(LinearScrollCell.KEY_INDICATOR_MARGIN), LinearScrollCell.DEFAULT_INDICATOR_MARGIN);
                linearScrollCard.cell.indicatorRadius = Style.parseSize(styleJson.getString(LinearScrollCell.KEY_INDICATOR_RADIUS), LinearScrollCell.DEFAULT_INDICATOR_RADIUS);
                if (styleJson.containsKey(LinearScrollCell.KEY_FOOTER_TYPE)) {
                    linearScrollCard.cell.footerType = styleJson.getString(LinearScrollCell.KEY_FOOTER_TYPE);
                }
                linearScrollCard.cell.bgColor = Style.parseColor(styleJson.getString(KEY_BG_COLOR), Color.TRANSPARENT);
                Boolean retainScrollState = styleJson.getBoolean(LinearScrollCell.KEY_RETAIN_SCROLL_STATE);
                if (retainScrollState == null) {
                    linearScrollCard.cell.retainScrollState = true;
                } else {
                    linearScrollCard.cell.retainScrollState = retainScrollState;
                }
                linearScrollCard.cell.scrollMarginLeft = Style.parseSize(styleJson.getString(LinearScrollCell.KEY_SCROLL_MARGIN_LEFT), 0);
                linearScrollCard.cell.scrollMarginRight = Style.parseSize(styleJson.getString(LinearScrollCell.KEY_SCROLL_MARGIN_RIGHT), 0);
                linearScrollCard.cell.hGap = Style.parseSize(styleJson.getString(LinearScrollCell.KEY_HGAP), 0);
                linearScrollCard.cell.vGap = Style.parseSize(styleJson.getString(LinearScrollCell.KEY_VGAP), 0);
                linearScrollCard.cell.nativeBackgroundImage = styleJson.getString(LinearScrollCell.KEY_NATIVE_BG_IMAGE);
                Integer maxRows = styleJson.getInteger(LinearScrollCell.KEY_MAX_ROWS);
                if (maxRows == null) {
                    maxRows = LinearScrollCell.DEFAULT_MAX_ROWS;
                }
                linearScrollCard.cell.maxRows = maxRows;
                try {
                    linearScrollCard.cell.maxCols = (int) styleJson.getDoubleValue(LinearScrollCell.KEY_MAX_COLS);
                } catch (Exception e) {
                    if (errorSupport == null) {
                        errorSupport = serviceManager.getService(InternalErrorSupport.class);
                    }
                    HashMap<String, Object> params = new HashMap<>();
                    params.put("exception", Log.getStackTraceString(e));
                    errorSupport.onError(InternalErrorSupport.ERROR_PARSE_CARDS_ERROR, "Parse linear scroll card max cols error.", params);
                    e.printStackTrace();
                }
                parseStyle(style, styleJson);
            }
            linearScrollCard.style = style;
            card = linearScrollCard;
        } else if (card instanceof StaggeredCard) {
            StaggeredCard staggeredCard = (StaggeredCard) card;
            StaggeredCard.StaggeredStyle style = new StaggeredCard.StaggeredStyle();
            if (styleJson != null) {
                parseStyle(style, styleJson);
                Integer column = styleJson.getInteger(KEY_COLUMN);
                if (column == null) {
                    column = 2;
                }
                style.column = column;
                style.hGap = Style.parseSize(styleJson.getString(KEY_H_GAP), 0);
                style.vGap = Style.parseSize(styleJson.getString(KEY_V_GAP), 0);
            }
            staggeredCard.style = style;
        } else if (isCustomCard(card.stringType)) {
            parseCustomCard(card, data, serviceManager, infoMap);
        } else {
            Style style = new Style();
            parseStyle(style, styleJson);
            card.style = style;
        }
        if (card.isValid()) {
            if (card.style != null && card.style.slidable) {
                return new SlideCard(card);
            } else {
                return card;
            }
        }
    } else {
        LogUtils.w(TAG, "Invalid card type when parse JSON data");
    }
    return Card.NaN;
}
Also used : WrapCellCard(com.tmall.wireless.tangram3.structure.card.WrapCellCard) BaseCell(com.tmall.wireless.tangram3.structure.BaseCell) BannerCell(com.tmall.wireless.tangram3.structure.cell.BannerCell) HashMap(java.util.HashMap) LinearScrollCard(com.tmall.wireless.tangram3.structure.card.LinearScrollCard) FixLinearScrollCard(com.tmall.wireless.tangram3.structure.card.FixLinearScrollCard) GridCard(com.tmall.wireless.tangram3.structure.card.GridCard) StaggeredCard(com.tmall.wireless.tangram3.structure.card.StaggeredCard) StickyEndCard(com.tmall.wireless.tangram3.structure.card.StickyEndCard) ColumnStyle(com.tmall.wireless.tangram3.structure.style.ColumnStyle) ColumnStyle(com.tmall.wireless.tangram3.structure.style.ColumnStyle) JSONArray(com.alibaba.fastjson.JSONArray) FixLinearScrollCard(com.tmall.wireless.tangram3.structure.card.FixLinearScrollCard) StickyCard(com.tmall.wireless.tangram3.structure.card.StickyCard) OnePlusNCard(com.tmall.wireless.tangram3.structure.card.OnePlusNCard) StickyCard(com.tmall.wireless.tangram3.structure.card.StickyCard) LinearScrollCard(com.tmall.wireless.tangram3.structure.card.LinearScrollCard) SlideCard(com.tmall.wireless.tangram3.structure.card.SlideCard) StickyEndCard(com.tmall.wireless.tangram3.structure.card.StickyEndCard) WrapCellCard(com.tmall.wireless.tangram3.structure.card.WrapCellCard) GridCard(com.tmall.wireless.tangram3.structure.card.GridCard) FixLinearScrollCard(com.tmall.wireless.tangram3.structure.card.FixLinearScrollCard) BannerCard(com.tmall.wireless.tangram3.structure.card.BannerCard) FixCard(com.tmall.wireless.tangram3.structure.card.FixCard) StaggeredCard(com.tmall.wireless.tangram3.structure.card.StaggeredCard) OnePlusNCard(com.tmall.wireless.tangram3.structure.card.OnePlusNCard) SlideCard(com.tmall.wireless.tangram3.structure.card.SlideCard) JSONObject(com.alibaba.fastjson.JSONObject) InternalErrorSupport(com.tmall.wireless.tangram3.support.InternalErrorSupport) BannerCard(com.tmall.wireless.tangram3.structure.card.BannerCard) FixCard(com.tmall.wireless.tangram3.structure.card.FixCard) JSONObject(com.alibaba.fastjson.JSONObject) NonNull(android.support.annotation.NonNull)

Example 2 with Style

use of com.tmall.wireless.tangram3.dataparser.concrete.Style 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 3 with Style

use of com.tmall.wireless.tangram3.dataparser.concrete.Style 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)

Example 4 with Style

use of com.tmall.wireless.tangram3.dataparser.concrete.Style in project Tangram-Android by alibaba.

the class OnePlusNCard method convertLayoutHelper.

@Nullable
@Override
public LayoutHelper convertLayoutHelper(@Nullable LayoutHelper oldHelper) {
    OnePlusNLayoutHelper layoutHelper;
    if (oldHelper instanceof OnePlusNLayoutHelper) {
        layoutHelper = (OnePlusNLayoutHelper) oldHelper;
    } else {
        layoutHelper = new OnePlusNLayoutHelper();
    }
    layoutHelper.setItemCount(mCells.size());
    if (mCells.size() == 1) {
        BaseCell isHeader = mCells.get(0);
        layoutHelper.setHasHeader(isHeader.gridDisplayType == BaseCell.GridDisplayType.block);
        layoutHelper.setHasFooter(false);
    } else if (mCells.size() >= 2) {
        BaseCell isHeader = mCells.get(0);
        layoutHelper.setHasHeader(isHeader.gridDisplayType == BaseCell.GridDisplayType.block);
        BaseCell isFooter = mCells.get(mCells.size() - 1);
        layoutHelper.setHasFooter(isFooter.gridDisplayType == BaseCell.GridDisplayType.block);
    }
    if (style instanceof ColumnStyle) {
        ColumnStyle columnStyle = (ColumnStyle) style;
        if (columnStyle.cols != null && columnStyle.cols.length > 0)
            layoutHelper.setColWeights(columnStyle.cols);
        else
            layoutHelper.setColWeights(EMPTY_WEIGHTS);
        if (!Float.isNaN(style.aspectRatio)) {
            layoutHelper.setAspectRatio(style.aspectRatio);
        }
        if (columnStyle.rows != null && columnStyle.rows.length > 0) {
            layoutHelper.setRowWeight(columnStyle.rows[0]);
        }
        layoutHelper.setBgColor(columnStyle.bgColor);
        layoutHelper.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]);
        layoutHelper.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]);
    }
    return layoutHelper;
}
Also used : ColumnStyle(com.tmall.wireless.tangram3.structure.style.ColumnStyle) BaseCell(com.tmall.wireless.tangram3.structure.BaseCell) OnePlusNLayoutHelper(com.alibaba.android.vlayout.layout.OnePlusNLayoutHelper) Nullable(android.support.annotation.Nullable)

Example 5 with Style

use of com.tmall.wireless.tangram3.dataparser.concrete.Style in project Tangram-Android by alibaba.

the class PojoDataParser method parseCell.

protected void parseCell(BaseCell cell, JSONObject json) {
    if (json != null) {
        cell.extras = json;
        cell.id = json.getString(KEY_BIZ_ID);
        if (TextUtils.isEmpty(cell.id) && json.containsKey(KEY_ID)) {
            cell.id = json.getString(KEY_ID);
        }
        cell.stringType = parseCellType(json);
        cell.typeKey = json.getString(KEY_TYPE_KEY);
        String reuseId = json.getString(KEY_TYPE_REUSEID);
        if (!TextUtils.isEmpty(reuseId)) {
            cell.typeKey = reuseId;
        }
        Integer position = json.getInteger(KEY_POSITION);
        if (position == null) {
            position = -1;
        }
        cell.position = position;
        JSONObject styleJson = json.getJSONObject(KEY_STYLE);
        Style style = new Style();
        cell.style = parseStyle(style, styleJson);
    } else {
        cell.extras = new JSONObject();
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) ColumnStyle(com.tmall.wireless.tangram3.structure.style.ColumnStyle)

Aggregations

ColumnStyle (com.tmall.wireless.tangram3.structure.style.ColumnStyle)3 Nullable (android.support.annotation.Nullable)2 View (android.view.View)2 BaseLayoutHelper (com.alibaba.android.vlayout.layout.BaseLayoutHelper)2 JSONObject (com.alibaba.fastjson.JSONObject)2 BaseCell (com.tmall.wireless.tangram3.structure.BaseCell)2 CardSupport (com.tmall.wireless.tangram3.support.CardSupport)2 NonNull (android.support.annotation.NonNull)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 OnePlusNLayoutHelper (com.alibaba.android.vlayout.layout.OnePlusNLayoutHelper)1 GridRangeStyle (com.alibaba.android.vlayout.layout.RangeGridLayoutHelper.GridRangeStyle)1 JSONArray (com.alibaba.fastjson.JSONArray)1 Card (com.tmall.wireless.tangram3.dataparser.concrete.Card)1 Style (com.tmall.wireless.tangram3.dataparser.concrete.Style)1 BannerCard (com.tmall.wireless.tangram3.structure.card.BannerCard)1 FixCard (com.tmall.wireless.tangram3.structure.card.FixCard)1