percent added
This commit is contained in:
parent
b184880433
commit
a4c64df0a6
@ -8,7 +8,9 @@
|
|||||||
<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="+…%"
|
||||||
a:text="-"
|
a:text="-"
|
||||||
|
calc:textDown="-…%"
|
||||||
calc:directionTextScale="0.5"
|
calc:directionTextScale="0.5"
|
||||||
style="?digitButtonStyle"
|
style="?digitButtonStyle"
|
||||||
a:onClick="digitButtonClickHandler"/>
|
a:onClick="digitButtonClickHandler"/>
|
@ -256,12 +256,19 @@ public enum CalculatorModel implements CursorControl, HistoryControl<CalculatorH
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doOperation(@NotNull EditText editor) {
|
public void doOperation(@NotNull EditText editor) {
|
||||||
|
int cursorPositionOffset = 0;
|
||||||
|
final StringBuilder textToBeInserted = new StringBuilder();
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
int cursorPositionOffset = 0;
|
|
||||||
|
|
||||||
final StringBuilder textToBeInserted = new StringBuilder(text);
|
|
||||||
switch (mathType.getMathType()) {
|
switch (mathType.getMathType()) {
|
||||||
case function:
|
case function:
|
||||||
textToBeInserted.append("()");
|
textToBeInserted.append("()");
|
||||||
@ -274,6 +281,7 @@ 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);
|
||||||
|
@ -301,7 +301,7 @@ public class CalculatorVarsActivity extends ListActivity {
|
|||||||
|
|
||||||
if (!StringUtils.isEmpty(name)) {
|
if (!StringUtils.isEmpty(name)) {
|
||||||
try {
|
try {
|
||||||
Identifier.parser.parse(name, new MutableInt(0), 0);
|
Identifier.parser.parse(name, new MutableInt(0), 0, null);
|
||||||
result = true;
|
result = true;
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
// not valid name;
|
// not valid name;
|
||||||
|
Loading…
Reference in New Issue
Block a user