Java Code Examples for com.alibaba.android.vlayout.VirtualLayoutManager#LayoutParams

The following examples show how to use com.alibaba.android.vlayout.VirtualLayoutManager#LayoutParams . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OnePlusNLayoutHelper.java    From vlayout with MIT License 6 votes vote down vote up
private int handleHeader(View header, LayoutStateWrapper layoutState, LayoutChunkResult result, LayoutManagerHelper helper,
    boolean layoutInVertical, int parentWidth, int parentHeight, int parentHPadding, int parentVPadding) {
    if (header == null) {
        return 0;
    }
    OrientationHelperEx orientationHelper = helper.getMainOrientationHelper();

    final VirtualLayoutManager.LayoutParams lp = (LayoutParams) header.getLayoutParams();


    // fill width
    int widthSpec = helper.getChildMeasureSpec(parentWidth - parentHPadding,
        layoutInVertical ? MATCH_PARENT : lp.width, !layoutInVertical);
    int heightSpec = helper.getChildMeasureSpec(parentHeight - parentVPadding,
        layoutInVertical ? lp.height : MeasureSpec.EXACTLY, layoutInVertical);
    helper.measureChildWithMargins(header, widthSpec, heightSpec);
    return orientationHelper.getDecoratedMeasurement(header);
}
 
Example 2
Source File: OnePlusNLayoutHelper.java    From vlayout with MIT License 6 votes vote down vote up
private int handleFooter(View footer, LayoutStateWrapper layoutState, LayoutChunkResult result, LayoutManagerHelper helper,
    boolean layoutInVertical, int parentWidth, int parentHeight, int parentHPadding, int parentVPadding) {
    if (footer == null) {
        return 0;
    }

    OrientationHelperEx orientationHelper = helper.getMainOrientationHelper();

    final VirtualLayoutManager.LayoutParams lp = (LayoutParams) footer.getLayoutParams();

    // fill width
    int widthSpec = helper.getChildMeasureSpec(parentWidth - parentHPadding,
        layoutInVertical ? MATCH_PARENT : lp.width, !layoutInVertical);
    int heightSpec = helper.getChildMeasureSpec(parentHeight - parentVPadding,
        layoutInVertical ? lp.height : MeasureSpec.EXACTLY, layoutInVertical);
    helper.measureChildWithMargins(footer, widthSpec, heightSpec);
    return orientationHelper.getDecoratedMeasurement(footer);
}
 
Example 3
Source File: BaseTangramEngine.java    From Tangram-Android with MIT License 6 votes vote down vote up
@Override
public int onGetChildDrawingOrder(int childCount, int i) {
    if (zIndex.length < childCount) {
        zIndex = doubleIndex(zIndex);
        viewIndex = doubleIndex(viewIndex);
    }
    // check all current zIndex
    for (int j = 0; j < childCount; j++) {
        View child = mContentView.getChildAt(j);
        if (child != null) {
            VirtualLayoutManager.LayoutParams layoutParams = (LayoutParams)child.getLayoutParams();
            zIndex[j] = layoutParams.zIndex;
        } else {
            zIndex[j] = 0;
        }
        viewIndex[j] = j;
    }
    // reorder drawing by zIndex
    bubbleSort(zIndex, viewIndex, childCount);

    int result = viewIndex[i];
    clearIndex(zIndex);
    clearIndex(viewIndex);
    return  result;
}
 
