android_calculator-5: App help

This commit is contained in:
serso 2011-11-19 16:06:24 +04:00
parent 3e051a0214
commit e7e7d7aca5
24 changed files with 536 additions and 24 deletions

View File

@ -37,6 +37,22 @@
a:label="@string/c_about"
a:configChanges="orientation|keyboardHidden"/>
<activity a:name=".help.HelpActivity"
a:label="@string/c_help"
a:configChanges="orientation|keyboardHidden"/>
<activity a:name=".help.HelpFaqActivity"
a:label="@string/c_help"
a:configChanges="orientation|keyboardHidden"/>
<activity a:name=".help.HelpHintsActivity"
a:label="@string/c_help"
a:configChanges="orientation|keyboardHidden"/>
<activity a:name=".help.HelpScreensActivity"
a:label="@string/c_help"
a:configChanges="orientation|keyboardHidden"/>
<activity a:name=".CalculatorFunctionsActivity"
a:label="@string/c_functions"
a:configChanges="orientation|keyboardHidden">

View File

@ -21,7 +21,7 @@
<TextView
a:id="@+id/aboutTextView"
a:text="@string/c_copyright"
a:text="@string/c_about_content"
a:layout_height="fill_parent"
a:layout_width="fill_parent"
a:layout_gravity="top|center_horizontal"

View File

@ -9,7 +9,7 @@
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
a:id="@+id/fiveDigitButton"
a:text="5"
calc:textUp="cosh"
calc:textDown="acosh"
calc:textUp="t"
calc:textDown="j"
style="?digitButtonStyle"
a:onClick="digitButtonClickHandler"/>

View File

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

30
res/layout/help.xml Normal file
View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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
-->
<TabHost xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@android:id/tabhost"
a:layout_width="fill_parent"
a:layout_height="fill_parent">
<LinearLayout
a:orientation="vertical"
a:layout_width="fill_parent"
a:layout_height="fill_parent">
<TabWidget
a:id="@android:id/tabs"
a:layout_width="fill_parent"
a:layout_height="wrap_content"/>
<FrameLayout
a:id="@android:id/tabcontent"
a:layout_width="fill_parent"
a:layout_height="fill_parent"/>
</LinearLayout>
</TabHost>

24
res/layout/help_faq.xml Normal file
View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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
-->
<ScrollView xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="fill_parent"
a:layout_height="fill_parent">
<TextView
a:text="@string/c_faq_content"
a:layout_width="fill_parent"
a:layout_height="fill_parent"
a:gravity="top|left"
a:layout_weight="1"
a:scrollbars="vertical"
style="@style/about_style"/>
</ScrollView>

20
res/layout/help_hints.xml Normal file
View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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
-->
<ScrollView xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="fill_parent"
a:layout_height="fill_parent">
<TextView
xmlns:a="http://schemas.android.com/apk/res/android"
a:text="@string/c_hints_content"
a:gravity="top|left"
a:layout_weight="1"
a:scrollbars="vertical"
style="@style/about_style"/>
</ScrollView>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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
-->
<ScrollView xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="fill_parent"
a:layout_height="fill_parent">
<TextView
xmlns:a="http://schemas.android.com/apk/res/android"
a:text="@string/c_screens_content"
a:gravity="top|left"
a:layout_weight="1"
a:scrollbars="vertical"
style="@style/about_style"/>
</ScrollView>

View File

@ -8,6 +8,9 @@
<item a:id="@+id/main_menu_item_history"
a:title="@string/c_history"/>
<item a:id="@+id/main_menu_item_help"
a:title="@string/c_help"/>
<item a:id="@+id/main_menu_item_about"
a:title="@string/c_about"/>

View File

