protected void setState(CalculatorState state) {
    if (mCurrentState != state) {
      mCurrentState = state;
      invalidateEqualsButton();

      if (state == CalculatorState.RESULT || state == CalculatorState.ERROR) {
        mDeleteButton.setVisibility(View.GONE);
        mClearButton.setVisibility(View.VISIBLE);
      } else {
        mDeleteButton.setVisibility(View.VISIBLE);
        mClearButton.setVisibility(View.GONE);
      }

      if (state == CalculatorState.ERROR) {
        final int errorColor = getResources().getColor(R.color.calculator_error_color);
        mFormulaEditText.setTextColor(errorColor);
        mResultEditText.setTextColor(errorColor);
        if (android.os.Build.VERSION.SDK_INT >= 21) {
          getWindow().setStatusBarColor(errorColor);
        }
      } else {
        mFormulaEditText.setTextColor(getResources().getColor(R.color.display_formula_text_color));
        mResultEditText.setTextColor(getResources().getColor(R.color.display_result_text_color));
        if (android.os.Build.VERSION.SDK_INT >= 21) {
          getWindow().setStatusBarColor(getResources().getColor(R.color.calculator_accent_color));
        }
      }
    }
  }
 @Override
 public void onEvaluate(String expr, String result, int errorResourceId) {
   if (mCurrentState == CalculatorState.INPUT || mCurrentState == CalculatorState.GRAPHING) {
     if (result == null || Solver.equal(result, expr)) {
       mResultEditText.setText(null);
     } else {
       mResultEditText.setText(result);
     }
   } else if (errorResourceId != INVALID_RES_ID) {
     onError(errorResourceId);
   } else if (saveHistory(expr, result, true)) {
     mDisplayView.scrollToMostRecent();
     onResult(result);
   } else if (mCurrentState == CalculatorState.EVALUATE) {
     // The current expression cannot be evaluated -> return to the input state.
     setState(CalculatorState.INPUT);
   }
   invalidateEqualsButton();
 }