@Override protected boolean isCandidateSelection(int childIndex,int direction){
  final int count=getChildCount();
  final int invertedIndex=count - 1 - childIndex;
  int rowStart;
  int rowEnd;
  if (!mStackFromBottom) {
    rowStart=childIndex - (childIndex % mNumColumns);
    rowEnd=Math.max(rowStart + mNumColumns - 1,count);
  }
 else {
    rowEnd=count - 1 - (invertedIndex - (invertedIndex % mNumColumns));
    rowStart=Math.max(0,rowEnd - mNumColumns + 1);
  }
switch (direction) {
case View.FOCUS_RIGHT:
    return childIndex == rowStart;
case View.FOCUS_DOWN:
  return rowStart == 0;
case View.FOCUS_LEFT:
return childIndex == rowEnd;
case View.FOCUS_UP:
return rowEnd == count - 1;
case View.FOCUS_FORWARD:
return childIndex == rowStart && rowStart == 0;
case View.FOCUS_BACKWARD:
return childIndex == rowEnd && rowEnd == count - 1;
default :
throw new IllegalArgumentException("direction must be one of " + "{FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT, " + "FOCUS_FORWARD, FOCUS_BACKWARD}");
}
}

@ Override protected boolean isCandidateSelection ( int childIndex , int direction ) { final int count = getChildCount ( ) ; final int invertedIndex = count - 1 - childIndex ; int rowStart ; int rowEnd ; if ( ! mStackFromBottom ) { rowStart = childIndex - ( childIndex % mNumColumns ) ; rowEnd = Math . max ( rowStart + mNumColumns - 1 , count ) ; } else { rowEnd = count - 1 - ( invertedIndex - ( invertedIndex % mNumColumns ) ) ; rowStart = Math . max ( 0 , rowEnd - mNumColumns + 1 ) ; } switch ( direction ) { case View . FOCUS_RIGHT : return childIndex == rowStart ; case View . FOCUS_DOWN : return rowStart == 0 ; case View . FOCUS_LEFT : return childIndex == rowEnd ; case View . FOCUS_UP : return rowEnd == count - 1 ; case View . FOCUS_FORWARD : return childIndex == rowStart && rowStart == 0 ; case View . FOCUS_BACKWARD : return childIndex == rowEnd && rowEnd == count - 1 ; default : throw new IllegalArgumentException ( "direction must be one of " + "{FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT, " + "FOCUS_FORWARD, FOCUS_BACKWARD}" ) ; } }
is childindex a candidate for next focus given the direction the focus change is coming from ?
