code: private void generatePatternBitmap() {
      if (getBounds().width() <= 0 || getBounds().height() <= 0) {
        return;
      }
  
      bitmap = Bitmap.createBitmap(getBounds().width(), getBounds().height(), Config.ARGB_8888);
      Canvas canvas = new Canvas(bitmap);
  
      Rect r = new Rect();
      boolean verticalStartWhite = true;
      for (int i = 0; i <= numRectanglesVertical; i++) {
        boolean isWhite = verticalStartWhite;
        for (int j = 0; j <= numRectanglesHorizontal; j++) {
          r.top = i * rectangleSize;
          r.left = j * rectangleSize;
          r.bottom = r.top + rectangleSize;
          r.right = r.left + rectangleSize;
          canvas.drawRect(r, isWhite ? paintWhite : paintGray);
          isWhite = !isWhite;
        }
        verticalStartWhite = !verticalStartWhite;
      }
    }
docs: This will generate a bitmap with the pattern as big as the rectangle we were allow to draw on.
  We do this to chache the bitmap so we don't need to recreate it each time draw() is called since it takes a few
  milliseconds