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

Unverified Commit f7591339 authored by Patrick Gaskin's avatar Patrick Gaskin
Browse files

ExactCalculator: Merge parentheses, add AC button

Like Google Calculator. I didn't reverse the APK directly, only
inferred the behavior, but I think it's correct.

Change-Id: I778dc2d466e8181080ae30fc827c72124a64bee4
parent 019027c9
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -13,21 +13,21 @@
    android:background="?colorSurface">

    <com.android.calculator2.HapticButton
        android:id="@+id/lparen"
        android:id="@+id/clr"
        style="@style/PadButtonStyle"
        android:contentDescription="@string/desc_lparen"
        android:text="@string/lparen"
        android:theme="@style/Theme.Button.Operator"
        android:contentDescription="@string/desc_clr"
        android:text="@string/clr"
        android:theme="@style/Theme.Button.Action"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@id/columnGuide4"
        app:layout_constraintTop_toBottomOf="@id/rowGuide3" />

    <com.android.calculator2.HapticButton
        android:id="@+id/rparen"
        android:id="@+id/paren"
        style="@style/PadButtonStyle"
        android:contentDescription="@string/desc_rparen"
        android:text="@string/rparen"
        android:contentDescription="@string/desc_paren"
        android:text="@string/paren"
        android:theme="@style/Theme.Button.Operator"
        app:layout_constraintBottom_toTopOf="@id/rowGuide3"
        app:layout_constraintEnd_toEndOf="parent"
+7 −7
Original line number Diff line number Diff line
@@ -13,21 +13,21 @@
    android:background="?colorSurface">

    <com.android.calculator2.HapticButton
        android:id="@+id/lparen"
        android:id="@+id/clr"
        style="@style/PadButtonStyle"
        android:contentDescription="@string/desc_lparen"
        android:text="@string/lparen"
        android:theme="@style/Theme.Button.Operator"
        android:contentDescription="@string/desc_clr"
        android:text="@string/clr"
        android:theme="@style/Theme.Button.Action"
        app:layout_constraintBottom_toTopOf="@id/rowGuide1"
        app:layout_constraintEnd_toStartOf="@id/columnGuide1"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <com.android.calculator2.HapticButton
        android:id="@+id/rparen"
        android:id="@+id/paren"
        style="@style/PadButtonStyle"
        android:contentDescription="@string/desc_rparen"
        android:text="@string/rparen"
        android:contentDescription="@string/desc_paren"
        android:text="@string/paren"
        android:theme="@style/Theme.Button.Operator"
        app:layout_constraintBottom_toTopOf="@id/rowGuide1"
        app:layout_constraintEnd_toStartOf="@id/columnGuide2"

res/values/ids.xml

0 → 100644
+9 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
     SPDX-FileCopyrightText: 2026 The LineageOS Project
     SPDX-License-Identifier: Apache-2.0
-->
<resources>
    <item name="lparen" type="id"/>
    <item name="rparen" type="id"/>
</resources>
+1 −1
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@
    <!-- Equals button (e.g. "1 + 2 = ?"). [CHAR_LIMIT=1] -->
    <string name="eq" translatable="false">=</string>
    <!-- Clear button to clear the currently entered expression. [CHAR_LIMIT=1] -->
    <string name="clr" translatable="false">c</string>
    <string name="clr" translatable="false">AC</string>
    <!--
      Announced when all characters are removed from Formula, e.g. after clear. [CHAR_LIMIT=NONE]
      -->
+15 −0
Original line number Diff line number Diff line
@@ -714,6 +714,8 @@ public class Calculator extends AppCompatActivity
            onEquals();
        } else if (id == R.id.del) {
            onDelete();
        } else if (id == R.id.clr) {
            onClear();
        } else if (id == R.id.toggle_inv) {
            final boolean selected = !mInverseToggle.isSelected();
            mInverseToggle.setSelected(selected);
@@ -739,6 +741,19 @@ public class Calculator extends AppCompatActivity
                evaluateInstantIfNecessary();
            }
            return;
        } else if (id == R.id.paren) {
            // If we just added a function or left paren, add another.
            // If we don't have any open parentheses, add a left one.
            // If we end with a digit or a right parenthesis, add a right one.
            // If we end with an operator, add a left one.
            if (!mEvaluator.getExpr(Evaluator.MAIN_INDEX).hasTrailingLeftParen() &&
                    mEvaluator.getExpr(Evaluator.MAIN_INDEX).hasOpenParentheses() &&
                    (mEvaluator.getExpr(Evaluator.MAIN_INDEX).hasTrailingRightParen() ||
                            mEvaluator.getExpr(Evaluator.MAIN_INDEX).hasTrailingConstant()))
                addExplicitKeyToExpr(R.id.rparen);
            else
                addExplicitKeyToExpr(R.id.lparen);
            redisplayAfterFormulaChange();
        } else {
            cancelIfEvaluating(false);
            if (haveUnprocessed()) {
Loading