question: private static int handleDpadHorizontal ( int iconIdx , int cntX , int cntY , int [ ] [ ] matrix , int increment , boolean isRtl ) { if ( matrix == null ) { throw new IllegalStateException ( "Dpad navigation requires a matrix." ) ; } int newIconIndex = NOOP ; int xPos = - 1 ; int yPos = - 1 ; for ( int i = 0 ; i < cntX ; i ++ ) { for ( int j = 0 ; j < cntY ; j ++ ) { if ( matrix [ i ] [ j ] == iconIdx ) { xPos = i ; yPos = j ; } } } if ( DEBUG ) { Log . v ( TAG , String . format ( "\thandleDpadHorizontal: \t[x, y]=[%d, %d] iconIndex=%d" , xPos , yPos , iconIdx ) ) ; } for ( int x = xPos + increment ; 0 <= x && x < cntX ; x += increment ) { if ( ( newIconIndex = inspectMatrix ( x , yPos , cntX , cntY , matrix ) ) != NOOP && newIconIndex != ALL_APPS_COLUMN ) { return newIconIndex ; } } int nextYPos1 ; int nextYPos2 ; boolean haveCrossedAllAppsColumn1 = false ; boolean haveCrossedAllAppsColumn2 = false ; int x = - 1 ; for ( int coeff = 1 ; coeff < cntY ; coeff ++ ) { nextYPos1 = yPos + coeff * increment ; nextYPos2 = yPos - coeff * increment ; x = xPos + increment * coeff ; if ( inspectMatrix ( x , nextYPos1 , cntX , cntY , matrix ) == ALL_APPS_COLUMN ) { haveCrossedAllAppsColumn1 = true ; } if ( inspectMatrix ( x , nextYPos2 , cntX , cntY , matrix ) == ALL_APPS_COLUMN ) { haveCrossedAllAppsColumn2 = true ; } for ( ; 0 <= x && x < cntX ; x += increment ) { int offset1 = haveCrossedAllAppsColumn1 && x < cntX - 1 ? increment : 0 ; newIconIndex = inspectMatrix ( x , nextYPos1 + offset1 , cntX , cntY , matrix ) ; if ( newIconIndex != NOOP ) { return newIconIndex ; } int offset2 = haveCrossedAllAppsColumn2 && x < cntX - 1 ? - increment : 0 ; newIconIndex = inspectMatrix ( x , nextYPos2 + offset2 , cntX , cntY , matrix ) ; if ( newIconIndex != NOOP ) { return newIconIndex ; } } } if ( iconIdx == PIVOT ) { if ( isRtl ) { return increment < 0 ? NEXT_PAGE_FIRST_ITEM : PREVIOUS_PAGE_LAST_ITEM ; } return increment < 0 ? PREVIOUS_PAGE_LAST_ITEM : NEXT_PAGE_FIRST_ITEM ; } return newIconIndex ; }
target:  Calculates icon that has is closest to the horizontal axis in reference to the cur icon. Example of the check order for KEYCODE_DPAD_RIGHT: [  ][  ][13][14][15] [  ][ 6][ 8][10][12] [ X][ 1][ 2][ 3][ 4] [  ][ 5][ 7][ 9][11]