Java Code Examples for android.support.v7.widget.RecyclerView.State

The following are Jave code examples for showing how to use State of the android.support.v7.widget.RecyclerView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: MultiViewAdapter   File: ItemDecorationManager.java   View Source Code Vote up 6 votes
@Override public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
  boolean isReverseLayout = getIsReverseLayout(parent);
  int childCount = parent.getChildCount();
  for (int i = 0; i < childCount; i++) {
    View child = parent.getChildAt(i);
    int adapterPosition = parent.getChildAdapterPosition(child);
    if (adapterPosition < 0) {
      return;
    }
    ItemBinder binder = adapter.getBinderForPosition(adapterPosition);
    if (binder.isItemDecorationEnabled()) {
      int itemPosition = adapter.getItemPositionInManager(parent.getChildAdapterPosition(child));
      int positionType = getPositionType(parent, adapterPosition, itemPosition, isReverseLayout);
      binder.onDraw(canvas, parent, child, itemPosition, positionType);
    }
  }
}
 
Example 2
Project: ChipsLayoutManager   File: ScrollingController.java   View Source Code Vote up 6 votes
private int computeScrollRange(RecyclerView.State state) {
    if (lm.getChildCount() == 0 || state.getItemCount() == 0) {
        return 0;
    }

    if (!lm.isSmoothScrollbarEnabled()) {
        return state.getItemCount();
    }

    int firstVisiblePos = lm.findFirstVisibleItemPosition();
    int lastVisiblePos = lm.findLastVisibleItemPosition();

    // smooth scrollbar enabled. try to estimate better.
    final int laidOutRange = Math.abs(firstVisiblePos - lastVisiblePos) + 1;

    // estimate a size for full list.
    return (int) ((float) getLaidOutArea() / laidOutRange * state.getItemCount());
}
 
Example 3
Project: GitHub   File: MaterialViewPagerHeaderDecorator.java   View Source Code Vote up 6 votes
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView recyclerView, RecyclerView.State state) {
    final RecyclerView.ViewHolder holder = recyclerView.getChildViewHolder(view);
    final Context context = recyclerView.getContext();

    if(!registered) {
        MaterialViewPagerHelper.registerRecyclerView(context, recyclerView);
        registered = true;
    }

    int headerCells = 1;

    //don't work with stagged
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if(layoutManager instanceof GridLayoutManager){
        GridLayoutManager gridLayoutManager = (GridLayoutManager)layoutManager;
        headerCells = gridLayoutManager.getSpanCount();
    }

    MaterialViewPagerAnimator animator = MaterialViewPagerHelper.getAnimator(context);
    if (animator != null) {
        if (holder.getAdapterPosition() < headerCells) {
            outRect.top = Math.round(Utils.dpToPx(animator.getHeaderHeight() + 10, context));
        }
    }
}
 
Example 4
Project: Mobike   File: CardViewtemDecortion.java   View Source Code Vote up 5 votes
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {

    int layoutOrientation = getOrientation(parent);
    if (layoutOrientation == LinearLayoutManager.VERTICAL) {
        outRect.top = 10;
        outRect.left=5;
        outRect.right=5;
    } else if(layoutOrientation == LinearLayoutManager.HORIZONTAL) {
        outRect.left = 5;
    }
}
 
Example 5
Project: qmui   File: GridDividerItemDecoration.java   View Source Code Vote up 5 votes
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    super.onDraw(c, parent, state);
    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        int position = parent.getChildLayoutPosition(child);
        int column = (position + 1) % 3;
        column  = column == 0 ? mSpanCount : column;

        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
                .getLayoutParams();
        final int top = child.getBottom() + params.bottomMargin +
                Math.round(ViewCompat.getTranslationY(child));
        final int bottom = top + mDivider.getIntrinsicHeight();
        final int left = child.getRight() + params.rightMargin +
                Math.round(ViewCompat.getTranslationX(child));
        final int right = left + mDivider.getIntrinsicHeight();

        mDivider.setBounds(child.getLeft(), top, right, bottom);
        mDivider.draw(c);

        if(column < mSpanCount) {
            mDivider.setBounds(left, child.getTop(), right, bottom);
            mDivider.draw(c);
        }

    }
}
 
Example 6
Project: GitHub   File: RangeGridLayoutHelper.java   View Source Code Vote up 5 votes
private void assignSpans(GridRangeStyle rangeStyle, RecyclerView.Recycler recycler, RecyclerView.State state, int count,
    int consumedSpanCount, boolean layingOutInPrimaryDirection, LayoutManagerHelper helper) {
    int span, spanDiff, start, end, diff;
    // make sure we traverse from min position to max position
    if (layingOutInPrimaryDirection) {
        start = 0;
        end = count;
        diff = 1;
    } else {
        start = count - 1;
        end = -1;
        diff = -1;
    }

    if (helper.getOrientation() == VERTICAL && helper.isDoLayoutRTL()) { // start from last span
        span = consumedSpanCount - 1;
        spanDiff = -1;
    } else {
        span = 0;
        spanDiff = 1;
    }

    for (int i = start; i != end; i += diff) {
        View view = rangeStyle.mSet[i];
        int spanSize = getSpanSize(rangeStyle.mSpanSizeLookup, recycler, state, helper.getPosition(view));
        if (spanDiff == -1 && spanSize > 1) {
            rangeStyle.mSpanIndices[i] = span - (spanSize - 1);
        } else {
            rangeStyle.mSpanIndices[i] = span;
        }
        span += spanDiff * spanSize;
    }
}
 
