Example usage for android.support.v4.util CircularIntArray size

List of usage examples for android.support.v4.util CircularIntArray size

Introduction

In this page you can find the example usage for android.support.v4.util CircularIntArray size.

Prototype

public int size() 

Source Link

Document

Get number of integers in the CircularIntArray.

Usage

From source file:android.support.v17.leanback.widget.StaggeredGrid.java

@Override
public final CircularIntArray[] getItemPositionsInRows(int startPos, int endPos) {
    for (int i = 0; i < mNumRows; i++) {
        mTmpItemPositionsInRows[i].clear();
    }//  w  ww . j av  a 2 s .  c o  m
    if (startPos >= 0) {
        for (int i = startPos; i <= endPos; i++) {
            CircularIntArray row = mTmpItemPositionsInRows[getLocation(i).row];
            if (row.size() > 0 && row.getLast() == i - 1) {
                // update continuous range
                row.popLast();
                row.addLast(i);
            } else {
                // add single position
                row.addLast(i);
                row.addLast(i);
            }
        }
    }
    return mTmpItemPositionsInRows;
}

From source file:io.github.clendy.leanback.widget.GridLayoutManager.java

private boolean processRowSizeSecondary(boolean measure) {
    if (mFixedRowSizeSecondary != 0 || mRowSizeSecondary == null) {
        return false;
    }//from  w w w.  j a  v  a 2 s  . c om

    if (TRACE)
        TraceHelper.beginSection("processRowSizeSecondary");
    CircularIntArray[] rows = mGrid == null ? null : mGrid.getItemPositionsInRows();
    boolean changed = false;
    int scrapChildWidth = -1;
    int scrapChildHeight = -1;

    for (int rowIndex = 0; rowIndex < mNumRows; rowIndex++) {
        CircularIntArray row = rows == null ? null : rows[rowIndex];
        final int rowItemsPairCount = row == null ? 0 : row.size();
        int rowSize = -1;
        for (int rowItemPairIndex = 0; rowItemPairIndex < rowItemsPairCount; rowItemPairIndex += 2) {
            final int rowIndexStart = row.get(rowItemPairIndex);
            final int rowIndexEnd = row.get(rowItemPairIndex + 1);
            for (int i = rowIndexStart; i <= rowIndexEnd; i++) {
                final View view = findViewByPosition(i);
                if (view == null) {
                    continue;
                }
                if (measure && view.isLayoutRequested()) {
                    measureChild(view);
                }
                final int secondarySize = mOrientation == HORIZONTAL ? view.getMeasuredHeight()
                        : view.getMeasuredWidth();
                if (secondarySize > rowSize) {
                    rowSize = secondarySize;
                }
            }
        }

        final int itemCount = mState.getItemCount();
        if (measure && rowSize < 0 && itemCount > 0) {
            if (scrapChildWidth < 0 && scrapChildHeight < 0) {
                int position;
                if (mFocusPosition == NO_POSITION) {
                    position = 0;
                } else if (mFocusPosition >= itemCount) {
                    position = itemCount - 1;
                } else {
                    position = mFocusPosition;
                }
                measureScrapChild(position, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
                        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), mMeasuredDimension);
                scrapChildWidth = mMeasuredDimension[0];
                scrapChildHeight = mMeasuredDimension[1];
                if (DEBUG)
                    Log.v(TAG, "measured scrap child: " + scrapChildWidth + " " + scrapChildHeight);
            }
            rowSize = mOrientation == HORIZONTAL ? scrapChildHeight : scrapChildWidth;
        }
        if (rowSize < 0) {
            rowSize = 0;
        }
        if (mRowSizeSecondary[rowIndex] != rowSize) {
            if (DEBUG)
                Log.v(getTag(), "row size secondary changed: " + mRowSizeSecondary[rowIndex] + ", " + rowSize);
            mRowSizeSecondary[rowIndex] = rowSize;
            changed = true;
        }
    }

    if (TRACE)
        TraceHelper.endSection();
    return changed;
}

From source file:android.support.v17.leanback.widget.GridLayoutManager.java

