private static int handleDpadHorizontal(int iconIdx,int cntX,int cntY,int[][] matrix,int increment){
  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 i=xPos + increment; 0 <= i && i < cntX; i=i + increment) {
    if ((newIconIndex=inspectMatrix(i,yPos,cntX,cntY,matrix)) != NOOP) {
      return newIconIndex;
    }
  }
  int nextYPos1;
  int nextYPos2;
  int i=-1;
  for (int coeff=1; coeff < cntY; coeff++) {
    nextYPos1=yPos + coeff * increment;
    nextYPos2=yPos - coeff * increment;
    for (i=xPos + increment * coeff; 0 <= i && i < cntX; i=i + increment) {
      if ((newIconIndex=inspectMatrix(i,nextYPos1,cntX,cntY,matrix)) != NOOP) {
        return newIconIndex;
      }
      if ((newIconIndex=inspectMatrix(i,nextYPos2,cntX,cntY,matrix)) != NOOP) {
        return newIconIndex;
      }
    }
  }
  return newIconIndex;
}

private static int handleDpadHorizontal ( int iconIdx , int cntX , int cntY , int [ ] [ ] matrix , int increment ) { 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 i = xPos + increment ; 0 <= i && i < cntX ; i = i + increment ) { if ( ( newIconIndex = inspectMatrix ( i , yPos , cntX , cntY , matrix ) ) != NOOP ) { return newIconIndex ; } } int nextYPos1 ; int nextYPos2 ; int i = - 1 ; for ( int coeff = 1 ; coeff < cntY ; coeff ++ ) { nextYPos1 = yPos + coeff * increment ; nextYPos2 = yPos - coeff * increment ; for ( i = xPos + increment * coeff ; 0 <= i && i < cntX ; i = i + increment ) { if ( ( newIconIndex = inspectMatrix ( i , nextYPos1 , cntX , cntY , matrix ) ) != NOOP ) { return newIconIndex ; } if ( ( newIconIndex = inspectMatrix ( i , nextYPos2 , cntX , cntY , matrix ) ) != NOOP ) { return newIconIndex ; } } } return newIconIndex ; }
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 ]
