public int addBand(Rect rect) {
    mBands.add(0, mCurrentBand = new Band(rect.centerX(), rect.centerY()));
    mCurrentBand.mask = false;
    int x = (mCurrentBand.xPos1 + mCurrentBand.xPos2) / 2;
    int y = (mCurrentBand.yPos1 + mCurrentBand.yPos2) / 2;
    double addDelta = ADD_MIN_DIST * Math.max(rect.width(), rect.height());
    boolean moved = true;
    int count = 0;
    int toMove = mBands.indexOf(mCurrentBand);

    while (moved) {
      moved = false;
      count++;
      if (count > 14) {
        break;
      }

      for (Band point : mBands) {
        if (point.mask) {
          break;
        }
      }

      for (Band point : mBands) {
        if (point.mask) {
          break;
        }
        int index = mBands.indexOf(point);

        if (toMove != index) {
          double dist = Math.hypot(point.xPos1 - x, point.yPos1 - y);
          if (dist < addDelta) {
            moved = true;
            mCurrentBand.xPos1 += addDelta;
            mCurrentBand.yPos1 += addDelta;
            mCurrentBand.xPos2 += addDelta;
            mCurrentBand.yPos2 += addDelta;
            x = (mCurrentBand.xPos1 + mCurrentBand.xPos2) / 2;
            y = (mCurrentBand.yPos1 + mCurrentBand.yPos2) / 2;

            if (mCurrentBand.yPos1 > rect.bottom) {
              mCurrentBand.yPos1 = (int) (rect.top + addDelta);
            }
            if (mCurrentBand.xPos1 > rect.right) {
              mCurrentBand.xPos1 = (int) (rect.left + addDelta);
            }
          }
        }
      }
    }
    trimVector();
    return 0;
  }
 private void creatExample() {
   Band p = new Band();
   p.mask = false;
   p.xPos1 = -1;
   p.yPos1 = 100;
   p.xPos2 = -1;
   p.yPos2 = 100;
   p.brightness = -50;
   p.contrast = 0;
   p.saturation = 0;
   mBands.add(0, p);
   mCurrentBand = p;
   trimVector();
 }
  @Override
  public void deSerializeRepresentation(JsonReader sreader) throws IOException {
    sreader.beginObject();
    Vector<Band> points = new Vector<Band>();

    while (sreader.hasNext()) {
      String name = sreader.nextName();
      if (name.startsWith(LINE_NAME)) {
        int pointNo = Integer.parseInt(name.substring(LINE_NAME.length()));
        sreader.beginArray();
        Band p = new Band();
        p.mask = false;
        sreader.hasNext();
        p.xPos1 = sreader.nextInt();
        sreader.hasNext();
        p.yPos1 = sreader.nextInt();
        sreader.hasNext();
        p.xPos2 = sreader.nextInt();
        sreader.hasNext();
        p.yPos2 = sreader.nextInt();
        sreader.hasNext();
        p.brightness = sreader.nextInt();
        sreader.hasNext();
        p.contrast = sreader.nextInt();
        sreader.hasNext();
        p.saturation = sreader.nextInt();
        sreader.hasNext();
        sreader.endArray();
        points.add(p);

      } else {
        sreader.skipValue();
      }
    }
    mBands = points;
    trimVector();
    mCurrentBand = mBands.get(0);
    sreader.endObject();
  }
 @Override
 public void setPoint2(float x, float y) {
   mCurrentBand.xPos2 = (int) x;
   mCurrentBand.yPos2 = (int) y;
 }