Handle font with missing FIGURE SPACE.

Bug: 27203752

Calculate digit width explicitly instead of relying on FIGURE SPACE.

This makes the calculator work correctly, even with fonts that are
utterly unreasonable for this purpose, like Nova Round. The result
remains ugly, due to highly variable digit widths. But it is correct.

This should have little to no impact on Nexus devices. Empirically
digit widths with our default font are slightly less than the width
of a FIGURE SPACE.  This version of the change does require careful
cross-device testing.

Change-Id: Id6feb0f312bc237ba462165ba2dff7030e04ae3b
diff --git a/src/com/android/calculator2/CalculatorResult.java b/src/com/android/calculator2/CalculatorResult.java
index 8abc0da..44ffdcd 100644
--- a/src/com/android/calculator2/CalculatorResult.java
+++ b/src/com/android/calculator2/CalculatorResult.java
@@ -194,13 +194,28 @@
         mEvaluator = evaluator;
     }
 
+    // Compute maximum digit width the hard way.
+    private static float getMaxDigitWidth(TextPaint paint) {
+        // Compute the maximum advance width for each digit, thus accounting for between-character
+        // spaces. If we ever support other kinds of digits, we may have to avoid kerning effects
+        // that could reduce the advance width within this particular string.
+        final String allDigits = "0123456789";
+        final float[] widths = new float[allDigits.length()];
+        paint.getTextWidths(allDigits, widths);
+        float maxWidth = 0;
+        for (float x : widths) {
+            maxWidth = Math.max(x, maxWidth);
+        }
+        return maxWidth;
+    }
+
     @Override
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
 
         final TextPaint paint = getPaint();
         final Context context = getContext();
-        final float newCharWidth = Layout.getDesiredWidth("\u2007", paint);
+        final float newCharWidth = getMaxDigitWidth(paint);
         // Digits are presumed to have no more than newCharWidth.
         // We sometimes replace a character by an ellipsis or, due to SCI_NOTATION_EXTRA, add
         // an extra decimal separator beyond the maximum number of characters we normally allow.