@ -22,7 +22,7 @@
<string name="c_restart">Перезапуск</string>
<!--ABOUT ACTIVITY-->
<string name="c_copyright">Copyright (c) 2009-2011\n\n<b>Программа создана\nserso aka se.solovyev</b>\n\n
<string name="c_about_content">Copyright (c) 2009-2011\n\n<b>Программа создана\nserso aka se.solovyev</b>\n\n
Эта программа с открытыми исходным кодом:\nон может быть найден на \n<a href="https://github.com/serso/android_calculator">http://github.com</a>\n\n
За подробной информацией, пожалуйста,\nобращайтесь на почту\n<a href="mailto:se.solovyev@gmail.com">se.solovyev@gmail.com</a>\n
или посетите сайт \n<a href="http://se.solovyev.org">http://se.solovyev.org</a>\n\n
@ -154,4 +154,100 @@
<string name="c_op_description_integral">Возвращает интеграл функции \'f(x)\' по переменно \'x\'.</string>
<string name="c_op_description_integral_ab">Интегрирует функцию \'f(x)\' по переменной \'x\' от \'a\' до \'b\'.</string>
<string name="c_pf_description_factorial">Возвращает факториал от предыдущего выражения.</string>
<string name="c_pf_description_percent" formatted="false">Возвращает процентное значение от предыдущего выражения.\nПримеры:\n
100 + 50% = 150\n
100 * 50% = 50\n
100 + 100 * 50% * 50% = 125
</string>
<string name="c_pf_description_degree">Преобразует градусы в радианы.\n
Примеры:\n
268° = 4.67748\n
30.21° = 0.52726
</string>
<string name="c_faq">FAQ</string>
<string name="c_hints">Подсказки</string>
<string name="c_screens">Экраны</string>
<string name="c_faq_content" formatted="false">
<b>Как я могу использовать функции написанные в верхнем правом и нижнем правом углах кнопки?</b>\n
\n
Нажмите на кнопку и потяните вверх или вниз. В зависимости от значения указанного на кнопке произойдёт действие.\n
\n
<b>Как я могу переключиться между радианами и градусами?</b>\n
\n
На данный момент К++ не поддерживает такого переключения, но вы можете использовать функции deg() и rad() или опертор ° для переода радиан в градусы и наоборот.\n
\n
<b>Примеры:</b>\n
268° = 4.67748\n
30.21° = 0.52726\n
rad(30, 21, 0) = 0.52726\n
deg(4.67748) = 268\n
\n
<b>Поддерживает ли К++ проценты?</b>\n
\n
Да, функция % может быть найдена в правом верхнем углу кнопки /.\n
\n
<b>Примеры:</b>\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
<b>Замечание:</b>\n
\n
100 + (20 + 20)% = 140, <b>но</b> 100+ (20% + 20%) = 124.0\n
100 + 50% ^ 2 = 2600, <b>но</b> 100 + 50 ^ 2% = 101.08\n
\n
<b>Поддерживает ли К++ дробные вычисления?</b>\n
\n
Да, вы можете ввести дробное выражение в редактор и нажать ≡ (в правом верхнем углу кнопки =). Также вы можете использовать ≡ для упрощения выражений.\n
\n
<b>Примеры:</b>\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
<b>Поддерживает ли К++ комплексные вычисления?</b>\n
\n
Да, просто введите комплексное выражение (используя i или √(-1) в качестве мнимого числа).\n
\n
<b>Примеры:</b>\n
\n
(2i + 1) ^ = -3 + 4i\n
e ^ i = 0.5403 + 0.84147i\n
\n
<b>Умеет ли К++ рисовать графики функций?</b>\n
\n
Нет.\n
\n
<b>Поддерживает ли К++ матричные вычисления?</b>\n
\n
Нет.\n
\n
<b>Почему я получаю 1.76732452452345E-17 вместо 0?</b>\n
\n
Проверьте опцию \'Округление результата\' в настройках приложения - она должно быть включена.\n
</string>
<string name="c_hints_content">
1. Вы можете опускать ненужные знаки произведения в выражении (вместо 3*t или t*sin(π*t) просто пишите 3t или tsin(πt)).\n\n
2. Используйте ≡ (в верхнем правом углу кнопки =) для упрощения выражения.\n\n
3. Нажмите на результат для того, чтобы скопировать его в буфер обмена.\n\n
4. Используйте кнопку = реже - результат вычисляется на лету.\n\n
4. Создайте константы для часто используемых значений (таким образом вы можете даже сохранять выражения)
</string>
<string name="c_screens_content">
1. <b>Основной экран:</b> открывается по старту приложения, на него можно попасть из любого другого экрана нажав кнопку Назад.\n\n
2. <b>Экран констант и переменных:</b> содержит список переменных и констант. Пользователь может добавить новые элементы нажав кнопку Добавить. Короткое нажатие вставляет значение в редактор, длинное - открывает окно редактирования. На экран можно попасть нажав кнопку π,… на основном экране.\n\n
3. <b>Экран функций:</b> содержит список всех доступных функций. Короткое нажатие вставляет функцию в редактор. На экран можно попасть нажав кнопку f(x) на основном экране.\n\n
4. <b>Экран операторов:</b> содержит список всех доступных операторов. Короткое нажатие вставляет оператор в редактор. На экран можно попасть нажав кнопку ∂,… на основном экране.\n\n
5. <b>Экран истории:</b> содержит список всех операций произведённых пользователем. Короткое нажатие на элемент списка вставляет его в редактор. На экран можно попасть нажав кнопку M на основном экране.\n\n
6. <b>Экран настроек:</b> содержит список настроек приложения. На экран можно попасть нажав кнопку Настройки в меню.
</string>
</resources>

