Merge remote-tracking branch 'origin/master'

Conflicts:
	android-app-core/res/values-ru/text_about.xml
	android-app-core/res/values-ru/text_wizard.xml
	android-app-core/res/values/text_about.xml
	android-app-core/res/values/text_wizard.xml
	pom.xml
This commit is contained in:
Sergey Solovyev 2013-07-03 00:08:50 +04:00
commit c772a4e429
33 changed files with 568 additions and 100 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 473 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 386 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 458 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 645 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 645 B

View File

@ -24,6 +24,6 @@
<ImageButton xmlns:a="http://schemas.android.com/apk/res/android" <ImageButton xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@id/cpp_button_like" a:id="@id/cpp_button_like"
a:src="@drawable/kb_facebook" a:src="@drawable/kb_share"
style="@style/cpp_simple_metro_control_image_button_style" style="@style/cpp_simple_metro_control_image_button_style"
a:contentDescription="Like"/> a:contentDescription="Like"/>

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2013 serso aka se.solovyev
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Contact details
~
~ Email: se.solovyev@gmail.com
~ Site: http://se.solovyev.org
-->
<Button xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@id/cpp_button_operators"
a:text="∂,…"
a:textStyle="italic"
style="@style/cpp_simple_metro_control_button_style"/>

View File

@ -78,7 +78,7 @@
<include layout="@layout/cpp_simple_button_plus"/> <include layout="@layout/cpp_simple_button_plus"/>
<include layout="@layout/cpp_simple_button_like"/> <include layout="@layout/cpp_simple_button_settings"/>
<include layout="@layout/cpp_simple_button_copy"/> <include layout="@layout/cpp_simple_button_copy"/>
@ -97,7 +97,7 @@
<include layout="@layout/cpp_simple_button_subtraction"/> <include layout="@layout/cpp_simple_button_subtraction"/>
<include layout="@layout/cpp_simple_button_settings"/> <include layout="@layout/cpp_simple_button_app"/>
<include layout="@layout/cpp_simple_button_paste"/> <include layout="@layout/cpp_simple_button_paste"/>
@ -117,7 +117,7 @@
<include layout="@layout/cpp_simple_button_functions"/> <include layout="@layout/cpp_simple_button_functions"/>
<include layout="@layout/cpp_simple_button_app"/> <include layout="@layout/cpp_simple_button_operators"/>
<include layout="@layout/cpp_simple_button_history"/> <include layout="@layout/cpp_simple_button_history"/>

View File

@ -21,20 +21,25 @@
--> -->
<resources> <resources>
<string name="c_about">О программе</string>
<string name="c_about_content">Копирайт © 20092013\n\n<b>Создано serso aka se.solovyev</b>\n\n <string name="c_about">О программе</string>
Страница на Facebook:<a href="http://facebook.com/calculatorpp">http://facebook.com/calculatorpp</a>\n\n
Эта программа распространяется под соглашением Apache 2.0 :\nисходный код может быть найден на\n <string name="c_about_content">Copyright (c) 2009-2013\n\n<b>Программа создана\nserso aka se.solovyev</b>\n\n
<a href="https://github.com/serso/android-calculatorpp">http://github.com</a>\n\n Сайт приложения: <a href="https://vk.com/calculatorpp">https://vk.com/calculatorpp</a>\n\n
Для получения большей информации\nсвяжитесь с автором по email\n Эта программа с открытыми исходным кодом:\nон может быть найден на \n
<a href="mailto:se.solovyev@gmail.com">se.solovyev@gmail.com</a> <a href="https://github.com/serso/android-calculatorpp">http://github.com</a>\n\n
\nor visit\n<a href="http://se.solovyev.org">http://se.solovyev.org</a>\n\n За подробной информацией, пожалуйста,\nобращайтесь на почту\n<a href="mailto:se.solovyev@gmail.com">
Если вы хотите поддержать проект\n\nвы можете купить специальную опцию из настроек приложения\n\n se.solovyev@gmail.com</a>\n
Если вам нравится приложение\nоценить его на 5 звёзд в\n или посетите сайт \n<a href="http://se.solovyev.org">http://se.solovyev.org</a>\n\n
<a href="https://market.android.com/details?id=org.solovyev.android.calculator">Google Play</a>\n\n Если вы хотите поддержать проект материально\nвы можете купить специальную опцию из настроек приложения\n\n
Это приложение использует открытые библиотеки:\n Если вам понравилось приложение -\nпоставьте 5 звёздочек в\n
<a href="http://simple.sourceforge.net">Simple (XML serialization)</a>\n <a href="https://market.android.com/details?id=org.solovyev.android.calculator">Google Play</a>\n\n
<a href="http://meditorworld.appspot.com/meditor.txt">JSCL</a></string> Это приложение использует следующие открытые библиотеки:\n
<string name="c_release_notes">Примечания к выпуску</string> <a href="http://simple.sourceforge.net">Simple (XML serialization)</a>\n
<string name="c_release_notes_for_title">"Примечания к выпуску версии "</string> <a href="http://meditorworld.appspot.com/meditor.txt">JSCL</a>
</string>
<string name="cpp_share_link">https://vk.com/calculatorpp</string>
<string name="c_release_notes">Примечания к выпуску</string>
<string name="c_release_notes_for_title">"Примечания к выпуску версии "</string>
</resources> </resources>

View File

