コード例 #1
0
  protected void initialize(Bundle savedInstanceState) {
    // Rebuild constants. If the user changed their locale, it won't kill the app
    // but it might change a decimal point from . to ,
    Constants.rebuildConstants();

    mDisplayView = (DisplayOverlay) findViewById(R.id.display);
    mDisplayView.setFade(findViewById(R.id.history_fade));
    mDisplayForeground = (ViewGroup) findViewById(R.id.the_clear_animation);
    mFormulaEditText = (CalculatorEditText) findViewById(R.id.formula);
    mResultEditText = (CalculatorEditText) findViewById(R.id.result);
    mPadViewPager = (CalculatorPadView) findViewById(R.id.pad_pager);
    mDeleteButton = findViewById(R.id.del);
    mClearButton = findViewById(R.id.clr);
    mEqualButton = (EqualsImageButton) findViewById(R.id.pad_numeric).findViewById(R.id.eq);

    if (mEqualButton == null || mEqualButton.getVisibility() != View.VISIBLE) {
      mEqualButton = (EqualsImageButton) findViewById(R.id.pad_operator).findViewById(R.id.eq);
    }

    mTokenizer = new CalculatorExpressionTokenizer(this);
    mEvaluator = new CalculatorExpressionEvaluator(mTokenizer);

    setState(
        CalculatorState.values()[
            savedInstanceState.getInt(KEY_CURRENT_STATE, CalculatorState.INPUT.ordinal())]);

    mFormulaEditText.setSolver(mEvaluator.getSolver());
    mResultEditText.setSolver(mEvaluator.getSolver());
    mFormulaEditText.setText(
        mTokenizer.getLocalizedExpression(
            savedInstanceState.getString(KEY_CURRENT_EXPRESSION, "")));
    mFormulaEditText.addTextChangedListener(mFormulaTextWatcher);
    mFormulaEditText.setOnKeyListener(mFormulaOnKeyListener);
    mFormulaEditText.setOnTextSizeChangeListener(this);
    mDeleteButton.setOnLongClickListener(this);
    mResultEditText.setEnabled(false);
    findViewById(R.id.lparen).setOnLongClickListener(this);
    findViewById(R.id.rparen).setOnLongClickListener(this);
    findViewById(R.id.fun_sin).setOnLongClickListener(this);
    findViewById(R.id.fun_cos).setOnLongClickListener(this);
    findViewById(R.id.fun_tan).setOnLongClickListener(this);

    // Disable IME for this application
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
            WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

    Button dot = (Button) findViewById(R.id.dec_point);
    dot.setText(String.valueOf(Constants.DECIMAL_POINT));
  }
コード例 #2
0
 private void onEquals() {
   String text = mFormulaEditText.getCleanText();
   if (mCurrentState == CalculatorState.INPUT) {
     switch (mEqualButton.getState()) {
       case EQUALS:
         setState(CalculatorState.EVALUATE);
         mEvaluator.evaluate(text, this);
         break;
       case NEXT:
         mFormulaEditText.next();
         break;
     }
   } else if (mCurrentState == CalculatorState.GRAPHING) {
     setState(CalculatorState.EVALUATE);
     onEvaluate(text, "", INVALID_RES_ID);
   }
 }