Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ffda5284 authored by Hans Boehm's avatar Hans Boehm
Browse files

Handle placeholder characters during translation

Bug: 21131556

If we fall behind, initially use blanks as placeholder characters.
Convert these to the right character (currently a correctly sized
space) during translation.

This avoids log spam by the translation code with minimal complication.
It also seems a bit cleaner.

Add some missing private qualifiers in the same vicinity.

Change-Id: I9c53d74ce2a234c888cee55ba72575c884f18cae
parent 957d2d0b
Loading
Loading
Loading
Loading
+1 −10
Original line number Diff line number Diff line
@@ -131,15 +131,6 @@ class Evaluator {

    static final BigInteger BIG_MILLION = BigInteger.valueOf(1000000);

    /**
     * Character used as a placeholder for digits that are currently unknown in a result that is
     * being computed.
     * <p/>
     * Note: the character must correspond closely to the width of a digit, otherwise the UI will
     * visibly shift once the computation is finished.
     */
    private static final char CHAR_DIGIT_UNKNOWN = '\u2007';

    private static final int EXTRA_DIGITS = 20;
                // Extra computed digits to minimize probably we will have
                // to change our minds about digits we already displayed.
@@ -583,7 +574,7 @@ class Evaluator {
    private String getPadding(int n) {
        StringBuilder padding = new StringBuilder();
        for (int i = 0; i < n; ++i) {
            padding.append(CHAR_DIGIT_UNKNOWN);
            padding.append(' ');   // To be replaced during final translation.
        }
        return padding.toString();
    }
+23 −9
Original line number Diff line number Diff line
@@ -27,6 +27,9 @@ import java.text.DecimalFormatSymbols;
import java.util.HashMap;
import java.util.Locale;

// This is a collection of various mapping functions between key ids,
// characters, internationalized and noninternationalized characters, etc.
//
// KeyMap instances are not meaningful; everything here is static.
// All functions are either pure, or are assumed to be called only from
// a single UI thread.
@@ -161,29 +164,39 @@ public class KeyMaps {
        }
    }

    static char mDecimalPt =
    private static char mDecimalPt =
            DecimalFormatSymbols.getInstance().getDecimalSeparator();

    static char mPiChar;
    private static char mPiChar;

    static char mFactChar;
    private static char mFactChar;

    static HashMap<String, Integer> sKeyValForFun;
    /**
     * Character used as a placeholder for digits that are currently unknown
     * in a result that is being computed.  We initially generate blanks, and
     * then use this as a replacement during final translation.
     * <p/>
     * Note: the character must correspond closely to the width of a digit,
     * otherwise the UI will visibly shift once the computation is finished.
     */
    private static final char CHAR_DIGIT_UNKNOWN = '\u2007';

    private static HashMap<String, Integer> sKeyValForFun;
        // Key value corresponding to given function name.
        // We include both localized and English names.

    static HashMap<Character, String> sOutputForResultChar;
    private static HashMap<Character, String> sOutputForResultChar;
        // Result string corresponding to a character in the
        // calculator result.
        // The string values in the map are expected to be one character
        // long.

    static String sLocaleForMaps = "none";
    private static String sLocaleForMaps = "none";
        // Locale string corresponding to preceding map and character
        // constants.
        // We recompute the map if this is not the current locale.

    static Activity mActivity;  // Activity to use for looking up
    private static Activity mActivity;  // Activity to use for looking up
                                        // buttons.

    // Called only by UI thread.
@@ -295,6 +308,7 @@ public class KeyMaps {
            sOutputForResultChar.put('e', "E");
            sOutputForResultChar.put('E', "E");
            sOutputForResultChar.put('.', String.valueOf(mDecimalPt));
            sOutputForResultChar.put(' ', String.valueOf(CHAR_DIGIT_UNKNOWN));
            sOutputForResultChar.put(ELLIPSIS.charAt(0), ELLIPSIS);
            sOutputForResultChar.put('/', "/");
                        // Translate numbers for fraction display, but not