@ -28,4 +28,25 @@
<string name="cpp_wizard_final_donate">Пожертвовать деньги</string> <string name="cpp_wizard_final_donate">Пожертвовать деньги</string>
<string name="cpp_wizard_final_translate">Перевести язык</string> <string name="cpp_wizard_final_translate">Перевести язык</string>
<string name="cpp_wizard_final_contribute">Поучавствовать в разработке</string> <string name="cpp_wizard_final_contribute">Поучавствовать в разработке</string>
<string name="cpp_wizard_layout_optimized">Оптимизированная</string>
<string name="cpp_wizard_layout_big_buttons">С большими кнопками</string>
<string name="cpp_wizard_mode_simple">Простой</string>
<string name="cpp_wizard_mode_simple_description">В простом режиме только базовая функциональность доступна на главном экране. Результат округляется до 5 знаков, градусы установлены единицами измерения углов по умолчанию.</string>
<string name="cpp_wizard_mode_engineer">Инженерный</string>
<string name="cpp_wizard_mode_engineer_description">В инженерном режиме дополнительные функции доступны на главном экране. Результат не округляется и представлен в инженерной нотации, радианы установлены единицами измерения углов по умолчанию.</string>
<string name="cpp_restart_wizard">Начать визард</string>
<string name="cpp_wizard_dragbutton_action_end">Замечательно! Нажмите на кнопку ещё раз, чтобы повторить сначала</string>
<string name="cpp_wizard_dragbutton_action_center">Нажмите на кнопку ниже для того, чтобы вопспользоваться 9</string>
<string name="cpp_wizard_dragbutton_action_up">Потяните из центра кнопки вниз для того, чтобы воспользоваться %</string>
<string name="cpp_wizard_dragbutton_action_left">Потяните из центра кнопки влево для того, чтобы воспользоваться sin</string>
<string name="cpp_wizard_dragbutton_action_down">Потяните из центра кнопки вниз для того, чтобы воспользоваться ^2</string>
<string name="cpp_wizard_welcome_title">Приветствие</string>
<string name="cpp_wizard_layout_title">Выберите раскладку</string>
<string name="cpp_wizard_mode_title">Выберите режим</string>
<string name="cpp_wizard_onscreen_calculator_title">Калькулятор в отдельном окне</string>
<string name="cpp_wizard_dragbutton_title">Основы использования кнопок</string>
<string name="cpp_wizard_onscreen_description">Калькулятор в отдельном окне позволяет вам произодить вычисления не закрывая при этом другие приложения</string>
<string name="cpp_wizard_onscreen_checkbox">Включить калькулятор в отдельном окне (вторая иконка появится в списке приложений)</string>
<string name="cpp_wizard_dragbutton_description">Специально разработанные кнопки позволяют быстро и просто использовать дополнительные возможности калькулятора
</string>
</resources> </resources>

View File

@ -1,9 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!--Generated by crowdin.net--> <!--Generated by crowdin.net-->
<resources> <resources>
<string name="c_about">About</string>
<string name="c_about_content">Copyright © 20092013\n\n<b>Created by serso aka se.solovyev</b>\n\n <string name="c_about">About</string>
We are on Facebook:<a href="http://facebook.com/calculatorpp">http://facebook.com/calculatorpp</a>\n\n
<string name="c_about_content">Copyright © 20092013\n\n<b>Created by serso aka se.solovyev</b>\n\n
We are on Facebook: <a href="http://facebook.com/calculatorpp">http://facebook.com/calculatorpp</a>\n\n
This program is distributed under Apache 2.0 License:\nsource code can be found on\n This program is distributed under Apache 2.0 License:\nsource code can be found on\n
<a href="https://github.com/serso/android-calculatorpp">http://github.com</a>\n\n <a href="https://github.com/serso/android-calculatorpp">http://github.com</a>\n\n
For more information please\ncontact the author by email\n For more information please\ncontact the author by email\n
@ -16,6 +18,9 @@
<a href="http://simple.sourceforge.net">Simple (XML serialization)</a>\n <a href="http://simple.sourceforge.net">Simple (XML serialization)</a>\n
<a href="http://meditorworld.appspot.com/meditor.txt">JSCL</a> <a href="http://meditorworld.appspot.com/meditor.txt">JSCL</a>
</string> </string>
<string name="c_release_notes">Release notes</string>
<string name="c_release_notes_for_title">"Release notes for version "</string> <string name="c_release_notes">Release notes</string>
<string name="c_release_notes_for_title">"Release notes for version "</string>
<string name="cpp_share_link">http://www.facebook.com/calculatorpp</string>
</resources> </resources>

View File

@ -34,7 +34,17 @@
</string> </string>
<string name="cpp_wizard_final_ways_to_help">There are several ways how you can help to make this app better: <string name="cpp_wizard_final_ways_to_help">There are several ways how you can help to make this app better:
</string> </string>
<string name="cpp_wizard_final_donate">Donating money</string> <string name="cpp_wizard_final_donate">Donating money</string>
<string name="cpp_wizard_final_translate">Translating</string> <string name="cpp_wizard_final_translate">Translating</string>
<string name="cpp_wizard_final_contribute">Contributing source code</string> <string name="cpp_wizard_final_contribute">Contributing source code</string>
<string name="cpp_wizard_onscreen_description">Calculator in separate window allows you to do calculations while
using other apps on your device
</string>
<string name="cpp_wizard_onscreen_checkbox">Enable calculator in separate window (second icon will appear in the
apps list)
</string>
<string name="cpp_wizard_dragbutton_description">Drag button is an exclusive feature of Calculator++ which provides
fast access to the secondary functions
</string>
</resources> </resources>

View File

