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

Commit 9691e2fe authored by Georg Veichtlbauer's avatar Georg Veichtlbauer
Browse files

ExactCalculator: Add support for a unified parenthesis button

Change-Id: I9c72066fbc8ba77fefd78b59c5b78db9d2ad3ece
parent 77894378
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@
    <!-- Constant for pi (i.e. "3.1415…"). [CHAR_LIMIT=1] -->
    <string name="const_pi" translatable="false">π</string>

    <!-- Parenthesis (e.g. "log(", "2 × (3 - 1)". [CHAR_LIMIT=1] -->
    <string name="paren" translatable="false">( )</string>
    <!-- Left parenthesis (e.g. "log(", "2 × (3 - 1)". [CHAR_LIMIT=1] -->
    <string name="lparen" translatable="false">(</string>
    <!-- Right parenthesis (e.g. "log(2)", "(3 - 1) × 2". [CHAR_LIMIT=1] -->
@@ -151,6 +153,8 @@
    <!-- Content description for '.' button. [CHAR_LIMIT=NONE] -->
    <string name="desc_dec_point">point</string>

    <!-- Content description for '( )' button. [CHAR_LIMIT=NONE] -->
    <string name="desc_paren">parenthesis</string>
    <!-- Content description for '(' button. [CHAR_LIMIT=NONE] -->
    <string name="desc_lparen">left parenthesis</string>
    <!-- Content description for ')' button. [CHAR_LIMIT=NONE] -->
+12 −0
Original line number Diff line number Diff line
@@ -851,6 +851,18 @@ public class Calculator extends AppCompatActivity
                evaluateInstantIfNecessary();
            }
            return;
        } else if (id == R.id.paren) {
            String expr = mEvaluator.getExprAsString(0);
            int openCount = expr.length() - expr.replace(KeyMaps.toString(this, R.id.lparen), "")
                    .length();
            int closeCount = expr.length() - expr.replace(KeyMaps.toString(this, R.id.rparen), "")
                    .length();

            if (openCount > closeCount && !expr.endsWith(KeyMaps.toString(this, R.id.lparen))) {
                addChars(KeyMaps.toString(this, R.id.rparen), true);
            } else {
                addChars(KeyMaps.toString(this, R.id.lparen), true);
            }
        } else {
            cancelIfEvaluating(false);
            if (haveUnprocessed()) {