Example 4
Source File: OnePlusNLayoutHelper.java    From vlayout with MIT License 5 votes vote down vote up
private int handleOne(LayoutStateWrapper layoutState, LayoutChunkResult result, LayoutManagerHelper helper,
    boolean layoutInVertical, int parentWidth, int parentHeight, int parentHPadding, int parentVPadding) {
    int mainConsumed = 0;
    OrientationHelperEx orientationHelper = helper.getMainOrientationHelper();

    View view = mChildrenViews[0];
    final VirtualLayoutManager.LayoutParams lp = (LayoutParams) view.getLayoutParams();

    if (!Float.isNaN(mAspectRatio)) {
        if (layoutInVertical) {
            lp.height = (int) ((parentWidth - parentHPadding) / mAspectRatio);
        } else {
            lp.width = (int) ((parentHeight - parentVPadding) * mAspectRatio);
        }
    }

    final float weight = getViewMainWeight(0);

    // fill width
    int widthSpec = helper.getChildMeasureSpec(
        Float.isNaN(weight) ? (parentWidth - parentHPadding)
            : (int) ((parentWidth - parentHPadding) * weight),
        layoutInVertical ? MATCH_PARENT : lp.width, !layoutInVertical);
    int heightSpec = helper.getChildMeasureSpec(parentHeight - parentVPadding,
        layoutInVertical ? lp.height : MeasureSpec.EXACTLY, layoutInVertical);

    helper.measureChildWithMargins(view, widthSpec, heightSpec);

    mainConsumed += orientationHelper.getDecoratedMeasurement(view);

    calculateRect(mainConsumed, mAreaRect, layoutState, helper);

    layoutChildWithMargin(view, mAreaRect.left, mAreaRect.top, mAreaRect.right, mAreaRect.bottom,
        helper);
    handleStateOnResult(result, view);
    mainConsumed = mAreaRect.bottom - mAreaRect.top + (hasHeader ? 0 : mMarginTop + mPaddingTop) + (hasFooter ? 0 : mMarginBottom + mPaddingBottom);
    return mainConsumed;
}
 
