Java Code Examples for android.support.v7.widget.RecyclerView.LayoutManager#getChildCount()

The following examples show how to use android.support.v7.widget.RecyclerView.LayoutManager#getChildCount() . 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: ItemTouchHelper.java    From letv with Apache License 2.0 5 votes vote down vote up
private List<ViewHolder> findSwapTargets(ViewHolder viewHolder) {
    if (this.mSwapTargets == null) {
        this.mSwapTargets = new ArrayList();
        this.mDistances = new ArrayList();
    } else {
        this.mSwapTargets.clear();
        this.mDistances.clear();
    }
    int margin = this.mCallback.getBoundingBoxMargin();
    int left = Math.round(this.mSelectedStartX + this.mDx) - margin;
    int top = Math.round(this.mSelectedStartY + this.mDy) - margin;
    int right = (viewHolder.itemView.getWidth() + left) + (margin * 2);
    int bottom = (viewHolder.itemView.getHeight() + top) + (margin * 2);
    int centerX = (left + right) / 2;
    int centerY = (top + bottom) / 2;
    LayoutManager lm = this.mRecyclerView.getLayoutManager();
    int childCount = lm.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View other = lm.getChildAt(i);
        if (other != viewHolder.itemView && other.getBottom() >= top && other.getTop() <= bottom && other.getRight() >= left && other.getLeft() <= right) {
            ViewHolder otherVh = this.mRecyclerView.getChildViewHolder(other);
            if (this.mCallback.canDropOver(this.mRecyclerView, this.mSelected, otherVh)) {
                int dx = Math.abs(centerX - ((other.getLeft() + other.getRight()) / 2));
                int dy = Math.abs(centerY - ((other.getTop() + other.getBottom()) / 2));
                int dist = (dx * dx) + (dy * dy);
                int pos = 0;
                int cnt = this.mSwapTargets.size();
                int j = 0;
                while (j < cnt && dist > ((Integer) this.mDistances.get(j)).intValue()) {
                    pos++;
                    j++;
                }
                this.mSwapTargets.add(pos, otherVh);
                this.mDistances.add(pos, Integer.valueOf(dist));
            }
        }
    }
    return this.mSwapTargets;
}
 
Example 2
Source File: ScrollbarHelper.java    From letv with Apache License 2.0 5 votes vote down vote up
static int computeScrollOffset(State state, OrientationHelper orientation, View startChild, View endChild, LayoutManager lm, boolean smoothScrollbarEnabled, boolean reverseLayout) {
    if (lm.getChildCount() == 0 || state.getItemCount() == 0 || startChild == null || endChild == null) {
        return 0;
    }
    int itemsBefore = reverseLayout ? Math.max(0, (state.getItemCount() - Math.max(lm.getPosition(startChild), lm.getPosition(endChild))) - 1) : Math.max(0, Math.min(lm.getPosition(startChild), lm.getPosition(endChild)));
    if (!smoothScrollbarEnabled) {
        return itemsBefore;
    }
    return Math.round((((float) itemsBefore) * (((float) Math.abs(orientation.getDecoratedEnd(endChild) - orientation.getDecoratedStart(startChild))) / ((float) (Math.abs(lm.getPosition(startChild) - lm.getPosition(endChild)) + 1)))) + ((float) (orientation.getStartAfterPadding() - orientation.getDecoratedStart(startChild))));
}
 
Example 3
Source File: ScrollbarHelper.java    From letv with Apache License 2.0 5 votes vote down vote up
static int computeScrollExtent(State state, OrientationHelper orientation, View startChild, View endChild, LayoutManager lm, boolean smoothScrollbarEnabled) {
    if (lm.getChildCount() == 0 || state.getItemCount() == 0 || startChild == null || endChild == null) {
        return 0;
    }
    if (!smoothScrollbarEnabled) {
        return Math.abs(lm.getPosition(startChild) - lm.getPosition(endChild)) + 1;
    }
    return Math.min(orientation.getTotalSpace(), orientation.getDecoratedEnd(endChild) - orientation.getDecoratedStart(startChild));
}
 
Example 4
Source File: ScrollbarHelper.java    From letv with Apache License 2.0 5 votes vote down vote up
static int computeScrollRange(State state, OrientationHelper orientation, View startChild, View endChild, LayoutManager lm, boolean smoothScrollbarEnabled) {
    if (lm.getChildCount() == 0 || state.getItemCount() == 0 || startChild == null || endChild == null) {
        return 0;
    }
    if (!smoothScrollbarEnabled) {
        return state.getItemCount();
    }
    return (int) ((((float) (orientation.getDecoratedEnd(endChild) - orientation.getDecoratedStart(startChild))) / ((float) (Math.abs(lm.getPosition(startChild) - lm.getPosition(endChild)) + 1))) * ((float) state.getItemCount()));
}