Search in sources :

Example 11 with LayoutParams

use of android.support.v7.widget.RecyclerView.LayoutParams in project SuperSLiM by TonicArtos.

the class LayoutManager method scrollVerticallyBy.

@Override
public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state) {
    int numChildren = getChildCount();
    if (numChildren == 0) {
        return 0;
    }
    LayoutState layoutState = new LayoutState(this, recycler, state);
    final Direction direction = dy > 0 ? Direction.END : Direction.START;
    final boolean isDirectionEnd = direction == Direction.END;
    final int height = getHeight();
    final int leadingEdge = isDirectionEnd ? height + dy : dy;
    // from the bottom up.
    if (isDirectionEnd) {
        final View end = getAnchorAtEnd();
        LayoutParams params = (LayoutParams) end.getLayoutParams();
        SectionLayoutManager slm = getSlm(params);
        final int endEdge = slm.getLowestEdge(params.getTestedFirstPosition(), getChildCount() - 1, getDecoratedBottom(end));
        if (endEdge < height - getPaddingBottom() && getPosition(end) == (state.getItemCount() - 1)) {
            return 0;
        }
    }
    final int fillEdge = fillUntil(leadingEdge, direction, layoutState);
    final int delta;
    if (isDirectionEnd) {
        // Add padding so we scroll to inset area at scroll end.
        int fillDelta = fillEdge - height + getPaddingBottom();
        delta = fillDelta < dy ? fillDelta : dy;
    } else {
        int fillDelta = fillEdge - getPaddingTop();
        delta = fillDelta > dy ? fillDelta : dy;
    }
    if (delta != 0) {
        offsetChildrenVertical(-delta);
        trimTail(isDirectionEnd ? Direction.START : Direction.END, layoutState);
    }
    layoutState.recycleCache();
    return delta;
}
Also used : View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView)

Example 12 with LayoutParams

use of android.support.v7.widget.RecyclerView.LayoutParams in project Carbon by ZieIony.

the class Toolbar method addCustomViewsWithGravity.

/**
     * Prepare a list of non-SYSTEM child views. If the layout direction is RTL
     * this will be in reverse child order.
     *
     * @param views   List to populate. It will be cleared before use.
     * @param gravity Horizontal gravity to match against
     */
private void addCustomViewsWithGravity(List<View> views, int gravity) {
    final boolean isRtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;
    final int childCount = getChildCount();
    final int absGrav = GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(this));
    views.clear();
    if (isRtl) {
        for (int i = childCount - 1; i >= 0; i--) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (lp.mViewType == LayoutParams.CUSTOM && shouldLayout(child) && getChildHorizontalGravity(lp.gravity) == absGrav) {
                views.add(child);
            }
        }
    } else {
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (lp.mViewType == LayoutParams.CUSTOM && shouldLayout(child) && getChildHorizontalGravity(lp.gravity) == absGrav) {
                views.add(child);
            }
        }
    }
}
Also used : CollapsibleActionView(android.support.v7.view.CollapsibleActionView) MenuView(android.support.v7.view.menu.MenuView) View(android.view.View) ImageView(carbon.widget.ImageView) TextView(carbon.widget.TextView) ActionMenuView(android.support.v7.widget.ActionMenuView)

Example 13 with LayoutParams

use of android.support.v7.widget.RecyclerView.LayoutParams in project Carbon by ZieIony.

the class Toolbar method ensureCollapseButtonView.

private void ensureCollapseButtonView() {
    if (mCollapseButtonView == null) {
        mCollapseButtonView = new ImageButton(getContext(), null, R.attr.toolbarNavigationButtonStyle);
        mCollapseButtonView.setImageDrawable(mCollapseIcon);
        mCollapseButtonView.setContentDescription(mCollapseDescription);
        final LayoutParams lp = generateDefaultLayoutParams();
        lp.gravity = GravityCompat.START | (mButtonGravity & Gravity.VERTICAL_GRAVITY_MASK);
        lp.mViewType = LayoutParams.EXPANDED;
        mCollapseButtonView.setLayoutParams(lp);
        mCollapseButtonView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                collapseActionView();
            }
        });
    }
}
Also used : ImageButton(android.widget.ImageButton) CollapsibleActionView(android.support.v7.view.CollapsibleActionView) MenuView(android.support.v7.view.menu.MenuView) View(android.view.View) ImageView(carbon.widget.ImageView) TextView(carbon.widget.TextView) ActionMenuView(android.support.v7.widget.ActionMenuView)

