code: @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) {
      super.onSizeChanged(w, h, oldw, oldh);
  
      setupBounds(w, h);
      setupPaints();
      invalidate();
    }
docs: Use onSizeChanged instead of onAttachedToWindow to get the dimensions of the view,
  because this method is called after measuring the dimensions of MATCH_PARENT & WRAP_CONTENT.
  Use this dimensions to setup the bounds and paints.