List of usage examples for android.support.v4.util CircularIntArray get
public int get(int n)
From source file:io.github.clendy.leanback.widget.GridLayoutManager.java
private boolean processRowSizeSecondary(boolean measure) { if (mFixedRowSizeSecondary != 0 || mRowSizeSecondary == null) { return false; }/* w w w.ja va2 s . co m*/ 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 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 w w w. j a va 2 s. co 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; }
From source file:android.support.v17.leanback.widget.GridLayoutManager.java
private boolean processRowSizeSecondary(boolean measure) { if (mFixedRowSizeSecondary != 0 || mRowSizeSecondary == null) { return false; }//from www . j a v a 2 s . co m 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; }