@ -32,6 +32,16 @@ import org.solovyev.android.calculator.core.R;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static org.solovyev.android.calculator.CalculatorSpecialButton.cursor_left;
import static org.solovyev.android.calculator.CalculatorSpecialButton.cursor_right;
import static org.solovyev.android.calculator.CalculatorSpecialButton.functions_detached;
import static org.solovyev.android.calculator.CalculatorSpecialButton.history_detached;
import static org.solovyev.android.calculator.CalculatorSpecialButton.like;
import static org.solovyev.android.calculator.CalculatorSpecialButton.open_app;
import static org.solovyev.android.calculator.CalculatorSpecialButton.operators_detached;
import static org.solovyev.android.calculator.CalculatorSpecialButton.settings_detached;
import static org.solovyev.android.calculator.CalculatorSpecialButton.vars_detached;
/** /**
* User: serso * User: serso
* Date: 10/20/12 * Date: 10/20/12
@ -54,16 +64,17 @@ public enum CalculatorButton {
period(R.id.cpp_button_period, "."), period(R.id.cpp_button_period, "."),
brackets(R.id.cpp_button_round_brackets, "()"), brackets(R.id.cpp_button_round_brackets, "()"),
settings(R.id.cpp_button_settings, CalculatorSpecialButton.settings_detached), settings(R.id.cpp_button_settings, settings_detached),
like(R.id.cpp_button_like, CalculatorSpecialButton.like), like(R.id.cpp_button_like, CalculatorSpecialButton.like),
/*last row*/ /*last row*/
left(R.id.cpp_button_left, CalculatorSpecialButton.cursor_left), left(R.id.cpp_button_left, cursor_left),
right(R.id.cpp_button_right, CalculatorSpecialButton.cursor_right), right(R.id.cpp_button_right, cursor_right),
vars(R.id.cpp_button_vars, CalculatorSpecialButton.vars_detached), vars(R.id.cpp_button_vars, vars_detached),
functions(R.id.cpp_button_functions, CalculatorSpecialButton.functions_detached), functions(R.id.cpp_button_functions, functions_detached),
app(R.id.cpp_button_app, CalculatorSpecialButton.open_app), operators(R.id.cpp_button_operators, operators_detached),
history(R.id.cpp_button_history, CalculatorSpecialButton.history_detached), app(R.id.cpp_button_app, open_app),
history(R.id.cpp_button_history, history_detached),
/*operations*/ /*operations*/
multiplication(R.id.cpp_button_multiplication, "*"), multiplication(R.id.cpp_button_multiplication, "*"),

View File

@ -274,12 +274,12 @@ public class AndroidCalculatorEngine implements CalculatorEngine, SharedPreferen
} }
@Nonnull @Nonnull
public NumeralBase getNumeralBaseFromPrefs(@Nonnull SharedPreferences preferences) { public static NumeralBase getNumeralBaseFromPrefs(@Nonnull SharedPreferences preferences) {
return Preferences.numeralBase.getPreference(preferences); return Preferences.numeralBase.getPreference(preferences);
} }
@Nonnull @Nonnull
public AngleUnit getAngleUnitsFromPrefs(@Nonnull SharedPreferences preferences) { public static AngleUnit getAngleUnitsFromPrefs(@Nonnull SharedPreferences preferences) {
return Preferences.angleUnit.getPreference(preferences); return Preferences.angleUnit.getPreference(preferences);
} }

View File

@ -27,6 +27,7 @@ import android.content.res.Resources;
import android.graphics.Paint; import android.graphics.Paint;
import android.text.TextPaint; import android.text.TextPaint;
import android.util.AttributeSet; import android.util.AttributeSet;
import jscl.AngleUnit;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -41,8 +42,12 @@ import org.solovyev.android.view.drag.DirectionDragButton;
*/ */
public class AngleUnitsButton extends DirectionDragButton { public class AngleUnitsButton extends DirectionDragButton {
@Nonnull
private AngleUnit angleUnit;
public AngleUnitsButton(Context context, @Nonnull AttributeSet attrs) { public AngleUnitsButton(Context context, @Nonnull AttributeSet attrs) {
super(context, attrs); super(context, attrs);
this.angleUnit = Locator.getInstance().getEngine().getAngleUnits();
} }
@Override @Override
@ -52,11 +57,32 @@ public class AngleUnitsButton extends DirectionDragButton {
super.initDirectionTextPaint(basePaint, directionTextData, resources); super.initDirectionTextPaint(basePaint, directionTextData, resources);
final TextPaint directionTextPaint = directionTextData.getPaint(); final TextPaint directionTextPaint = directionTextData.getPaint();
if (Locator.getInstance().getEngine().getAngleUnits().name().equals(directionTextData.getText())) { final int color = getDirectionTextColor(directionTextData.getText());
directionTextPaint.setColor(resources.getColor(R.color.cpp_selected_angle_unit_text_color)); directionTextPaint.setColor(color);
} else { if (!isCurrentAngleUnits(directionTextData.getText())) {
directionTextPaint.setColor(resources.getColor(R.color.cpp_default_text_color));
directionTextPaint.setAlpha(getDirectionTextAlpha()); directionTextPaint.setAlpha(getDirectionTextAlpha());
} }
} }
int getDirectionTextColor(@Nonnull String directionText) {
final int color;
final Resources resources = getResources();
if (isCurrentAngleUnits(directionText)) {
color = resources.getColor(R.color.cpp_selected_angle_unit_text_color);
} else {
color = resources.getColor(R.color.cpp_default_text_color);
}
return color;
}
boolean isCurrentAngleUnits(@Nonnull String directionText) {
return this.angleUnit.name().equals(directionText);
}
public void setAngleUnit(@Nonnull AngleUnit angleUnit) {
if (this.angleUnit != angleUnit) {
this.angleUnit = angleUnit;
invalidate();
}
}
} }

View File