Example 5
Source File: OnePlusNLayoutHelper.java    From vlayout with MIT License 4 votes vote down vote up
private int handleThree(LayoutStateWrapper layoutState, LayoutChunkResult result, LayoutManagerHelper helper,
    boolean layoutInVertical, int parentWidth, int parentHeight, int parentHPadding, int parentVPadding) {
    int mainConsumed = 0;
    OrientationHelperEx orientationHelper = helper.getMainOrientationHelper();

    final View child1 = mChildrenViews[0];
    final VirtualLayoutManager.LayoutParams lp1 = (VirtualLayoutManager.LayoutParams) child1.getLayoutParams();
    final View child2 = helper.getReverseLayout() ? mChildrenViews[2] : mChildrenViews[1];
    final View child3 = helper.getReverseLayout() ? mChildrenViews[1] : mChildrenViews[2];

    final VirtualLayoutManager.LayoutParams lp2 = (VirtualLayoutManager.LayoutParams) child2.getLayoutParams();
    final VirtualLayoutManager.LayoutParams lp3 = (VirtualLayoutManager.LayoutParams) child3.getLayoutParams();

    final float weight1 = getViewMainWeight(0);
    final float weight2 = getViewMainWeight(1);
    final float weight3 = getViewMainWeight(2);

    if (layoutInVertical) {

        if (!Float.isNaN(mAspectRatio)) {
            lp1.height = (int) ((parentWidth - parentHPadding) / mAspectRatio);
        }

        // make border consistent
        lp2.topMargin = lp1.topMargin;
        lp3.bottomMargin = lp1.bottomMargin;

        lp3.leftMargin = lp2.leftMargin;
        lp3.rightMargin = lp2.rightMargin;

        int availableSpace = parentWidth - parentHPadding - lp1.leftMargin - lp1.rightMargin
            - lp2.leftMargin - lp2.rightMargin;
        int width1 = Float.isNaN(weight1) ? (int) (availableSpace / 2.0f + 0.5f)
            : (int) (availableSpace * weight1 / 100 + 0.5f);
        int width2 = Float.isNaN(weight2) ? (int) (availableSpace - width1)
            : (int) (availableSpace * weight2 / 100 + 0.5);
        int width3 = Float.isNaN(weight3) ? (int) (width2)
            : (int) (availableSpace * weight3 / 100 + 0.5);

        helper.measureChildWithMargins(child1,
            MeasureSpec.makeMeasureSpec(width1 + lp1.leftMargin + lp1.rightMargin,
                MeasureSpec.EXACTLY),
            helper.getChildMeasureSpec(helper.getContentHeight(), lp1.height, true));

        int height1 = child1.getMeasuredHeight();
        int height2 =
            Float.isNaN(mRowWeight) ?
                (int) ((height1 - lp2.bottomMargin - lp3.topMargin) / 2.0f + 0.5f)
                : (int) ((height1 - lp2.bottomMargin - lp3.topMargin) * mRowWeight
                    / 100 + 0.5f);

        int height3 = height1 - lp2.bottomMargin - lp3.topMargin - height2;

        helper.measureChildWithMargins(child2,
            MeasureSpec.makeMeasureSpec(width2 + lp2.leftMargin + lp2.rightMargin,
                MeasureSpec.EXACTLY),
            MeasureSpec.makeMeasureSpec(height2 + lp2.topMargin + lp2.bottomMargin,
                MeasureSpec.EXACTLY));

        helper.measureChildWithMargins(child3,
            MeasureSpec.makeMeasureSpec(width3 + lp3.leftMargin + lp3.rightMargin,
                MeasureSpec.EXACTLY),
            MeasureSpec.makeMeasureSpec(height3 + lp3.topMargin + lp3.bottomMargin,
                MeasureSpec.EXACTLY));

        mainConsumed += Math.max(height1 + lp1.topMargin + lp1.bottomMargin,
            height2 + lp2.topMargin + lp2.bottomMargin + height3 + lp3.topMargin
                + lp3.bottomMargin);

        calculateRect(mainConsumed, mAreaRect, layoutState, helper);

        int right1 = mAreaRect.left + orientationHelper
            .getDecoratedMeasurementInOther(child1);
        layoutChildWithMargin(child1, mAreaRect.left, mAreaRect.top, right1, mAreaRect.bottom, helper);

        int right2 = right1 + orientationHelper.getDecoratedMeasurementInOther(child2);
        layoutChildWithMargin(child2, right1, mAreaRect.top, right2,
            mAreaRect.top + child2.getMeasuredHeight() + lp2.topMargin + lp2.bottomMargin, helper);

        layoutChildWithMargin(child3, right1, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child3),
            right1 + orientationHelper.getDecoratedMeasurementInOther(child3), mAreaRect.bottom, helper);
        mainConsumed = mAreaRect.bottom - mAreaRect.top + (hasHeader ? 0 : mMarginTop + mPaddingTop) + (hasFooter ? 0 : mMarginBottom + mPaddingBottom);
    } else {
        // TODO: horizontal support
    }

    handleStateOnResult(result, mChildrenViews);
    return mainConsumed;
}
 
Example 6
Source File: MVHelper.java    From Tangram-Android with MIT License 4 votes vote down vote up
protected void renderLayout(BaseCell cell, View view) {
    if (cell.style != null) {
        ViewGroup.LayoutParams lp = view.getLayoutParams();

        if (lp == null || !(lp instanceof VirtualLayoutManager.LayoutParams)) {
            if (lp == null) {
                lp = new VirtualLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            } else {
                lp = new VirtualLayoutManager.LayoutParams(lp.width, lp.height);
            }
            view.setLayoutParams(lp);
        }
        if (lp instanceof VirtualLayoutManager.LayoutParams) {
            VirtualLayoutManager.LayoutParams params = (VirtualLayoutManager.LayoutParams) lp;

            if (cell.style.height >= 0) {
                params.storeOriginHeight();
                params.height = cell.style.height;
            } else {
                params.restoreOriginHeight();
            }

            if (cell.style.width >= 0) {
                params.storeOriginWidth();
                params.width = cell.style.width;
            } else {
                params.restoreOriginWidth();
            }

            params.mAspectRatio = cell.style.aspectRatio;

            params.zIndex = cell.style.zIndex;
            if (params.zIndex == 0) {
                if (cell.parent != null && cell.parent.style != null) {
                    params.zIndex = cell.parent.style.zIndex;
                }
            }
            if (VERSION.SDK_INT >= 21) {
                view.setZ(params.zIndex);
            }
        } else {
            if (cell.style.height >= 0) {
                lp.height = cell.style.height;
            }

            if (cell.style.width >= 0) {
                lp.width = cell.style.width;
            }
        }


        if (lp instanceof ViewGroup.MarginLayoutParams) {
            ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) lp;
            layoutParams.topMargin = cell.style.margin[MARGIN_TOP_INDEX];
            layoutParams.leftMargin = cell.style.margin[MARGIN_LEFT_INDEX];
            layoutParams.bottomMargin = cell.style.margin[MARGIN_BOTTOM_INDEX];
            layoutParams.rightMargin = cell.style.margin[MARGIN_RIGHT_INDEX];
        }

        // reset translation animation before reused
        view.setTranslationX(0);
        view.setTranslationY(0);
    }
}
 
