@Override
  protected void onDraw(final Canvas canvas) {
    super.onDraw(canvas);
    if (profile == null) {
      return;
    }

    final int width = getWidth();
    final int height = getHeight();

    canvas.drawRect(0, 0, width, height, bgPaint);

    final float xStep = width / GRID_X;
    final float yStep = height / GRID_Y;

    int cIndex = 0;
    ListIterator<Region> regions = profile.regions(false);
    while (regions.hasPrevious()) {
      final Region region = regions.previous();
      final RectF r = region.getActualRect(width, height);

      rPaint.setColor(COLORS[cIndex]);
      rPaint.setAlpha(0x80);
      canvas.drawRect(r, rPaint);

      cIndex = (cIndex + 1) % COLORS.length;
    }

    drawGrid(canvas, xStep, yStep);

    cIndex = 0;
    regions = profile.regions(false);
    while (regions.hasPrevious()) {
      final Region region = regions.previous();
      final RectF r = region.getActualRect(width, height);
      rPaint.setColor(COLORS[cIndex]);
      drawBounds(canvas, r, rPaint);

      cIndex = (cIndex + 1) % COLORS.length;
    }

    if (current != null) {
      rPaint.setColor(Color.WHITE);
      rPaint.setAlpha(0x80);
      final RectF r = current.getActualRect(width, height);
      canvas.drawRect(r, rPaint);
      rPaint.setColor(Color.WHITE);
      drawBounds(canvas, r, rPaint);
    }
  }
 protected Region getOrCreareRegion(final PointF startPoint, final PointF endPoint) {
   final Region selected = getRegion(startPoint, endPoint);
   for (final Region r : profile.regions) {
     if (r.getRect().equals(selected.getRect())) {
       return r;
     }
   }
   profile.addRegion(selected);
   return selected;
 }