This commit is contained in:
serso 2011-10-17 23:56:18 +04:00
parent 8305b7ed10
commit 6503503edc
5 changed files with 30 additions and 30 deletions

View File

@ -45,7 +45,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
private final Announcer<DragPreferencesChangeListener> dpclRegister = new Announcer<DragPreferencesChangeListener>(DragPreferencesChangeListener.class); private final Announcer<DragPreferencesChangeListener> dpclRegister = new Announcer<DragPreferencesChangeListener>(DragPreferencesChangeListener.class);
@NotNull @NotNull
private CalculatorView calculatorView; private CalculatorModel calculatorModel;
private volatile boolean initialized; private volatile boolean initialized;
@ -73,7 +73,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
firstTimeInit(preferences); firstTimeInit(preferences);
calculatorView = CalculatorView.instance.init(this, preferences, CalculatorEngine.instance); calculatorModel = CalculatorModel.instance.init(this, preferences, CalculatorEngine.instance);
dpclRegister.clear(); dpclRegister.clear();
@ -81,11 +81,11 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
setOnDragListeners(dragPreferences); setOnDragListeners(dragPreferences);
final SimpleOnDragListener historyOnDragListener = new SimpleOnDragListener(new HistoryDragProcessor<CalculatorHistoryState>(this.calculatorView), dragPreferences); final SimpleOnDragListener historyOnDragListener = new SimpleOnDragListener(new HistoryDragProcessor<CalculatorHistoryState>(this.calculatorModel), dragPreferences);
((DragButton) findViewById(R.id.historyButton)).setOnDragListener(historyOnDragListener); ((DragButton) findViewById(R.id.historyButton)).setOnDragListener(historyOnDragListener);
dpclRegister.addListener(historyOnDragListener); dpclRegister.addListener(historyOnDragListener);
final SimpleOnDragListener toPositionOnDragListener = new SimpleOnDragListener(new CursorDragProcessor(calculatorView), dragPreferences); final SimpleOnDragListener toPositionOnDragListener = new SimpleOnDragListener(new CursorDragProcessor(calculatorModel), dragPreferences);
((DragButton) findViewById(R.id.rightButton)).setOnDragListener(toPositionOnDragListener); ((DragButton) findViewById(R.id.rightButton)).setOnDragListener(toPositionOnDragListener);
((DragButton) findViewById(R.id.leftButton)).setOnDragListener(toPositionOnDragListener); ((DragButton) findViewById(R.id.leftButton)).setOnDragListener(toPositionOnDragListener);
dpclRegister.addListener(toPositionOnDragListener); dpclRegister.addListener(toPositionOnDragListener);
@ -96,7 +96,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
} }
private synchronized void setOnDragListeners(@NotNull SimpleOnDragListener.Preferences dragPreferences) { private synchronized void setOnDragListeners(@NotNull SimpleOnDragListener.Preferences dragPreferences) {
final SimpleOnDragListener onDragListener = new SimpleOnDragListener(new DigitButtonDragProcessor(calculatorView), dragPreferences); final SimpleOnDragListener onDragListener = new SimpleOnDragListener(new DigitButtonDragProcessor(calculatorModel), dragPreferences);
dpclRegister.addListener(onDragListener); dpclRegister.addListener(onDragListener);
if (dragButtonIds == null) { if (dragButtonIds == null) {
@ -172,7 +172,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
@SuppressWarnings({"UnusedDeclaration"}) @SuppressWarnings({"UnusedDeclaration"})
public void numericButtonClickHandler(@NotNull View v) { public void numericButtonClickHandler(@NotNull View v) {
this.calculatorView.evaluate(); this.calculatorModel.evaluate();
} }
@SuppressWarnings({"UnusedDeclaration"}) @SuppressWarnings({"UnusedDeclaration"})
@ -182,7 +182,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
@SuppressWarnings({"UnusedDeclaration"}) @SuppressWarnings({"UnusedDeclaration"})
public void eraseButtonClickHandler(@NotNull View v) { public void eraseButtonClickHandler(@NotNull View v) {
calculatorView.doTextOperation(new CalculatorView.TextOperation() { calculatorModel.doTextOperation(new CalculatorModel.TextOperation() {
@Override @Override
public void doOperation(@NotNull EditText editor) { public void doOperation(@NotNull EditText editor) {
if (editor.getSelectionStart() > 0) { if (editor.getSelectionStart() > 0) {
@ -199,17 +199,17 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
@SuppressWarnings({"UnusedDeclaration"}) @SuppressWarnings({"UnusedDeclaration"})
public void moveLeftButtonClickHandler(@NotNull View v) { public void moveLeftButtonClickHandler(@NotNull View v) {
calculatorView.moveCursorLeft(); calculatorModel.moveCursorLeft();
} }
@SuppressWarnings({"UnusedDeclaration"}) @SuppressWarnings({"UnusedDeclaration"})
public void moveRightButtonClickHandler(@NotNull View v) { public void moveRightButtonClickHandler(@NotNull View v) {
calculatorView.moveCursorRight(); calculatorModel.moveCursorRight();
} }
@SuppressWarnings({"UnusedDeclaration"}) @SuppressWarnings({"UnusedDeclaration"})
public void pasteButtonClickHandler(@NotNull View v) { public void pasteButtonClickHandler(@NotNull View v) {
calculatorView.doTextOperation(new CalculatorView.TextOperation() { calculatorModel.doTextOperation(new CalculatorModel.TextOperation() {
@Override @Override
public void doOperation(@NotNull EditText editor) { public void doOperation(@NotNull EditText editor) {
final ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); final ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
@ -222,18 +222,18 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
@SuppressWarnings({"UnusedDeclaration"}) @SuppressWarnings({"UnusedDeclaration"})
public void copyButtonClickHandler(@NotNull View v) { public void copyButtonClickHandler(@NotNull View v) {
calculatorView.copyResult(this); calculatorModel.copyResult(this);
} }
@SuppressWarnings({"UnusedDeclaration"}) @SuppressWarnings({"UnusedDeclaration"})
public void clearButtonClickHandler(@NotNull View v) { public void clearButtonClickHandler(@NotNull View v) {
calculatorView.clear(); calculatorModel.clear();
} }
@SuppressWarnings({"UnusedDeclaration"}) @SuppressWarnings({"UnusedDeclaration"})
public void digitButtonClickHandler(@NotNull View v) { public void digitButtonClickHandler(@NotNull View v) {
Log.d(String.valueOf(v.getId()), "digitButtonClickHandler() for: " + v.getId() + ". Pressed: " + v.isPressed()); Log.d(String.valueOf(v.getId()), "digitButtonClickHandler() for: " + v.getId() + ". Pressed: " + v.isPressed());
calculatorView.processDigitButtonAction(((DirectionDragButton) v).getTextMiddle()); calculatorModel.processDigitButtonAction(((DirectionDragButton) v).getTextMiddle());
} }
@SuppressWarnings({"UnusedDeclaration"}) @SuppressWarnings({"UnusedDeclaration"})
@ -270,7 +270,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
@Override @Override
public boolean onKeyDown(int keyCode, KeyEvent event) { public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) { if (keyCode == KeyEvent.KEYCODE_BACK) {
calculatorView.doHistoryAction(HistoryAction.undo); calculatorModel.doHistoryAction(HistoryAction.undo);
return true; return true;
} }
return super.onKeyDown(keyCode, event); return super.onKeyDown(keyCode, event);
@ -362,9 +362,9 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
restart(); restart();
} }
calculatorView = CalculatorView.instance.init(this, preferences, CalculatorEngine.instance); calculatorModel = CalculatorModel.instance.init(this, preferences, CalculatorEngine.instance);
this.calculatorView.evaluate(); this.calculatorModel.evaluate();
} }
@Override @Override
@ -375,6 +375,6 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
final Boolean colorExpressionsInBracketsDefault = new BooleanMapper().parseValue(this.getString(R.string.p_calc_color_display)); final Boolean colorExpressionsInBracketsDefault = new BooleanMapper().parseValue(this.getString(R.string.p_calc_color_display));
assert colorExpressionsInBracketsDefault != null; assert colorExpressionsInBracketsDefault != null;
this.calculatorView.getEditor().setHighlightText(preferences.getBoolean(this.getString(R.string.p_calc_color_display_key), colorExpressionsInBracketsDefault)); this.calculatorModel.getEditor().setHighlightText(preferences.getBoolean(this.getString(R.string.p_calc_color_display_key), colorExpressionsInBracketsDefault));
} }
} }

View File

@ -53,7 +53,7 @@ public class CalculatorHistoryActivity extends ListActivity {
final int position, final int position,
final long id) { final long id) {
CalculatorView.instance.doTextOperation(new CalculatorView.TextOperation() { CalculatorModel.instance.doTextOperation(new CalculatorModel.TextOperation() {
@Override @Override
public void doOperation(@NotNull EditText editor) { public void doOperation(@NotNull EditText editor) {
final EditorHistoryState editorState = ((CalculatorHistoryState) parent.getItemAtPosition(position)).getEditorState(); final EditorHistoryState editorState = ((CalculatorHistoryState) parent.getItemAtPosition(position)).getEditorState();
@ -62,7 +62,7 @@ public class CalculatorHistoryActivity extends ListActivity {
} }
}, false); }, false);
CalculatorView.instance.setCursorOnEnd(); CalculatorModel.instance.setCursorOnEnd();
CalculatorHistoryActivity.this.finish(); CalculatorHistoryActivity.this.finish();
} }

View File

@ -33,7 +33,7 @@ import org.solovyev.common.utils.history.HistoryAction;
* Date: 9/12/11 * Date: 9/12/11
* Time: 11:15 PM * Time: 11:15 PM
*/ */
public enum CalculatorView implements CursorControl, HistoryControl<CalculatorHistoryState> { public enum CalculatorModel implements CursorControl, HistoryControl<CalculatorHistoryState> {
instance; instance;
@ -49,7 +49,7 @@ public enum CalculatorView implements CursorControl, HistoryControl<CalculatorHi
@NotNull @NotNull
private CalculatorEngine calculatorEngine; private CalculatorEngine calculatorEngine;
public CalculatorView init(@NotNull final Activity activity, @NotNull SharedPreferences preferences, @NotNull CalculatorEngine calculator) { public CalculatorModel init(@NotNull final Activity activity, @NotNull SharedPreferences preferences, @NotNull CalculatorEngine calculator) {
this.calculatorEngine = calculator; this.calculatorEngine = calculator;
this.editor = (CalculatorEditor) activity.findViewById(R.id.calculatorEditor); this.editor = (CalculatorEditor) activity.findViewById(R.id.calculatorEditor);
@ -121,7 +121,7 @@ public enum CalculatorView implements CursorControl, HistoryControl<CalculatorHi
final String editorStateBefore = this.editor.getText().toString(); final String editorStateBefore = this.editor.getText().toString();
operation.doOperation(this.editor); operation.doOperation(this.editor);
//Log.d(CalculatorView.class.getName(), "Doing text operation" + StringUtils.fromStackTrace(Thread.currentThread().getStackTrace())); //Log.d(CalculatorModel.class.getName(), "Doing text operation" + StringUtils.fromStackTrace(Thread.currentThread().getStackTrace()));
final String editorStateAfter = this.editor.getText().toString(); final String editorStateAfter = this.editor.getText().toString();
if (!editorStateBefore.equals(editorStateAfter)) { if (!editorStateBefore.equals(editorStateAfter)) {
@ -173,7 +173,7 @@ public enum CalculatorView implements CursorControl, HistoryControl<CalculatorHi
final CalculatorDisplay localDisplay = display; final CalculatorDisplay localDisplay = display;
if (!StringUtils.isEmpty(expression)) { if (!StringUtils.isEmpty(expression)) {
try { try {
Log.d(CalculatorView.class.getName(), "Trying to evaluate: " + expression /*+ StringUtils.fromStackTrace(Thread.currentThread().getStackTrace())*/); Log.d(CalculatorModel.class.getName(), "Trying to evaluate: " + expression /*+ StringUtils.fromStackTrace(Thread.currentThread().getStackTrace())*/);
localDisplay.setText(calculatorEngine.evaluate(JsclOperation.numeric, expression)); localDisplay.setText(calculatorEngine.evaluate(JsclOperation.numeric, expression));
} catch (EvalError e) { } catch (EvalError e) {
handleEvaluationException(expression, localDisplay, e); handleEvaluationException(expression, localDisplay, e);
@ -186,7 +186,7 @@ public enum CalculatorView implements CursorControl, HistoryControl<CalculatorHi
} }
private void handleEvaluationException(@NotNull String expression, @NotNull CalculatorDisplay localDisplay, @NotNull Exception e) { private void handleEvaluationException(@NotNull String expression, @NotNull CalculatorDisplay localDisplay, @NotNull Exception e) {
Log.d(CalculatorView.class.getName(), "Evaluation failed for : " + expression + ". Error message: " + e.getMessage()); Log.d(CalculatorModel.class.getName(), "Evaluation failed for : " + expression + ". Error message: " + e.getMessage());
localDisplay.setText(R.string.c_syntax_error); localDisplay.setText(R.string.c_syntax_error);
localDisplay.setValid(false); localDisplay.setValid(false);
} }
@ -203,7 +203,7 @@ public enum CalculatorView implements CursorControl, HistoryControl<CalculatorHi
//Toast.makeText(CalculatorActivity.this, text, Toast.LENGTH_SHORT).show(); //Toast.makeText(CalculatorActivity.this, text, Toast.LENGTH_SHORT).show();
if (!StringUtils.isEmpty(text)) { if (!StringUtils.isEmpty(text)) {
doTextOperation(new CalculatorView.TextOperation() { doTextOperation(new CalculatorModel.TextOperation() {
@Override @Override
public void doOperation(@NotNull EditText editor) { public void doOperation(@NotNull EditText editor) {

View File

@ -67,7 +67,7 @@ public class CalculatorVarsActivity extends ListActivity {
final int position, final int position,
final long id) { final long id) {
CalculatorView.instance.doTextOperation(new CalculatorView.TextOperation() { CalculatorModel.instance.doTextOperation(new CalculatorModel.TextOperation() {
@Override @Override
public void doOperation(@NotNull EditText editor) { public void doOperation(@NotNull EditText editor) {
editor.getText().insert(editor.getSelectionStart(), ((Var) parent.getItemAtPosition(position)).getName()); editor.getText().insert(editor.getSelectionStart(), ((Var) parent.getItemAtPosition(position)).getName());

View File

@ -21,16 +21,16 @@ import org.solovyev.common.utils.Point2d;
public class DigitButtonDragProcessor implements SimpleOnDragListener.DragProcessor { public class DigitButtonDragProcessor implements SimpleOnDragListener.DragProcessor {
@NotNull @NotNull
private final CalculatorView calculatorView; private final CalculatorModel calculatorModel;
public DigitButtonDragProcessor(@NotNull CalculatorView calculatorView) { public DigitButtonDragProcessor(@NotNull CalculatorModel calculatorModel) {
this.calculatorView = calculatorView; this.calculatorModel = calculatorModel;
} }
@Override @Override
public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) { public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) {
assert dragButton instanceof DirectionDragButton; assert dragButton instanceof DirectionDragButton;
calculatorView.processDigitButtonAction(((DirectionDragButton) dragButton).getDirectionText(dragDirection)); calculatorModel.processDigitButtonAction(((DirectionDragButton) dragButton).getDirectionText(dragDirection));
return true; return true;
} }