View File

@ -23,7 +23,7 @@
<string name="c_restart">Restart</string>
<!--ABOUT ACTIVITY-->
<string name="c_copyright">Copyright (c) 2009-2011\n\n<b>Created by serso aka se.solovyev</b>\n\n
<string name="c_about_content">Copyright (c) 2009-2011\n\n<b>Created by serso aka se.solovyev</b>\n\n
This program is open source:\nall source code can be found on\n<a href="https://github.com/serso/android_calculator">http://github.com</a>\n\n
For more information please\ncontact the author by email\n<a href="mailto:se.solovyev@gmail.com">se.solovyev@gmail.com</a>
\nor visit\n<a href="http://se.solovyev.org">http://se.solovyev.org</a>\n\n
@ -155,5 +155,102 @@
<string name="c_op_description_integral">Gives integral of function \'f(x)\' by \'x\' variable.</string>
<string name="c_op_description_integral_ab">Integrates function \'f(x)\' by \'x\' variable from \'a\' to \'b\'.</string>
<string name="c_pf_description_factorial">Gives the factorial for expression before.</string>
<string name="c_pf_description_percent" formatted="false">Gives the percent value for expression
before.\nExamples:\n
100 + 50% = 150\n
100 * 50% = 50\n
100 + 100 * 50% * 50% = 125
</string>
<string name="c_pf_description_degree">Converts degrees to radians.\n
Examples:\n
268° = 4.67748\n
30.21° = 0.52726
</string>
<string name="c_faq">FAQ</string>
<string name="c_hints">Hints</string>
<string name="c_screens">Screens</string>
<string name="c_faq_content" formatted="false">
<b>How can I use functions written in the top right and bottom right corners of the button?</b>\n
\n
Push the button and slide lightly up or down. Depending on value showed on the button action will occur.\n
\n
<b>How can I toggle between radians and degrees?</b>\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
<b>Examples:</b>\n
268° = 4.67748\n
30.21° = 0.52726\n
rad(30, 21, 0) = 0.52726\n
deg(4.67748) = 268\n
\n
<b>Does C++ support %?</b>\n
\n
Yes, % function can be found in the top right corner of / button.\n
\n
<b>Examples:</b>\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
<b>Note:</b>\n
\n
100 + (20 + 20)% = 140, <b>but</b> 100+ (20% + 20%) = 124.0\n
100 + 50% ^ 2 = 2600, <b>but</b> 100 + 50 ^ 2% = 101.08\n
\n
<b>Does C++ support fractional calculations?</b>\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
<b>Examples:</b>\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
<b>Does C++ support complex calculations?</b>\n
\n
Yes, just enter complex expression (using i or √(-1) as imaginary number).\n
\n
<b>Examples:</b>\n
\n
(2i + 1) ^ = -3 + 4i\n
e ^ i = 0.5403 + 0.84147i\n
\n
<b>Can C++ plot graph of the function?</b>\n
\n
No, currently C++ cannot plot functions\' graphs.\n
\n
<b>Does C++ support matrix calculations?</b>\n
\n
No, it doesn\'t.\n
\n
<b>Why I\'ve got 1.76732452452345E-17 instead of 0?</b>\n
\n
Check the \'Round result\' preference in application settings - it should be turned on.\n</string>
<string name="c_hints_content">
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
</string>
<string name="c_screens_content">
1. <b>Main screen:</b> is shown on application start, can be reached from another screen by pressing Back button.\n\n
2. <b>Variables and Constants screen:</b> 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. <b>Functions screen:</b> 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. <b>Operators screen:</b> 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. <b>History screen:</b> 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. <b>Settings screen:</b> contains application preferences. Can be reached from the main screen by pressing Settings in menu.
</string>
</resources>

