@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);
  }
  @Override
  public boolean onLongClick(View view) {
    if (((BrickAdapter) getAdapter()).getActionMode() != BrickAdapter.ActionModeEnum.NO_ACTION) {
      return true;
    }

    ((BrickAdapter) getAdapter()).isDragging = true;
    ((BrickAdapter) getAdapter()).setSpinnersEnabled(false);

    int itemPosition = calculateItemPositionAndTouchPointY(view);
    boolean drawingCacheEnabled = view.isDrawingCacheEnabled();

    view.setDrawingCacheEnabled(true);
    view.measure(
        MeasureSpec.makeMeasureSpec(ScreenValues.SCREEN_WIDTH, MeasureSpec.EXACTLY),
        MeasureSpec.makeMeasureSpec(
            Utils.getPhysicalPixels(WIDTH_OF_BRICK_PREVIEW_IMAGE, getContext()),
            MeasureSpec.AT_MOST));
    view.layout(0, 0, ScreenValues.SCREEN_WIDTH, view.getMeasuredHeight());
    view.setDrawingCacheBackgroundColor(Color.TRANSPARENT);

    view.buildDrawingCache(true);

    Bitmap bitmap;
    if (view.getDrawingCache() == null) {
      view.setDrawingCacheEnabled(drawingCacheEnabled);
      bitmap = getBitmapFromView(view, getMeasuredWidth(), view.getHeight());
    } else {
      bitmap = Bitmap.createBitmap(view.getDrawingCache());
    }

    view.setDrawingCacheEnabled(drawingCacheEnabled);

    startDragging(bitmap, touchPointY);

    if (!dragNewBrick) {
      setDragViewAnimation(0);
      dragNewBrick = false;
    }

    dragAndDropListener.drag(itemPosition, itemPosition);
    dimBackground = true;

    previousItemPosition = itemPosition;

    return true;
  }