private View moveSelection(int delta,int childrenTop,int childrenBottom){
  if (DEBUG)   Log.i(TAG,"moveSelection() delta: " + delta + " childrenTop: "+ childrenTop+ CHILDREN_BOTTOM+ childrenBottom+ M_FIRST_POSITION+ mFirstPosition);
  final int fadingEdgeLength=getVerticalFadingEdgeLength();
  final int selectedPosition=mSelectedPosition;
  final int numColumns=mNumColumns;
  final int verticalSpacing=mVerticalSpacing;
  int oldRowStart;
  int rowStart;
  int rowEnd=-1;
  if (!mStackFromBottom) {
    oldRowStart=(selectedPosition - delta) - ((selectedPosition - delta) % numColumns);
    rowStart=selectedPosition - (selectedPosition % numColumns);
  }
 else {
    int invertedSelection=mItemCount - 1 - selectedPosition;
    rowEnd=mItemCount - 1 - (invertedSelection - (invertedSelection % numColumns));
    rowStart=Math.max(0,rowEnd - numColumns + 1);
    invertedSelection=mItemCount - 1 - (selectedPosition - delta);
    oldRowStart=mItemCount - 1 - (invertedSelection - (invertedSelection % numColumns));
    oldRowStart=Math.max(0,oldRowStart - numColumns + 1);
  }
  final int rowDelta=rowStart - oldRowStart;
  final int topSelectionPixel=getTopSelectionPixel(childrenTop,fadingEdgeLength,rowStart);
  final int bottomSelectionPixel=getBottomSelectionPixel(childrenBottom,fadingEdgeLength,numColumns,rowStart);
  mFirstPosition=rowStart;
  View sel;
  View referenceView;
  if (rowDelta > 0) {
    final int oldBottom=mReferenceViewInSelectedRow == null ? 0 : mReferenceViewInSelectedRow.getBottom();
    sel=makeRow(mStackFromBottom ? rowEnd : rowStart,oldBottom + verticalSpacing,true);
    referenceView=mReferenceView;
    adjustForBottomFadingEdge(referenceView,topSelectionPixel,bottomSelectionPixel);
  }
 else   if (rowDelta < 0) {
    final int oldTop=mReferenceViewInSelectedRow == null ? 0 : mReferenceViewInSelectedRow.getTop();
    sel=makeRow(mStackFromBottom ? rowEnd : rowStart,oldTop - verticalSpacing,false);
    referenceView=mReferenceView;
    adjustForTopFadingEdge(referenceView,topSelectionPixel,bottomSelectionPixel);
  }
 else {
    final int oldTop=mReferenceViewInSelectedRow == null ? 0 : mReferenceViewInSelectedRow.getTop();
    sel=makeRow(mStackFromBottom ? rowEnd : rowStart,oldTop,true);
    referenceView=mReferenceView;
  }
  if (!mStackFromBottom) {
    fillUp(rowStart - numColumns,referenceView.getTop() - verticalSpacing);
    adjustViewsUpOrDown();
    fillDown(rowStart + numColumns,referenceView.getBottom() + verticalSpacing);
  }
 else {
    fillDown(rowEnd + numColumns,referenceView.getBottom() + verticalSpacing);
    adjustViewsUpOrDown();
    fillUp(rowStart - 1,referenceView.getTop() - verticalSpacing);
  }
  return sel;
}

private View moveSelection ( int delta , int childrenTop , int childrenBottom ) { if ( DEBUG ) Log . i ( TAG , "moveSelection() delta: " + delta + " childrenTop: " + childrenTop + CHILDREN_BOTTOM + childrenBottom + M_FIRST_POSITION + mFirstPosition ) ; final int fadingEdgeLength = getVerticalFadingEdgeLength ( ) ; final int selectedPosition = mSelectedPosition ; final int numColumns = mNumColumns ; final int verticalSpacing = mVerticalSpacing ; int oldRowStart ; int rowStart ; int rowEnd = - 1 ; if ( ! mStackFromBottom ) { oldRowStart = ( selectedPosition - delta ) - ( ( selectedPosition - delta ) % numColumns ) ; rowStart = selectedPosition - ( selectedPosition % numColumns ) ; } else { int invertedSelection = mItemCount - 1 - selectedPosition ; rowEnd = mItemCount - 1 - ( invertedSelection - ( invertedSelection % numColumns ) ) ; rowStart = Math . max ( 0 , rowEnd - numColumns + 1 ) ; invertedSelection = mItemCount - 1 - ( selectedPosition - delta ) ; oldRowStart = mItemCount - 1 - ( invertedSelection - ( invertedSelection % numColumns ) ) ; oldRowStart = Math . max ( 0 , oldRowStart - numColumns + 1 ) ; } final int rowDelta = rowStart - oldRowStart ; final int topSelectionPixel = getTopSelectionPixel ( childrenTop , fadingEdgeLength , rowStart ) ; final int bottomSelectionPixel = getBottomSelectionPixel ( childrenBottom , fadingEdgeLength , numColumns , rowStart ) ; mFirstPosition = rowStart ; View sel ; View referenceView ; if ( rowDelta > 0 ) { final int oldBottom = mReferenceViewInSelectedRow == null ? 0 : mReferenceViewInSelectedRow . getBottom ( ) ; sel = makeRow ( mStackFromBottom ? rowEnd : rowStart , oldBottom + verticalSpacing , true ) ; referenceView = mReferenceView ; adjustForBottomFadingEdge ( referenceView , topSelectionPixel , bottomSelectionPixel ) ; } else if ( rowDelta < 0 ) { final int oldTop = mReferenceViewInSelectedRow == null ? 0 : mReferenceViewInSelectedRow . getTop ( ) ; sel = makeRow ( mStackFromBottom ? rowEnd : rowStart , oldTop - verticalSpacing , false ) ; referenceView = mReferenceView ; adjustForTopFadingEdge ( referenceView , topSelectionPixel , bottomSelectionPixel ) ; } else { final int oldTop = mReferenceViewInSelectedRow == null ? 0 : mReferenceViewInSelectedRow . getTop ( ) ; sel = makeRow ( mStackFromBottom ? rowEnd : rowStart , oldTop , true ) ; referenceView = mReferenceView ; } if ( ! mStackFromBottom ) { fillUp ( rowStart - numColumns , referenceView . getTop ( ) - verticalSpacing ) ; adjustViewsUpOrDown ( ) ; fillDown ( rowStart + numColumns , referenceView . getBottom ( ) + verticalSpacing ) ; } else { fillDown ( rowEnd + numColumns , referenceView . getBottom ( ) + verticalSpacing ) ; adjustViewsUpOrDown ( ) ; fillUp ( rowStart - 1 , referenceView . getTop ( ) - verticalSpacing ) ; } return sel ; }
fills the grid based on positioning the new selection relative to the old selection . the new selection will be placed at , above , or below the location of the new selection depending on how the selection is moving . the selection will then be pinned to the visible part of the screen , excluding the edges that are faded . the grid is then filled upwards and downwards from there .
