percent added

This commit is contained in:
serso 2011-11-14 15:54:39 +04:00
parent b184880433
commit a4c64df0a6
3 changed files with 24 additions and 14 deletions

View File

@ -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"/>

View File

@ -256,22 +256,30 @@ public enum CalculatorModel implements CursorControl, HistoryControl<CalculatorH
@Override @Override
public void doOperation(@NotNull EditText editor) { public void doOperation(@NotNull EditText editor) {
final MathType.Result mathType = MathType.getType(text, 0);
int cursorPositionOffset = 0; int cursorPositionOffset = 0;
final StringBuilder textToBeInserted = new StringBuilder();
final StringBuilder textToBeInserted = new StringBuilder(text); if (text.equals("+…%")) {
switch (mathType.getMathType()) { textToBeInserted .append("+%");
case function: cursorPositionOffset = -1;
textToBeInserted.append("()"); } else if (text.equals("-…%")) {
cursorPositionOffset = -1; textToBeInserted.append("-%");
break; cursorPositionOffset = -1;
} } else {
textToBeInserted.append(text);
if (cursorPositionOffset == 0) { final MathType.Result mathType = MathType.getType(text, 0);
if ( MathType.openGroupSymbols.contains(text) ) { switch (mathType.getMathType()) {
cursorPositionOffset = -1; case function:
textToBeInserted.append("()");
cursorPositionOffset = -1;
break;
}
if (cursorPositionOffset == 0) {
if (MathType.openGroupSymbols.contains(text)) {
cursorPositionOffset = -1;
}
} }
} }

View File

@ -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;