@Override
  public void onResize(int mode, int delta) {
    if (mTarget == null) return;
    if (mResizeFrame == null) return;

    int w = getMeasuredWidth() - (getPaddingLeft() + getPaddingRight());
    int h = getMeasuredHeight() - (getPaddingTop() + getPaddingBottom());
    int minWidth = (w / mCols) + (w / mCols) / 2;
    int minHeight = (h / mRows) + (h / mRows) / 2;

    FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mResizeFrame.getLayoutParams();
    switch (mode) {
      case Gravity.LEFT:
        float newpos = mResizeFrame.getX() + delta;
        if ((delta < 0 && newpos < (getPaddingLeft() * -1))
            || (delta > 0 && newpos > (mResizeFrame.getX() + params.width - minWidth))) {
          return;
        }
        mResizeFrame.setX(newpos);
        params.width -= delta;
        break;
      case Gravity.RIGHT:
        if ((delta < 0 && ((params.width + delta) < minWidth))
            || (delta > 0
                && (mResizeFrame.getX() + delta + params.width)
                    > (getPaddingLeft() + getMeasuredWidth()))) {
          return;
        }
        params.width += delta;
        break;
      case Gravity.TOP:
        newpos = mResizeFrame.getY() + delta;
        if ((delta < 0 && newpos < (getPaddingTop() * -1))
            || (delta > 0 && newpos > (mResizeFrame.getY() + params.height - minHeight))) {
          return;
        }
        mResizeFrame.setY(newpos);
        params.height -= delta;
        break;
      case Gravity.BOTTOM:
        if ((delta < 0 && ((params.height + delta) < minHeight))
            || (delta > 0
                && (mResizeFrame.getY() + delta + params.height)
                    > (getPaddingTop() + getMeasuredHeight()))) {
          return;
        }
        params.height += delta;
        break;

      default:
        break;
    }
    mResizeFrame.setLayoutParams(params);
  }
  /**
   * Method that select a view as the target of to resize
   *
   * @param v The target view
   */
  boolean selectTarget(View v) {
    // Do not do long click if we do not have a target
    if (mTarget != null && v.equals(mTarget)) return false;
    if (mResizeFrame == null) return false;

    // Show the resize frame view just in place of the current clicked view

    mResizeFrame.hide();
    FrameLayout.LayoutParams frameParams =
        (FrameLayout.LayoutParams) mResizeFrame.getLayoutParams();
    int padding = mInternalPadding + mResizeFrame.getNeededPadding();
    frameParams.width = v.getWidth() + (padding * 2);
    frameParams.height = v.getHeight() + (padding * 2);
    mResizeFrame.setX(v.getX() - padding);
    mResizeFrame.setY(v.getY() - padding);
    mResizeFrame.show();

    // Save the new view
    mTarget = v;
    if (mOnFrameSelectedListener != null) {
      mOnFrameSelectedListener.onFrameSelectedListener(v);
    }
    return true;
  }