Methods Summary |
---|
boolean | acceptInsert(java.lang.String delta)
String text = getText();
return !mIsError &&
(!mResult.equals(text) ||
isOperator(delta) ||
mDisplay.getSelectionStart() != text.length());
|
private void | clear(boolean scroll)
mDisplay.setText("", scroll ? CalculatorDisplay.Scroll.UP : CalculatorDisplay.Scroll.NONE);
cleared();
|
private void | clearWithHistory(boolean scroll)
mDisplay.setText(mHistory.getText(),
scroll ? CalculatorDisplay.Scroll.UP : CalculatorDisplay.Scroll.NONE);
mResult = "";
mIsError = false;
|
void | cleared()
mResult = "";
mIsError = false;
updateHistory();
|
boolean | eatHorizontalMove(boolean toLeft)
EditText editText = mDisplay.getEditText();
int cursorPos = editText.getSelectionStart();
return toLeft ? cursorPos == 0 : cursorPos >= editText.length();
|
java.lang.String | evaluate(java.lang.String input)
if (input.trim().equals("")) {
return "";
}
// drop final infix operators (they can only result in error)
int size = input.length();
while (size > 0 && isOperator(input.charAt(size - 1))) {
input = input.substring(0, size - 1);
--size;
}
String result = Util.doubleToString(mSymbols.eval(input), mLineLength, ROUND_DIGITS);
if (result.equals(NAN)) { // treat NaN as Error
mIsError = true;
return mErrorString;
}
return result.replace('-", MINUS).replace(INFINITY, INFINITY_UNICODE);
|
private java.lang.String | getText()
return mDisplay.getText().toString();
|
void | insert(java.lang.String delta)
mDisplay.insert(delta);
|
static boolean | isOperator(java.lang.String text)
return text.length() == 1 && isOperator(text.charAt(0));
|
static boolean | isOperator(char c)
//plus minus times div
return "+\u2212\u00d7\u00f7/*".indexOf(c) != -1;
|
void | onClear()
clear(false);
|
void | onDelete()
if (getText().equals(mResult) || mIsError) {
clear(false);
} else {
mDisplay.dispatchKeyEvent(new KeyEvent(0, KeyEvent.KEYCODE_DEL));
mResult = "";
}
|
void | onDown()
String text = getText();
if (!text.equals(mResult)) {
mHistory.update(text);
}
if (mHistory.moveToNext()) {
mDisplay.setText(mHistory.getText(), CalculatorDisplay.Scroll.UP);
}
|
void | onEnter()
String text = getText();
if (text.equals(mResult)) {
clearWithHistory(false); //clear after an Enter on result
} else {
mHistory.enter(text);
try {
mResult = evaluate(text);
} catch (SyntaxException e) {
mIsError = true;
mResult = mErrorString;
}
if (text.equals(mResult)) {
//no need to show result, it is exactly what the user entered
clearWithHistory(true);
} else {
setText(mResult);
//mEqualButton.setText(mEnterString);
}
}
|
void | onUp()
String text = getText();
if (!text.equals(mResult)) {
mHistory.update(text);
}
if (mHistory.moveToPrevious()) {
mDisplay.setText(mHistory.getText(), CalculatorDisplay.Scroll.DOWN);
}
|
private void | setText(java.lang.CharSequence text)
mDisplay.setText(text, CalculatorDisplay.Scroll.UP);
|
void | updateHistory()
mHistory.update(getText());
|