Search in sources :

Example 16 with LEFT

use of android.support.v7.widget.helper.ItemTouchHelper.LEFT in project EasyRecyclerView by Jude95.

the class DividerDecoration method onDrawOver.

public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    if (parent.getAdapter() == null) {
        return;
    }
    int orientation = 0;
    int headerCount = 0, footerCount = 0, dataCount;
    if (parent.getAdapter() instanceof RecyclerArrayAdapter) {
        headerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getHeaderCount();
        footerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getFooterCount();
        dataCount = ((RecyclerArrayAdapter) parent.getAdapter()).getCount();
    } else {
        dataCount = parent.getAdapter().getItemCount();
    }
    int dataStartPosition = headerCount;
    int dataEndPosition = headerCount + dataCount;
    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof StaggeredGridLayoutManager) {
        orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation();
    } else if (layoutManager instanceof GridLayoutManager) {
        orientation = ((GridLayoutManager) layoutManager).getOrientation();
    } else if (layoutManager instanceof LinearLayoutManager) {
        orientation = ((LinearLayoutManager) layoutManager).getOrientation();
    }
    int start, end;
    if (orientation == OrientationHelper.VERTICAL) {
        start = parent.getPaddingLeft() + mPaddingLeft;
        end = parent.getWidth() - parent.getPaddingRight() - mPaddingRight;
    } else {
        start = parent.getPaddingTop() + mPaddingLeft;
        end = parent.getHeight() - parent.getPaddingBottom() - mPaddingRight;
    }
    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = parent.getChildAt(i);
        int position = parent.getChildAdapterPosition(child);
        if (//数据项除了最后一项
        position >= dataStartPosition && position < dataEndPosition - 1 || //数据项最后一项
        (position == dataEndPosition - 1 && mDrawLastItem) || //header&footer且可绘制
        (!(position >= dataStartPosition && position < dataEndPosition) && mDrawHeaderFooter)) {
            if (orientation == OrientationHelper.VERTICAL) {
                RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
                int top = child.getBottom() + params.bottomMargin;
                int bottom = top + mHeight;
                mColorDrawable.setBounds(start, top, end, bottom);
                mColorDrawable.draw(c);
            } else {
                RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
                int left = child.getRight() + params.rightMargin;
                int right = left + mHeight;
                mColorDrawable.setBounds(left, start, right, end);
                mColorDrawable.draw(c);
            }
        }
    }
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) RecyclerArrayAdapter(com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter) RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 17 with LEFT

use of android.support.v7.widget.helper.ItemTouchHelper.LEFT in project UltimateAndroid by cymcsg.

the class DividerItemDecoration method drawHorizontal.

