@Override
 public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
   switch (keyCode) {
     case KeyEvent.KEYCODE_NUMPAD_ENTER:
     case KeyEvent.KEYCODE_ENTER:
       if (keyEvent.getAction() == KeyEvent.ACTION_UP) {
         mCurrentButton = mEqualButton;
         onEquals();
       }
       // ignore all other actions
       return true;
   }
   return false;
 }
 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;
   }
 }