@ -27,6 +27,7 @@ import android.content.res.Resources;
import android.graphics.Paint; import android.graphics.Paint;
import android.text.TextPaint; import android.text.TextPaint;
import android.util.AttributeSet; import android.util.AttributeSet;
import jscl.NumeralBase;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -41,8 +42,12 @@ import org.solovyev.android.view.drag.DirectionDragButton;
*/ */
public class NumeralBasesButton extends DirectionDragButton { public class NumeralBasesButton extends DirectionDragButton {
@Nonnull
private NumeralBase numeralBase;
public NumeralBasesButton(Context context, @Nonnull AttributeSet attrs) { public NumeralBasesButton(Context context, @Nonnull AttributeSet attrs) {
super(context, attrs); super(context, attrs);
this.numeralBase = Locator.getInstance().getEngine().getNumeralBase();
} }
@Override @Override
@ -52,11 +57,33 @@ public class NumeralBasesButton extends DirectionDragButton {
super.initDirectionTextPaint(basePaint, directionTextData, resources); super.initDirectionTextPaint(basePaint, directionTextData, resources);
final TextPaint directionTextPaint = directionTextData.getPaint(); final TextPaint directionTextPaint = directionTextData.getPaint();
if (Locator.getInstance().getEngine().getNumeralBase().name().equals(directionTextData.getText())) {
directionTextPaint.setColor(resources.getColor(R.color.cpp_selected_angle_unit_text_color)); final int color = getDirectionTextColor(directionTextData.getText());
} else { directionTextPaint.setColor(color);
directionTextPaint.setColor(resources.getColor(R.color.cpp_default_text_color));
if (!isCurrentNumberBase(directionTextData.getText())) {
directionTextPaint.setAlpha(getDirectionTextAlpha()); directionTextPaint.setAlpha(getDirectionTextAlpha());
} }
} }
int getDirectionTextColor(@Nonnull String directionText) {
final int color;
if (isCurrentNumberBase(directionText)) {
color = getResources().getColor(R.color.cpp_selected_angle_unit_text_color);
} else {
color = getResources().getColor(R.color.cpp_default_text_color);
}
return color;
}
boolean isCurrentNumberBase(@Nonnull String directionText) {
return this.numeralBase.name().equals(directionText);
}
public void setNumeralBase(@Nonnull NumeralBase numeralBase) {
if (this.numeralBase != numeralBase) {
this.numeralBase = numeralBase;
invalidate();
}
}
} }

View File

@ -0,0 +1,79 @@
/*
* Copyright 2013 serso aka se.solovyev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Contact details
*
* Email: se.solovyev@gmail.com
* Site: http://se.solovyev.org
*/
package org.solovyev.android.calculator;
import android.content.Context;
import jscl.JsclMathEngine;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.mockito.Mockito;
import org.solovyev.android.calculator.history.CalculatorHistory;
import org.solovyev.android.calculator.plot.CalculatorPlotter;
/**
* User: serso
* Date: 10/7/12
* Time: 8:56 PM
*/
public class CalculatorTestUtils {
public static void staticSetUp(@Nullable Context context) throws Exception {
Locator.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class), new SystemOutCalculatorLogger(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(CalculatorKeyboard.class), Mockito.mock(CalculatorPlotter.class), null);
Locator.getInstance().getEngine().init();
if (context != null) {
initViews(context);
}
}
public static void initViews(@Nonnull Context context) {
final AndroidCalculatorEditorView editor = new AndroidCalculatorEditorView(context);
editor.init();
Locator.getInstance().getEditor().setView(editor);
final AndroidCalculatorDisplayView display = new AndroidCalculatorDisplayView(context);
display.init(context);
Locator.getInstance().getDisplay().setView(display);
}
public static void staticSetUp() throws Exception {
staticSetUp(null);
}
@Nonnull
static CalculatorEngineImpl newCalculatorEngine() {
final MathEntityDao mathEntityDao = Mockito.mock(MathEntityDao.class);
final JsclMathEngine jsclEngine = JsclMathEngine.getInstance();
final CalculatorVarsRegistry varsRegistry = new CalculatorVarsRegistry(jsclEngine.getConstantsRegistry(), mathEntityDao);
final CalculatorFunctionsMathRegistry functionsRegistry = new CalculatorFunctionsMathRegistry(jsclEngine.getFunctionsRegistry(), mathEntityDao);
final CalculatorOperatorsMathRegistry operatorsRegistry = new CalculatorOperatorsMathRegistry(jsclEngine.getOperatorsRegistry(), mathEntityDao);
final CalculatorPostfixFunctionsRegistry postfixFunctionsRegistry = new CalculatorPostfixFunctionsRegistry(jsclEngine.getPostfixFunctionsRegistry(), mathEntityDao);
return new CalculatorEngineImpl(jsclEngine, varsRegistry, functionsRegistry, operatorsRegistry, postfixFunctionsRegistry, null);
}
}

View File