private boolean processRowSizeSecondary(boolean measure) {
    if (mFixedRowSizeSecondary != 0 || mRowSizeSecondary == null) {
        return false;
    }/*from   ww w  . j a  v  a 2 s .c  om*/

    if (TRACE)
        TraceHelper.beginSection("processRowSizeSecondary");
    CircularIntArray[] rows = mGrid == null ? null : mGrid.getItemPositionsInRows();
    boolean changed = false;
    int scrapChildWidth = -1;
    int scrapChildHeight = -1;

    for (int rowIndex = 0; rowIndex < mNumRows; rowIndex++) {
        CircularIntArray row = rows == null ? null : rows[rowIndex];
        final int rowItemsPairCount = row == null ? 0 : row.size();
        int rowSize = -1;
        for (int rowItemPairIndex = 0; rowItemPairIndex < rowItemsPairCount; rowItemPairIndex += 2) {
            final int rowIndexStart = row.get(rowItemPairIndex);
            final int rowIndexEnd = row.get(rowItemPairIndex + 1);
            for (int i = rowIndexStart; i <= rowIndexEnd; i++) {
                final View view = findViewByPosition(i);
                if (view == null) {
                    continue;
                }
                if (measure) {
                    measureChild(view);
                }
                final int secondarySize = mOrientation == HORIZONTAL
                        ? getDecoratedMeasuredHeightWithMargin(view)
                        : getDecoratedMeasuredWidthWithMargin(view);
                if (secondarySize > rowSize) {
                    rowSize = secondarySize;
                }
            }
        }

        final int itemCount = mState.getItemCount();
        if (!mBaseGridView.hasFixedSize() && measure && rowSize < 0 && itemCount > 0) {
            if (scrapChildWidth < 0 && scrapChildHeight < 0) {
                int position;
                if (mFocusPosition == NO_POSITION) {
                    position = 0;
                } else if (mFocusPosition >= itemCount) {
                    position = itemCount - 1;
                } else {
                    position = mFocusPosition;
                }
                measureScrapChild(position, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
                        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), mMeasuredDimension);
                scrapChildWidth = mMeasuredDimension[0];
                scrapChildHeight = mMeasuredDimension[1];
                if (DEBUG)
                    Log.v(TAG, "measured scrap child: " + scrapChildWidth + " " + scrapChildHeight);
            }
            rowSize = mOrientation == HORIZONTAL ? scrapChildHeight : scrapChildWidth;
        }
        if (rowSize < 0) {
            rowSize = 0;
        }
        if (mRowSizeSecondary[rowIndex] != rowSize) {
            if (DEBUG)
                Log.v(getTag(), "row size secondary changed: " + mRowSizeSecondary[rowIndex] + ", " + rowSize);
            mRowSizeSecondary[rowIndex] = rowSize;
            changed = true;
        }
    }

    if (TRACE)
        TraceHelper.endSection();
    return changed;
}

From source file:android.support.v17.leanback.widget.GridLayoutManager.java

private boolean getNoneAlignedPosition(View view, int[] deltas) {
    int pos = getPositionByView(view);
    int viewMin = getViewMin(view);
    int viewMax = getViewMax(view);
    // we either align "firstView" to left/top padding edge
    // or align "lastView" to right/bottom padding edge
    View firstView = null;/*from   ww  w . ja  v  a  2  s  .c  o  m*/
    View lastView = null;
    int paddingLow = mWindowAlignment.mainAxis().getPaddingLow();
    int clientSize = mWindowAlignment.mainAxis().getClientSize();
    final int row = mGrid.getRowIndex(pos);
    if (viewMin < paddingLow) {
        // view enters low padding area:
        firstView = view;
        if (mFocusScrollStrategy == BaseGridView.FOCUS_SCROLL_PAGE) {
            // scroll one "page" left/top,
            // align first visible item of the "page" at the low padding edge.
            while (prependOneColumnVisibleItems()) {
                CircularIntArray positions = mGrid.getItemPositionsInRows(mGrid.getFirstVisibleIndex(),
                        pos)[row];
                firstView = findViewByPosition(positions.get(0));
                if (viewMax - getViewMin(firstView) > clientSize) {
                    if (positions.size() > 2) {
                        firstView = findViewByPosition(positions.get(2));
                    }
                    break;
                }
            }
        }
    } else if (viewMax > clientSize + paddingLow) {
        // view enters high padding area:
        if (mFocusScrollStrategy == BaseGridView.FOCUS_SCROLL_PAGE) {
            // scroll whole one page right/bottom, align view at the low padding edge.
            firstView = view;
            do {
                CircularIntArray positions = mGrid.getItemPositionsInRows(pos,
                        mGrid.getLastVisibleIndex())[row];
                lastView = findViewByPosition(positions.get(positions.size() - 1));
                if (getViewMax(lastView) - viewMin > clientSize) {
                    lastView = null;
                    break;
                }
            } while (appendOneColumnVisibleItems());
            if (lastView != null) {
                // however if we reached end,  we should align last view.
                firstView = null;
            }
        } else {
            lastView = view;
        }
    }
    int scrollPrimary = 0;
    int scrollSecondary = 0;
    if (firstView != null) {
        scrollPrimary = getViewMin(firstView) - paddingLow;
    } else if (lastView != null) {
        scrollPrimary = getViewMax(lastView) - (paddingLow + clientSize);
    }
    View secondaryAlignedView;
    if (firstView != null) {
        secondaryAlignedView = firstView;
    } else if (lastView != null) {
        secondaryAlignedView = lastView;
    } else {
        secondaryAlignedView = view;
    }
    scrollSecondary = getSecondarySystemScrollPosition(secondaryAlignedView);
    scrollSecondary -= mScrollOffsetSecondary;
    if (scrollPrimary != 0 || scrollSecondary != 0) {
        deltas[0] = scrollPrimary;
        deltas[1] = scrollSecondary;
        return true;
    }
    return false;
}