title: How to draw a transparent rectangle in the center?
body: <p>I'm using CameraX to scan QR. For the UI side, I need to create a translucent black background along with a transparent box in the center (of given side [or of given padding if the side can be calculated]).</p>
  <p>I tried using different solutions on stackoverflow but for some reason was unable to achieve this. Currently, I'm trying to use this solution to create a square of given side (width/height) but am unable to do so. I tried modifying the code provided in the first answer here <a href="https://stackoverflow.com/questions/36763696/how-to-create-a-transparent-circleinside-rectangle-shape-in-xml-in-android">How to create a &#39;transparent circle inside rectangle&#39; shape in XML in Android?</a>, but it isn't working as expected.</p>
  <p>Code:</p>
  <pre><code>import android.content.Context;
  import android.graphics.Canvas;
  import android.graphics.Color;
  import android.graphics.Paint;
  import android.graphics.Path;
  import android.graphics.RectF;
  import android.util.AttributeSet;
  import android.view.View;
  
  public class QROverlay extends View {
      private Paint mTransparentPaint;
      private Paint mSemiBlackPaint;
      private RectF rectF;
      private Path mPath = new Path();
  
      private int cx = 0;
      private int cy = 0;
      private final int SIDE = 10;
  
      public QROverlay(Context context) {
          super(context);
          initPaints();
      }
  
      public QROverlay(Context context, AttributeSet attrs) {
          super(context, attrs);
          initPaints();
      }
  
      public QROverlay(Context context, AttributeSet attrs, int defStyleAttr) {
          super(context, attrs, defStyleAttr);
          initPaints();
      }
  
      private void initPaints() {
          mTransparentPaint = new Paint();
          mTransparentPaint.setColor(Color.TRANSPARENT);
          mTransparentPaint.setStrokeWidth(10);
  
          mSemiBlackPaint = new Paint();
          mSemiBlackPaint.setColor(Color.parseColor(&quot;#A6000000&quot;));
          mSemiBlackPaint.setStrokeWidth(10);
      }
  
      @Override
      protected void onDraw(Canvas canvas) {
          super.onDraw(canvas);
  
          mPath.reset();
  
          RectF rectF = new RectF(
                  getLeft() + 100, getTop() + 100, getRight() - 100, getBottom() - 100
          );
  
  //        mPath.addCircle(canvas.getWidth() / 3, canvas.getHeight() / 3, 0, Path.Direction);
          mPath.addRect(rectF, Path.Direction.CW);
          mPath.setFillType(Path.FillType.INVERSE_EVEN_ODD);
  
          canvas.drawRect(rectF, mTransparentPaint);
  
          canvas.drawPath(mPath, mSemiBlackPaint);
          canvas.clipPath(mPath);
          canvas.drawColor(Color.parseColor(&quot;#A6000000&quot;));
      }
  }
  </code></pre>
  <p>Could someone please help me out with this code?</p>