@ -0,0 +1,75 @@
package org.solovyev.android.calculator.view;
import android.app.Activity;
import jscl.AngleUnit;
import java.util.ArrayList;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.res.Attribute;
import org.robolectric.shadows.ShadowActivity;
import static jscl.AngleUnit.deg;
import static jscl.AngleUnit.grad;
import static jscl.AngleUnit.rad;
import static jscl.AngleUnit.turns;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.solovyev.android.calculator.CalculatorTestUtils.staticSetUp;
@RunWith(RobolectricTestRunner.class)
public class AngleUnitsButtonTest {
private AngleUnitsButton button;
@Before
public void setUp() throws Exception {
staticSetUp();
final Activity context = Robolectric.buildActivity(Activity.class).create().get();
final ShadowActivity activity = Robolectric.shadowOf(context);
button = new AngleUnitsButton(context, activity.createAttributeSet(new ArrayList<Attribute>(), AngleUnitsButton.class));
}
@Test
public void testShouldReturnDifferentColorsForDifferentAngleUnits() throws Exception {
button.setAngleUnit(deg);
assertEquals(button.getDirectionTextColor(deg.name()), button.getDirectionTextColor(deg.name()));
assertEquals(button.getDirectionTextColor(grad.name()), button.getDirectionTextColor(rad.name()));
assertNotSame(button.getDirectionTextColor(deg.name()), button.getDirectionTextColor(rad.name()));
assertNotSame(button.getDirectionTextColor(deg.name()), button.getDirectionTextColor(grad.name()));
assertNotSame(button.getDirectionTextColor(deg.name()), button.getDirectionTextColor(turns.name()));
}
@Test
public void testIsCurrentAngleUnits() throws Exception {
button.setAngleUnit(rad);
assertTrue(button.isCurrentAngleUnits(rad.name()));
assertFalse(button.isCurrentAngleUnits(deg.name()));
assertFalse(button.isCurrentAngleUnits(grad.name()));
}
@Test
public void testInvalidateShouldBeCalledOnlyWhenChangeIsDone() throws Exception {
button.setAngleUnit(rad);
button = Mockito.spy(button);
button.setAngleUnit(deg);
verify(button, times(1)).invalidate();
button.setAngleUnit(deg);
verify(button, times(1)).invalidate();
}
}

View File

@ -0,0 +1,76 @@
package org.solovyev.android.calculator.view;
import android.app.Activity;
import jscl.NumeralBase;
import java.util.ArrayList;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.res.Attribute;
import org.robolectric.shadows.ShadowActivity;
import static jscl.AngleUnit.deg;
import static jscl.AngleUnit.rad;
import static jscl.NumeralBase.bin;
import static jscl.NumeralBase.dec;
import static jscl.NumeralBase.hex;
import static jscl.NumeralBase.oct;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.solovyev.android.calculator.CalculatorTestUtils.staticSetUp;
@RunWith(RobolectricTestRunner.class)
public class NumeralBasesButtonTest {
private NumeralBasesButton button;
@Before
public void setUp() throws Exception {
staticSetUp();
final Activity context = Robolectric.buildActivity(Activity.class).create().get();
final ShadowActivity activity = Robolectric.shadowOf(context);
button = new NumeralBasesButton(context, activity.createAttributeSet(new ArrayList<Attribute>(), NumeralBasesButton.class));
}
@Test
public void testShouldReturnDifferentColorsForDifferentNumeralBase() throws Exception {
button.setNumeralBase(dec);
assertEquals(button.getDirectionTextColor(dec.name()), button.getDirectionTextColor(dec.name()));
assertEquals(button.getDirectionTextColor(hex.name()), button.getDirectionTextColor(bin.name()));
assertNotSame(button.getDirectionTextColor(dec.name()), button.getDirectionTextColor(bin.name()));
assertNotSame(button.getDirectionTextColor(dec.name()), button.getDirectionTextColor(hex.name()));
assertNotSame(button.getDirectionTextColor(dec.name()), button.getDirectionTextColor(oct.name()));
}
@Test
public void testIsCurrentNumeralBase() throws Exception {
button.setNumeralBase(dec);
assertTrue(button.isCurrentNumberBase(dec.name()));
assertFalse(button.isCurrentNumberBase(hex.name()));
assertFalse(button.isCurrentNumberBase(bin.name()));
}
@Test
public void testInvalidateShouldBeCalledOnlyWhenChangeIsDone() throws Exception {
button.setNumeralBase(dec);
button = Mockito.spy(button);
button.setNumeralBase(hex);
verify(button, times(1)).invalidate();
button.setNumeralBase(hex);
verify(button, times(1)).invalidate();
}
}

View File

@ -24,6 +24,6 @@
<ImageButton xmlns:a="http://schemas.android.com/apk/res/android" <ImageButton xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@id/cpp_button_like" a:id="@id/cpp_button_like"
a:src="@drawable/kb_facebook" a:src="@drawable/kb_share"
style="?cpp_control_image_button_style" style="?cpp_control_image_button_style"
a:onClick="likeButtonClickHandler"/> a:onClick="likeButtonClickHandler"/>

View File

@ -29,7 +29,7 @@
a:orientation="vertical"> a:orientation="vertical">
<TextView <TextView
a:text="Drag button is an exclusive feature of Calculator++ which provides fast access to the secondary functions" a:text="@string/cpp_wizard_dragbutton_description"
a:layout_height="wrap_content" a:layout_height="wrap_content"
a:layout_width="match_parent"/> a:layout_width="match_parent"/>

View File

@ -28,7 +28,7 @@
a:orientation="vertical"> a:orientation="vertical">
<TextView <TextView
a:text="Calculator in separate window allows you to do calculations while using other apps on your device" a:text="@string/cpp_wizard_onscreen_description"
a:layout_height="wrap_content" a:layout_height="wrap_content"
a:layout_width="match_parent"/> a:layout_width="match_parent"/>
@ -36,6 +36,6 @@
a:id="@+id/wizard_onscreen_app_enabled_checkbox" a:id="@+id/wizard_onscreen_app_enabled_checkbox"
a:layout_height="wrap_content" a:layout_height="wrap_content"
a:layout_width="match_parent" a:layout_width="match_parent"
a:text="Enable calculator in separate window (second icon will appear in the apps list)"/> a:text="@string/cpp_wizard_onscreen_checkbox"/>
</LinearLayout> </LinearLayout>

