private Cell detectAndAddHit(float x,float y){
  final Cell cell=checkForNewHit(x,y);
  if (cell != null) {
    final ArrayList<Cell> newCells=new ArrayList<>();
    if (!mPattern.isEmpty()) {
      final Cell lastCell=mPattern.get(mPattern.size() - 1);
      int dRow=cell.getRow() - lastCell.getRow();
      int dCol=cell.getColumn() - lastCell.getColumn();
      int rsign=dRow > 0 ? 1 : -1;
      int csign=dCol > 0 ? 1 : -1;
      if (dRow == 0) {
        for (int i=1; i < Math.abs(dCol); i++) {
          newCells.add(new Cell(lastCell.getRow(),lastCell.getColumn() + i * csign));
        }
      }
 else       if (dCol == 0) {
        for (int i=1; i < Math.abs(dRow); i++) {
          newCells.add(new Cell(lastCell.getRow() + i * rsign,lastCell.getColumn()));
        }
      }
 else       if (Math.abs(dCol) == Math.abs(dRow)) {
        for (int i=1; i < Math.abs(dRow); i++) {
          newCells.add(new Cell(lastCell.getRow() + i * rsign,lastCell.getColumn() + i * csign));
        }
      }
    }
    for (    Cell fillInGapCell : newCells) {
      if (fillInGapCell != null && !cellManager.isDrawn(fillInGapCell)) {
        addCellToPattern(fillInGapCell);
      }
    }
    addCellToPattern(cell);
    if (enableHapticFeedback) {
      performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY,HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING | HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
    }
    return cell;
  }
  return null;
}

private Cell detectAndAddHit ( float x , float y ) { final Cell cell = checkForNewHit ( x , y ) ; if ( cell != null ) { final ArrayList < Cell > newCells = new ArrayList < > ( ) ; if ( ! mPattern . isEmpty ( ) ) { final Cell lastCell = mPattern . get ( mPattern . size ( ) - 1 ) ; int dRow = cell . getRow ( ) - lastCell . getRow ( ) ; int dCol = cell . getColumn ( ) - lastCell . getColumn ( ) ; int rsign = dRow > 0 ? 1 : - 1 ; int csign = dCol > 0 ? 1 : - 1 ; if ( dRow == 0 ) { for ( int i = 1 ; i < Math . abs ( dCol ) ; i ++ ) { newCells . add ( new Cell ( lastCell . getRow ( ) , lastCell . getColumn ( ) + i * csign ) ) ; } } else if ( dCol == 0 ) { for ( int i = 1 ; i < Math . abs ( dRow ) ; i ++ ) { newCells . add ( new Cell ( lastCell . getRow ( ) + i * rsign , lastCell . getColumn ( ) ) ) ; } } else if ( Math . abs ( dCol ) == Math . abs ( dRow ) ) { for ( int i = 1 ; i < Math . abs ( dRow ) ; i ++ ) { newCells . add ( new Cell ( lastCell . getRow ( ) + i * rsign , lastCell . getColumn ( ) + i * csign ) ) ; } } } for ( Cell fillInGapCell : newCells ) { if ( fillInGapCell != null && ! cellManager . isDrawn ( fillInGapCell ) ) { addCellToPattern ( fillInGapCell ) ; } } addCellToPattern ( cell ) ; if ( enableHapticFeedback ) { performHapticFeedback ( HapticFeedbackConstants . VIRTUAL_KEY , HapticFeedbackConstants . FLAG_IGNORE_VIEW_SETTING | HapticFeedbackConstants . FLAG_IGNORE_GLOBAL_SETTING ) ; } return cell ; } return null ; }
determines whether the point x , y will add a new point to the current pattern ( in addition to finding the cell , also makes heuristic choices such as filling in gaps based on current pattern ) .