Example 14 with LayoutParams

use of android.support.v7.widget.RecyclerView.LayoutParams in project Carbon by ZieIony.

the class Toolbar method onLayout.

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    final boolean isRtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;
    final int width = getWidth();
    final int height = getHeight();
    final int paddingLeft = getPaddingLeft();
    final int paddingRight = getPaddingRight();
    final int paddingTop = getPaddingTop();
    final int paddingBottom = getPaddingBottom();
    int left = paddingLeft;
    int right = width - paddingRight;
    final int[] collapsingMargins = mTempMargins;
    collapsingMargins[0] = collapsingMargins[1] = 0;
    // Align views within the minimum toolbar height, if set.
    final int alignmentHeight = getMinimumHeightCompat();
    if (shouldLayout(mNavButtonView)) {
        if (isRtl) {
            right = layoutChildRight(mNavButtonView, right, collapsingMargins, alignmentHeight);
        } else {
            left = layoutChildLeft(mNavButtonView, left, collapsingMargins, alignmentHeight);
        }
    }
    if (shouldLayout(mCollapseButtonView)) {
        if (isRtl) {
            right = layoutChildRight(mCollapseButtonView, right, collapsingMargins, alignmentHeight);
        } else {
            left = layoutChildLeft(mCollapseButtonView, left, collapsingMargins, alignmentHeight);
        }
    }
    if (shouldLayout(mMenuView)) {
        if (isRtl) {
            left = layoutChildLeft(mMenuView, left, collapsingMargins, alignmentHeight);
        } else {
            right = layoutChildRight(mMenuView, right, collapsingMargins, alignmentHeight);
        }
    }
    collapsingMargins[0] = Math.max(0, getContentInsetLeft() - left);
    collapsingMargins[1] = Math.max(0, getContentInsetRight() - (width - paddingRight - right));
    left = Math.max(left, getContentInsetLeft());
    right = Math.min(right, width - paddingRight - getContentInsetRight());
    if (shouldLayout(mExpandedActionView)) {
        if (isRtl) {
            right = layoutChildRight(mExpandedActionView, right, collapsingMargins, alignmentHeight);
        } else {
            left = layoutChildLeft(mExpandedActionView, left, collapsingMargins, alignmentHeight);
        }
    }
    if (shouldLayout(mLogoView)) {
        if (isRtl) {
            right = layoutChildRight(mLogoView, right, collapsingMargins, alignmentHeight);
        } else {
            left = layoutChildLeft(mLogoView, left, collapsingMargins, alignmentHeight);
        }
    }
    final boolean layoutTitle = shouldLayout(mTitleTextView);
    final boolean layoutSubtitle = shouldLayout(mSubtitleTextView);
    int titleHeight = 0;
    if (layoutTitle) {
        final LayoutParams lp = (LayoutParams) mTitleTextView.getLayoutParams();
        titleHeight += lp.topMargin + mTitleTextView.getMeasuredHeight() + lp.bottomMargin;
    }
    if (layoutSubtitle) {
        final LayoutParams lp = (LayoutParams) mSubtitleTextView.getLayoutParams();
        titleHeight += lp.topMargin + mSubtitleTextView.getMeasuredHeight() + lp.bottomMargin;
    }
    if (layoutTitle || layoutSubtitle) {
        int titleTop;
        final View topChild = layoutTitle ? mTitleTextView : mSubtitleTextView;
        final View bottomChild = layoutSubtitle ? mSubtitleTextView : mTitleTextView;
        final LayoutParams toplp = (LayoutParams) topChild.getLayoutParams();
        final LayoutParams bottomlp = (LayoutParams) bottomChild.getLayoutParams();
        final boolean titleHasWidth = layoutTitle && mTitleTextView.getMeasuredWidth() > 0 || layoutSubtitle && mSubtitleTextView.getMeasuredWidth() > 0;
        switch(mGravity & Gravity.VERTICAL_GRAVITY_MASK) {
            case Gravity.TOP:
                titleTop = getPaddingTop() + toplp.topMargin + mTitleMarginTop;
                break;
            default:
            case Gravity.CENTER_VERTICAL:
                final int space = height - paddingTop - paddingBottom;
                int spaceAbove = (space - titleHeight) / 2;
                if (spaceAbove < toplp.topMargin + mTitleMarginTop) {
                    spaceAbove = toplp.topMargin + mTitleMarginTop;
                } else {
                    final int spaceBelow = height - paddingBottom - titleHeight - spaceAbove - paddingTop;
                    if (spaceBelow < toplp.bottomMargin + mTitleMarginBottom) {
                        spaceAbove = Math.max(0, spaceAbove - (bottomlp.bottomMargin + mTitleMarginBottom - spaceBelow));
                    }
                }
                titleTop = paddingTop + spaceAbove;
                break;
            case Gravity.BOTTOM:
                titleTop = height - paddingBottom - bottomlp.bottomMargin - mTitleMarginBottom - titleHeight;
                break;
        }
        if (isRtl) {
            final int rd = (titleHasWidth ? mTitleMarginStart : 0) - collapsingMargins[1];
            right -= Math.max(0, rd);
            collapsingMargins[1] = Math.max(0, -rd);
            int titleRight = right;
            int subtitleRight = right;
            if (layoutTitle) {
                final LayoutParams lp = (LayoutParams) mTitleTextView.getLayoutParams();
                final int titleLeft = titleRight - mTitleTextView.getMeasuredWidth();
                final int titleBottom = titleTop + mTitleTextView.getMeasuredHeight();
                mTitleTextView.layout(titleLeft, titleTop, titleRight, titleBottom);
                titleRight = titleLeft - mTitleMarginEnd;
                titleTop = titleBottom + lp.bottomMargin;
            }
            if (layoutSubtitle) {
                final LayoutParams lp = (LayoutParams) mSubtitleTextView.getLayoutParams();
                titleTop += lp.topMargin;
                final int subtitleLeft = subtitleRight - mSubtitleTextView.getMeasuredWidth();
                final int subtitleBottom = titleTop + mSubtitleTextView.getMeasuredHeight();
                mSubtitleTextView.layout(subtitleLeft, titleTop, subtitleRight, subtitleBottom);
                subtitleRight = subtitleRight - mTitleMarginEnd;
                titleTop = subtitleBottom + lp.bottomMargin;
            }
            if (titleHasWidth) {
                right = Math.min(titleRight, subtitleRight);
            }
        } else {
            final int ld = (titleHasWidth ? mTitleMarginStart : 0) - collapsingMargins[0];
            left += Math.max(0, ld);
            collapsingMargins[0] = Math.max(0, -ld);
            int titleLeft = left;
            int subtitleLeft = left;
            if (layoutTitle) {
                final LayoutParams lp = (LayoutParams) mTitleTextView.getLayoutParams();
                final int titleRight = titleLeft + mTitleTextView.getMeasuredWidth();
                final int titleBottom = titleTop + mTitleTextView.getMeasuredHeight();
                mTitleTextView.layout(titleLeft, titleTop, titleRight, titleBottom);
                titleLeft = titleRight + mTitleMarginEnd;
                titleTop = titleBottom + lp.bottomMargin;
            }
            if (layoutSubtitle) {
                final LayoutParams lp = (LayoutParams) mSubtitleTextView.getLayoutParams();
                titleTop += lp.topMargin;
                final int subtitleRight = subtitleLeft + mSubtitleTextView.getMeasuredWidth();
                final int subtitleBottom = titleTop + mSubtitleTextView.getMeasuredHeight();
                mSubtitleTextView.layout(subtitleLeft, titleTop, subtitleRight, subtitleBottom);
                subtitleLeft = subtitleRight + mTitleMarginEnd;
                titleTop = subtitleBottom + lp.bottomMargin;
            }
            if (titleHasWidth) {
                left = Math.max(titleLeft, subtitleLeft);
            }
        }
    }
    // Get all remaining children sorted for layout. This is all prepared
    // such that absolute layout direction can be used below.
    addCustomViewsWithGravity(mTempViews, Gravity.LEFT);
    final int leftViewsCount = mTempViews.size();
    for (int i = 0; i < leftViewsCount; i++) {
        left = layoutChildLeft(mTempViews.get(i), left, collapsingMargins, alignmentHeight);
    }
    addCustomViewsWithGravity(mTempViews, Gravity.RIGHT);
    final int rightViewsCount = mTempViews.size();
    for (int i = 0; i < rightViewsCount; i++) {
        right = layoutChildRight(mTempViews.get(i), right, collapsingMargins, alignmentHeight);
    }
    // Centered views try to center with respect to the whole bar, but views pinned
    // to the left or right can push the mass of centered views to one side or the other.
    addCustomViewsWithGravity(mTempViews, Gravity.CENTER_HORIZONTAL);
    final int centerViewsWidth = getViewListMeasuredWidth(mTempViews, collapsingMargins);
    final int parentCenter = paddingLeft + (width - paddingLeft - paddingRight) / 2;
    final int halfCenterViewsWidth = centerViewsWidth / 2;
    int centerLeft = parentCenter - halfCenterViewsWidth;
    final int centerRight = centerLeft + centerViewsWidth;
    if (centerLeft < left) {
        centerLeft = left;
    } else if (centerRight > right) {
        centerLeft -= centerRight - right;
    }
    final int centerViewsCount = mTempViews.size();
    for (int i = 0; i < centerViewsCount; i++) {
        centerLeft = layoutChildLeft(mTempViews.get(i), centerLeft, collapsingMargins, alignmentHeight);
    }
    mTempViews.clear();
}
Also used : CollapsibleActionView(android.support.v7.view.CollapsibleActionView) MenuView(android.support.v7.view.menu.MenuView) View(android.view.View) ImageView(carbon.widget.ImageView) TextView(carbon.widget.TextView) ActionMenuView(android.support.v7.widget.ActionMenuView)

