diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 717d3dbe..8aca064d 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -37,6 +37,22 @@
a:label="@string/c_about"
a:configChanges="orientation|keyboardHidden"/>
+
+
+
+
+
+
+
+
diff --git a/res/layout/about.xml b/res/layout/about.xml
index b8a08823..d219da3d 100644
--- a/res/layout/about.xml
+++ b/res/layout/about.xml
@@ -21,7 +21,7 @@
\ No newline at end of file
diff --git a/res/layout/calc_four_digit_button.xml b/res/layout/calc_four_digit_button.xml
index 2e3d1311..9cca9b65 100644
--- a/res/layout/calc_four_digit_button.xml
+++ b/res/layout/calc_four_digit_button.xml
@@ -9,7 +9,7 @@
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
a:id="@+id/fourDigitButton"
a:text="4"
- calc:textUp="sinh"
- calc:textDown="asinh"
+ calc:textUp="x"
+ calc:textDown="y"
style="?digitButtonStyle"
a:onClick="digitButtonClickHandler"/>
\ No newline at end of file
diff --git a/res/layout/help.xml b/res/layout/help.xml
new file mode 100644
index 00000000..d25fabe6
--- /dev/null
+++ b/res/layout/help.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/help_faq.xml b/res/layout/help_faq.xml
new file mode 100644
index 00000000..4c86e954
--- /dev/null
+++ b/res/layout/help_faq.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/res/layout/help_hints.xml b/res/layout/help_hints.xml
new file mode 100644
index 00000000..f2449c53
--- /dev/null
+++ b/res/layout/help_hints.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/help_screens.xml b/res/layout/help_screens.xml
new file mode 100644
index 00000000..4190a3e1
--- /dev/null
+++ b/res/layout/help_screens.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/menu/main_menu.xml b/res/menu/main_menu.xml
index 16d64fa0..fd504271 100644
--- a/res/menu/main_menu.xml
+++ b/res/menu/main_menu.xml
@@ -8,6 +8,9 @@
+
+
diff --git a/res/values-ru/strings.xml b/res/values-ru/strings.xml
index d06bb804..18a17353 100644
--- a/res/values-ru/strings.xml
+++ b/res/values-ru/strings.xml
@@ -22,7 +22,7 @@
Перезапуск
- Copyright (c) 2009-2011\n\nПрограмма создана\nserso aka se.solovyev\n\n
+ Copyright (c) 2009-2011\n\nПрограмма создана\nserso aka se.solovyev\n\n
Эта программа с открытыми исходным кодом:\nон может быть найден на \nhttp://github.com\n\n
За подробной информацией, пожалуйста,\nобращайтесь на почту\nse.solovyev@gmail.com\n
или посетите сайт \nhttp://se.solovyev.org\n\n
@@ -154,4 +154,100 @@
Возвращает интеграл функции \'f(x)\' по переменно \'x\'.
Интегрирует функцию \'f(x)\' по переменной \'x\' от \'a\' до \'b\'.
+ Возвращает факториал от предыдущего выражения.
+ Возвращает процентное значение от предыдущего выражения.\nПримеры:\n
+ 100 + 50% = 150\n
+ 100 * 50% = 50\n
+ 100 + 100 * 50% * 50% = 125
+
+ Преобразует градусы в радианы.\n
+ Примеры:\n
+ 268° = 4.67748\n
+ 30.21° = 0.52726
+
+
+ FAQ
+ Подсказки
+ Экраны
+
+
+Как я могу использовать функции написанные в верхнем правом и нижнем правом углах кнопки?\n
+\n
+Нажмите на кнопку и потяните вверх или вниз. В зависимости от значения указанного на кнопке произойдёт действие.\n
+\n
+Как я могу переключиться между радианами и градусами?\n
+\n
+На данный момент К++ не поддерживает такого переключения, но вы можете использовать функции deg() и rad() или опертор ° для переода радиан в градусы и наоборот.\n
+\n
+Примеры:\n
+268° = 4.67748\n
+30.21° = 0.52726\n
+rad(30, 21, 0) = 0.52726\n
+deg(4.67748) = 268\n
+\n
+Поддерживает ли К++ проценты?\n
+\n
+Да, функция % может быть найдена в правом верхнем углу кнопки /.\n
+\n
+Примеры:\n
+\n
+100 + 50% = 150\n
+100 * 50% = 50\n
+100 + 100 * 50% * 50% = 125\n
+100 + (100 * 50% * (25 + 25)% + 100%) = 150\n
+\n
+Замечание:\n
+\n
+100 + (20 + 20)% = 140, но 100+ (20% + 20%) = 124.0\n
+100 + 50% ^ 2 = 2600, но 100 + 50 ^ 2% = 101.08\n
+\n
+Поддерживает ли К++ дробные вычисления?\n
+\n
+Да, вы можете ввести дробное выражение в редактор и нажать ≡ (в правом верхнем углу кнопки =). Также вы можете использовать ≡ для упрощения выражений.\n
+\n
+Примеры:\n
+\n
+2/3 + 5/9 ≡ 11/9\n
+2/9 + 3/123 ≡ 91/369\n
+(6 - t) ^ 3 ≡ 216 - 108t + 18t ^ 2 - t ^ 3\n
+\n
+Поддерживает ли К++ комплексные вычисления?\n
+\n
+Да, просто введите комплексное выражение (используя i или √(-1) в качестве мнимого числа).\n
+\n
+Примеры:\n
+\n
+(2i + 1) ^ = -3 + 4i\n
+e ^ i = 0.5403 + 0.84147i\n
+\n
+Умеет ли К++ рисовать графики функций?\n
+\n
+Нет.\n
+\n
+Поддерживает ли К++ матричные вычисления?\n
+\n
+Нет.\n
+\n
+Почему я получаю 1.76732452452345E-17 вместо 0?\n
+\n
+Проверьте опцию \'Округление результата\' в настройках приложения - она должно быть включена.\n
+
+
+
+ 1. Вы можете опускать ненужные знаки произведения в выражении (вместо 3*t или t*sin(π*t) просто пишите 3t или tsin(πt)).\n\n
+2. Используйте ≡ (в верхнем правом углу кнопки =) для упрощения выражения.\n\n
+3. Нажмите на результат для того, чтобы скопировать его в буфер обмена.\n\n
+4. Используйте кнопку = реже - результат вычисляется на лету.\n\n
+4. Создайте константы для часто используемых значений (таким образом вы можете даже сохранять выражения)
+
+
+
+ 1. Основной экран: открывается по старту приложения, на него можно попасть из любого другого экрана нажав кнопку Назад.\n\n
+2. Экран констант и переменных: содержит список переменных и констант. Пользователь может добавить новые элементы нажав кнопку Добавить. Короткое нажатие вставляет значение в редактор, длинное - открывает окно редактирования. На экран можно попасть нажав кнопку π,… на основном экране.\n\n
+3. Экран функций: содержит список всех доступных функций. Короткое нажатие вставляет функцию в редактор. На экран можно попасть нажав кнопку f(x) на основном экране.\n\n
+4. Экран операторов: содержит список всех доступных операторов. Короткое нажатие вставляет оператор в редактор. На экран можно попасть нажав кнопку ∂,… на основном экране.\n\n
+5. Экран истории: содержит список всех операций произведённых пользователем. Короткое нажатие на элемент списка вставляет его в редактор. На экран можно попасть нажав кнопку M на основном экране.\n\n
+6. Экран настроек: содержит список настроек приложения. На экран можно попасть нажав кнопку Настройки в меню.
+
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 302eee32..d1240159 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -23,7 +23,7 @@
Restart
- Copyright (c) 2009-2011\n\nCreated by serso aka se.solovyev\n\n
+ Copyright (c) 2009-2011\n\nCreated by serso aka se.solovyev\n\n
This program is open source:\nall source code can be found on\nhttp://github.com\n\n
For more information please\ncontact the author by email\nse.solovyev@gmail.com
\nor visit\nhttp://se.solovyev.org\n\n
@@ -155,5 +155,102 @@
Gives integral of function \'f(x)\' by \'x\' variable.
Integrates function \'f(x)\' by \'x\' variable from \'a\' to \'b\'.
+ Gives the factorial for expression before.
+ Gives the percent value for expression
+ before.\nExamples:\n
+ 100 + 50% = 150\n
+ 100 * 50% = 50\n
+ 100 + 100 * 50% * 50% = 125
+
+ Converts degrees to radians.\n
+ Examples:\n
+ 268° = 4.67748\n
+ 30.21° = 0.52726
+
+
+ FAQ
+ Hints
+ Screens
+
+
+How can I use functions written in the top right and bottom right corners of the button?\n
+\n
+Push the button and slide lightly up or down. Depending on value showed on the button action will occur.\n
+\n
+How can I toggle between radians and degrees?\n
+\n
+Currently C++ doesn\'t support this feature but you can use deg() and rad() functions and ° operator to convert degrees to radians and vice versa.\n
+\n
+Examples:\n
+268° = 4.67748\n
+30.21° = 0.52726\n
+rad(30, 21, 0) = 0.52726\n
+deg(4.67748) = 268\n
+\n
+Does C++ support %?\n
+\n
+Yes, % function can be found in the top right corner of / button.\n
+\n
+Examples:\n
+\n
+100 + 50% = 150\n
+100 * 50% = 50\n
+100 + 100 * 50% * 50% = 125\n
+100 + (100 * 50% * (25 + 25)% + 100%) = 150\n
+\n
+Note:\n
+\n
+100 + (20 + 20)% = 140, but 100+ (20% + 20%) = 124.0\n
+100 + 50% ^ 2 = 2600, but 100 + 50 ^ 2% = 101.08\n
+\n
+Does C++ support fractional calculations?\n
+\n
+Yes, you can type your fractional expression in the editor and use ≡ (in the top right corner of = button). Also you can use ≡ to simplify expression.\n
+\n
+Examples:\n
+\n
+2/3 + 5/9 ≡ 11/9\n
+2/9 + 3/123 ≡ 91/369\n
+(6 - t) ^ 3 ≡ 216 - 108t + 18t ^ 2 - t ^ 3\n
+\n
+Does C++ support complex calculations?\n
+\n
+Yes, just enter complex expression (using i or √(-1) as imaginary number).\n
+\n
+Examples:\n
+\n
+(2i + 1) ^ = -3 + 4i\n
+e ^ i = 0.5403 + 0.84147i\n
+\n
+Can C++ plot graph of the function?\n
+\n
+No, currently C++ cannot plot functions\' graphs.\n
+\n
+Does C++ support matrix calculations?\n
+\n
+No, it doesn\'t.\n
+\n
+Why I\'ve got 1.76732452452345E-17 instead of 0?\n
+\n
+Check the \'Round result\' preference in application settings - it should be turned on.\n
+
+
+ 1. You can omit unnecessary multiplication signs (instead of 3*t or t*sin(π*t) just type 3t or tsin(πt))\n\n
+2. Use ≡ (in the top right corner of = button) to simplify expression\n\n
+3. Just click on the result to copy it to the clipboard\n\n
+4. Use = button seldom - result is calculating on the fly\n\n
+4. Add constants for often used values (you can even save expressions)\n\n
+
+
+
+ 1. Main screen: is shown on application start, can be reached from another screen by pressing Back button.\n\n
+2. Variables and Constants screen: contains list of available constants. User may add some constants and variables here by clicking Add button. Short click on variable/constant inserts it into the editor, long click - opens variable editor window. Can be reached from the main screen by pressing π,… button.\n\n
+3. Functions screen: contains list of all available functions. Short click on function inserts it into the editor. Can be reached from the main screen by pressing f(x) button.\n\n
+4. Operators screen: contains list of all available operators. Short click on operator inserts it into the editor. Can be reached from the main screen by pressing ∂,… button.\n\n
+5. History screen: contains list of all actions done by user. Short click on history item sets it into the editor. Can be reached from the main screen by pressing M button.\n\n
+6. Settings screen: contains application preferences. Can be reached from the main screen by pressing Settings in menu.
+
+
+
diff --git a/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java b/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java
index 760129f7..ee629396 100644
--- a/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java
+++ b/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java
@@ -415,6 +415,10 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
CalculatorActivityLauncher.showAbout(this);
result = true;
break;
+ case R.id.main_menu_item_help:
+ CalculatorActivityLauncher.showHelp(this);
+ result = true;
+ break;
case R.id.main_menu_item_exit:
this.finish();
result = true;
diff --git a/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java b/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java
index 23036374..3e3d58c7 100644
--- a/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java
+++ b/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java
@@ -4,6 +4,7 @@ import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
import org.jetbrains.annotations.NotNull;
+import org.solovyev.android.calculator.help.HelpActivity;
import org.solovyev.common.utils.StringUtils;
/**
@@ -17,6 +18,10 @@ public class CalculatorActivityLauncher {
context.startActivity(new Intent(context, CalculatorHistoryActivity.class));
}
+ public static void showHelp(@NotNull final Context context) {
+ context.startActivity(new Intent(context, HelpActivity.class));
+ }
+
public static void showSettings(@NotNull final Context context) {
context.startActivity(new Intent(context, CalculatorPreferencesActivity.class));
}
diff --git a/src/main/java/org/solovyev/android/calculator/CalculatorOperatorsActivity.java b/src/main/java/org/solovyev/android/calculator/CalculatorOperatorsActivity.java
index 44b231c4..0003d497 100644
--- a/src/main/java/org/solovyev/android/calculator/CalculatorOperatorsActivity.java
+++ b/src/main/java/org/solovyev/android/calculator/CalculatorOperatorsActivity.java
@@ -10,7 +10,6 @@ import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
-import jscl.math.function.Function;
import jscl.math.operator.Operator;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.model.CalculatorEngine;
@@ -37,7 +36,10 @@ public class CalculatorOperatorsActivity extends ListActivity {
setContentView(R.layout.operators);
- adapter = new OperatorsArrayAdapter(this, R.layout.var, R.id.var_text, new ArrayList(CalculatorEngine.instance.getOperatorsRegistry().getEntities()));
+ List elements = new ArrayList();
+ elements.addAll(CalculatorEngine.instance.getOperatorsRegistry().getEntities());
+ elements.addAll(CalculatorEngine.instance.getPostfixFunctionsRegistry().getEntities());
+ adapter = new OperatorsArrayAdapter(this, R.layout.var, R.id.var_text, elements);
setListAdapter(adapter);
final ListView lv = getListView();
@@ -82,7 +84,11 @@ public class CalculatorOperatorsActivity extends ListActivity {
final Operator operator = getItem(position);
- final String operatorDescription = CalculatorEngine.instance.getOperatorsRegistry().getDescription(getContext(), operator.getName());
+ String operatorDescription = CalculatorEngine.instance.getOperatorsRegistry().getDescription(getContext(), operator.getName());
+ if (StringUtils.isEmpty(operatorDescription)) {
+ operatorDescription = CalculatorEngine.instance.getPostfixFunctionsRegistry().getDescription(getContext(), operator.getName());
+ }
+
if (!StringUtils.isEmpty(operatorDescription)) {
TextView description = (TextView) result.findViewById(R.id.var_description);
if (description == null) {
diff --git a/src/main/java/org/solovyev/android/calculator/help/HelpActivity.java b/src/main/java/org/solovyev/android/calculator/help/HelpActivity.java
new file mode 100644
index 00000000..874af8c7
--- /dev/null
+++ b/src/main/java/org/solovyev/android/calculator/help/HelpActivity.java
@@ -0,0 +1,57 @@
+/*
+ * 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.calculator.help;
+
+import android.app.Activity;
+import android.app.TabActivity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.widget.TabHost;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.solovyev.android.calculator.R;
+
+/**
+ * User: serso
+ * Date: 11/19/11
+ * Time: 11:35 AM
+ */
+public class HelpActivity extends TabActivity {
+
+ @Override
+ public void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.help);
+
+ final TabHost tabHost = getTabHost();
+
+ createTab(tabHost, "faq", "Faq", HelpFaqActivity.class);
+ createTab(tabHost, "hints", "Hints", HelpHintsActivity.class);
+ createTab(tabHost, "screens", "Screens", HelpScreensActivity.class);
+
+ tabHost.setCurrentTab(0);
+
+
+ }
+
+ private void createTab(@NotNull TabHost tabHost,
+ @NotNull String tabId,
+ @NotNull String tabCaption,
+ @NotNull Class extends Activity> activityClass) {
+
+ TabHost.TabSpec spec;
+
+ final Intent intent = new Intent().setClass(this, activityClass);
+
+ // Initialize a TabSpec for each tab and add it to the TabHost
+ spec = tabHost.newTabSpec(tabId).setIndicator(tabCaption)
+ .setContent(intent);
+
+ tabHost.addTab(spec);
+ }
+}
diff --git a/src/main/java/org/solovyev/android/calculator/help/HelpFaqActivity.java b/src/main/java/org/solovyev/android/calculator/help/HelpFaqActivity.java
new file mode 100644
index 00000000..5f32c5fc
--- /dev/null
+++ b/src/main/java/org/solovyev/android/calculator/help/HelpFaqActivity.java
@@ -0,0 +1,27 @@
+/*
+ * 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.calculator.help;
+
+import android.app.Activity;
+import android.os.Bundle;
+import org.jetbrains.annotations.Nullable;
+import org.solovyev.android.calculator.R;
+
+/**
+ * User: serso
+ * Date: 11/19/11
+ * Time: 11:37 AM
+ */
+public class HelpFaqActivity extends Activity {
+
+ @Override
+ public void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.help_faq);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/solovyev/android/calculator/help/HelpHintsActivity.java b/src/main/java/org/solovyev/android/calculator/help/HelpHintsActivity.java
new file mode 100644
index 00000000..c4b20a4b
--- /dev/null
+++ b/src/main/java/org/solovyev/android/calculator/help/HelpHintsActivity.java
@@ -0,0 +1,27 @@
+/*
+ * 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.calculator.help;
+
+import android.app.Activity;
+import android.os.Bundle;
+import org.jetbrains.annotations.Nullable;
+import org.solovyev.android.calculator.R;
+
+/**
+ * User: serso
+ * Date: 11/19/11
+ * Time: 11:37 AM
+ */
+public class HelpHintsActivity extends Activity {
+
+ @Override
+ public void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.help_hints);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/solovyev/android/calculator/help/HelpScreensActivity.java b/src/main/java/org/solovyev/android/calculator/help/HelpScreensActivity.java
new file mode 100644
index 00000000..1336f8ea
--- /dev/null
+++ b/src/main/java/org/solovyev/android/calculator/help/HelpScreensActivity.java
@@ -0,0 +1,27 @@
+/*
+ * 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.calculator.help;
+
+import android.app.Activity;
+import android.os.Bundle;
+import org.jetbrains.annotations.Nullable;
+import org.solovyev.android.calculator.R;
+
+/**
+ * User: serso
+ * Date: 11/19/11
+ * Time: 11:38 AM
+ */
+public class HelpScreensActivity extends Activity {
+
+ @Override
+ public void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.help_screens);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/solovyev/android/calculator/model/AndroidFunctionsMathRegistry.java b/src/main/java/org/solovyev/android/calculator/model/AndroidFunctionsMathRegistry.java
index 6596ff4f..8d25d821 100644
--- a/src/main/java/org/solovyev/android/calculator/model/AndroidFunctionsMathRegistry.java
+++ b/src/main/java/org/solovyev/android/calculator/model/AndroidFunctionsMathRegistry.java
@@ -7,7 +7,6 @@
package org.solovyev.android.calculator.model;
import org.jetbrains.annotations.NotNull;
-import org.solovyev.common.math.MathEntity;
import org.solovyev.common.math.MathRegistry;
import java.util.HashMap;
@@ -18,7 +17,7 @@ import java.util.Map;
* Date: 11/17/11
* Time: 11:28 PM
*/
-public class AndroidFunctionsMathRegistry extends AndroidMathRegistryImpl {
+public class AndroidFunctionsMathRegistry extends AndroidMathRegistryImpl {
@NotNull
private static final Map substitutes = new HashMap();
@@ -29,7 +28,7 @@ public class AndroidFunctionsMathRegistry extends AndroidM
@NotNull
private static final String FUNCTION_DESCRIPTION_PREFIX = "c_fun_description_";
- public AndroidFunctionsMathRegistry(@NotNull MathRegistry functionsRegistry) {
+ public AndroidFunctionsMathRegistry(@NotNull MathRegistry functionsRegistry) {
super(functionsRegistry, FUNCTION_DESCRIPTION_PREFIX);
}
diff --git a/src/main/java/org/solovyev/android/calculator/model/AndroidMathRegistryImpl.java b/src/main/java/org/solovyev/android/calculator/model/AndroidMathRegistryImpl.java
index 3c68ece4..1ddb30d8 100644
--- a/src/main/java/org/solovyev/android/calculator/model/AndroidMathRegistryImpl.java
+++ b/src/main/java/org/solovyev/android/calculator/model/AndroidMathRegistryImpl.java
@@ -53,7 +53,6 @@ public abstract class AndroidMathRegistryImpl implements A
if (substitute == null) {
stringId = stringsCache.get(prefix + name);
} else {
- // todo serso: think
stringId = stringsCache.get(prefix + substitute);
}
diff --git a/src/main/java/org/solovyev/android/calculator/model/AndroidOperatorsMathRegistry.java b/src/main/java/org/solovyev/android/calculator/model/AndroidOperatorsMathRegistry.java
index 7de0bfc3..261b61de 100644
--- a/src/main/java/org/solovyev/android/calculator/model/AndroidOperatorsMathRegistry.java
+++ b/src/main/java/org/solovyev/android/calculator/model/AndroidOperatorsMathRegistry.java
@@ -6,8 +6,8 @@
package org.solovyev.android.calculator.model;
+import jscl.math.operator.Operator;
import org.jetbrains.annotations.NotNull;
-import org.solovyev.common.math.MathEntity;
import org.solovyev.common.math.MathRegistry;
import java.util.HashMap;
@@ -18,7 +18,7 @@ import java.util.Map;
* Date: 11/17/11
* Time: 11:29 PM
*/
-public class AndroidOperatorsMathRegistry extends AndroidMathRegistryImpl {
+public class AndroidOperatorsMathRegistry extends AndroidMathRegistryImpl {
@NotNull
private static final Map substitutes = new HashMap();
@@ -34,7 +34,7 @@ public class AndroidOperatorsMathRegistry extends AndroidM
@NotNull
private static final String OPERATOR_DESCRIPTION_PREFIX = "c_op_description_";
- protected AndroidOperatorsMathRegistry(@NotNull MathRegistry functionsRegistry) {
+ protected AndroidOperatorsMathRegistry(@NotNull MathRegistry functionsRegistry) {
super(functionsRegistry, OPERATOR_DESCRIPTION_PREFIX);
}
diff --git a/src/main/java/org/solovyev/android/calculator/model/AndroidPostfixFunctionsRegistry.java b/src/main/java/org/solovyev/android/calculator/model/AndroidPostfixFunctionsRegistry.java
new file mode 100644
index 00000000..db1db6e4
--- /dev/null
+++ b/src/main/java/org/solovyev/android/calculator/model/AndroidPostfixFunctionsRegistry.java
@@ -0,0 +1,44 @@
+/*
+ * 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.calculator.model;
+
+import jscl.math.operator.Operator;
+import org.jetbrains.annotations.NotNull;
+import org.solovyev.common.math.MathRegistry;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * User: serso
+ * Date: 11/19/11
+ * Time: 1:48 PM
+ */
+public class AndroidPostfixFunctionsRegistry extends AndroidMathRegistryImpl {
+
+ @NotNull
+ private static final Map substitutes = new HashMap();
+ static {
+ substitutes.put("%", "percent");
+ substitutes.put("!", "factorial");
+ substitutes.put("°", "degree");
+ }
+
+ @NotNull
+ private static final String POSTFIX_FUNCTION_DESCRIPTION_PREFIX = "c_pf_description_";
+
+ protected AndroidPostfixFunctionsRegistry(@NotNull MathRegistry functionsRegistry) {
+ super(functionsRegistry, POSTFIX_FUNCTION_DESCRIPTION_PREFIX);
+ }
+
+
+ @NotNull
+ @Override
+ protected Map getSubstitutes() {
+ return substitutes;
+ }
+}
diff --git a/src/main/java/org/solovyev/android/calculator/model/AndroidVarsRegistryImpl.java b/src/main/java/org/solovyev/android/calculator/model/AndroidVarsRegistryImpl.java
index fd9a3e06..5e1c04e4 100644
--- a/src/main/java/org/solovyev/android/calculator/model/AndroidVarsRegistryImpl.java
+++ b/src/main/java/org/solovyev/android/calculator/model/AndroidVarsRegistryImpl.java
@@ -102,6 +102,11 @@ class AndroidVarsRegistryImpl implements AndroidVarsRegistry {
add(builder);
}
+ tryToAddAuxVar("x");
+ tryToAddAuxVar("y");
+ tryToAddAuxVar("t");
+ tryToAddAuxVar("j");
+
/*Log.d(AndroidVarsRegistry.class.getName(), vars.size() + " variables registered!");
for (Var var : vars) {
@@ -109,6 +114,12 @@ class AndroidVarsRegistryImpl implements AndroidVarsRegistry {
}*/
}
+ private void tryToAddAuxVar(@NotNull String name) {
+ if ( !contains(name) ) {
+ add(new Var.Builder(name, (String)null));
+ }
+ }
+
private Var.Builder createBuilder(@NotNull String varName, @NotNull String varValue) {
final Var.Builder result;
diff --git a/src/main/java/org/solovyev/android/calculator/model/CalculatorEngine.java b/src/main/java/org/solovyev/android/calculator/model/CalculatorEngine.java
index 4047e4c6..97bb1925 100644
--- a/src/main/java/org/solovyev/android/calculator/model/CalculatorEngine.java
+++ b/src/main/java/org/solovyev/android/calculator/model/CalculatorEngine.java
@@ -9,6 +9,7 @@ import android.content.Context;
import android.content.SharedPreferences;
import jscl.JsclMathEngine;
import jscl.MathEngine;
+import jscl.math.function.Function;
import jscl.math.operator.Operator;
import jscl.text.ParseInterruptedException;
import org.jetbrains.annotations.NotNull;
@@ -16,7 +17,6 @@ import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.jscl.JsclOperation;
import org.solovyev.android.msg.AndroidMessage;
import org.solovyev.common.NumberMapper;
-import org.solovyev.common.math.MathRegistry;
import org.solovyev.common.msg.MessageRegistry;
import org.solovyev.common.utils.MutableObject;
import org.solovyev.common.utils.StringUtils;
@@ -64,12 +64,12 @@ public enum CalculatorEngine {
private final AndroidVarsRegistry varsRegister = new AndroidVarsRegistryImpl(engine.getConstantsRegistry());
@NotNull
- private final AndroidMathRegistry functionsRegistry = new AndroidFunctionsMathRegistry(engine.getFunctionsRegistry());
+ private final AndroidMathRegistry functionsRegistry = new AndroidFunctionsMathRegistry(engine.getFunctionsRegistry());
@NotNull
- private final AndroidMathRegistry operatorsRegistry = new AndroidOperatorsMathRegistry(engine.getOperatorsRegistry());
+ private final AndroidMathRegistry operatorsRegistry = new AndroidOperatorsMathRegistry(engine.getOperatorsRegistry());
- private final MathRegistry postfixFunctionsRegistry = engine.getPostfixFunctionsRegistry();
+ private final AndroidMathRegistry postfixFunctionsRegistry = new AndroidPostfixFunctionsRegistry(engine.getPostfixFunctionsRegistry());
@NotNull
private DecimalFormatSymbols decimalGroupSymbols = new DecimalFormatSymbols(Locale.getDefault());
@@ -294,17 +294,17 @@ public enum CalculatorEngine {
}
@NotNull
- public AndroidMathRegistry getFunctionsRegistry() {
+ public AndroidMathRegistry getFunctionsRegistry() {
return functionsRegistry;
}
@NotNull
- public AndroidMathRegistry getOperatorsRegistry() {
+ public AndroidMathRegistry getOperatorsRegistry() {
return operatorsRegistry;
}
@NotNull
- public MathRegistry getPostfixFunctionsRegistry() {
+ public AndroidMathRegistry getPostfixFunctionsRegistry() {
return postfixFunctionsRegistry;
}