private static int handleDpadVertical(int iconIndex,int cntX,int cntY,int[][] matrix,int increment){
  int newIconIndex=NOOP;
  if (matrix == null) {
    throw new IllegalStateException("Dpad navigation requires a matrix.");
  }
  int xPos=-1;
  int yPos=-1;
  for (int i=0; i < cntX; i++) {
    for (int j=0; j < cntY; j++) {
      if (matrix[i][j] == iconIndex) {
        xPos=i;
        yPos=j;
      }
    }
  }
  if (DEBUG) {
    Log.v(TAG,String.format("\thandleDpadVertical: \t[x, y]=[%d, %d] iconIndex=%d",xPos,yPos,iconIndex));
  }
  for (int j=yPos + increment; 0 <= j && j < cntY && 0 <= j; j=j + increment) {
    if ((newIconIndex=inspectMatrix(xPos,j,cntX,cntY,matrix)) != NOOP) {
      return newIconIndex;
    }
  }
  int nextXPos1;
  int nextXPos2;
  int j=-1;
  for (int coeff=1; coeff < cntX; coeff++) {
    nextXPos1=xPos + coeff * increment;
    nextXPos2=xPos - coeff * increment;
    for (j=yPos + increment * coeff; 0 <= j && j < cntY; j=j + increment) {
      if ((newIconIndex=inspectMatrix(nextXPos1,j,cntX,cntY,matrix)) != NOOP) {
        return newIconIndex;
      }
      if ((newIconIndex=inspectMatrix(nextXPos2,j,cntX,cntY,matrix)) != NOOP) {
        return newIconIndex;
      }
    }
  }
  return newIconIndex;
}

private static int handleDpadVertical ( int iconIndex , int cntX , int cntY , int [ ] [ ] matrix , int increment ) { int newIconIndex = NOOP ; if ( matrix == null ) { throw new IllegalStateException ( "Dpad navigation requires a matrix." ) ; } int xPos = - 1 ; int yPos = - 1 ; for ( int i = 0 ; i < cntX ; i ++ ) { for ( int j = 0 ; j < cntY ; j ++ ) { if ( matrix [ i ] [ j ] == iconIndex ) { xPos = i ; yPos = j ; } } } if ( DEBUG ) { Log . v ( TAG , String . format ( "\thandleDpadVertical: \t[x, y]=[%d, %d] iconIndex=%d" , xPos , yPos , iconIndex ) ) ; } for ( int j = yPos + increment ; 0 <= j && j < cntY && 0 <= j ; j = j + increment ) { if ( ( newIconIndex = inspectMatrix ( xPos , j , cntX , cntY , matrix ) ) != NOOP ) { return newIconIndex ; } } int nextXPos1 ; int nextXPos2 ; int j = - 1 ; for ( int coeff = 1 ; coeff < cntX ; coeff ++ ) { nextXPos1 = xPos + coeff * increment ; nextXPos2 = xPos - coeff * increment ; for ( j = yPos + increment * coeff ; 0 <= j && j < cntY ; j = j + increment ) { if ( ( newIconIndex = inspectMatrix ( nextXPos1 , j , cntX , cntY , matrix ) ) != NOOP ) { return newIconIndex ; } if ( ( newIconIndex = inspectMatrix ( nextXPos2 , j , cntX , cntY , matrix ) ) != NOOP ) { return newIconIndex ; } } } return newIconIndex ; }
calculates icon that is closest to the vertical axis in reference to the current icon . example of the check order for keycode_dpad_down : [ ] [ ] [ ] [ x ] [ ] [ ] [ ] [ ] [ ] [ 5 ] [ 1 ] [ 4 ] [ ] [ ] [ ] [ 10 ] [ 7 ] [ 2 ] [ 6 ] [ 9 ] [ ] [ 14 ] [ 12 ] [ 9 ] [ 3 ] [ 8 ] [ 11 ] [ 13 ]
