messages
This commit is contained in:
parent
5df4222e2f
commit
a211c76fd8
@ -266,4 +266,11 @@ e ^ i = 0.5403 + 0.84147i\n
|
|||||||
6. <b>Экран настроек:</b> содержит список настроек приложения. На экран можно попасть нажав кнопку Настройки в меню.
|
6. <b>Экран настроек:</b> содержит список настроек приложения. На экран можно попасть нажав кнопку Настройки в меню.
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
|
<string name="msg_1">Арифметическая ошибка: {0}</string>
|
||||||
|
<string name="msg_2">Слишком сложное выражение</string>
|
||||||
|
<string name="msg_3">Вычисление выражения занимает слишком много времени - проверьте выражение</string>
|
||||||
|
<string name="msg_4">Вычисление было отменено</string>
|
||||||
|
<string name="msg_5">Для функции {0} не определены параметры</string>
|
||||||
|
<string name="msg_6">В выражении найден Бесконечный цикл - проверьте выражение</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -269,26 +269,11 @@ Check the \'Round result\' preference in application settings - it should be tur
|
|||||||
</string>
|
</string>
|
||||||
|
|
||||||
|
|
||||||
<string name="msg_msg_1">Arithmetic error occurred: {0}</string>
|
<string name="msg_1">Arithmetic error occurred: {0}</string>
|
||||||
<string name="msg_msg_2">Too complex expression</string>
|
<string name="msg_2">Too complex expression</string>
|
||||||
<string name="msg_msg_3">Too long execution time - check the expression</string>
|
<string name="msg_3">Too long execution time - check the expression</string>
|
||||||
<string name="msg_msg_4">Evaluation was cancelled</string>
|
<string name="msg_4">Evaluation was cancelled</string>
|
||||||
<string name="msg_msg_5">No parameters are specified for function: {0}</string>
|
<string name="msg_5">No parameters are specified for function: {0}</string>
|
||||||
<string name="msg_msg_6">Infinite loop is detected in expression</string>
|
<string name="msg_6">Infinite loop is detected in expression</string>
|
||||||
|
|
||||||
<string name="msg_jscl_msg_1">Premature end of processing</string>
|
|
||||||
<string name="msg_jscl_msg_2">There is no operator with name: {0}</string>
|
|
||||||
<string name="msg_jscl_msg_3">Operator name is not valid: {0}</string>
|
|
||||||
<string name="msg_jscl_msg_4">Postfix function with name {0} doesn\'\'t exist</string>
|
|
||||||
<string name="msg_jscl_msg_5">Constant name must start with character</string>
|
|
||||||
<string name="msg_jscl_msg_6">Cannot be implicit function - usual function or operator with same name is defined: {0}</string>
|
|
||||||
<string name="msg_jscl_msg_7">Digit is expected</string>
|
|
||||||
<string name="msg_jscl_msg_8">Invalid number: {0}</string>
|
|
||||||
<string name="msg_jscl_msg_9">First letter of number must be digit</string>
|
|
||||||
<string name="msg_jscl_msg_10">Expected characters are {0} or {1}</string>
|
|
||||||
<string name="msg_jscl_msg_11">Expected characters are {0}</string>
|
|
||||||
<string name="msg_jscl_msg_12">Expected character is {0}</string>
|
|
||||||
<string name="msg_jscl_msg_13">Function name is not valid: {0}</string>
|
|
||||||
<string name="msg_jscl_msg_14">Expected number of parameters differs from actual {0}</string>
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -19,7 +19,6 @@ import android.text.method.LinkMovementMethod;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import jscl.AngleUnit;
|
import jscl.AngleUnit;
|
||||||
@ -27,7 +26,6 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.math.MathType;
|
import org.solovyev.android.calculator.math.MathType;
|
||||||
import org.solovyev.android.calculator.model.CalculatorEngine;
|
import org.solovyev.android.calculator.model.CalculatorEngine;
|
||||||
import org.solovyev.android.msg.AndroidMessageRegistry;
|
|
||||||
import org.solovyev.android.view.FontSizeAdjuster;
|
import org.solovyev.android.view.FontSizeAdjuster;
|
||||||
import org.solovyev.android.view.prefs.ResourceCache;
|
import org.solovyev.android.view.prefs.ResourceCache;
|
||||||
import org.solovyev.android.view.widgets.*;
|
import org.solovyev.android.view.widgets.*;
|
||||||
@ -36,11 +34,7 @@ import org.solovyev.common.utils.Announcer;
|
|||||||
import org.solovyev.common.utils.Point2d;
|
import org.solovyev.common.utils.Point2d;
|
||||||
import org.solovyev.common.utils.history.HistoryAction;
|
import org.solovyev.common.utils.history.HistoryAction;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
import java.text.DecimalFormatSymbols;
|
import java.text.DecimalFormatSymbols;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -500,14 +494,11 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
}
|
}
|
||||||
|
|
||||||
calculatorModel = CalculatorModel.instance.init(this, preferences, CalculatorEngine.instance);
|
calculatorModel = CalculatorModel.instance.init(this, preferences, CalculatorEngine.instance);
|
||||||
AndroidMessageRegistry.instance.init(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
|
||||||
AndroidMessageRegistry.instance.finish();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -6,30 +6,25 @@
|
|||||||
|
|
||||||
package org.solovyev.android.calculator.model;
|
package org.solovyev.android.calculator.model;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.view.prefs.ResourceCache;
|
import org.solovyev.android.msg.AndroidMessage;
|
||||||
import org.solovyev.common.exceptions.SersoException;
|
import org.solovyev.common.exceptions.SersoException;
|
||||||
import org.solovyev.common.utils.CollectionsUtils;
|
import org.solovyev.common.msg.Message;
|
||||||
|
import org.solovyev.common.msg.MessageType;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 10/6/11
|
* Date: 10/6/11
|
||||||
* Time: 9:25 PM
|
* Time: 9:25 PM
|
||||||
*/
|
*/
|
||||||
public class ParseException extends SersoException {
|
public class ParseException extends SersoException implements Message {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final String messageId;
|
private final Message message;
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private final List<Object> parameters;
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final String expression;
|
private final String expression;
|
||||||
@ -38,38 +33,21 @@ public class ParseException extends SersoException {
|
|||||||
private final Integer position;
|
private final Integer position;
|
||||||
|
|
||||||
public ParseException(@NotNull jscl.text.ParseException jsclParseException) {
|
public ParseException(@NotNull jscl.text.ParseException jsclParseException) {
|
||||||
this.messageId = "jscl_" + jsclParseException.getMessageId();
|
this.message = jsclParseException;
|
||||||
this.expression = jsclParseException.getExpression();
|
this.expression = jsclParseException.getExpression();
|
||||||
this.position = jsclParseException.getPosition();
|
this.position = jsclParseException.getPosition();
|
||||||
this.parameters = jsclParseException.getParameters();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParseException(@NotNull String messageId, @Nullable Integer position, @NotNull String expression, Object... parameters) {
|
public ParseException(@NotNull String messageId, @Nullable Integer position, @NotNull String expression, Object... parameters) {
|
||||||
this.messageId = messageId;
|
this.message = new AndroidMessage(messageId, MessageType.error, parameters);
|
||||||
this.expression = expression;
|
this.expression = expression;
|
||||||
this.position = position;
|
this.position = position;
|
||||||
|
|
||||||
if (CollectionsUtils.isEmpty(parameters)) {
|
|
||||||
this.parameters = Collections.emptyList();
|
|
||||||
} else {
|
|
||||||
this.parameters = Arrays.asList(parameters);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParseException(@NotNull String messageId, @NotNull String expression, Object... parameters) {
|
public ParseException(@NotNull String messageId, @NotNull String expression, Object... parameters) {
|
||||||
this(messageId, null, expression, parameters);
|
this(messageId, null, expression, parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public String getMessageId() {
|
|
||||||
return messageId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public List<Object> getParameters() {
|
|
||||||
return parameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public String getExpression() {
|
public String getExpression() {
|
||||||
return expression;
|
return expression;
|
||||||
@ -80,20 +58,33 @@ public class ParseException extends SersoException {
|
|||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String getMessageCode() {
|
||||||
|
return this.message.getMessageCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public List<Object> getParameters() {
|
||||||
|
return this.message.getParameters();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public MessageType getMessageType() {
|
||||||
|
return this.message.getMessageType();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getLocalizedMessage() {
|
public String getLocalizedMessage() {
|
||||||
String result = null;
|
return this.message.getLocalizedMessage(Locale.getDefault());
|
||||||
|
|
||||||
final String message = ResourceCache.instance.getCaption("msg_" + getMessageId());
|
|
||||||
if (message != null) {
|
|
||||||
if ( parameters.size() > 0 ) {
|
|
||||||
result = MessageFormat.format(message, parameters.toArray(new Object[parameters.size()]));
|
|
||||||
} else {
|
|
||||||
result = message;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String getLocalizedMessage(@NotNull Locale locale) {
|
||||||
|
return this.message.getLocalizedMessage(locale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,27 +7,34 @@
|
|||||||
package org.solovyev.android.msg;
|
package org.solovyev.android.msg;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.solovyev.android.view.prefs.ResourceCache;
|
||||||
import org.solovyev.common.msg.AbstractMessage;
|
import org.solovyev.common.msg.AbstractMessage;
|
||||||
import org.solovyev.common.msg.MessageType;
|
import org.solovyev.common.msg.MessageType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 10/18/11
|
* Date: 10/18/11
|
||||||
* Time: 11:57 PM
|
* Time: 11:57 PM
|
||||||
*/
|
*/
|
||||||
public class AndroidMessage extends AbstractMessage<Integer> {
|
public class AndroidMessage extends AbstractMessage {
|
||||||
|
|
||||||
public AndroidMessage(@NotNull Integer messageCode,
|
public AndroidMessage(@NotNull String messageCode,
|
||||||
@NotNull MessageType messageType,
|
@NotNull MessageType messageType,
|
||||||
@org.jetbrains.annotations.Nullable Object... arguments) {
|
@org.jetbrains.annotations.Nullable Object... arguments) {
|
||||||
super(messageCode, messageType, arguments);
|
super(messageCode, messageType, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AndroidMessage(@NotNull Integer messageCode,
|
public AndroidMessage(@NotNull String messageCode,
|
||||||
@NotNull MessageType messageType,
|
@NotNull MessageType messageType,
|
||||||
@org.jetbrains.annotations.Nullable List<?> arguments) {
|
@NotNull List<?> arguments) {
|
||||||
super(messageCode, messageType, arguments);
|
super(messageCode, messageType, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getMessagePattern(@NotNull Locale locale) {
|
||||||
|
return ResourceCache.instance.getCaption(getMessageCode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,66 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
|
||||||
* For more information, please, contact se.solovyev@gmail.com
|
|
||||||
* or visit http://se.solovyev.org
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.solovyev.android.msg;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.widget.Toast;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.solovyev.common.msg.MessageRegistry;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User: serso
|
|
||||||
* Date: 10/18/11
|
|
||||||
* Time: 11:49 PM
|
|
||||||
*/
|
|
||||||
public enum AndroidMessageRegistry implements MessageRegistry<AndroidMessage> {
|
|
||||||
|
|
||||||
instance;
|
|
||||||
|
|
||||||
private Context context;
|
|
||||||
|
|
||||||
public void init(@NotNull Context context) {
|
|
||||||
this.context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addMessage(@NotNull AndroidMessage message) {
|
|
||||||
if (context != null) {
|
|
||||||
Toast.makeText(context, formatMessage(message), Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public AndroidMessage getMessage() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasMessage() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public String formatMessage(@NotNull AndroidMessage message) {
|
|
||||||
final String messagePattern = context.getString(message.getMessageCode());
|
|
||||||
|
|
||||||
final String result;
|
|
||||||
if (messagePattern != null) {
|
|
||||||
result = message.formatMessage(messagePattern, Locale.getDefault());
|
|
||||||
} else {
|
|
||||||
result = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void finish() {
|
|
||||||
this.context = null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
|
* For more information, please, contact se.solovyev@gmail.com
|
||||||
|
* or visit http://se.solovyev.org
|
||||||
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.view.prefs;
|
package org.solovyev.android.view.prefs;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@ -6,7 +12,6 @@ import android.view.View;
|
|||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.R;
|
|
||||||
import org.solovyev.android.view.widgets.DragButton;
|
import org.solovyev.android.view.widgets.DragButton;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
|
||||||
* For more information, please, contact se.solovyev@gmail.com
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.solovyev.util.math;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User: serso
|
|
||||||
* Date: 9/17/11
|
|
||||||
* Time: 11:35 PM
|
|
||||||
*/
|
|
||||||
public class Complex {
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private Double real;
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private Double imaginary;
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public Double getReal() {
|
|
||||||
return real;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setReal(@Nullable Double real) {
|
|
||||||
this.real = real;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public Double getImaginary() {
|
|
||||||
return imaginary;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setImaginary(@Nullable Double imaginary) {
|
|
||||||
this.imaginary = imaginary;
|
|
||||||
}
|
|
||||||
}
|
|
@ -40,7 +40,7 @@ public class CalculatorEngineTest {
|
|||||||
cm.evaluate(JsclOperation.numeric, "3^10^10^10");
|
cm.evaluate(JsclOperation.numeric, "3^10^10^10");
|
||||||
Assert.fail();
|
Assert.fail();
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
if (e.getMessageId().equals(Messages.msg_3)) {
|
if (e.getMessageCode().equals(Messages.msg_3)) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
System.out.print(e.getCause().getMessage());
|
System.out.print(e.getCause().getMessage());
|
||||||
@ -52,7 +52,7 @@ public class CalculatorEngineTest {
|
|||||||
cm.evaluate(JsclOperation.numeric, "9999999!");
|
cm.evaluate(JsclOperation.numeric, "9999999!");
|
||||||
Assert.fail();
|
Assert.fail();
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
if (e.getMessageId().equals(Messages.msg_3)) {
|
if (e.getMessageCode().equals(Messages.msg_3)) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
System.out.print(e.getCause().getMessage());
|
System.out.print(e.getCause().getMessage());
|
||||||
|
Loading…
Reference in New Issue
Block a user