public void drawHorizontal(Canvas c, RecyclerView parent) {
    final int top = parent.getPaddingTop();
    final int bottom = parent.getHeight() - parent.getPaddingBottom();
    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        final int left = child.getRight() + params.rightMargin;
        final int right = left + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 18 with LEFT

use of android.support.v7.widget.helper.ItemTouchHelper.LEFT in project UltimateAndroid by cymcsg.

the class GridDividerDecoration method drawHorizontal.

/** Draw dividers to the right of each child view */
public void drawHorizontal(Canvas c, RecyclerView parent) {
    final int top = parent.getPaddingTop();
    final int bottom = parent.getHeight() - parent.getPaddingBottom();
    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        final int left = child.getRight() + params.rightMargin + mInsets;
        final int right = left + mDivider.getIntrinsicWidth();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 19 with LEFT

use of android.support.v7.widget.helper.ItemTouchHelper.LEFT in project UltimateAndroid by cymcsg.

the class GridDividerDecoration method drawVertical.

/** Draw dividers at each expected grid interval */
public void drawVertical(Canvas c, RecyclerView parent) {
    if (parent.getChildCount() == 0)
        return;
    final int left = parent.getPaddingLeft();
    final int right = parent.getWidth() - parent.getPaddingRight();
    final View child = parent.getChildAt(0);
    if (child.getHeight() == 0)
        return;
    final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
    int top = child.getBottom() + params.bottomMargin + mInsets;
    int bottom = top + mDivider.getIntrinsicHeight();
    final int parentBottom = parent.getHeight() - parent.getPaddingBottom();
    while (bottom < parentBottom) {
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
        top += mInsets + params.topMargin + child.getHeight() + params.bottomMargin + mInsets;
        bottom = top + mDivider.getIntrinsicHeight();
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 20 with LEFT

use of android.support.v7.widget.helper.ItemTouchHelper.LEFT in project UltimateAndroid by cymcsg.

the class StaticGridLayoutManager method scrollHorizontallyBy.

/*
     * This method describes how far RecyclerView thinks the contents should scroll horizontally.
     * You are responsible for verifying edge boundaries, and determining if this scroll
     * event somehow requires that new views be added or old views get recycled.
     */
@Override
public int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state) {
    if (getChildCount() == 0) {
        return 0;
    }
    //Take leftmost measurements from the top-left child
    final View topView = getChildAt(0);
    //Take rightmost measurements from the top-right child
    final View bottomView = getChildAt(mVisibleColumnCount - 1);
    //Optimize the case where the entire data set is too small to scroll
    int viewSpan = getDecoratedRight(bottomView) - getDecoratedLeft(topView);
    if (viewSpan <= getHorizontalSpace()) {
        //We cannot scroll in either direction
        return 0;
    }
    int delta;
    boolean leftBoundReached = getFirstVisibleColumn() == 0;
    boolean rightBoundReached = getLastVisibleColumn() >= getTotalColumnCount();
    if (dx > 0) {
        //Check right bound
        if (rightBoundReached) {
            //If we've reached the last column, enforce limits
            int rightOffset = getHorizontalSpace() - getDecoratedRight(bottomView) + getPaddingRight();
            delta = Math.max(-dx, rightOffset);
        } else {
            //No limits while the last column isn't visible
            delta = -dx;
        }
    } else {
        //Check left bound
        if (leftBoundReached) {
            int leftOffset = -getDecoratedLeft(topView) + getPaddingLeft();
            delta = Math.min(-dx, leftOffset);
        } else {
            delta = -dx;
        }
    }
    offsetChildrenHorizontal(delta);
    if (dx > 0) {
        if (getDecoratedRight(topView) < 0 && !rightBoundReached) {
            fillGrid(DIRECTION_END, recycler);
        } else if (!rightBoundReached) {
            fillGrid(DIRECTION_NONE, recycler);
        }
    } else {
        if (getDecoratedLeft(topView) > 0 && !leftBoundReached) {
            fillGrid(DIRECTION_START, recycler);
        } else if (!leftBoundReached) {
            fillGrid(DIRECTION_NONE, recycler);
        }
    }
    /*
         * Return value determines if a boundary has been reached
         * (for edge effects and flings). If returned value does not
         * match original delta (passed in), RecyclerView will draw
         * an edge effect.
         */
    return -delta;
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Aggregations

View (android.view.View)291 RecyclerView (android.support.v7.widget.RecyclerView)276 Paint (android.graphics.Paint)43 TextView (android.widget.TextView)36 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)22 ImageView (android.widget.ImageView)20 Rect (android.graphics.Rect)11 Intent (android.content.Intent)9 SuppressLint (android.annotation.SuppressLint)8 OnLayoutChangeListener (android.view.View.OnLayoutChangeListener)8 OrientationHelperEx (com.alibaba.android.vlayout.OrientationHelperEx)8 ArrayList (java.util.ArrayList)8 AlertDialog (android.support.v7.app.AlertDialog)7 Toolbar (android.support.v7.widget.Toolbar)7 ViewGroup (android.view.ViewGroup)7 GridLayoutManager (android.support.v7.widget.GridLayoutManager)6 Button (android.widget.Button)6 Animator (android.animation.Animator)5 TargetApi (android.annotation.TargetApi)5 Activity (android.app.Activity)5