From 75e50893c3c917d30ec970a0f1127139616c82d9 Mon Sep 17 00:00:00 2001 From: serso Date: Sat, 6 Feb 2016 22:50:33 +0100 Subject: [PATCH] Use cached instance of TextPaint --- .../org/solovyev/android/views/AutoResizeTextView.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/solovyev/android/views/AutoResizeTextView.java b/app/src/main/java/org/solovyev/android/views/AutoResizeTextView.java index 604a5a54..41f6bf1a 100644 --- a/app/src/main/java/org/solovyev/android/views/AutoResizeTextView.java +++ b/app/src/main/java/org/solovyev/android/views/AutoResizeTextView.java @@ -53,6 +53,7 @@ public class AutoResizeTextView extends TextView { private float mSpacingAdd = 0.0f; // Add ellipsis to text that overflows at the smallest text size private boolean mAddEllipsis = true; + private final TextPaint tmpPaint = new TextPaint(); // Default constructor override public AutoResizeTextView(Context context) { @@ -286,11 +287,11 @@ public class AutoResizeTextView extends TextView { // modified: make a copy of the original TextPaint object for measuring // (apparently the object gets modified while measuring, see also the // docs for TextView.getPaint() (which states to access it read-only) - TextPaint paintCopy = new TextPaint(paint); + tmpPaint.set(paint); // Update the text paint object - paintCopy.setTextSize(textSize); + tmpPaint.setTextSize(textSize); // Measure using a static layout - StaticLayout layout = new StaticLayout(source, paintCopy, width, Alignment.ALIGN_NORMAL, mSpacingMult, mSpacingAdd, true); + StaticLayout layout = new StaticLayout(source, tmpPaint, width, Alignment.ALIGN_NORMAL, mSpacingMult, mSpacingAdd, true); return layout.getHeight(); }