View File

@ -43,7 +43,6 @@
a:id="@+id/history_item" a:id="@+id/history_item"
a:layout_width="fill_parent" a:layout_width="fill_parent"
a:layout_height="fill_parent" a:layout_height="fill_parent"
a:textColor="@color/cpp_button_operator_text_color"
style="@style/history_item"/> style="@style/history_item"/>
</LinearLayout> </LinearLayout>

View File

@ -36,7 +36,6 @@
a:id="@+id/history_item" a:id="@+id/history_item"
a:layout_width="fill_parent" a:layout_width="fill_parent"
a:layout_height="fill_parent" a:layout_height="fill_parent"
a:textColor="@color/cpp_button_operator_text_color"
style="@style/history_item"/> style="@style/history_item"/>
<LinearLayout <LinearLayout

View File

@ -46,6 +46,69 @@
style="@style/cpp_default_text_size" style="@style/cpp_default_text_size"
a:inputType="text"/> a:inputType="text"/>
<LinearLayout
a:id="@+id/var_edit_greek_buttons_1"
a:layout_height="wrap_content"
a:layout_width="match_parent"
a:orientation="horizontal">
<Button a:text="α"
a:layout_height="wrap_content"
a:layout_width="0dp"
a:layout_weight="1"/>
<Button a:text="β"
a:layout_height="wrap_content"
a:layout_width="0dp"
a:layout_weight="1"/>
<Button a:text="γ"
a:layout_height="wrap_content"
a:layout_width="0dp"
a:layout_weight="1"/>
<Button a:text="δ"
a:layout_height="wrap_content"
a:layout_width="0dp"
a:layout_weight="1"/>
<Button a:text="ε"
a:layout_height="wrap_content"
a:layout_width="0dp"
a:layout_weight="1"/>
</LinearLayout>
<LinearLayout a:id="@+id/var_edit_greek_buttons_2"
a:layout_height="wrap_content"
a:layout_width="match_parent"
a:orientation="horizontal">
<Button a:text="θ"
a:layout_height="wrap_content"
a:layout_width="0dp"
a:layout_weight="1"/>
<Button a:text="λ"
a:layout_height="wrap_content"
a:layout_width="0dp"
a:layout_weight="1"/>
<Button a:text="μ"
a:layout_height="wrap_content"
a:layout_width="0dp"
a:layout_weight="1"/>
<Button a:text="τ"
a:layout_height="wrap_content"
a:layout_width="0dp"
a:layout_weight="1"/>
<Button a:text="φ"
a:layout_height="wrap_content"
a:layout_width="0dp"
a:layout_weight="1"/>
</LinearLayout>
<TextView <TextView
a:layout_height="wrap_content" a:layout_height="wrap_content"
a:layout_width="match_parent" a:layout_width="match_parent"

View File

@ -52,6 +52,8 @@ import java.util.List;
import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.simple; import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.simple;
import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.simple_mobile; import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.simple_mobile;
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.angleUnit;
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.numeralBase;
/** /**
* User: serso * User: serso
@ -75,6 +77,12 @@ public abstract class AbstractCalculatorHelper implements SharedPreferences.OnSh
@Nonnull @Nonnull
private String logTag = "CalculatorActivity"; private String logTag = "CalculatorActivity";
@Nullable
private AngleUnitsButton angleUnitsButton;
@Nullable
private NumeralBasesButton clearButton;
protected AbstractCalculatorHelper() { protected AbstractCalculatorHelper() {
} }
@ -151,12 +159,12 @@ public abstract class AbstractCalculatorHelper implements SharedPreferences.OnSh
equalsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new EqualsDragProcessor(), dragPreferences), vibrator, preferences)); equalsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new EqualsDragProcessor(), dragPreferences), vibrator, preferences));
} }
final AngleUnitsButton angleUnitsButton = (AngleUnitsButton) getButton(root, R.id.cpp_button_6); angleUnitsButton = getButton(root, R.id.cpp_button_6);
if (angleUnitsButton != null) { if (angleUnitsButton != null) {
angleUnitsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.AngleUnitsChanger(activity), dragPreferences), vibrator, preferences)); angleUnitsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.AngleUnitsChanger(activity), dragPreferences), vibrator, preferences));
} }
final NumeralBasesButton clearButton = (NumeralBasesButton) getButton(root, R.id.cpp_button_clear); clearButton = getButton(root, R.id.cpp_button_clear);
if (clearButton != null) { if (clearButton != null) {
clearButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.NumeralBasesChanger(activity), dragPreferences), vibrator, preferences)); clearButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.NumeralBasesChanger(activity), dragPreferences), vibrator, preferences));
} }
@ -266,12 +274,22 @@ public abstract class AbstractCalculatorHelper implements SharedPreferences.OnSh
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
if (key != null && key.startsWith("org.solovyev.android.calculator.DragButtonCalibrationActivity")) { if (key.startsWith("org.solovyev.android.calculator.DragButtonCalibrationActivity")) {
final SimpleOnDragListener.Preferences dragPreferences = SimpleOnDragListener.getPreferences(preferences, CalculatorApplication.getInstance()); final SimpleOnDragListener.Preferences dragPreferences = SimpleOnDragListener.getPreferences(preferences, CalculatorApplication.getInstance());
for (DragPreferencesChangeListener dragPreferencesChangeListener : dpclRegister.getListeners()) { for (DragPreferencesChangeListener dragPreferencesChangeListener : dpclRegister.getListeners()) {
dragPreferencesChangeListener.onDragPreferencesChange(dragPreferences); dragPreferencesChangeListener.onDragPreferencesChange(dragPreferences);
} }
} }
if (angleUnit.isSameKey(key) || numeralBase.isSameKey(key)) {
if (angleUnitsButton != null) {
angleUnitsButton.setAngleUnit(angleUnit.getPreference(preferences));
}
if (clearButton != null) {
clearButton.setNumeralBase(numeralBase.getPreference(preferences));
}
}
} }
public void onDestroy(@Nonnull Activity activity) { public void onDestroy(@Nonnull Activity activity) {

View File

@ -205,7 +205,7 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener
} }
public static void likeButtonPressed(@Nonnull final Context context) { public static void likeButtonPressed(@Nonnull final Context context) {
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(CalculatorApplication.FACEBOOK_APP_URL)); final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(context.getString(R.string.cpp_share_link)));
Android.addIntentFlags(intent, false, context); Android.addIntentFlags(intent, false, context);
context.startActivity(intent); context.startActivity(intent);
} }

View File

@ -72,7 +72,6 @@ public class CalculatorApplication extends android.app.Application implements Sh
*/ */
private static final String TAG = "Calculator++ Application"; private static final String TAG = "Calculator++ Application";
public static final String FACEBOOK_APP_URL = "http://www.facebook.com/calculatorpp";
public static final String AD_FREE_PRODUCT_ID = "ad_free"; public static final String AD_FREE_PRODUCT_ID = "ad_free";
public static final String AD_FREE_P_KEY = "org.solovyev.android.calculator_ad_free"; public static final String AD_FREE_P_KEY = "org.solovyev.android.calculator_ad_free";

