public void draw()

in Unsplash/app/src/main/java/com/example/android/unsplash/transition/TextResize.java [402:436]


        public void draw(Canvas canvas) {
            int saveCount = canvas.save();
            // The threshold changes depending on the target font sizes. Because scaled-up
            // fonts look bad, we want to switch when closer to the smaller font size. This
            // algorithm ensures that null bitmaps (font size = 0) are never used.
            final float threshold = startFontSize / (startFontSize + endFontSize);
            final float fontSize = getFontSize();
            final float progress = (fontSize - startFontSize)/(endFontSize - startFontSize);

            // The drawn text width is a more accurate scale than font size. This avoids
            // jump when switching bitmaps.
            final float expectedWidth = interpolate(startWidth, endWidth, progress);
            if (progress < threshold) {
                // draw start bitmap
                final float scale = expectedWidth / startWidth;
                float tx = getTranslationPoint(horizontalGravity, left, right,
                        startBitmap.getWidth(), scale);
                float ty = getTranslationPoint(verticalGravity, top, bottom,
                        startBitmap.getHeight(), scale);
                canvas.translate(tx, ty);
                canvas.scale(scale, scale);
                canvas.drawBitmap(startBitmap, 0, 0, paint);
            } else {
                // draw end bitmap
                final float scale = expectedWidth / endWidth;
                float tx = getTranslationPoint(horizontalGravity, left, right,
                        endBitmap.getWidth(), scale);
                float ty = getTranslationPoint(verticalGravity, top, bottom,
                        endBitmap.getHeight(), scale);
                canvas.translate(tx, ty);
                canvas.scale(scale, scale);
                canvas.drawBitmap(endBitmap, 0, 0, paint);
            }
            canvas.restoreToCount(saveCount);
        }