Example 7
Source File: BannerView.java    From Tangram-Android with MIT License 4 votes vote down vote up
@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);
    }
}
 
Example 8
Source File: MVHelper.java    From Tangram-Android with MIT License 4 votes vote down vote up
protected void renderLayout(BaseCell cell, View view) {
    if (cell.style != null) {
        ViewGroup.LayoutParams lp = view.getLayoutParams();

        if (lp == null || !(lp instanceof VirtualLayoutManager.LayoutParams)) {
            if (lp == null) {
                lp = new VirtualLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            } else {
                lp = new VirtualLayoutManager.LayoutParams(lp.width, lp.height);
            }
            view.setLayoutParams(lp);
        }
        if (lp instanceof VirtualLayoutManager.LayoutParams) {
            VirtualLayoutManager.LayoutParams params = (VirtualLayoutManager.LayoutParams) lp;

            if (cell.style.height >= 0) {
                params.storeOriginHeight();
                params.height = cell.style.height;
            } else {
                params.restoreOriginHeight();
            }

            if (cell.style.width >= 0) {
                params.storeOriginWidth();
                params.width = cell.style.width;
            } else {
                params.restoreOriginWidth();
            }

            params.mAspectRatio = cell.style.aspectRatio;

            params.zIndex = cell.style.zIndex;
            if (params.zIndex == 0) {
                if (cell.parent != null && cell.parent.style != null) {
                    params.zIndex = cell.parent.style.zIndex;
                }
            }
            if (VERSION.SDK_INT >= 21) {
                view.setZ(params.zIndex);
            }
        } else {
            if (cell.style.height >= 0) {
                lp.height = cell.style.height;
            }

            if (cell.style.width >= 0) {
                lp.width = cell.style.width;
            }
        }


        if (lp instanceof ViewGroup.MarginLayoutParams) {
            ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) lp;
            layoutParams.topMargin = cell.style.margin[MARGIN_TOP_INDEX];
            layoutParams.leftMargin = cell.style.margin[MARGIN_LEFT_INDEX];
            layoutParams.bottomMargin = cell.style.margin[MARGIN_BOTTOM_INDEX];
            layoutParams.rightMargin = cell.style.margin[MARGIN_RIGHT_INDEX];
        }

        // reset translation animation before reused
        view.setTranslationX(0);
        view.setTranslationY(0);
    }
}
 
Example 9
Source File: BannerView.java    From Tangram-Android with MIT License 4 votes vote down vote up
@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.extras.getIntValue(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);
    }
}
 
Example 10
Source File: SubAdapter.java    From AndroidSamples with Apache License 2.0 4 votes vote down vote up
public SubAdapter(Context context, LayoutHelper layoutHelper, int count) {
    this(context, layoutHelper, count, new VirtualLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
}
 
Example 11
Source File: SubAdapter.java    From AndroidSamples with Apache License 2.0 4 votes vote down vote up
public SubAdapter(Context context, LayoutHelper layoutHelper, int count, @NonNull VirtualLayoutManager.LayoutParams layoutParams) {
    this.mContext = context;
    this.mLayoutHelper = layoutHelper;
    this.mCount = count;
    this.mLayoutParams = layoutParams;
}