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

Commit 40538322 authored by Inhishonor's avatar Inhishonor Committed by Luca Stefani
Browse files

ExactCalculator: Clean up unused and redundant code

Change-Id: I68dbd5945db5a525eeddbead53d4c315c2199b6c
parent a9ce2abb
Loading
Loading
Loading
Loading
+0 −19
Original line number Diff line number Diff line
@@ -127,13 +127,6 @@ public class BoundedRational {
        return result;
    }

    public static String toString(BoundedRational r) {
        if (r == null) {
            return "not a small rational";
        }
        return r.toString();
    }

    /**
     * Returns a truncated (rounded towards 0) representation of the result.
     * Includes n digits to the right of the decimal point.
@@ -334,10 +327,6 @@ public class BoundedRational {
        return new BoundedRational(r.mNum.negate(), r.mDen);
    }

    public static BoundedRational subtract(BoundedRational r1, BoundedRational r2) {
        return add(r1, negate(r2));
    }

    /**
     * Return product of r1 and r2 without reducing the result.
     */
@@ -418,14 +407,6 @@ public class BoundedRational {
    public final static BoundedRational MINUS_TWO = new BoundedRational(-2);
    public final static BoundedRational TEN = new BoundedRational(10);
    public final static BoundedRational TWELVE = new BoundedRational(12);
    public final static BoundedRational THIRTY = new BoundedRational(30);
    public final static BoundedRational MINUS_THIRTY = new BoundedRational(-30);
    public final static BoundedRational FORTY_FIVE = new BoundedRational(45);
    public final static BoundedRational MINUS_FORTY_FIVE = new BoundedRational(-45);
    public final static BoundedRational NINETY = new BoundedRational(90);
    public final static BoundedRational MINUS_NINETY = new BoundedRational(-90);

    private static final BigInteger BIG_TWO = BigInteger.valueOf(2);
    private static final BigInteger BIG_MINUS_ONE = BigInteger.valueOf(-1);

    /**
+8 −9
Original line number Diff line number Diff line
@@ -48,7 +48,6 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.constraintlayout.motion.widget.MotionLayout;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.Insets;
@@ -309,17 +308,17 @@ public class Calculator extends AppCompatActivity

        setContentView(R.layout.activity_calculator);
        setupEdgeToEdge();
        setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
        setSupportActionBar(findViewById(R.id.toolbar));

        // Hide all default options in the ActionBar.
        getSupportActionBar().setDisplayOptions(0);

        mMainCalculator = findViewById(R.id.main_calculator);
        mModeView = (TextView) findViewById(R.id.mode);
        mFormulaText = (CalculatorFormula) findViewById(R.id.formula);
        mDeleteButton = (HapticButton) findViewById(R.id.del);
        mResultText = (CalculatorResult) findViewById(R.id.result);
        mFormulaContainer = (HorizontalScrollView) findViewById(R.id.formula_scroll_view);
        mModeView = findViewById(R.id.mode);
        mFormulaText = findViewById(R.id.formula);
        mDeleteButton = findViewById(R.id.del);
        mResultText = findViewById(R.id.result);
        mFormulaContainer = findViewById(R.id.formula_scroll_view);
        mEvaluator = Evaluator.getInstance(this);
        mEvaluator.setCallback(mEvaluatorCallback);
        mResultText.setEvaluator(mEvaluator, Evaluator.MAIN_INDEX);
@@ -328,8 +327,8 @@ public class Calculator extends AppCompatActivity
        final TextView dpButton = findViewById(R.id.input_pad).findViewById(R.id.dec_point);
        dpButton.setText(getDecimalSeparator());

        mInverseToggle = (TextView) findViewById(R.id.toggle_inv);
        mModeToggle = (TextView) findViewById(R.id.toggle_mode);
        mInverseToggle = findViewById(R.id.toggle_inv);
        mModeToggle = findViewById(R.id.toggle_mode);

        mIsOneLine = mResultText.getVisibility() == View.INVISIBLE;

+0 −1
Original line number Diff line number Diff line
@@ -7,7 +7,6 @@ package com.android.calculator2;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;

public class CalculatorDisplay extends LinearLayout {
+7 −18
Original line number Diff line number Diff line
@@ -66,10 +66,8 @@ class CalculatorExpr {
                                     // as a list of tokens.  Constant
                                     // tokens are always nonempty.

    private static enum TokenKind { CONSTANT, OPERATOR, PRE_EVAL };
    private enum TokenKind { CONSTANT, OPERATOR, PRE_EVAL };
    private static TokenKind[] tokenKindValues = TokenKind.values();
    private final static BigInteger BIG_MILLION = BigInteger.valueOf(1000000);
    private final static BigInteger BIG_BILLION = BigInteger.valueOf(1000000000);

    private static abstract class Token {
        abstract TokenKind kind();
@@ -137,9 +135,7 @@ class CalculatorExpr {
        Constant() {
            mWhole = "";
            mFraction = "";
            // mSawDecimal = false;
            // mExponent = 0;
        };
        }

        Constant(DataInput in) throws IOException {
            mWhole = in.readUTF();
@@ -226,7 +222,7 @@ class CalculatorExpr {
        }

        public boolean isEmpty() {
            return (mSawDecimal == false && mWhole.isEmpty());
            return (!mSawDecimal && mWhole.isEmpty());
        }

        /**
@@ -379,7 +375,7 @@ class CalculatorExpr {
    }

    CalculatorExpr() {
        mExpr = new ArrayList<Token>();
        mExpr = new ArrayList<>();
    }

    private CalculatorExpr(ArrayList<Token> expr) {
@@ -390,7 +386,7 @@ class CalculatorExpr {
     * Construct CalculatorExpr, by reading it from in.
     */
    CalculatorExpr(DataInput in) throws IOException {
        mExpr = new ArrayList<Token>();
        mExpr = new ArrayList<>();
        int size = in.readInt();
        for (int i = 0; i < size; ++i) {
            mExpr.add(newToken(in));
@@ -653,9 +649,6 @@ class CalculatorExpr {
            mPrefixLength = len;
            mExprResolver = er;
        }
        void write(DataOutput out) throws IOException {
            out.writeBoolean(mDegreeMode);
        }
    }

    private UnifiedReal toRadians(UnifiedReal x, EvalContext ec) {
@@ -854,10 +847,7 @@ class CalculatorExpr {
        if (!(t instanceof Operator)) return true;
        int id = ((Operator)(t)).id;
        if (KeyMaps.isBinary(id)) return false;
        if (id == R.id.op_fact || id == R.id.rparen) {
            return false;
        }
        return true;
        return id != R.id.op_fact && id != R.id.rparen;
    }

    private EvalRet evalTerm(int i, EvalContext ec) throws SyntaxException {
@@ -877,7 +867,6 @@ class CalculatorExpr {
                val = val.multiply(tmp.val);
            }
            cpos = tmp.pos;
            is_mul = is_div = false;
        }
        return new EvalRet(cpos, val);
    }
@@ -1029,7 +1018,7 @@ class CalculatorExpr {
        // for positive and negative indices separately, but not their union. Currently we
        // just settle for reverse breadth-first-search order, which handles the common case
        // of simple dependency chains well.
        ArrayList<Long> list = new ArrayList<Long>();
        ArrayList<Long> list = new ArrayList<>();
        int scanned = 0;  // We've added expressions referenced by [0, scanned) to the list
        addReferencedExprs(list, er);
        while (scanned != list.size()) {
+10 −22
Original line number Diff line number Diff line
@@ -272,12 +272,9 @@ public class CalculatorFormula extends AlignedTextView implements MenuItem.OnMen
                outRect.left = (int) (outRect.right * 0.9f);
            }
        };
        setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
        setOnLongClickListener(v -> {
            mActionMode = startActionMode(mPasteActionModeCallback, ActionMode.TYPE_FLOATING);
            return true;
            }
        });
    }

@@ -285,24 +282,15 @@ public class CalculatorFormula extends AlignedTextView implements MenuItem.OnMen
     * Use ContextMenu for paste support on L and lower.
     */
    private void setupContextMenu() {
        setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
            @Override
            public void onCreateContextMenu(ContextMenu contextMenu, View view,
                    ContextMenu.ContextMenuInfo contextMenuInfo) {
        setOnCreateContextMenuListener((contextMenu, view, contextMenuInfo) -> {
            final MenuInflater inflater = new MenuInflater(getContext());
            createContextMenu(inflater, contextMenu);
            mContextMenu = contextMenu;
            for (int i = 0; i < contextMenu.size(); i++) {
                contextMenu.getItem(i).setOnMenuItemClickListener(CalculatorFormula.this);
            }
            }
        });
        setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                return showContextMenu();
            }
        });
        setOnLongClickListener(v -> showContextMenu());
    }

    private boolean createContextMenu(MenuInflater inflater, Menu menu) {
Loading