View File

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

View File

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

View File

@ -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<Operator>(CalculatorEngine.instance.getOperatorsRegistry().getEntities()));
List<Operator> elements = new ArrayList<Operator>();
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) {

View File

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

View File

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

View File

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

View File

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

View File

@ -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<T extends MathEntity> extends AndroidMathRegistryImpl<T> {
public class AndroidFunctionsMathRegistry extends AndroidMathRegistryImpl<jscl.math.function.Function> {
@NotNull
private static final Map<String, String> substitutes = new HashMap<String, String>();
@ -29,7 +28,7 @@ public class AndroidFunctionsMathRegistry<T extends MathEntity> extends AndroidM
@NotNull
private static final String FUNCTION_DESCRIPTION_PREFIX = "c_fun_description_";
public AndroidFunctionsMathRegistry(@NotNull MathRegistry<T> functionsRegistry) {
public AndroidFunctionsMathRegistry(@NotNull MathRegistry<jscl.math.function.Function> functionsRegistry) {
super(functionsRegistry, FUNCTION_DESCRIPTION_PREFIX);
}

View File

@ -53,7 +53,6 @@ public abstract class AndroidMathRegistryImpl<T extends MathEntity> implements A
if (substitute == null) {
stringId = stringsCache.get(prefix + name);
} else {
// todo serso: think
stringId = stringsCache.get(prefix + substitute);
}

View File

@ -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<T extends MathEntity> extends AndroidMathRegistryImpl<T> {
public class AndroidOperatorsMathRegistry extends AndroidMathRegistryImpl<Operator> {
@NotNull
private static final Map<String, String> substitutes = new HashMap<String, String>();
@ -34,7 +34,7 @@ public class AndroidOperatorsMathRegistry<T extends MathEntity> extends AndroidM
@NotNull
private static final String OPERATOR_DESCRIPTION_PREFIX = "c_op_description_";
protected AndroidOperatorsMathRegistry(@NotNull MathRegistry<T> functionsRegistry) {
protected AndroidOperatorsMathRegistry(@NotNull MathRegistry<Operator> functionsRegistry) {
super(functionsRegistry, OPERATOR_DESCRIPTION_PREFIX);
}

View File

@ -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<Operator> {
@NotNull
private static final Map<String, String> substitutes = new HashMap<String, String>();
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<Operator> functionsRegistry) {
super(functionsRegistry, POSTFIX_FUNCTION_DESCRIPTION_PREFIX);
}
@NotNull
@Override
protected Map<String, String> getSubstitutes() {
return substitutes;
}
}

View File

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

View File

@ -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<jscl.math.function.Function> functionsRegistry = new AndroidFunctionsMathRegistry(engine.getFunctionsRegistry());
@NotNull
private final AndroidMathRegistry operatorsRegistry = new AndroidOperatorsMathRegistry(engine.getOperatorsRegistry());
private final AndroidMathRegistry<Operator> operatorsRegistry = new AndroidOperatorsMathRegistry(engine.getOperatorsRegistry());
private final MathRegistry<Operator> postfixFunctionsRegistry = engine.getPostfixFunctionsRegistry();
private final AndroidMathRegistry<Operator> 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<Function> getFunctionsRegistry() {
return functionsRegistry;
}
@NotNull
public AndroidMathRegistry getOperatorsRegistry() {
public AndroidMathRegistry<Operator> getOperatorsRegistry() {
return operatorsRegistry;
}
@NotNull
public MathRegistry<Operator> getPostfixFunctionsRegistry() {
public AndroidMathRegistry<Operator> getPostfixFunctionsRegistry() {
return postfixFunctionsRegistry;
}