CalculatorDisplaypublic class CalculatorDisplay extends android.widget.ViewSwitcher Provides vertical scrolling for the input/result EditText. |
Fields Summary |
---|
private static final char[] | ACCEPTED_CHARS | private static final int | ANIM_DURATION | android.view.animation.TranslateAnimation | inAnimUp | android.view.animation.TranslateAnimation | outAnimUp | android.view.animation.TranslateAnimation | inAnimDown | android.view.animation.TranslateAnimation | outAnimDown |
Methods Summary |
---|
android.widget.EditText | getEditText()
return (EditText) getCurrentView();
| int | getSelectionStart()
EditText text = (EditText) getCurrentView();
return text.getSelectionStart();
| android.text.Editable | getText()
EditText text = (EditText) getCurrentView();
return text.getText();
| void | insert(java.lang.String delta)
EditText editor = (EditText) getCurrentView();
int cursor = editor.getSelectionStart();
editor.getText().insert(cursor, delta);
| protected void | onFocusChanged(boolean gain, int direction, android.graphics.Rect prev)
//Calculator.log("focus " + gain + "; " + direction + "; " + prev);
if (!gain) {
requestFocus();
}
| protected void | onSizeChanged(int w, int h, int oldW, int oldH)
inAnimUp = new TranslateAnimation(0, 0, h, 0);
inAnimUp.setDuration(ANIM_DURATION);
outAnimUp = new TranslateAnimation(0, 0, 0, -h);
outAnimUp.setDuration(ANIM_DURATION);
inAnimDown = new TranslateAnimation(0, 0, -h, 0);
inAnimDown.setDuration(ANIM_DURATION);
outAnimDown = new TranslateAnimation(0, 0, 0, h);
outAnimDown.setDuration(ANIM_DURATION);
| protected void | setLogic(Logic logic)
NumberKeyListener calculatorKeyListener =
new NumberKeyListener() {
public int getInputType() {
// Don't display soft keyboard.
return InputType.TYPE_NULL;
}
protected char[] getAcceptedChars() {
return ACCEPTED_CHARS;
}
public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend) {
/* the EditText should still accept letters (eg. 'sin')
coming from the on-screen touch buttons, so don't filter anything.
*/
return null;
}
};
Editable.Factory factory = new CalculatorEditable.Factory(logic);
for (int i = 0; i < 2; ++i) {
EditText text = (EditText) getChildAt(i);
text.setBackgroundDrawable(null);
text.setEditableFactory(factory);
text.setKeyListener(calculatorKeyListener);
}
| public void | setOnKeyListener(OnKeyListener l)
getChildAt(0).setOnKeyListener(l);
getChildAt(1).setOnKeyListener(l);
| void | setSelection(int i)
EditText text = (EditText) getCurrentView();
text.setSelection(i);
| void | setText(java.lang.CharSequence text, com.android.calculator2.CalculatorDisplay$Scroll dir)
if (getText().length() == 0) {
dir = Scroll.NONE;
}
if (dir == Scroll.UP) {
setInAnimation(inAnimUp);
setOutAnimation(outAnimUp);
} else if (dir == Scroll.DOWN) {
setInAnimation(inAnimDown);
setOutAnimation(outAnimDown);
} else { // Scroll.NONE
setInAnimation(null);
setOutAnimation(null);
}
EditText editText = (EditText) getNextView();
editText.setText(text);
//Calculator.log("selection to " + text.length() + "; " + text);
editText.setSelection(text.length());
showNext();
|
|