View File

@ -36,6 +36,14 @@ import javax.annotation.Nullable;
import org.solovyev.android.calculator.model.AndroidCalculatorEngine; import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
import static org.solovyev.android.calculator.CalculatorPreferences.Gui.hideNumeralBaseDigits;
import static org.solovyev.android.calculator.CalculatorPreferences.Gui.showEqualsButton;
import static org.solovyev.android.calculator.NumeralBaseButtons.toggleNumericDigits;
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences;
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.angleUnit;
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.multiplicationSign;
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.numeralBase;
/** /**
* User: Solovyev_S * User: Solovyev_S
* Date: 25.09.12 * Date: 25.09.12
@ -108,21 +116,6 @@ public class CalculatorKeyboardFragment extends SherlockFragment implements Shar
} }
/* private static void setMarginsForView(@Nullable View view, int marginLeft, int marginBottom, @Nonnull Context context) {
// IMPORTANT: this is workaround for probably android bug
// currently margin values set in styles are not applied for some reasons to the views (using include tag) => set them manually
if (view != null) {
final DisplayMetrics dm = context.getResources().getDisplayMetrics();
if (view.getLayoutParams() instanceof LinearLayout.LayoutParams) {
final LinearLayout.LayoutParams oldParams = (LinearLayout.LayoutParams) view.getLayoutParams();
final LinearLayout.LayoutParams newParams = new LinearLayout.LayoutParams(oldParams.width, oldParams.height, oldParams.weight);
newParams.setMargins(AndroidUtils.toPixels(dm, marginLeft), 0, 0, AndroidUtils.toPixels(dm, marginBottom));
view.setLayoutParams(newParams);
}
}
}*/
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
@ -130,25 +123,15 @@ public class CalculatorKeyboardFragment extends SherlockFragment implements Shar
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
if (AndroidCalculatorEngine.Preferences.numeralBase.getKey().equals(key) || if (numeralBase.isSameKey(key) || hideNumeralBaseDigits.isSameKey(key)) {
CalculatorPreferences.Gui.hideNumeralBaseDigits.getKey().equals(key)) { toggleNumericDigits(this.getActivity(), preferences);
NumeralBaseButtons.toggleNumericDigits(this.getActivity(), preferences);
} }
if (AndroidCalculatorEngine.Preferences.angleUnit.getKey().equals(key) || if (showEqualsButton.isSameKey(key)) {
AndroidCalculatorEngine.Preferences.numeralBase.getKey().equals(key)) {
View view = getView();
if (view != null) {
// we should update state of angle units/numeral base button => we can achieve it by invalidating the whole view
view.invalidate();
}
}
if (CalculatorPreferences.Gui.showEqualsButton.getKey().equals(key)) {
CalculatorButtons.toggleEqualsButton(preferences, this.getActivity()); CalculatorButtons.toggleEqualsButton(preferences, this.getActivity());
} }
if (AndroidCalculatorEngine.Preferences.multiplicationSign.getKey().equals(key)) { if (multiplicationSign.isSameKey(key)) {
CalculatorButtons.initMultiplicationButton(getView()); CalculatorButtons.initMultiplicationButton(getView());
} }
} }

View File

