If the composition is larger than the canvas, we have to use a different method to scale it up.
See the comments in {@link #draw(Canvas)} for more info.
14948
private float getMaxScale(@NonNull Canvas canvas) {
    float maxScaleX = canvas.getWidth() / (float) composition.getBounds().width();
    float maxScaleY = canvas.getHeight() / (float) composition.getBounds().height();
    return Math.min(maxScaleX, maxScaleY);
  }
432159
@Override
	protected void onDrawFrame(SurfaceView view, Canvas canvas) {
		super.onDrawFrame(view, canvas);

		// Display info on the image being process and how fast input camera
		// stream (probably in YUV420) is converted into a BoofCV format
		int width = bitmap.getWidth();
		int height = bitmap.getHeight();
		canvas.drawText(String.format(Locale.getDefault(),
				"%d x %d Convert: %4.1f (ms)",
				width,height,periodConvert.getAverage()),
				0,120,paintText);
		canvas.drawText(String.format(Locale.getDefault(),
				"detector: %4.1f (ms)",timeDetection.getAverage()),
				180,170,paintText);


		// This line is magical and will save you hours/days of anguish
		// What it does is correctly convert the coordinate system from
		// image pixels that were processed into display coordinates
		// taking in account rotations and weird CCD layouts
		canvas.concat(imageToView);

		// Draw the bounding squares around the QR Codes
		synchronized (foundQR) {
			for (int foundIdx = 0; foundIdx < foundQR.size(); foundIdx++) {
				renderPolygon(foundQR.get(foundIdx),path,canvas,colorDetected);
			}
			if( foundQR.size() > 0 )
				textMessageView.setText(message);
		}

		// Pro tip: Run in app fast or release mode for a dramatic speed up!
		// In Android Studio expand "Build Variants" tab on left.
	}
630765
void draw(Canvas canvas) {
        mCanvasRect.set(0.0f, 0.0f, canvas.getWidth(), canvas.getHeight());
        switch (mShape) {
            case SHAPE_RECTANGLE:
                canvas.drawRect(mCanvasRect, mCanvasPaint);
                break;
            case SHAPE_OVAL:
                canvas.drawOval(mCanvasRect, mCanvasPaint);
                break;
            case SHAPE_STAR_3_VERTICES:
            case SHAPE_STAR_4_VERTICES:
            case SHAPE_STAR_5_VERTICES:
            case SHAPE_STAR_6_VERTICES:
                drawStar(canvas, mShape);
                break;
            case SHAPE_HEART:
                drawHeart(canvas);
                break;
        }
    }
448231
@Override protected void resize() {
        width  = clock.getWidth() - clock.getInsets().getLeft() - clock.getInsets().getRight();
        height = clock.getHeight() - clock.getInsets().getTop() - clock.getInsets().getBottom();

        if (aspectRatio * width > height) {
            width = 1 / (aspectRatio / height);
        } else if (1 / (aspectRatio / height) > width) {
            height = aspectRatio * width;
        }

        if (width > 0 && height > 0) {
            pane.setMaxSize(width, height);
            pane.relocate((clock.getWidth() - height) * 0.5, (clock.getHeight() - height) * 0.5);

            canvas.setWidth(width);
            canvas.setHeight(height);

            dotSize     = height * 0.045455;
            spacer      = height * 0.022727;
            digitWidth  = 8 * dotSize + 7 * spacer;
            digitHeight = 15 * dotSize + 14 * spacer;
            digitSpacer = height * 0.09090909;
        }
    }
478029
private void resize() {
        width                        = getWidth() - getInsets().getLeft() - getInsets().getRight();
        height                       = getHeight() - getInsets().getTop() - getInsets().getBottom();
        pixelSize                    = (width / cols) < (height / rows) ? (width / cols) : (height / rows);
        pixelWidth                   = (width / cols);
        pixelHeight                  = (height / rows);
        spacer                       = useSpacer ? pixelSize * getSpacerSizeFactor() : 0;
        pixelSizeMinusDoubleSpacer   = pixelSize - spacer * 2;
        pixelWidthMinusDoubleSpacer  = pixelWidth - spacer * 2;
        pixelHeightMinusDoubleSpacer = pixelHeight - spacer * 2;


        if (width > 0 && height > 0) {
            if (squarePixels) {
                pixelWidth                   = pixelSize;
                pixelHeight                  = pixelSize;
                pixelWidthMinusDoubleSpacer  = pixelSizeMinusDoubleSpacer;
                pixelHeightMinusDoubleSpacer = pixelSizeMinusDoubleSpacer;
            }
            canvas.setWidth(cols * pixelWidth);
            canvas.setHeight(rows * pixelHeight);

            canvas.relocate((getWidth() - (cols *pixelWidth)) * 0.5, (getHeight() - (rows * pixelHeight)) * 0.5);

            drawMatrix();
        }
    }
373615
public void draw(GraphicContext graphicContext) {
        /*
         * Swap bitmaps here (and only here).
         * Swapping is done when layer manager has finished. Else draw old bitmap again.
         * This draw() is always called when layer manager has finished. This ensures that the
         * last generated frame is always put on screen.
         */

        // FIXME: resetting the background color is redundant if the background color of the map view is already set
        graphicContext.fillColor(this.displayModel.getBackgroundColor());

        swapBitmaps();

        synchronized (this.matrix) {
            Bitmap b = this.odBitmap.lock();
            if (b != null) {
                graphicContext.drawBitmap(b, this.matrix);
            }
        }

        /*
         * Release here so destroy() can free resources
         */
        this.odBitmap.release();
    }
1043139
public void draw(){
        if (!mIsVisible)
            return;
        try {
            MapView.LayoutParams lp = new MapView.LayoutParams(
                    MapView.LayoutParams.WRAP_CONTENT,
                    MapView.LayoutParams.WRAP_CONTENT,
                    mPosition, MapView.LayoutParams.BOTTOM_CENTER,
                    mOffsetX, mOffsetY);
            mMapView.updateViewLayout(mView, lp); // supposed to work only on the UI Thread
        } catch(Exception e) {
            if (MapSnapshot.isUIThread()) {
                throw e;
            }
            // in order to avoid a CalledFromWrongThreadException crash
        }
    }
615434
@Override
    protected void paintComponent(Graphics g) {
        if (!initialized) {
            return;
        }

        final Graphics2D G2 = (Graphics2D) g.create();

        G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        G2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        G2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);

        G2.translate(INNER_BOUNDS.x, INNER_BOUNDS.y);

        G2.drawImage(batteryImage, 0, 0, null);

        G2.translate(-INNER_BOUNDS.x, -INNER_BOUNDS.y);

        G2.dispose();
    }
