@Override
  @SuppressLint("DrawAllocation")
  protected void onDraw(Canvas canvas) {
    if (!drawContent) {
      return;
    }
    int width = canvas.getWidth();
    int height = canvas.getHeight();

    Rect frame = BarcodeCentralFilter.getSquareFrame(width, height);

    if (scannerBitmap == null) {
      scannerBitmap =
          BitmapFactory.decodeResource(
              getContext().getResources(), R.drawable.barcode_scanner_image);
    }

    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(ContextCompat.getColor(getContext(), R.color.barcode_scanner_border_background));
    canvas.drawRect(0, 0, width, frame.top, paint);
    canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint);
    canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint);
    canvas.drawRect(0, frame.bottom + 1, width, height, paint);

    paint.setAlpha(255);
    Rect expandedFrame = BarcodeCentralFilter.getExtraSquareFrame(width, height);
    canvas.drawBitmap(scannerBitmap, null, expandedFrame, paint);

    // Draw text below the square with white color and 16sp size.
    Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    textPaint.setColor(Color.WHITE);
    textPaint.setTypeface(Typeface.create("sans-serif", Typeface.NORMAL));
    textPaint.setTextAlign(Align.CENTER);
    textPaint.setTextSize(TypedValue
        .applyDimension(TypedValue.COMPLEX_UNIT_SP, BARCODE_INSTRUCTION_TEXT_SIZE,
            getResources().getDisplayMetrics()));

    float marginTop = TypedValue
        .applyDimension(TypedValue.COMPLEX_UNIT_SP, BARCODE_INSTRUCTION_TEXT_MARGIN_TOP,
            getResources().getDisplayMetrics());
    canvas.drawText(getResources().getString(R.string.barcode_instruction_text),
        width / 2, frame.bottom + marginTop + (textPaint.ascent() + textPaint.descent()) / 2,
        textPaint);
  }
A view group that contains the barcode scanner image at the center of the screen. This screen
will be overlayed on top of an associated preview (i.e., the camera preview).
java/com/google/android/apps/authenticator/barcode/preview/GraphicOverlay.java