@ -30,6 +30,10 @@ import javax.annotation.Nonnull;
import org.solovyev.android.calculator.model.AndroidCalculatorEngine; import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
import static jscl.NumeralBase.hex;
import static org.solovyev.android.calculator.CalculatorPreferences.Gui.hideNumeralBaseDigits;
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.numeralBase;
/** /**
* User: serso * User: serso
* Date: 4/20/12 * Date: 4/20/12
@ -48,12 +52,12 @@ public class NumeralBaseButtons {
} }
public static void toggleNumericDigits(@Nonnull Activity activity, @Nonnull SharedPreferences preferences) { public static void toggleNumericDigits(@Nonnull Activity activity, @Nonnull SharedPreferences preferences) {
if (CalculatorPreferences.Gui.hideNumeralBaseDigits.getPreference(preferences)) { if (hideNumeralBaseDigits.getPreference(preferences)) {
final NumeralBase nb = AndroidCalculatorEngine.Preferences.numeralBase.getPreference(preferences); final NumeralBase nb = numeralBase.getPreference(preferences);
toggleNumericDigits(activity, nb); toggleNumericDigits(activity, nb);
} else { } else {
// set HEX to show all digits // set HEX to show all digits
AndroidNumeralBase.valueOf(NumeralBase.hex).toggleButtons(true, activity); AndroidNumeralBase.valueOf(hex).toggleButtons(true, activity);
} }
} }
} }

View File

@ -80,8 +80,6 @@ public abstract class AbstractMathEntityListFragment<T extends MathEntity> exten
public static final String MATH_ENTITY_CATEGORY_EXTRA_STRING = "org.solovyev.android.calculator.CalculatorVarsActivity_math_entity_category"; public static final String MATH_ENTITY_CATEGORY_EXTRA_STRING = "org.solovyev.android.calculator.CalculatorVarsActivity_math_entity_category";
protected final static List<Character> acceptableChars = Arrays.asList(Strings.toObjects("1234567890abcdefghijklmnopqrstuvwxyzйцукенгшщзхъфывапролджэячсмитьбюё_".toCharArray()));
/* /*
********************************************************************** **********************************************************************

View File

@ -22,6 +22,7 @@
package org.solovyev.android.calculator.math.edit; package org.solovyev.android.calculator.math.edit;
import android.app.Dialog;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
@ -30,17 +31,24 @@ import android.text.TextWatcher;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.WindowManager; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Toast; import android.widget.Toast;
import jscl.math.function.IConstant; import jscl.math.function.IConstant;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.solovyev.android.Views;
import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.model.Var; import org.solovyev.android.calculator.model.Var;
import org.solovyev.android.sherlock.AndroidSherlockUtils; import org.solovyev.android.sherlock.AndroidSherlockUtils;
import org.solovyev.common.text.Strings;
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE;
/** /**
* User: Solovyev_S * User: Solovyev_S
@ -49,6 +57,8 @@ import org.solovyev.android.sherlock.AndroidSherlockUtils;
*/ */
public class VarEditDialogFragment extends DialogFragment implements CalculatorEventListener { public class VarEditDialogFragment extends DialogFragment implements CalculatorEventListener {
private final static List<Character> acceptableChars = Arrays.asList(Strings.toObjects("1234567890abcdefghijklmnopqrstuvwxyzйцукенгшщзхъфывапролджэячсмитьбюёαβγδεζηθικλμνξοπρστυφχψω_".toCharArray()));
@Nonnull @Nonnull
private final Input input; private final Input input;
@ -101,7 +111,7 @@ public class VarEditDialogFragment extends DialogFragment implements CalculatorE
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
for (int i = 0; i < s.length(); i++) { for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i); char c = s.charAt(i);
if (!AbstractMathEntityListFragment.acceptableChars.contains(c)) { if (!acceptableChars.contains(c)) {
s.delete(i, i + 1); s.delete(i, i + 1);
Toast.makeText(getActivity(), String.format(errorMsg, c), Toast.LENGTH_SHORT).show(); Toast.makeText(getActivity(), String.format(errorMsg, c), Toast.LENGTH_SHORT).show();
} }
@ -109,9 +119,12 @@ public class VarEditDialogFragment extends DialogFragment implements CalculatorE
} }
}); });
processGreekButtons(root, editName, R.id.var_edit_greek_buttons_1);
processGreekButtons(root, editName, R.id.var_edit_greek_buttons_2);
// show soft keyboard automatically // show soft keyboard automatically
editName.requestFocus(); editName.requestFocus();
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); getDialog().getWindow().setSoftInputMode(SOFT_INPUT_STATE_VISIBLE);
final EditText editValue = (EditText) root.findViewById(R.id.var_edit_value); final EditText editValue = (EditText) root.findViewById(R.id.var_edit_value);
editValue.setText(input.getValue()); editValue.setText(input.getValue());
@ -149,6 +162,21 @@ public class VarEditDialogFragment extends DialogFragment implements CalculatorE
} }
} }
private void processGreekButtons(@Nonnull View root, @Nonnull final EditText editName, int greekButtonsViewId) {
final ViewGroup greekButtons = (ViewGroup) root.findViewById(greekButtonsViewId);
Views.processViewsOfType(greekButtons, Button.class, new Views.ViewProcessor<Button>() {
@Override
public void process(@Nonnull final Button greekButton) {
greekButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
editName.append(greekButton.getText());
}
});
}
});
}
@Override @Override
public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) { public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) {
switch (calculatorEventType) { switch (calculatorEventType) {

View File

@ -179,13 +179,26 @@ public class CalculatorEngineImpl implements CalculatorEngine {
@Override @Override
public void reset() { public void reset() {
synchronized (lock) { synchronized (lock) {
varsRegistry.load(); safeLoadRegistry(varsRegistry);
functionsRegistry.load(); safeLoadRegistry(functionsRegistry);
operatorsRegistry.load(); safeLoadRegistry(operatorsRegistry);
postfixFunctionsRegistry.load(); safeLoadRegistry(postfixFunctionsRegistry);
} }
} }
private void safeLoadRegistry(@Nonnull CalculatorMathRegistry<?> registry) {
try {
registry.load();
} catch (Exception e) {
logException(e);
}
}
private void logException(@Nonnull Exception e) {
final CalculatorLogger logger = Locator.getInstance().getLogger();
logger.error("Engine", e.getMessage(), e);
}
@Override @Override
public void softReset() { public void softReset() {
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.engine_preferences_changed, null); Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.engine_preferences_changed, null);