1014190
function (size) {
        this.canvasContext.canvas.width = size.w;
        this.canvasContext.canvas.height = size.h;

        this.size = size;
    }
281053
@Override
    protected void onGraphDraw(Canvas _Canvas) {
        super.onGraphDraw(_Canvas);
        _Canvas.translate(-mCurrentViewport.left, -mCurrentViewport.top);
        drawBars(_Canvas);
    }
1181535
private void drawCircle(Canvas canvas, float x, float y, int color, float circleScale) {
        dayPaint.setColor(color);
        if (animationStatus == ANIMATE_INDICATORS) {
            float maxRadius = circleScale * bigCircleIndicatorRadius * 1.4f;
            drawCircle(canvas, growfactorIndicator > maxRadius ? maxRadius: growfactorIndicator, x, y - (textHeight / 6));
        } else {
            drawCircle(canvas, circleScale * bigCircleIndicatorRadius, x, y - (textHeight / 6));
        }
    }
1224270
function() {
      var ctxt=this.getContext();
      
      // Canvas Region
      var canvasRegion = Dom.getRegion(this.element);
      var canvasWidth = canvasRegion.right-canvasRegion.left-4;
      var canvasHeight = canvasRegion.bottom-canvasRegion.top-4;
      
      // Clear Rect
      ctxt.clearRect(0,0, canvasWidth, canvasHeight);
      
      // Calculate ratio
      var layerWidth = this.layer.el.scrollWidth;
      var layerHeight = this.layer.el.scrollHeight;
      var hRatio = Math.floor(100*canvasWidth/layerWidth)/100;
      var vRatio = Math.floor(100*canvasHeight/layerHeight)/100;

      // Draw the viewport
      var region = Dom.getRegion(this.layer.el);
      var viewportWidth = region.right-region.left;
      var viewportHeight = region.bottom-region.top;
      var viewportX = this.layer.el.scrollLeft;
      var viewportY = this.layer.el.scrollTop;
      ctxt.strokeStyle= "rgb(200, 50, 50)";
      ctxt.lineWidth=1;
      ctxt.strokeRect(viewportX*hRatio, viewportY*vRatio, viewportWidth*hRatio, viewportHeight*vRatio);
   
      // Draw containers and wires
      ctxt.fillStyle = this.style;
      ctxt.strokeStyle= this.style;
      ctxt.lineWidth=this.lineWidth;
      this.drawContainers(ctxt, hRatio, vRatio);
      this.drawWires(ctxt, hRatio, vRatio);
   }