Example 7
Project: HexagonRecyclerView   File: PolygonLayoutManager.java   View Source Code Vote up 5 votes
/**
 * 填充方法
 *
 * @param recycler
 * @param state
 */
private void fill(RecyclerView.Recycler recycler, RecyclerView.State state) {
    if (getItemCount() <= 0 || state.isPreLayout()) {
        return;
    }
    //考虑到当前RecyclerView会处于滑动的状态,所以这里的Rect的作用是展示当前显示的区域
    //需要考虑到RecyclerView的滑动量
    //mHorizontalOffset 横向的滑动偏移量
    //mVerticalOffset  纵向的滑动偏移量
    Rect displayRect = new Rect(0, mVerticalOffset,
            getHorizontalSpace(),
            getVerticalSpace() + mVerticalOffset);

    /**
     * 对这些View进行测量和布局操作
     */
    for (int i = 0; i < getItemCount(); i++) {
        Rect frame = mItemFrames.get(i);
        if (Rect.intersects(displayRect, frame)) {
            View scrap = recycler.getViewForPosition(i);
            addView(scrap);
            //测量子View
            measureChildWithMargins(scrap, 0, 0);
            //布局方法
            layoutDecorated(scrap, frame.left - mHorizontalOffset, frame.top - mVerticalOffset,
                    frame.right - mHorizontalOffset, frame.bottom - mVerticalOffset);
        }
    }
}
 
Example 8
Project: HeadlineNews   File: UIDivider.java   View Source Code Vote up 5 votes
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
   if (mOrientation == OrientationHelper.HORIZONTAL){
       drawHorizontal(c,parent);
   }else {
       drawVertical(c,parent); 
   }
}
 
Example 9
Project: Android-skin-support   File: CustomDividerItemDecoration.java   View Source Code Vote up 5 votes
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
                           RecyclerView.State state) {
    if (mOrientation == VERTICAL) {
        outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
    } else {
        outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
    }
}
 
Example 10
Project: qmui   File: DividerItemDecoration.java   View Source Code Vote up 5 votes
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    if (mOrientation == VERTICAL_LIST) {
        outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
    } else {
        outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
    }
}
 
Example 11
Project: android-apps   File: MyRecylerViewAdapter.java   View Source Code Vote up 5 votes
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
  if (mOrientation == VERTICAL_LIST) {
    outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
  } else {
    outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
  }
}
 
Example 12
Project: black-mirror   File: ScrollingLinearLayoutManager.java   View Source Code Vote up 5 votes
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state,
                                   int position) {
    View firstVisibleChild = recyclerView.getChildAt(0);
    int itemHeight = firstVisibleChild.getHeight();
    int currentPosition = recyclerView.getChildLayoutPosition(firstVisibleChild);
    int distanceInPixels = Math.abs((currentPosition - position) * itemHeight);
    if (distanceInPixels == 0) {
        distanceInPixels = (int) Math.abs(firstVisibleChild.getY());
    }
    SmoothScroller smoothScroller = new SmoothScroller(recyclerView.getContext(), distanceInPixels, duration);
    smoothScroller.setTargetPosition(position);
    startSmoothScroll(smoothScroller);
}
 
Example 13
Project: revolution-irc   File: ScrollPosLinearLayoutManager.java   View Source Code Vote up 4 votes
@Override
public void onLayoutCompleted(RecyclerView.State state) {
    super.onLayoutCompleted(state);
    mPendingScrollPosition = -1;
}
 
Example 14
Project: MenuSet   File: DividerItemDecoration.java   View Source Code Vote up 4 votes
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    outRect.set(0, 0, 0, dividerHeight);
}
 
Example 15
Project: RetroMusicPlayer   File: SpannedGridLayoutManager.java   View Source Code Vote up 4 votes
private void layoutDisappearingViews(
        RecyclerView.Recycler recycler, RecyclerView.State state, int startTop) {
    // TODO
}
 
Example 16
Project: MusicX-music-player   File: ItemOffsetDecoration.java   View Source Code Vote up 4 votes
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
                           RecyclerView.State state) {
    super.getItemOffsets(outRect, view, parent, state);
    outRect.set(mItemOffset, mItemOffset, mItemOffset, mItemOffset);
}
 
Example 17
Project: SnakeRecyclerViewExample   File: SnakeGridLayoutManager.java   View Source Code Vote up 4 votes
private void layoutDisappearingViews(RecyclerView.Recycler recycler, RecyclerView.State state, int startTop) {
}
 
Example 18
Project: GitHub   File: LayoutHelper.java   View Source Code Vote up 4 votes
public abstract void doLayout(RecyclerView.Recycler recycler, RecyclerView.State state,
LayoutStateWrapper layoutState, LayoutChunkResult result,
LayoutManagerHelper helper);
 
Example 19
Project: GitHub   File: VirtualLayoutManagerTest.java   View Source Code Vote up 4 votes
void after(RecyclerView.Recycler recycler, RecyclerView.State state) {
}
 
Example 20
Project: vlayout   File: LayoutHelper.java   View Source Code Vote up 2 votes
/**
 * Called before <code>doLayout</code>
 *
 * @param recycler recycler
 * @param state    RecyclerView's State
 * @param helper   LayoutManagerHelper to handle views
 */
public abstract void beforeLayout(RecyclerView.Recycler recycler, RecyclerView.State state,
                                  LayoutManagerHelper helper);