This commit is contained in:
Sergey Solovyev 2011-11-14 18:36:33 +04:00
parent a5ef63400e
commit 5881883f77
2 changed files with 12 additions and 23 deletions

View File

@ -8,9 +8,8 @@
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android" <org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator" xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
a:id="@+id/subtractionButton" a:id="@+id/subtractionButton"
calc:textUp="+…%" calc:textUp="%"
a:text="-" a:text="-"
calc:textDown="-…%"
calc:directionTextScale="0.5" calc:directionTextScale="0.5"
style="?digitButtonStyle" style="?digitButtonStyle"
a:onClick="digitButtonClickHandler"/> a:onClick="digitButtonClickHandler"/>

View File

@ -257,16 +257,7 @@ public enum CalculatorModel implements CursorControl, HistoryControl<CalculatorH
@Override @Override
public void doOperation(@NotNull EditText editor) { public void doOperation(@NotNull EditText editor) {
int cursorPositionOffset = 0; int cursorPositionOffset = 0;
final StringBuilder textToBeInserted = new StringBuilder(); final StringBuilder textToBeInserted = new StringBuilder(text);
if (text.equals("+…%")) {
textToBeInserted .append("+%");
cursorPositionOffset = -1;
} else if (text.equals("-…%")) {
textToBeInserted.append("-%");
cursorPositionOffset = -1;
} else {
textToBeInserted.append(text);
final MathType.Result mathType = MathType.getType(text, 0); final MathType.Result mathType = MathType.getType(text, 0);
switch (mathType.getMathType()) { switch (mathType.getMathType()) {
@ -281,7 +272,6 @@ public enum CalculatorModel implements CursorControl, HistoryControl<CalculatorH
cursorPositionOffset = -1; cursorPositionOffset = -1;
} }
} }
}
editor.getText().insert(editor.getSelectionStart(), textToBeInserted.toString()); editor.getText().insert(editor.getSelectionStart(), textToBeInserted.toString());
editor.setSelection(editor.getSelectionStart() + cursorPositionOffset, editor.getSelectionEnd() + cursorPositionOffset); editor.setSelection(editor.getSelectionStart() + cursorPositionOffset, editor.getSelectionEnd() + cursorPositionOffset);