@Override
  public boolean onTouchEvent(MotionEvent event) {

    int x = (int) event.getX();
    int y = (int) event.getY();

    if (y < 0) {
      y = 0;
    } else if (y > getHeight()) {
      y = getHeight();
    }

    int itemPosition = pointToPosition(x, y);
    itemPosition =
        itemPosition < 0 ? ((BrickAdapter) dragAndDropListener).getCount() - 1 : itemPosition;

    if (touchedListPosition != itemPosition) {
      touchedListPosition = itemPosition;
      if (dragAndDropListener != null) {
        dragAndDropListener.setTouchedScript(touchedListPosition);
      }
    }

    if (dragAndDropListener != null && dragView != null) {
      int action = event.getAction();
      switch (action) {
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
          setDragViewAnimation(0);
          dragAndDropListener.drop();

          stopDragging();

          dimBackground = false;
          dragNewBrick = false;
          break;

        case MotionEvent.ACTION_MOVE:
          scrollListWithDraggedItem(y);

          dragTouchedListItem((int) event.getRawY());
          dragItemInList(y, itemPosition);

          dimBackground = true;
          break;
      }
      return true;
    }
    return super.onTouchEvent(event);
  }