question: 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 y = yPos + increment ; 0 <= y && y < cntY && 0 <= y ; y += increment ) { if ( ( newIconIndex = inspectMatrix ( xPos , y , cntX , cntY , matrix ) ) != NOOP && newIconIndex != ALL_APPS_COLUMN ) { return newIconIndex ; } } int nextXPos1 ; int nextXPos2 ; boolean haveCrossedAllAppsColumn1 = false ; boolean haveCrossedAllAppsColumn2 = false ; int y = - 1 ; for ( int coeff = 1 ; coeff < cntX ; coeff ++ ) { nextXPos1 = xPos + coeff * increment ; nextXPos2 = xPos - coeff * increment ; y = yPos + increment * coeff ; if ( inspectMatrix ( nextXPos1 , y , cntX , cntY , matrix ) == ALL_APPS_COLUMN ) { haveCrossedAllAppsColumn1 = true ; } if ( inspectMatrix ( nextXPos2 , y , cntX , cntY , matrix ) == ALL_APPS_COLUMN ) { haveCrossedAllAppsColumn2 = true ; } for ( ; 0 <= y && y < cntY ; y = y + increment ) { int offset1 = haveCrossedAllAppsColumn1 && y < cntY - 1 ? increment : 0 ; newIconIndex = inspectMatrix ( nextXPos1 + offset1 , y , cntX , cntY , matrix ) ; if ( newIconIndex != NOOP ) { return newIconIndex ; } int offset2 = haveCrossedAllAppsColumn2 && y < cntY - 1 ? - increment : 0 ; newIconIndex = inspectMatrix ( nextXPos2 + offset2 , y , cntX , cntY , matrix ) ; if ( newIconIndex != NOOP ) { return newIconIndex ; } } } return newIconIndex ; }
target:  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]