622646
public void drawInBackground(Canvas canvas) {
        Axis axis = chart.getChartData().getAxisYLeft();
        if (null != axis) {
            prepareAxisToDraw(axis, LEFT);
            drawAxisLines(canvas, axis, LEFT);
        }

        axis = chart.getChartData().getAxisYRight();
        if (null != axis) {
            prepareAxisToDraw(axis, RIGHT);
            drawAxisLines(canvas, axis, RIGHT);
        }

        axis = chart.getChartData().getAxisXBottom();
        if (null != axis) {
            prepareAxisToDraw(axis, BOTTOM);
            drawAxisLines(canvas, axis, BOTTOM);
        }

        axis = chart.getChartData().getAxisXTop();
        if (null != axis) {
            prepareAxisToDraw(axis, TOP);
            drawAxisLines(canvas, axis, TOP);
        }
    }
368213
public void draw() {
		//=================================================================
		//Now plot the STP with the Utility.PlotSTPTemporalModule class
		//=================================================================
		PlotSTPTemporalModule view;
		Toolkit tk = Toolkit.getDefaultToolkit();
		int xSize = ((int) tk.getScreenSize().getWidth());
		int ySize = ((int) tk.getScreenSize().getHeight());
		//int ySize = 500;

		//GIVE tm TO VISIUALIZER		
		view = new PlotSTPTemporalModule(this, xSize, ySize);
		JFrame myFrame = new JFrame("Simple Temporal Network");

		Container pane = myFrame.getContentPane();
		pane.setLayout(new BorderLayout());
		pane.add(view, BorderLayout.NORTH);
		myFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

		myFrame.setSize(xSize,ySize);

		myFrame.pack();
		myFrame.setVisible(true);

		view.touchLBUBNodes();
		//=================================================================
		//End STP plotting
		//=================================================================
	}
112564
private void drawTexts(Canvas canvas, float textSize, Typeface typeface, String[] texts,
            float[] textGridWidths, float[] textGridHeights) {
        mPaint.setTextSize(textSize);
        mPaint.setTypeface(typeface);
        Paint[] textPaints = assignTextColors(texts);
        canvas.drawText(texts[0], textGridWidths[3], textGridHeights[0], textPaints[0]);
        canvas.drawText(texts[1], textGridWidths[4], textGridHeights[1], textPaints[1]);
        canvas.drawText(texts[2], textGridWidths[5], textGridHeights[2], textPaints[2]);
        canvas.drawText(texts[3], textGridWidths[6], textGridHeights[3], textPaints[3]);
        canvas.drawText(texts[4], textGridWidths[5], textGridHeights[4], textPaints[4]);
        canvas.drawText(texts[5], textGridWidths[4], textGridHeights[5], textPaints[5]);
        canvas.drawText(texts[6], textGridWidths[3], textGridHeights[6], textPaints[6]);
        canvas.drawText(texts[7], textGridWidths[2], textGridHeights[5], textPaints[7]);
        canvas.drawText(texts[8], textGridWidths[1], textGridHeights[4], textPaints[8]);
        canvas.drawText(texts[9], textGridWidths[0], textGridHeights[3], textPaints[9]);
        canvas.drawText(texts[10], textGridWidths[1], textGridHeights[2], textPaints[10]);
        canvas.drawText(texts[11], textGridWidths[2], textGridHeights[1], textPaints[11]);
    }
920717
@Override
    protected void onGraphDraw(Canvas _Canvas) {
        super.onGraphDraw(_Canvas);
        if(mUseOverlapFill) {
            mLinePaint.setStyle(Paint.Style.FILL);
        }
        else {
            mLinePaint.setStrokeWidth(mLineStroke);
            mLinePaint.setStyle(Paint.Style.STROKE);
        }

        _Canvas.concat(mDrawMatrix);
        if(mHasNegativeValues) {
            _Canvas.translate(0, -mNegativeOffset);
        }

        // drawing of lines
        for (ValueLineSeries series : mSeries) {
            mLinePaint.setColor(series.getColor());
            _Canvas.drawPath(series.getPath(), mLinePaint);
        }
    }
592199
@Override
  public void draw(Canvas canvas) {
    mBounds = getBounds();
    canvas.clipRect(mBounds);

    //new turn
    if (mNewTurn) {
      mColorsIndex = decrementColor(mColorsIndex);
      mNewTurn = false;

      if (isFinishing()) {
        mStartSection++;

        if (mStartSection > mSectionsCount) {
          stop();
          return;
        }
      }
      if (mCurrentSections < mSectionsCount) {
        mCurrentSections++;
      }
    }

    if (mUseGradients)
      prepareGradient();

    drawStrokes(canvas);
  }