/**
  * Inserts text into the formula EditText. If an equation was recently solved, it will replace the
  * formula's text instead of appending.
  */
 protected void insert(String text) {
   // Add left parenthesis after functions.
   if (mCurrentState.equals(CalculatorState.INPUT)
       || mCurrentState.equals(CalculatorState.GRAPHING)
       || mFormulaEditText.isCursorModified()) {
     mFormulaEditText.insert(text);
   } else {
     mFormulaEditText.setText(text);
     incrementGroupId();
   }
 }
 public void onButtonClick(View view) {
   mCurrentButton = view;
   switch (view.getId()) {
     case R.id.eq:
       onEquals();
       break;
     case R.id.del:
       onDelete();
       break;
     case R.id.clr:
       onClear();
       break;
     case R.id.parentheses:
       mFormulaEditText.setText('(' + mFormulaEditText.getCleanText() + ')');
       break;
     case R.id.fun_cos:
     case R.id.fun_sin:
     case R.id.fun_tan:
     case R.id.fun_ln:
     case R.id.fun_log:
     case R.id.fun_det:
     case R.id.fun_transpose:
     case R.id.fun_inverse:
     case R.id.fun_trace:
     case R.id.fun_norm:
     case R.id.fun_polar:
       // Add left parenthesis after functions.
       insert(((Button) view).getText() + "(");
       break;
     case R.id.op_add:
     case R.id.op_sub:
     case R.id.op_mul:
     case R.id.op_div:
     case R.id.op_fact:
     case R.id.op_pow:
       mFormulaEditText.insert(((Button) view).getText().toString());
       break;
     default:
       insert(((Button) view).getText().toString());
       break;
   }
 }