changes
This commit is contained in:
@@ -2,10 +2,8 @@ package org.solovyev.android.calculator;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.common.utils.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -39,7 +37,7 @@ public class CalculatorActivityLauncher {
|
||||
if (calculatorModel.getDisplay().isValid() ) {
|
||||
final String varValue = calculatorModel.getDisplay().getText().toString();
|
||||
if (!StringUtils.isEmpty(varValue)) {
|
||||
if (CalculatorVarsActivity.isValid(varValue)) {
|
||||
if (CalculatorVarsActivity.isValidValue(varValue)) {
|
||||
final Intent intent = new Intent(context, CalculatorVarsActivity.class);
|
||||
intent.putExtra(CalculatorVarsActivity.CREATE_VAR_EXTRA_STRING, varValue);
|
||||
context.startActivity(intent);
|
||||
|
@@ -16,9 +16,11 @@ import android.widget.*;
|
||||
import jscl.math.function.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.calculator.model.CalculatorEngine;
|
||||
import org.solovyev.android.calculator.model.Var;
|
||||
import org.solovyev.common.utils.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -26,7 +28,7 @@ import java.util.List;
|
||||
* Date: 10/29/11
|
||||
* Time: 4:55 PM
|
||||
*/
|
||||
public class CalculatorFunctionsActivity extends ListActivity{
|
||||
public class CalculatorFunctionsActivity extends ListActivity {
|
||||
|
||||
@NotNull
|
||||
private FunctionsArrayAdapter adapter;
|
||||
@@ -55,6 +57,19 @@ public class CalculatorFunctionsActivity extends ListActivity{
|
||||
}
|
||||
});
|
||||
|
||||
sort();
|
||||
|
||||
}
|
||||
|
||||
private void sort() {
|
||||
CalculatorFunctionsActivity.this.adapter.sort(new Comparator<Function>() {
|
||||
@Override
|
||||
public int compare(Function function1, Function function2) {
|
||||
return function1.getName().compareTo(function2.getName());
|
||||
}
|
||||
});
|
||||
|
||||
CalculatorFunctionsActivity.this.adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private class FunctionsArrayAdapter extends ArrayAdapter<Function> {
|
||||
|
@@ -16,6 +16,9 @@ import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
import jscl.text.Identifier;
|
||||
import jscl.text.MutableInt;
|
||||
import jscl.text.ParseException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.math.MathType;
|
||||
@@ -38,7 +41,7 @@ public class CalculatorVarsActivity extends ListActivity {
|
||||
|
||||
public static final String CREATE_VAR_EXTRA_STRING = "org.solovyev.android.calculator.CalculatorVarsActivity_create_var";
|
||||
|
||||
private final static List<Character> acceptableChars = Arrays.asList(StringUtils.toObject("1234567890abcdefghijklmnopqrstuvwxyzйцукенгшщзхъфывапролджэячсмитьбюё".toCharArray()));
|
||||
private final static List<Character> acceptableChars = Arrays.asList(StringUtils.toObject("1234567890abcdefghijklmnopqrstuvwxyzйцукенгшщзхъфывапролджэячсмитьбюё_".toCharArray()));
|
||||
|
||||
@NotNull
|
||||
private VarsArrayAdapter adapter;
|
||||
@@ -208,7 +211,7 @@ public class CalculatorVarsActivity extends ListActivity {
|
||||
|
||||
|
||||
final AndroidVarsRegistry varsRegistry = CalculatorEngine.instance.getVarsRegister();
|
||||
if (!StringUtils.isEmpty(name)) {
|
||||
if (isValidName(name)) {
|
||||
|
||||
boolean canBeSaved = false;
|
||||
|
||||
@@ -232,7 +235,7 @@ public class CalculatorVarsActivity extends ListActivity {
|
||||
error = null;
|
||||
} else {
|
||||
// value is not empty => must be a number
|
||||
boolean valid = isValid(value);
|
||||
boolean valid = isValidValue(value);
|
||||
|
||||
if (valid) {
|
||||
varBuilder.setName(name);
|
||||
@@ -250,7 +253,7 @@ public class CalculatorVarsActivity extends ListActivity {
|
||||
error = R.string.c_var_already_exists;
|
||||
}
|
||||
} else {
|
||||
error = R.string.c_name_is_empty;
|
||||
error = R.string.c_name_is_not_valid;
|
||||
}
|
||||
|
||||
if (error != null) {
|
||||
@@ -284,7 +287,22 @@ public class CalculatorVarsActivity extends ListActivity {
|
||||
CalculatorVarsActivity.this.adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public static boolean isValid(@NotNull String value) {
|
||||
private static boolean isValidName(@Nullable String name) {
|
||||
boolean result = false;
|
||||
|
||||
if (!StringUtils.isEmpty(name)) {
|
||||
try {
|
||||
Identifier.parser.parse(name, new MutableInt(0));
|
||||
result = true;
|
||||
} catch (ParseException e) {
|
||||
// not valid name;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isValidValue(@NotNull String value) {
|
||||
// now every string might be constant
|
||||
return true;
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@ import java.util.List;
|
||||
class ToJsclTextProcessor implements TextProcessor<PreparedExpression> {
|
||||
|
||||
@NotNull
|
||||
private static final Integer MAX_DEPTH = 10;
|
||||
private static final Integer MAX_DEPTH = 20;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
@@ -93,7 +93,9 @@ class ToJsclTextProcessor implements TextProcessor<PreparedExpression> {
|
||||
assert value != null;
|
||||
|
||||
if ( var.getDoubleValue() != null ) {
|
||||
result.append(value);
|
||||
//result.append(value);
|
||||
// NOTE: append varName as JSCL engine will convert it to double if needed
|
||||
result.append(varName);
|
||||
} else {
|
||||
result.append("(").append(processWithDepth(value, depth, undefinedVars)).append(")");
|
||||
}
|
||||
|
@@ -189,16 +189,6 @@ public class Var implements IConstant {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean same(@Nullable MathEntity mathEntity) {
|
||||
if (mathEntity instanceof IConstant) {
|
||||
if (mathEntity.getId().equals(this.getId())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return name;
|
||||
|
Reference in New Issue
Block a user