Example 15 with LayoutParams

use of android.support.v7.widget.RecyclerView.LayoutParams in project Carbon by ZieIony.

the class Toolbar method onMeasure.

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int width = 0;
    int height = 0;
    int childState = 0;
    final int[] collapsingMargins = mTempMargins;
    final int marginStartIndex;
    final int marginEndIndex;
    if (ViewUtils.isLayoutRtl(this)) {
        marginStartIndex = 1;
        marginEndIndex = 0;
    } else {
        marginStartIndex = 0;
        marginEndIndex = 1;
    }
    // System views measure first.
    int navWidth = 0;
    if (shouldLayout(mNavButtonView)) {
        measureChildConstrained(mNavButtonView, widthMeasureSpec, width, heightMeasureSpec, 0, mMaxButtonHeight);
        navWidth = mNavButtonView.getMeasuredWidth() + getHorizontalMargins(mNavButtonView);
        height = Math.max(height, mNavButtonView.getMeasuredHeight() + getVerticalMargins(mNavButtonView));
        childState = ViewUtils.combineMeasuredStates(childState, ViewCompat.getMeasuredState(mNavButtonView));
    }
    if (shouldLayout(mCollapseButtonView)) {
        measureChildConstrained(mCollapseButtonView, widthMeasureSpec, width, heightMeasureSpec, 0, mMaxButtonHeight);
        navWidth = mCollapseButtonView.getMeasuredWidth() + getHorizontalMargins(mCollapseButtonView);
        height = Math.max(height, mCollapseButtonView.getMeasuredHeight() + getVerticalMargins(mCollapseButtonView));
        childState = ViewUtils.combineMeasuredStates(childState, ViewCompat.getMeasuredState(mCollapseButtonView));
    }
    final int contentInsetStart = getContentInsetStart();
    width += Math.max(contentInsetStart, navWidth);
    collapsingMargins[marginStartIndex] = Math.max(0, contentInsetStart - navWidth);
    int menuWidth = 0;
    if (shouldLayout(mMenuView)) {
        measureChildConstrained(mMenuView, widthMeasureSpec, width, heightMeasureSpec, 0, mMaxButtonHeight);
        menuWidth = mMenuView.getMeasuredWidth() + getHorizontalMargins(mMenuView);
        height = Math.max(height, mMenuView.getMeasuredHeight() + getVerticalMargins(mMenuView));
        childState = ViewUtils.combineMeasuredStates(childState, ViewCompat.getMeasuredState(mMenuView));
    }
    final int contentInsetEnd = getContentInsetEnd();
    width += Math.max(contentInsetEnd, menuWidth);
    collapsingMargins[marginEndIndex] = Math.max(0, contentInsetEnd - menuWidth);
    if (shouldLayout(mExpandedActionView)) {
        width += measureChildCollapseMargins(mExpandedActionView, widthMeasureSpec, width, heightMeasureSpec, 0, collapsingMargins);
        height = Math.max(height, mExpandedActionView.getMeasuredHeight() + getVerticalMargins(mExpandedActionView));
        childState = ViewUtils.combineMeasuredStates(childState, ViewCompat.getMeasuredState(mExpandedActionView));
    }
    if (shouldLayout(mLogoView)) {
        width += measureChildCollapseMargins(mLogoView, widthMeasureSpec, width, heightMeasureSpec, 0, collapsingMargins);
        height = Math.max(height, mLogoView.getMeasuredHeight() + getVerticalMargins(mLogoView));
        childState = ViewUtils.combineMeasuredStates(childState, ViewCompat.getMeasuredState(mLogoView));
    }
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        if (lp.mViewType != LayoutParams.CUSTOM || !shouldLayout(child)) {
            // We already got all system views above. Skip them and GONE views.
            continue;
        }
        width += measureChildCollapseMargins(child, widthMeasureSpec, width, heightMeasureSpec, 0, collapsingMargins);
        height = Math.max(height, child.getMeasuredHeight() + getVerticalMargins(child));
        childState = ViewUtils.combineMeasuredStates(childState, ViewCompat.getMeasuredState(child));
    }
    int titleWidth = 0;
    int titleHeight = 0;
    final int titleVertMargins = mTitleMarginTop + mTitleMarginBottom;
    final int titleHorizMargins = mTitleMarginStart + mTitleMarginEnd;
    if (shouldLayout(mTitleTextView)) {
        titleWidth = measureChildCollapseMargins(mTitleTextView, widthMeasureSpec, width + titleHorizMargins, heightMeasureSpec, titleVertMargins, collapsingMargins);
        titleWidth = mTitleTextView.getMeasuredWidth() + getHorizontalMargins(mTitleTextView);
        titleHeight = mTitleTextView.getMeasuredHeight() + getVerticalMargins(mTitleTextView);
        childState = ViewUtils.combineMeasuredStates(childState, ViewCompat.getMeasuredState(mTitleTextView));
    }
    if (shouldLayout(mSubtitleTextView)) {
        titleWidth = Math.max(titleWidth, measureChildCollapseMargins(mSubtitleTextView, widthMeasureSpec, width + titleHorizMargins, heightMeasureSpec, titleHeight + titleVertMargins, collapsingMargins));
        titleHeight += mSubtitleTextView.getMeasuredHeight() + getVerticalMargins(mSubtitleTextView);
        childState = ViewUtils.combineMeasuredStates(childState, ViewCompat.getMeasuredState(mSubtitleTextView));
    }
    width += titleWidth;
    height = Math.max(height, titleHeight);
    // Measurement already took padding into account for available space for the children,
    // add it in for the final size.
    width += getPaddingLeft() + getPaddingRight();
    height += getPaddingTop() + getPaddingBottom();
    final int measuredWidth = ViewCompat.resolveSizeAndState(Math.max(width, getSuggestedMinimumWidth()), widthMeasureSpec, childState & ViewCompat.MEASURED_STATE_MASK);
    final int measuredHeight = ViewCompat.resolveSizeAndState(Math.max(height, getSuggestedMinimumHeight()), heightMeasureSpec, childState << ViewCompat.MEASURED_HEIGHT_STATE_SHIFT);
    setMeasuredDimension(measuredWidth, shouldCollapse() ? 0 : measuredHeight);
}
Also used : CollapsibleActionView(android.support.v7.view.CollapsibleActionView) MenuView(android.support.v7.view.menu.MenuView) View(android.view.View) ImageView(carbon.widget.ImageView) TextView(carbon.widget.TextView) ActionMenuView(android.support.v7.widget.ActionMenuView)

Aggregations

View (android.view.View)77 RecyclerView (android.support.v7.widget.RecyclerView)67 ViewGroup (android.view.ViewGroup)21 TextView (android.widget.TextView)21 ImageView (android.widget.ImageView)13 LayoutParams (android.support.v7.widget.RecyclerView.LayoutParams)12 Toolbar (android.support.v7.widget.Toolbar)9 FrameLayout (android.widget.FrameLayout)9 Rect (android.graphics.Rect)8 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)8 BindView (butterknife.BindView)8 ActionMenuView (android.support.v7.widget.ActionMenuView)7 MarginLayoutParams (android.view.ViewGroup.MarginLayoutParams)6 LinearLayout (android.widget.LinearLayout)6 CollapsibleActionView (android.support.v7.view.CollapsibleActionView)5 MenuView (android.support.v7.view.menu.MenuView)5 EditText (android.widget.EditText)5 ImageView (carbon.widget.ImageView)5 TextView (carbon.widget.TextView)5 VirtualLayoutManager (com.alibaba.android.vlayout.VirtualLayoutManager)5