rename
This commit is contained in:
parent
8305b7ed10
commit
6503503edc
@ -45,7 +45,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
||||
private final Announcer<DragPreferencesChangeListener> dpclRegister = new Announcer<DragPreferencesChangeListener>(DragPreferencesChangeListener.class);
|
||||
|
||||
@NotNull
|
||||
private CalculatorView calculatorView;
|
||||
private CalculatorModel calculatorModel;
|
||||
|
||||
private volatile boolean initialized;
|
||||
|
||||
@ -73,7 +73,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
||||
|
||||
firstTimeInit(preferences);
|
||||
|
||||
calculatorView = CalculatorView.instance.init(this, preferences, CalculatorEngine.instance);
|
||||
calculatorModel = CalculatorModel.instance.init(this, preferences, CalculatorEngine.instance);
|
||||
|
||||
dpclRegister.clear();
|
||||
|
||||
@ -81,11 +81,11 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
||||
|
||||
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);
|
||||
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.leftButton)).setOnDragListener(toPositionOnDragListener);
|
||||
dpclRegister.addListener(toPositionOnDragListener);
|
||||
@ -96,7 +96,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (dragButtonIds == null) {
|
||||
@ -172,7 +172,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
||||
|
||||
@SuppressWarnings({"UnusedDeclaration"})
|
||||
public void numericButtonClickHandler(@NotNull View v) {
|
||||
this.calculatorView.evaluate();
|
||||
this.calculatorModel.evaluate();
|
||||
}
|
||||
|
||||
@SuppressWarnings({"UnusedDeclaration"})
|
||||
@ -182,7 +182,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
||||
|
||||
@SuppressWarnings({"UnusedDeclaration"})
|
||||
public void eraseButtonClickHandler(@NotNull View v) {
|
||||
calculatorView.doTextOperation(new CalculatorView.TextOperation() {
|
||||
calculatorModel.doTextOperation(new CalculatorModel.TextOperation() {
|
||||
@Override
|
||||
public void doOperation(@NotNull EditText editor) {
|
||||
if (editor.getSelectionStart() > 0) {
|
||||
@ -199,17 +199,17 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
||||
|
||||
@SuppressWarnings({"UnusedDeclaration"})
|
||||
public void moveLeftButtonClickHandler(@NotNull View v) {
|
||||
calculatorView.moveCursorLeft();
|
||||
calculatorModel.moveCursorLeft();
|
||||
}
|
||||
|
||||
@SuppressWarnings({"UnusedDeclaration"})
|
||||
public void moveRightButtonClickHandler(@NotNull View v) {
|
||||
calculatorView.moveCursorRight();
|
||||
calculatorModel.moveCursorRight();
|
||||
}
|
||||
|
||||
@SuppressWarnings({"UnusedDeclaration"})
|
||||
public void pasteButtonClickHandler(@NotNull View v) {
|
||||
calculatorView.doTextOperation(new CalculatorView.TextOperation() {
|
||||
calculatorModel.doTextOperation(new CalculatorModel.TextOperation() {
|
||||
@Override
|
||||
public void doOperation(@NotNull EditText editor) {
|
||||
final ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||||
@ -222,18 +222,18 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
||||
|
||||
@SuppressWarnings({"UnusedDeclaration"})
|
||||
public void copyButtonClickHandler(@NotNull View v) {
|
||||
calculatorView.copyResult(this);
|
||||
calculatorModel.copyResult(this);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"UnusedDeclaration"})
|
||||
public void clearButtonClickHandler(@NotNull View v) {
|
||||
calculatorView.clear();
|
||||
calculatorModel.clear();
|
||||
}
|
||||
|
||||
@SuppressWarnings({"UnusedDeclaration"})
|
||||
public void digitButtonClickHandler(@NotNull View v) {
|
||||
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"})
|
||||
@ -270,7 +270,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
calculatorView.doHistoryAction(HistoryAction.undo);
|
||||
calculatorModel.doHistoryAction(HistoryAction.undo);
|
||||
return true;
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
@ -362,9 +362,9 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
||||
restart();
|
||||
}
|
||||
|
||||
calculatorView = CalculatorView.instance.init(this, preferences, CalculatorEngine.instance);
|
||||
calculatorModel = CalculatorModel.instance.init(this, preferences, CalculatorEngine.instance);
|
||||
|
||||
this.calculatorView.evaluate();
|
||||
this.calculatorModel.evaluate();
|
||||
}
|
||||
|
||||
@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));
|
||||
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));
|
||||
}
|
||||
}
|
@ -53,7 +53,7 @@ public class CalculatorHistoryActivity extends ListActivity {
|
||||
final int position,
|
||||
final long id) {
|
||||
|
||||
CalculatorView.instance.doTextOperation(new CalculatorView.TextOperation() {
|
||||
CalculatorModel.instance.doTextOperation(new CalculatorModel.TextOperation() {
|
||||
@Override
|
||||
public void doOperation(@NotNull EditText editor) {
|
||||
final EditorHistoryState editorState = ((CalculatorHistoryState) parent.getItemAtPosition(position)).getEditorState();
|
||||
@ -62,7 +62,7 @@ public class CalculatorHistoryActivity extends ListActivity {
|
||||
}
|
||||
}, false);
|
||||
|
||||
CalculatorView.instance.setCursorOnEnd();
|
||||
CalculatorModel.instance.setCursorOnEnd();
|
||||
|
||||
CalculatorHistoryActivity.this.finish();
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ import org.solovyev.common.utils.history.HistoryAction;
|
||||
* Date: 9/12/11
|
||||
* Time: 11:15 PM
|
||||
*/
|
||||
public enum CalculatorView implements CursorControl, HistoryControl<CalculatorHistoryState> {
|
||||
public enum CalculatorModel implements CursorControl, HistoryControl<CalculatorHistoryState> {
|
||||
|
||||
instance;
|
||||
|
||||
@ -49,7 +49,7 @@ public enum CalculatorView implements CursorControl, HistoryControl<CalculatorHi
|
||||
@NotNull
|
||||
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.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();
|
||||
|
||||
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();
|
||||
if (!editorStateBefore.equals(editorStateAfter)) {
|
||||
@ -173,7 +173,7 @@ public enum CalculatorView implements CursorControl, HistoryControl<CalculatorHi
|
||||
final CalculatorDisplay localDisplay = display;
|
||||
if (!StringUtils.isEmpty(expression)) {
|
||||
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));
|
||||
} catch (EvalError 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) {
|
||||
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.setValid(false);
|
||||
}
|
||||
@ -203,7 +203,7 @@ public enum CalculatorView implements CursorControl, HistoryControl<CalculatorHi
|
||||
//Toast.makeText(CalculatorActivity.this, text, Toast.LENGTH_SHORT).show();
|
||||
|
||||
if (!StringUtils.isEmpty(text)) {
|
||||
doTextOperation(new CalculatorView.TextOperation() {
|
||||
doTextOperation(new CalculatorModel.TextOperation() {
|
||||
|
||||
@Override
|
||||
public void doOperation(@NotNull EditText editor) {
|
@ -67,7 +67,7 @@ public class CalculatorVarsActivity extends ListActivity {
|
||||
final int position,
|
||||
final long id) {
|
||||
|
||||
CalculatorView.instance.doTextOperation(new CalculatorView.TextOperation() {
|
||||
CalculatorModel.instance.doTextOperation(new CalculatorModel.TextOperation() {
|
||||
@Override
|
||||
public void doOperation(@NotNull EditText editor) {
|
||||
editor.getText().insert(editor.getSelectionStart(), ((Var) parent.getItemAtPosition(position)).getName());
|
||||
|
@ -21,16 +21,16 @@ import org.solovyev.common.utils.Point2d;
|
||||
public class DigitButtonDragProcessor implements SimpleOnDragListener.DragProcessor {
|
||||
|
||||
@NotNull
|
||||
private final CalculatorView calculatorView;
|
||||
private final CalculatorModel calculatorModel;
|
||||
|
||||
public DigitButtonDragProcessor(@NotNull CalculatorView calculatorView) {
|
||||
this.calculatorView = calculatorView;
|
||||
public DigitButtonDragProcessor(@NotNull CalculatorModel calculatorModel) {
|
||||
this.calculatorModel = calculatorModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) {
|
||||
assert dragButton instanceof DirectionDragButton;
|
||||
calculatorView.processDigitButtonAction(((DirectionDragButton) dragButton).getDirectionText(dragDirection));
|
||||
calculatorModel.processDigitButtonAction(((DirectionDragButton) dragButton).getDirectionText(dragDirection));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user