CalculatorAndroidEngine and CalculatorEngineImple merged into one Engine
This commit is contained in:
		@@ -25,19 +25,15 @@ package org.solovyev.android.calculator;
 | 
				
			|||||||
import android.app.Application;
 | 
					import android.app.Application;
 | 
				
			||||||
import android.content.SharedPreferences;
 | 
					import android.content.SharedPreferences;
 | 
				
			||||||
import android.preference.PreferenceManager;
 | 
					import android.preference.PreferenceManager;
 | 
				
			||||||
 | 
					import jscl.AngleUnit;
 | 
				
			||||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
 | 
					import jscl.NumeralBase;
 | 
				
			||||||
import org.solovyev.android.msg.AndroidMessage;
 | 
					import org.solovyev.android.msg.AndroidMessage;
 | 
				
			||||||
import org.solovyev.common.msg.MessageType;
 | 
					import org.solovyev.common.msg.MessageType;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import javax.annotation.Nonnull;
 | 
				
			||||||
import java.util.ArrayList;
 | 
					import java.util.ArrayList;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.annotation.Nonnull;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import jscl.AngleUnit;
 | 
					 | 
				
			||||||
import jscl.NumeralBase;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * User: serso
 | 
					 * User: serso
 | 
				
			||||||
 * Date: 11/17/12
 | 
					 * Date: 11/17/12
 | 
				
			||||||
@@ -63,10 +59,10 @@ public class AndroidCalculatorPreferenceService implements CalculatorPreferenceS
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        if (force || (Preferences.Calculations.showCalculationMessagesDialog.getPreference(prefs) && isTimeForCheck(currentTime, prefs))) {
 | 
					        if (force || (Preferences.Calculations.showCalculationMessagesDialog.getPreference(prefs) && isTimeForCheck(currentTime, prefs))) {
 | 
				
			||||||
            final NumeralBase preferredNumeralBase = Preferences.Calculations.preferredNumeralBase.getPreference(prefs);
 | 
					            final NumeralBase preferredNumeralBase = Preferences.Calculations.preferredNumeralBase.getPreference(prefs);
 | 
				
			||||||
            final NumeralBase numeralBase = AndroidCalculatorEngine.Preferences.numeralBase.getPreference(prefs);
 | 
					            final NumeralBase numeralBase = Engine.Preferences.numeralBase.getPreference(prefs);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            final AngleUnit preferredAngleUnits = Preferences.Calculations.preferredAngleUnits.getPreference(prefs);
 | 
					            final AngleUnit preferredAngleUnits = Preferences.Calculations.preferredAngleUnits.getPreference(prefs);
 | 
				
			||||||
            final AngleUnit angleUnits = AndroidCalculatorEngine.Preferences.angleUnit.getPreference(prefs);
 | 
					            final AngleUnit angleUnits = Engine.Preferences.angleUnit.getPreference(prefs);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            final List<FixableMessage> messages = new ArrayList<FixableMessage>(2);
 | 
					            final List<FixableMessage> messages = new ArrayList<FixableMessage>(2);
 | 
				
			||||||
            if (numeralBase != preferredNumeralBase) {
 | 
					            if (numeralBase != preferredNumeralBase) {
 | 
				
			||||||
@@ -98,7 +94,7 @@ public class AndroidCalculatorPreferenceService implements CalculatorPreferenceS
 | 
				
			|||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void setAngleUnits(@Nonnull AngleUnit angleUnit) {
 | 
					    public void setAngleUnits(@Nonnull AngleUnit angleUnit) {
 | 
				
			||||||
        final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(application);
 | 
					        final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(application);
 | 
				
			||||||
        AndroidCalculatorEngine.Preferences.angleUnit.putPreference(preferences, angleUnit);
 | 
					        Engine.Preferences.angleUnit.putPreference(preferences, angleUnit);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Locator.getInstance().getNotifier().showMessage(new AndroidMessage(R.string.c_angle_units_changed_to, MessageType.info, application, angleUnit.name()));
 | 
					        Locator.getInstance().getNotifier().showMessage(new AndroidMessage(R.string.c_angle_units_changed_to, MessageType.info, application, angleUnit.name()));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -112,7 +108,7 @@ public class AndroidCalculatorPreferenceService implements CalculatorPreferenceS
 | 
				
			|||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void setNumeralBase(@Nonnull NumeralBase numeralBase) {
 | 
					    public void setNumeralBase(@Nonnull NumeralBase numeralBase) {
 | 
				
			||||||
        final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(application);
 | 
					        final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(application);
 | 
				
			||||||
        AndroidCalculatorEngine.Preferences.numeralBase.putPreference(preferences, numeralBase);
 | 
					        Engine.Preferences.numeralBase.putPreference(preferences, numeralBase);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Locator.getInstance().getNotifier().showMessage(new AndroidMessage(R.string.c_numeral_base_changed_to, MessageType.info, application, numeralBase.name()));
 | 
					        Locator.getInstance().getNotifier().showMessage(new AndroidMessage(R.string.c_numeral_base_changed_to, MessageType.info, application, numeralBase.name()));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -40,7 +40,7 @@ import jscl.NumeralBase;
 | 
				
			|||||||
public abstract class BaseNumberBuilder {
 | 
					public abstract class BaseNumberBuilder {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Nonnull
 | 
					    @Nonnull
 | 
				
			||||||
    protected final CalculatorEngine engine;
 | 
					    protected final Engine engine;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Nullable
 | 
					    @Nullable
 | 
				
			||||||
    protected StringBuilder numberBuilder = null;
 | 
					    protected StringBuilder numberBuilder = null;
 | 
				
			||||||
@@ -48,7 +48,7 @@ public abstract class BaseNumberBuilder {
 | 
				
			|||||||
    @Nullable
 | 
					    @Nullable
 | 
				
			||||||
    protected NumeralBase nb;
 | 
					    protected NumeralBase nb;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected BaseNumberBuilder(@Nonnull CalculatorEngine engine) {
 | 
					    protected BaseNumberBuilder(@Nonnull Engine engine) {
 | 
				
			||||||
        this.engine = engine;
 | 
					        this.engine = engine;
 | 
				
			||||||
        this.nb = engine.getNumeralBase();
 | 
					        this.nb = engine.getNumeralBase();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -56,8 +56,8 @@ import javax.inject.Inject;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple;
 | 
					import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple;
 | 
				
			||||||
import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple_mobile;
 | 
					import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple_mobile;
 | 
				
			||||||
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.angleUnit;
 | 
					import static org.solovyev.android.calculator.Engine.Preferences.angleUnit;
 | 
				
			||||||
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.numeralBase;
 | 
					import static org.solovyev.android.calculator.Engine.Preferences.numeralBase;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChangeListener {
 | 
					public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChangeListener {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -36,7 +36,6 @@ import org.solovyev.android.Android;
 | 
				
			|||||||
import org.solovyev.android.calculator.history.History;
 | 
					import org.solovyev.android.calculator.history.History;
 | 
				
			||||||
import org.solovyev.android.calculator.language.Language;
 | 
					import org.solovyev.android.calculator.language.Language;
 | 
				
			||||||
import org.solovyev.android.calculator.language.Languages;
 | 
					import org.solovyev.android.calculator.language.Languages;
 | 
				
			||||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
 | 
					 | 
				
			||||||
import org.solovyev.android.calculator.onscreen.CalculatorOnscreenStartActivity;
 | 
					import org.solovyev.android.calculator.onscreen.CalculatorOnscreenStartActivity;
 | 
				
			||||||
import org.solovyev.android.calculator.plot.AndroidCalculatorPlotter;
 | 
					import org.solovyev.android.calculator.plot.AndroidCalculatorPlotter;
 | 
				
			||||||
import org.solovyev.android.calculator.plot.CalculatorPlotterImpl;
 | 
					import org.solovyev.android.calculator.plot.CalculatorPlotterImpl;
 | 
				
			||||||
@@ -117,7 +116,7 @@ public class CalculatorApplication extends android.app.Application implements Sh
 | 
				
			|||||||
        App.getGa().reportInitially(preferences);
 | 
					        App.getGa().reportInitially(preferences);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Locator.getInstance().init(calculator,
 | 
					        Locator.getInstance().init(calculator,
 | 
				
			||||||
                new AndroidCalculatorEngine(this),
 | 
					                new Engine(this),
 | 
				
			||||||
                new AndroidCalculatorClipboard(this),
 | 
					                new AndroidCalculatorClipboard(this),
 | 
				
			||||||
                new AndroidCalculatorNotifier(this),
 | 
					                new AndroidCalculatorNotifier(this),
 | 
				
			||||||
                errorReporter,
 | 
					                errorReporter,
 | 
				
			||||||
@@ -144,7 +143,7 @@ public class CalculatorApplication extends android.app.Application implements Sh
 | 
				
			|||||||
    private void warmUpEngine() {
 | 
					    private void warmUpEngine() {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            // warm-up engine
 | 
					            // warm-up engine
 | 
				
			||||||
            MathEngine mathEngine = Locator.getInstance().getEngine().getEngine();
 | 
					            MathEngine mathEngine = Locator.getInstance().getEngine().getMathEngine();
 | 
				
			||||||
            mathEngine.evaluate("1+1");
 | 
					            mathEngine.evaluate("1+1");
 | 
				
			||||||
            mathEngine.evaluate("1*1");
 | 
					            mathEngine.evaluate("1*1");
 | 
				
			||||||
        } catch (Throwable e) {
 | 
					        } catch (Throwable e) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -33,9 +33,9 @@ import android.util.TypedValue;
 | 
				
			|||||||
import android.view.MotionEvent;
 | 
					import android.view.MotionEvent;
 | 
				
			||||||
import android.view.View;
 | 
					import android.view.View;
 | 
				
			||||||
import android.widget.Button;
 | 
					import android.widget.Button;
 | 
				
			||||||
 | 
					import jscl.AngleUnit;
 | 
				
			||||||
 | 
					import jscl.NumeralBase;
 | 
				
			||||||
import org.solovyev.android.Views;
 | 
					import org.solovyev.android.Views;
 | 
				
			||||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
 | 
					 | 
				
			||||||
import org.solovyev.android.calculator.view.AngleUnitsButton;
 | 
					import org.solovyev.android.calculator.view.AngleUnitsButton;
 | 
				
			||||||
import org.solovyev.android.calculator.view.NumeralBasesButton;
 | 
					import org.solovyev.android.calculator.view.NumeralBasesButton;
 | 
				
			||||||
import org.solovyev.android.calculator.view.ScreenMetrics;
 | 
					import org.solovyev.android.calculator.view.ScreenMetrics;
 | 
				
			||||||
@@ -46,9 +46,6 @@ import org.solovyev.android.views.dragbutton.SimpleDragListener;
 | 
				
			|||||||
import javax.annotation.Nonnull;
 | 
					import javax.annotation.Nonnull;
 | 
				
			||||||
import javax.annotation.Nullable;
 | 
					import javax.annotation.Nullable;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import jscl.AngleUnit;
 | 
					 | 
				
			||||||
import jscl.NumeralBase;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public final class CalculatorButtons {
 | 
					public final class CalculatorButtons {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private CalculatorButtons() {
 | 
					    private CalculatorButtons() {
 | 
				
			||||||
@@ -178,7 +175,7 @@ public final class CalculatorButtons {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                            final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
 | 
					                            final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            final AngleUnit oldAngleUnits = AndroidCalculatorEngine.Preferences.angleUnit.getPreference(preferences);
 | 
					                            final AngleUnit oldAngleUnits = Engine.Preferences.angleUnit.getPreference(preferences);
 | 
				
			||||||
                            if (oldAngleUnits != angleUnits) {
 | 
					                            if (oldAngleUnits != angleUnits) {
 | 
				
			||||||
                                Locator.getInstance().getPreferenceService().setAngleUnits(angleUnits);
 | 
					                                Locator.getInstance().getPreferenceService().setAngleUnits(angleUnits);
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
@@ -218,7 +215,7 @@ public final class CalculatorButtons {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                        final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
 | 
					                        final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        final NumeralBase oldNumeralBase = AndroidCalculatorEngine.Preferences.numeralBase.getPreference(preferences);
 | 
					                        final NumeralBase oldNumeralBase = Engine.Preferences.numeralBase.getPreference(preferences);
 | 
				
			||||||
                        if (oldNumeralBase != numeralBase) {
 | 
					                        if (oldNumeralBase != numeralBase) {
 | 
				
			||||||
                            Locator.getInstance().getPreferenceService().setNumeralBase(numeralBase);
 | 
					                            Locator.getInstance().getPreferenceService().setNumeralBase(numeralBase);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,67 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * 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 jscl.AngleUnit;
 | 
					 | 
				
			||||||
import jscl.MathEngine;
 | 
					 | 
				
			||||||
import jscl.NumeralBase;
 | 
					 | 
				
			||||||
import jscl.math.function.Function;
 | 
					 | 
				
			||||||
import jscl.math.function.IConstant;
 | 
					 | 
				
			||||||
import jscl.math.operator.Operator;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import javax.annotation.Nonnull;
 | 
					 | 
				
			||||||
import java.text.DecimalFormatSymbols;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public interface CalculatorEngine {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    void init();
 | 
					 | 
				
			||||||
    void reset();
 | 
					 | 
				
			||||||
    void softReset();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					 | 
				
			||||||
    EntitiesRegistry<IConstant> getVarsRegistry();
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					 | 
				
			||||||
    EntitiesRegistry<Function> getFunctionsRegistry();
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					 | 
				
			||||||
    EntitiesRegistry<Operator> getOperatorsRegistry();
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					 | 
				
			||||||
    EntitiesRegistry<Operator> getPostfixFunctionsRegistry();
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					 | 
				
			||||||
    MathEngine getEngine();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					 | 
				
			||||||
    String getMultiplicationSign();
 | 
					 | 
				
			||||||
    void setMultiplicationSign(@Nonnull String multiplicationSign);
 | 
					 | 
				
			||||||
    void setUseGroupingSeparator(boolean useGroupingSeparator);
 | 
					 | 
				
			||||||
    void setGroupingSeparator(char groupingSeparator);
 | 
					 | 
				
			||||||
    void setPrecision(@Nonnull Integer precision);
 | 
					 | 
				
			||||||
    void setRoundResult(@Nonnull Boolean round);
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					 | 
				
			||||||
    AngleUnit getAngleUnits();
 | 
					 | 
				
			||||||
    void setAngleUnits(@Nonnull AngleUnit angleUnits);
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					 | 
				
			||||||
    NumeralBase getNumeralBase();
 | 
					 | 
				
			||||||
    void setNumeralBase(@Nonnull NumeralBase numeralBase);
 | 
					 | 
				
			||||||
    void setScienceNotation(@Nonnull Boolean scienceNotation);
 | 
					 | 
				
			||||||
    void setDecimalGroupSymbols(@Nonnull DecimalFormatSymbols decimalGroupSymbols);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,262 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * 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 jscl.AngleUnit;
 | 
					 | 
				
			||||||
import jscl.JsclMathEngine;
 | 
					 | 
				
			||||||
import jscl.MathEngine;
 | 
					 | 
				
			||||||
import jscl.NumeralBase;
 | 
					 | 
				
			||||||
import jscl.math.function.Function;
 | 
					 | 
				
			||||||
import jscl.math.function.IConstant;
 | 
					 | 
				
			||||||
import jscl.math.operator.Operator;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import javax.annotation.Nonnull;
 | 
					 | 
				
			||||||
import javax.annotation.Nullable;
 | 
					 | 
				
			||||||
import java.text.DecimalFormatSymbols;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class CalculatorEngineImpl implements CalculatorEngine {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/*
 | 
					 | 
				
			||||||
    **********************************************************************
 | 
					 | 
				
			||||||
	*
 | 
					 | 
				
			||||||
	*                           CONSTANTS
 | 
					 | 
				
			||||||
	*
 | 
					 | 
				
			||||||
	**********************************************************************
 | 
					 | 
				
			||||||
	*/
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private static final String MULTIPLICATION_SIGN_DEFAULT = "×";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /*
 | 
					 | 
				
			||||||
    **********************************************************************
 | 
					 | 
				
			||||||
    *
 | 
					 | 
				
			||||||
    *                           ENGINE/REGISTRIES
 | 
					 | 
				
			||||||
    *
 | 
					 | 
				
			||||||
    **********************************************************************
 | 
					 | 
				
			||||||
    */
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					 | 
				
			||||||
    private final MathEngine engine;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					 | 
				
			||||||
    private final EntitiesRegistry<IConstant> varsRegistry;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					 | 
				
			||||||
    private final EntitiesRegistry<Function> functionsRegistry;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					 | 
				
			||||||
    private final EntitiesRegistry<Operator> operatorsRegistry;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					 | 
				
			||||||
    private final EntitiesRegistry<Operator> postfixFunctionsRegistry;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					 | 
				
			||||||
    private final Object lock;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/*
 | 
					 | 
				
			||||||
	**********************************************************************
 | 
					 | 
				
			||||||
	*
 | 
					 | 
				
			||||||
	*                           PREFERENCES
 | 
					 | 
				
			||||||
	*
 | 
					 | 
				
			||||||
	**********************************************************************
 | 
					 | 
				
			||||||
	*/
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					 | 
				
			||||||
    private String multiplicationSign = MULTIPLICATION_SIGN_DEFAULT;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public CalculatorEngineImpl(@Nonnull JsclMathEngine engine,
 | 
					 | 
				
			||||||
                                @Nonnull EntitiesRegistry<IConstant> varsRegistry,
 | 
					 | 
				
			||||||
                                @Nonnull EntitiesRegistry<Function> functionsRegistry,
 | 
					 | 
				
			||||||
                                @Nonnull EntitiesRegistry<Operator> operatorsRegistry,
 | 
					 | 
				
			||||||
                                @Nonnull EntitiesRegistry<Operator> postfixFunctionsRegistry,
 | 
					 | 
				
			||||||
                                @Nullable Object lock) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        this.engine = engine;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        this.engine.setRoundResult(true);
 | 
					 | 
				
			||||||
        this.engine.setUseGroupingSeparator(true);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        this.varsRegistry = varsRegistry;
 | 
					 | 
				
			||||||
        this.functionsRegistry = functionsRegistry;
 | 
					 | 
				
			||||||
        this.operatorsRegistry = operatorsRegistry;
 | 
					 | 
				
			||||||
        this.postfixFunctionsRegistry = postfixFunctionsRegistry;
 | 
					 | 
				
			||||||
        this.lock = lock == null ? new Object() : lock;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /*
 | 
					 | 
				
			||||||
    **********************************************************************
 | 
					 | 
				
			||||||
    *
 | 
					 | 
				
			||||||
    *                           REGISTRIES
 | 
					 | 
				
			||||||
    *
 | 
					 | 
				
			||||||
    **********************************************************************
 | 
					 | 
				
			||||||
    */
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public EntitiesRegistry<IConstant> getVarsRegistry() {
 | 
					 | 
				
			||||||
        return this.varsRegistry;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public EntitiesRegistry<Function> getFunctionsRegistry() {
 | 
					 | 
				
			||||||
        return this.functionsRegistry;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public EntitiesRegistry<Operator> getOperatorsRegistry() {
 | 
					 | 
				
			||||||
        return this.operatorsRegistry;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public EntitiesRegistry<Operator> getPostfixFunctionsRegistry() {
 | 
					 | 
				
			||||||
        return this.postfixFunctionsRegistry;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public MathEngine getEngine() {
 | 
					 | 
				
			||||||
        return engine;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /*
 | 
					 | 
				
			||||||
	**********************************************************************
 | 
					 | 
				
			||||||
	*
 | 
					 | 
				
			||||||
	*                           INIT
 | 
					 | 
				
			||||||
	*
 | 
					 | 
				
			||||||
	**********************************************************************
 | 
					 | 
				
			||||||
	*/
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void init() {
 | 
					 | 
				
			||||||
        synchronized (lock) {
 | 
					 | 
				
			||||||
            reset();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void reset() {
 | 
					 | 
				
			||||||
        synchronized (lock) {
 | 
					 | 
				
			||||||
            safeLoadRegistry(varsRegistry);
 | 
					 | 
				
			||||||
            safeLoadRegistry(functionsRegistry);
 | 
					 | 
				
			||||||
            safeLoadRegistry(operatorsRegistry);
 | 
					 | 
				
			||||||
            safeLoadRegistry(postfixFunctionsRegistry);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private void safeLoadRegistry(@Nonnull EntitiesRegistry<?> registry) {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            registry.load();
 | 
					 | 
				
			||||||
        } catch (Exception e) {
 | 
					 | 
				
			||||||
            Locator.getInstance().getErrorReporter().onException(e);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void softReset() {
 | 
					 | 
				
			||||||
        Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.engine_preferences_changed, null);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getMultiplicationSign() {
 | 
					 | 
				
			||||||
        return this.multiplicationSign;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setMultiplicationSign(@Nonnull String multiplicationSign) {
 | 
					 | 
				
			||||||
        this.multiplicationSign = multiplicationSign;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setUseGroupingSeparator(boolean useGroupingSeparator) {
 | 
					 | 
				
			||||||
        synchronized (lock) {
 | 
					 | 
				
			||||||
            this.engine.setUseGroupingSeparator(true);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setGroupingSeparator(char groupingSeparator) {
 | 
					 | 
				
			||||||
        synchronized (lock) {
 | 
					 | 
				
			||||||
            this.engine.setGroupingSeparator(groupingSeparator);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPrecision(@Nonnull Integer precision) {
 | 
					 | 
				
			||||||
        synchronized (lock) {
 | 
					 | 
				
			||||||
            this.engine.setPrecision(precision);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setRoundResult(@Nonnull Boolean round) {
 | 
					 | 
				
			||||||
        synchronized (lock) {
 | 
					 | 
				
			||||||
            this.engine.setRoundResult(round);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public AngleUnit getAngleUnits() {
 | 
					 | 
				
			||||||
        synchronized (lock) {
 | 
					 | 
				
			||||||
            return this.engine.getAngleUnits();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setAngleUnits(@Nonnull AngleUnit angleUnits) {
 | 
					 | 
				
			||||||
        synchronized (lock) {
 | 
					 | 
				
			||||||
            this.engine.setAngleUnits(angleUnits);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public NumeralBase getNumeralBase() {
 | 
					 | 
				
			||||||
        synchronized (lock) {
 | 
					 | 
				
			||||||
            return this.engine.getNumeralBase();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setNumeralBase(@Nonnull NumeralBase numeralBase) {
 | 
					 | 
				
			||||||
        synchronized (lock) {
 | 
					 | 
				
			||||||
            this.engine.setNumeralBase(numeralBase);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setScienceNotation(@Nonnull Boolean scienceNotation) {
 | 
					 | 
				
			||||||
        synchronized (lock) {
 | 
					 | 
				
			||||||
            this.engine.setScienceNotation(scienceNotation);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setDecimalGroupSymbols(@Nonnull DecimalFormatSymbols decimalGroupSymbols) {
 | 
					 | 
				
			||||||
        synchronized (lock) {
 | 
					 | 
				
			||||||
            this.engine.setDecimalGroupSymbols(decimalGroupSymbols);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -255,10 +255,10 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                try {
 | 
					                try {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    final MathEngine mathEngine = Locator.getInstance().getEngine().getEngine();
 | 
					                    final MathEngine mathEngine = Locator.getInstance().getEngine().getMathEngine();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    final MessageRegistry messageRegistry = new ListMessageRegistry();
 | 
					                    final MessageRegistry messageRegistry = new ListMessageRegistry();
 | 
				
			||||||
                    Locator.getInstance().getEngine().getEngine().setMessageRegistry(messageRegistry);
 | 
					                    Locator.getInstance().getEngine().getMathEngine().setMessageRegistry(messageRegistry);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    final Generic result = operation.evaluateGeneric(jsclExpression, mathEngine);
 | 
					                    final Generic result = operation.evaluateGeneric(jsclExpression, mathEngine);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -496,14 +496,14 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
 | 
				
			|||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        final EntitiesRegistry<IConstant> varsRegistry = Locator.getInstance().getEngine().getVarsRegistry();
 | 
					        final EntitiesRegistry<IConstant> varsRegistry = Locator.getInstance().getEngine().getVarsRegistry();
 | 
				
			||||||
        final IConstant ansVar = varsRegistry.get(CalculatorVarsRegistry.ANS);
 | 
					        final IConstant ansVar = varsRegistry.get(VarsRegistry.ANS);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        final Var.Builder builder = ansVar != null ? new Var.Builder(ansVar) : new Var.Builder();
 | 
					        final Var.Builder builder = ansVar != null ? new Var.Builder(ansVar) : new Var.Builder();
 | 
				
			||||||
        builder.setName(CalculatorVarsRegistry.ANS);
 | 
					        builder.setName(VarsRegistry.ANS);
 | 
				
			||||||
        builder.setValue(text);
 | 
					        builder.setValue(text);
 | 
				
			||||||
        builder.setDescription(CalculatorMessages.getBundle().getString(CalculatorMessages.ans_description));
 | 
					        builder.setDescription(CalculatorMessages.getBundle().getString(CalculatorMessages.ans_description));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        CalculatorVarsRegistry.saveVariable(varsRegistry, builder, ansVar, this, false);
 | 
					        VarsRegistry.saveVariable(varsRegistry, builder, ansVar, this, false);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
@@ -512,7 +512,7 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
 | 
				
			|||||||
        switch (calculatorEventType) {
 | 
					        switch (calculatorEventType) {
 | 
				
			||||||
            case constant_changed:
 | 
					            case constant_changed:
 | 
				
			||||||
                final IConstant newConstant = ((Change<IConstant>) data).getNewValue();
 | 
					                final IConstant newConstant = ((Change<IConstant>) data).getNewValue();
 | 
				
			||||||
                if (!newConstant.getName().equals(CalculatorVarsRegistry.ANS)) {
 | 
					                if (!newConstant.getName().equals(VarsRegistry.ANS)) {
 | 
				
			||||||
                    evaluate();
 | 
					                    evaluate();
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -34,8 +34,8 @@ import javax.annotation.Nonnull;
 | 
				
			|||||||
import static org.solovyev.android.calculator.NumeralBaseButtons.toggleNumericDigits;
 | 
					import static org.solovyev.android.calculator.NumeralBaseButtons.toggleNumericDigits;
 | 
				
			||||||
import static org.solovyev.android.calculator.Preferences.Gui.hideNumeralBaseDigits;
 | 
					import static org.solovyev.android.calculator.Preferences.Gui.hideNumeralBaseDigits;
 | 
				
			||||||
import static org.solovyev.android.calculator.Preferences.Gui.showEqualsButton;
 | 
					import static org.solovyev.android.calculator.Preferences.Gui.showEqualsButton;
 | 
				
			||||||
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.multiplicationSign;
 | 
					import static org.solovyev.android.calculator.Engine.Preferences.multiplicationSign;
 | 
				
			||||||
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.numeralBase;
 | 
					import static org.solovyev.android.calculator.Engine.Preferences.numeralBase;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * User: Solovyev_S
 | 
					 * User: Solovyev_S
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,7 +29,7 @@ import javax.annotation.Nonnull;
 | 
				
			|||||||
public interface CalculatorLocator {
 | 
					public interface CalculatorLocator {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void init(@Nonnull Calculator calculator,
 | 
					    void init(@Nonnull Calculator calculator,
 | 
				
			||||||
              @Nonnull CalculatorEngine engine,
 | 
					              @Nonnull Engine engine,
 | 
				
			||||||
              @Nonnull CalculatorClipboard clipboard,
 | 
					              @Nonnull CalculatorClipboard clipboard,
 | 
				
			||||||
              @Nonnull CalculatorNotifier notifier,
 | 
					              @Nonnull CalculatorNotifier notifier,
 | 
				
			||||||
              @Nonnull ErrorReporter errorReporter,
 | 
					              @Nonnull ErrorReporter errorReporter,
 | 
				
			||||||
@@ -41,7 +41,7 @@ public interface CalculatorLocator {
 | 
				
			|||||||
    Calculator getCalculator();
 | 
					    Calculator getCalculator();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Nonnull
 | 
					    @Nonnull
 | 
				
			||||||
    CalculatorEngine getEngine();
 | 
					    Engine getEngine();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Nonnull
 | 
					    @Nonnull
 | 
				
			||||||
    Keyboard getKeyboard();
 | 
					    Keyboard getKeyboard();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,7 +20,7 @@
 | 
				
			|||||||
 * Site:  http://se.solovyev.org
 | 
					 * Site:  http://se.solovyev.org
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package org.solovyev.android.calculator.model;
 | 
					package org.solovyev.android.calculator;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import android.app.Application;
 | 
					import android.app.Application;
 | 
				
			||||||
import android.content.Context;
 | 
					import android.content.Context;
 | 
				
			||||||
@@ -33,7 +33,9 @@ import jscl.NumeralBase;
 | 
				
			|||||||
import jscl.math.function.Function;
 | 
					import jscl.math.function.Function;
 | 
				
			||||||
import jscl.math.function.IConstant;
 | 
					import jscl.math.function.IConstant;
 | 
				
			||||||
import jscl.math.operator.Operator;
 | 
					import jscl.math.operator.Operator;
 | 
				
			||||||
import org.solovyev.android.calculator.*;
 | 
					import org.solovyev.android.calculator.model.AndroidMathEntityDao;
 | 
				
			||||||
 | 
					import org.solovyev.android.calculator.model.Functions;
 | 
				
			||||||
 | 
					import org.solovyev.android.calculator.model.Vars;
 | 
				
			||||||
import org.solovyev.android.prefs.BooleanPreference;
 | 
					import org.solovyev.android.prefs.BooleanPreference;
 | 
				
			||||||
import org.solovyev.android.prefs.Preference;
 | 
					import org.solovyev.android.prefs.Preference;
 | 
				
			||||||
import org.solovyev.android.prefs.StringPreference;
 | 
					import org.solovyev.android.prefs.StringPreference;
 | 
				
			||||||
@@ -47,18 +49,13 @@ import java.util.ArrayList;
 | 
				
			|||||||
import java.util.Collections;
 | 
					import java.util.Collections;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					public class Engine implements SharedPreferences.OnSharedPreferenceChangeListener {
 | 
				
			||||||
 * User: serso
 | 
					 | 
				
			||||||
 * Date: 9/12/11
 | 
					 | 
				
			||||||
 * Time: 11:38 PM
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class AndroidCalculatorEngine implements CalculatorEngine, SharedPreferences.OnSharedPreferenceChangeListener {
 | 
					    private static final String MULTIPLICATION_SIGN_DEFAULT = "×";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static final String GROUPING_SEPARATOR_P_KEY = "org.solovyev.android.calculator.CalculatorActivity_calc_grouping_separator";
 | 
					    private static final String GROUPING_SEPARATOR_P_KEY = "org.solovyev.android.calculator.CalculatorActivity_calc_grouping_separator";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static final String MULTIPLICATION_SIGN_P_KEY = "org.solovyev.android.calculator.CalculatorActivity_calc_multiplication_sign";
 | 
					    private static final String MULTIPLICATION_SIGN_P_KEY = "org.solovyev.android.calculator.CalculatorActivity_calc_multiplication_sign";
 | 
				
			||||||
    private static final String MULTIPLICATION_SIGN_DEFAULT = "×";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static final String SCIENCE_NOTATION_P_KEY = "calculation.output.science_notation";
 | 
					    private static final String SCIENCE_NOTATION_P_KEY = "calculation.output.science_notation";
 | 
				
			||||||
    private static final boolean SCIENCE_NOTATION_DEFAULT = false;
 | 
					    private static final boolean SCIENCE_NOTATION_DEFAULT = false;
 | 
				
			||||||
@@ -77,24 +74,44 @@ public class AndroidCalculatorEngine implements CalculatorEngine, SharedPreferen
 | 
				
			|||||||
    @Nonnull
 | 
					    @Nonnull
 | 
				
			||||||
    private final Context context;
 | 
					    private final Context context;
 | 
				
			||||||
    @Nonnull
 | 
					    @Nonnull
 | 
				
			||||||
    private final CalculatorEngine calculatorEngine;
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					 | 
				
			||||||
    private final Object lock;
 | 
					    private final Object lock;
 | 
				
			||||||
 | 
					    @Nonnull
 | 
				
			||||||
 | 
					    private final MathEngine mathEngine;
 | 
				
			||||||
 | 
					    @Nonnull
 | 
				
			||||||
 | 
					    private final EntitiesRegistry<IConstant> varsRegistry;
 | 
				
			||||||
 | 
					    @Nonnull
 | 
				
			||||||
 | 
					    private final EntitiesRegistry<Function> functionsRegistry;
 | 
				
			||||||
 | 
					    @Nonnull
 | 
				
			||||||
 | 
					    private final EntitiesRegistry<Operator> operatorsRegistry;
 | 
				
			||||||
 | 
					    @Nonnull
 | 
				
			||||||
 | 
					    private final EntitiesRegistry<Operator> postfixFunctionsRegistry;
 | 
				
			||||||
 | 
					    @Nonnull
 | 
				
			||||||
 | 
					    private String multiplicationSign = MULTIPLICATION_SIGN_DEFAULT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public AndroidCalculatorEngine(@Nonnull Application application) {
 | 
					    public Engine(@Nonnull Context context, @Nonnull MathEngine mathEngine, @Nonnull EntitiesRegistry<IConstant> varsRegistry, @Nonnull EntitiesRegistry<Function> functionsRegistry, @Nonnull EntitiesRegistry<Operator> operatorsRegistry, @Nonnull EntitiesRegistry<Operator> postfixFunctionsRegistry) {
 | 
				
			||||||
 | 
					        this.context = context;
 | 
				
			||||||
 | 
					        this.lock = new Object();
 | 
				
			||||||
 | 
					        this.mathEngine = mathEngine;
 | 
				
			||||||
 | 
					        this.varsRegistry = varsRegistry;
 | 
				
			||||||
 | 
					        this.functionsRegistry = functionsRegistry;
 | 
				
			||||||
 | 
					        this.operatorsRegistry = operatorsRegistry;
 | 
				
			||||||
 | 
					        this.postfixFunctionsRegistry = postfixFunctionsRegistry;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Engine(@Nonnull Application application) {
 | 
				
			||||||
 | 
					        this.mathEngine = JsclMathEngine.getInstance();
 | 
				
			||||||
        this.context = application;
 | 
					        this.context = application;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        PreferenceManager.getDefaultSharedPreferences(application).registerOnSharedPreferenceChangeListener(this);
 | 
					        PreferenceManager.getDefaultSharedPreferences(application).registerOnSharedPreferenceChangeListener(this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.lock = new Object();
 | 
					        this.lock = new Object();
 | 
				
			||||||
 | 
					        this.mathEngine.setRoundResult(true);
 | 
				
			||||||
 | 
					        this.mathEngine.setUseGroupingSeparator(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        final JsclMathEngine engine = JsclMathEngine.getInstance();
 | 
					        this.varsRegistry = new VarsRegistry(mathEngine.getConstantsRegistry(), new AndroidMathEntityDao<>("org.solovyev.android.calculator.CalculatorModel_vars", application, Vars.class));
 | 
				
			||||||
        this.calculatorEngine = new CalculatorEngineImpl(engine,
 | 
					        this.functionsRegistry = new FunctionsRegistry(mathEngine.getFunctionsRegistry(), new AndroidMathEntityDao<>("org.solovyev.android.calculator.CalculatorModel_functions", application, Functions.class));
 | 
				
			||||||
                new CalculatorVarsRegistry(engine.getConstantsRegistry(), new AndroidMathEntityDao<Var>("org.solovyev.android.calculator.CalculatorModel_vars", application, Vars.class)),
 | 
					        this.operatorsRegistry = new OperatorsRegistry(mathEngine.getOperatorsRegistry(), new AndroidMathEntityDao<>(null, application, null));
 | 
				
			||||||
                new FunctionsRegistry(engine.getFunctionsRegistry(), new AndroidMathEntityDao<AFunction>("org.solovyev.android.calculator.CalculatorModel_functions", application, Functions.class)),
 | 
					        this.postfixFunctionsRegistry = new PostfixFunctionsRegistry(mathEngine.getPostfixFunctionsRegistry(), new AndroidMathEntityDao<>(null, application, null));
 | 
				
			||||||
                new CalculatorOperatorsMathRegistry(engine.getOperatorsRegistry(), new AndroidMathEntityDao<MathPersistenceEntity>(null, application, null)),
 | 
					 | 
				
			||||||
                new CalculatorPostfixFunctionsRegistry(engine.getPostfixFunctionsRegistry(), new AndroidMathEntityDao<MathPersistenceEntity>(null, application, null)),
 | 
					 | 
				
			||||||
                this.lock);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Nonnull
 | 
					    @Nonnull
 | 
				
			||||||
@@ -107,147 +124,147 @@ public class AndroidCalculatorEngine implements CalculatorEngine, SharedPreferen
 | 
				
			|||||||
        return Preferences.angleUnit.getPreference(preferences);
 | 
					        return Preferences.angleUnit.getPreference(preferences);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					    @Nonnull
 | 
				
			||||||
    public EntitiesRegistry<IConstant> getVarsRegistry() {
 | 
					    public EntitiesRegistry<IConstant> getVarsRegistry() {
 | 
				
			||||||
        return calculatorEngine.getVarsRegistry();
 | 
					        return this.varsRegistry;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					    @Nonnull
 | 
				
			||||||
    public EntitiesRegistry<Function> getFunctionsRegistry() {
 | 
					    public EntitiesRegistry<Function> getFunctionsRegistry() {
 | 
				
			||||||
        return calculatorEngine.getFunctionsRegistry();
 | 
					        return this.functionsRegistry;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					    @Nonnull
 | 
				
			||||||
    public EntitiesRegistry<Operator> getOperatorsRegistry() {
 | 
					    public EntitiesRegistry<Operator> getOperatorsRegistry() {
 | 
				
			||||||
        return calculatorEngine.getOperatorsRegistry();
 | 
					        return this.operatorsRegistry;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					    @Nonnull
 | 
				
			||||||
    public EntitiesRegistry<Operator> getPostfixFunctionsRegistry() {
 | 
					    public EntitiesRegistry<Operator> getPostfixFunctionsRegistry() {
 | 
				
			||||||
        return calculatorEngine.getPostfixFunctionsRegistry();
 | 
					        return this.postfixFunctionsRegistry;
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					 | 
				
			||||||
    public MathEngine getEngine() {
 | 
					 | 
				
			||||||
        return calculatorEngine.getEngine();
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Nonnull
 | 
					    @Nonnull
 | 
				
			||||||
    @Override
 | 
					    public MathEngine getMathEngine() {
 | 
				
			||||||
    public NumeralBase getNumeralBase() {
 | 
					        return mathEngine;
 | 
				
			||||||
        return calculatorEngine.getNumeralBase();
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setNumeralBase(@Nonnull NumeralBase numeralBase) {
 | 
					 | 
				
			||||||
        calculatorEngine.setNumeralBase(numeralBase);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void init() {
 | 
					    public void init() {
 | 
				
			||||||
        synchronized (lock) {
 | 
					 | 
				
			||||||
            reset();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void reset() {
 | 
					 | 
				
			||||||
        synchronized (lock) {
 | 
					        synchronized (lock) {
 | 
				
			||||||
            final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
 | 
					            final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
 | 
				
			||||||
 | 
					            resetPreferences(preferences);
 | 
				
			||||||
            softReset(preferences);
 | 
					            safeLoadRegistry(varsRegistry);
 | 
				
			||||||
 | 
					            safeLoadRegistry(functionsRegistry);
 | 
				
			||||||
            calculatorEngine.reset();
 | 
					            safeLoadRegistry(operatorsRegistry);
 | 
				
			||||||
 | 
					            safeLoadRegistry(postfixFunctionsRegistry);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    public void resetPreferences() {
 | 
				
			||||||
    public void softReset() {
 | 
					        resetPreferences(App.getPreferences());
 | 
				
			||||||
        synchronized (lock) {
 | 
					    }
 | 
				
			||||||
            softReset(PreferenceManager.getDefaultSharedPreferences(context));
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            calculatorEngine.softReset();
 | 
					    private void safeLoadRegistry(@Nonnull EntitiesRegistry<?> registry) {
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            registry.load();
 | 
				
			||||||
 | 
					        } catch (Exception e) {
 | 
				
			||||||
 | 
					            Locator.getInstance().getErrorReporter().onException(e);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    private void resetPreferences(@Nonnull SharedPreferences preferences) {
 | 
				
			||||||
    public void setUseGroupingSeparator(boolean useGroupingSeparator) {
 | 
					        setPrecision(Preferences.precision.getPreference(preferences));
 | 
				
			||||||
        calculatorEngine.setUseGroupingSeparator(useGroupingSeparator);
 | 
					        setRoundResult(Preferences.roundResult.getPreference(preferences));
 | 
				
			||||||
    }
 | 
					        setAngleUnits(getAngleUnitsFromPrefs(preferences));
 | 
				
			||||||
 | 
					        setNumeralBase(getNumeralBaseFromPrefs(preferences));
 | 
				
			||||||
    @Override
 | 
					        setMultiplicationSign(Preferences.multiplicationSign.getPreference(preferences));
 | 
				
			||||||
    public void setGroupingSeparator(char groupingSeparator) {
 | 
					        setScienceNotation(Preferences.scienceNotation.getPreference(preferences));
 | 
				
			||||||
        calculatorEngine.setGroupingSeparator(groupingSeparator);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPrecision(@Nonnull Integer precision) {
 | 
					 | 
				
			||||||
        calculatorEngine.setPrecision(precision);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setRoundResult(@Nonnull Boolean round) {
 | 
					 | 
				
			||||||
        calculatorEngine.setRoundResult(round);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public AngleUnit getAngleUnits() {
 | 
					 | 
				
			||||||
        return calculatorEngine.getAngleUnits();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setAngleUnits(@Nonnull AngleUnit angleUnits) {
 | 
					 | 
				
			||||||
        calculatorEngine.setAngleUnits(angleUnits);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setScienceNotation(@Nonnull Boolean scienceNotation) {
 | 
					 | 
				
			||||||
        calculatorEngine.setScienceNotation(scienceNotation);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private void softReset(@Nonnull SharedPreferences preferences) {
 | 
					 | 
				
			||||||
        this.setPrecision(Preferences.precision.getPreference(preferences));
 | 
					 | 
				
			||||||
        this.setRoundResult(Preferences.roundResult.getPreference(preferences));
 | 
					 | 
				
			||||||
        this.setAngleUnits(getAngleUnitsFromPrefs(preferences));
 | 
					 | 
				
			||||||
        this.setNumeralBase(getNumeralBaseFromPrefs(preferences));
 | 
					 | 
				
			||||||
        this.setMultiplicationSign(Preferences.multiplicationSign.getPreference(preferences));
 | 
					 | 
				
			||||||
        this.setScienceNotation(Preferences.scienceNotation.getPreference(preferences));
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        final String groupingSeparator = Preferences.groupingSeparator.getPreference(preferences);
 | 
					        final String groupingSeparator = Preferences.groupingSeparator.getPreference(preferences);
 | 
				
			||||||
        if (Strings.isEmpty(groupingSeparator)) {
 | 
					        if (Strings.isEmpty(groupingSeparator)) {
 | 
				
			||||||
            this.setUseGroupingSeparator(false);
 | 
					            setUseGroupingSeparator(false);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            this.setUseGroupingSeparator(true);
 | 
					            setUseGroupingSeparator(true);
 | 
				
			||||||
            setGroupingSeparator(groupingSeparator.charAt(0));
 | 
					            setGroupingSeparator(groupingSeparator.charAt(0));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.engine_preferences_changed, null);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //for tests only
 | 
					 | 
				
			||||||
    public void setDecimalGroupSymbols(@Nonnull DecimalFormatSymbols decimalGroupSymbols) {
 | 
					 | 
				
			||||||
        this.calculatorEngine.setDecimalGroupSymbols(decimalGroupSymbols);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    @Nonnull
 | 
					    @Nonnull
 | 
				
			||||||
    public String getMultiplicationSign() {
 | 
					    public String getMultiplicationSign() {
 | 
				
			||||||
        return calculatorEngine.getMultiplicationSign();
 | 
					        return this.multiplicationSign;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setMultiplicationSign(@Nonnull String multiplicationSign) {
 | 
					    public void setMultiplicationSign(@Nonnull String multiplicationSign) {
 | 
				
			||||||
        calculatorEngine.setMultiplicationSign(multiplicationSign);
 | 
					        this.multiplicationSign = multiplicationSign;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setUseGroupingSeparator(boolean useGroupingSeparator) {
 | 
				
			||||||
 | 
					        synchronized (lock) {
 | 
				
			||||||
 | 
					            this.mathEngine.setUseGroupingSeparator(useGroupingSeparator);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setGroupingSeparator(char groupingSeparator) {
 | 
				
			||||||
 | 
					        synchronized (lock) {
 | 
				
			||||||
 | 
					            this.mathEngine.setGroupingSeparator(groupingSeparator);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setPrecision(@Nonnull Integer precision) {
 | 
				
			||||||
 | 
					        synchronized (lock) {
 | 
				
			||||||
 | 
					            this.mathEngine.setPrecision(precision);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setRoundResult(@Nonnull Boolean round) {
 | 
				
			||||||
 | 
					        synchronized (lock) {
 | 
				
			||||||
 | 
					            this.mathEngine.setRoundResult(round);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Nonnull
 | 
				
			||||||
 | 
					    public AngleUnit getAngleUnits() {
 | 
				
			||||||
 | 
					        synchronized (lock) {
 | 
				
			||||||
 | 
					            return this.mathEngine.getAngleUnits();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setAngleUnits(@Nonnull AngleUnit angleUnits) {
 | 
				
			||||||
 | 
					        synchronized (lock) {
 | 
				
			||||||
 | 
					            this.mathEngine.setAngleUnits(angleUnits);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Nonnull
 | 
				
			||||||
 | 
					    public NumeralBase getNumeralBase() {
 | 
				
			||||||
 | 
					        synchronized (lock) {
 | 
				
			||||||
 | 
					            return this.mathEngine.getNumeralBase();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setNumeralBase(@Nonnull NumeralBase numeralBase) {
 | 
				
			||||||
 | 
					        synchronized (lock) {
 | 
				
			||||||
 | 
					            this.mathEngine.setNumeralBase(numeralBase);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setScienceNotation(@Nonnull Boolean scienceNotation) {
 | 
				
			||||||
 | 
					        synchronized (lock) {
 | 
				
			||||||
 | 
					            this.mathEngine.setScienceNotation(scienceNotation);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setDecimalGroupSymbols(@Nonnull DecimalFormatSymbols decimalGroupSymbols) {
 | 
				
			||||||
 | 
					        synchronized (lock) {
 | 
				
			||||||
 | 
					            this.mathEngine.setDecimalGroupSymbols(decimalGroupSymbols);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
 | 
					    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
 | 
				
			||||||
        if (Preferences.getPreferenceKeys().contains(key)) {
 | 
					        if (Preferences.getPreferenceKeys().contains(key)) {
 | 
				
			||||||
            this.softReset();
 | 
					            this.resetPreferences();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -260,7 +277,7 @@ public class AndroidCalculatorEngine implements CalculatorEngine, SharedPreferen
 | 
				
			|||||||
        public static final Preference<AngleUnit> angleUnit = StringPreference.ofTypedValue(ANGLE_UNITS_P_KEY, ANGLE_UNITS_DEFAULT, EnumMapper.of(AngleUnit.class));
 | 
					        public static final Preference<AngleUnit> angleUnit = StringPreference.ofTypedValue(ANGLE_UNITS_P_KEY, ANGLE_UNITS_DEFAULT, EnumMapper.of(AngleUnit.class));
 | 
				
			||||||
        public static final Preference<Boolean> scienceNotation = BooleanPreference.of(SCIENCE_NOTATION_P_KEY, SCIENCE_NOTATION_DEFAULT);
 | 
					        public static final Preference<Boolean> scienceNotation = BooleanPreference.of(SCIENCE_NOTATION_P_KEY, SCIENCE_NOTATION_DEFAULT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private static final List<String> preferenceKeys = new ArrayList<String>();
 | 
					        private static final List<String> preferenceKeys = new ArrayList<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        static {
 | 
					        static {
 | 
				
			||||||
            preferenceKeys.add(groupingSeparator.getKey());
 | 
					            preferenceKeys.add(groupingSeparator.getKey());
 | 
				
			||||||
@@ -277,5 +294,4 @@ public class AndroidCalculatorEngine implements CalculatorEngine, SharedPreferen
 | 
				
			|||||||
            return Collections.unmodifiableList(preferenceKeys);
 | 
					            return Collections.unmodifiableList(preferenceKeys);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -37,6 +37,7 @@ import org.solovyev.common.text.Strings;
 | 
				
			|||||||
import javax.annotation.Nonnull;
 | 
					import javax.annotation.Nonnull;
 | 
				
			||||||
import javax.annotation.Nullable;
 | 
					import javax.annotation.Nullable;
 | 
				
			||||||
import java.util.Arrays;
 | 
					import java.util.Arrays;
 | 
				
			||||||
 | 
					import java.util.Collections;
 | 
				
			||||||
import java.util.HashMap;
 | 
					import java.util.HashMap;
 | 
				
			||||||
import java.util.Map;
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -76,11 +77,11 @@ public class FunctionsRegistry extends BaseEntitiesRegistry<Function, AFunction>
 | 
				
			|||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void load() {
 | 
					    public void load() {
 | 
				
			||||||
        add(new CustomFunction.Builder(true, "log", Arrays.asList("base", "x"), "ln(x)/ln(base)"));
 | 
					        add(new CustomFunction.Builder(true, "log", Arrays.asList("base", "x"), "ln(x)/ln(base)"));
 | 
				
			||||||
        add(new CustomFunction.Builder(true, "√3", Arrays.asList("x"), "x^(1/3)"));
 | 
					        add(new CustomFunction.Builder(true, "√3", Collections.singletonList("x"), "x^(1/3)"));
 | 
				
			||||||
        add(new CustomFunction.Builder(true, "√4", Arrays.asList("x"), "x^(1/4)"));
 | 
					        add(new CustomFunction.Builder(true, "√4", Collections.singletonList("x"), "x^(1/4)"));
 | 
				
			||||||
        add(new CustomFunction.Builder(true, "√n", Arrays.asList("x", "n"), "x^(1/n)"));
 | 
					        add(new CustomFunction.Builder(true, "√n", Arrays.asList("x", "n"), "x^(1/n)"));
 | 
				
			||||||
        add(new CustomFunction.Builder(true, "re", Arrays.asList("x"), "(x+conjugate(x))/2"));
 | 
					        add(new CustomFunction.Builder(true, "re", Collections.singletonList("x"), "(x+conjugate(x))/2"));
 | 
				
			||||||
        add(new CustomFunction.Builder(true, "im", Arrays.asList("x"), "(x-conjugate(x))/(2*i)"));
 | 
					        add(new CustomFunction.Builder(true, "im", Collections.singletonList("x"), "(x-conjugate(x))/(2*i)"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        super.load();
 | 
					        super.load();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -38,7 +38,7 @@ import jscl.NumeralBase;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
public class LiteNumberBuilder extends BaseNumberBuilder {
 | 
					public class LiteNumberBuilder extends BaseNumberBuilder {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public LiteNumberBuilder(@Nonnull CalculatorEngine engine) {
 | 
					    public LiteNumberBuilder(@Nonnull Engine engine) {
 | 
				
			||||||
        super(engine);
 | 
					        super(engine);
 | 
				
			||||||
        this.nb = engine.getNumeralBase();
 | 
					        this.nb = engine.getNumeralBase();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -31,7 +31,7 @@ public class Locator implements CalculatorLocator {
 | 
				
			|||||||
    @Nonnull
 | 
					    @Nonnull
 | 
				
			||||||
    private static final Locator instance = new Locator();
 | 
					    private static final Locator instance = new Locator();
 | 
				
			||||||
    @Nonnull
 | 
					    @Nonnull
 | 
				
			||||||
    private CalculatorEngine calculatorEngine;
 | 
					    private Engine engine;
 | 
				
			||||||
    @Nonnull
 | 
					    @Nonnull
 | 
				
			||||||
    private Calculator calculator;
 | 
					    private Calculator calculator;
 | 
				
			||||||
    @Nonnull
 | 
					    @Nonnull
 | 
				
			||||||
@@ -58,7 +58,7 @@ public class Locator implements CalculatorLocator {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void init(@Nonnull Calculator calculator,
 | 
					    public void init(@Nonnull Calculator calculator,
 | 
				
			||||||
                     @Nonnull CalculatorEngine engine,
 | 
					                     @Nonnull Engine engine,
 | 
				
			||||||
                     @Nonnull CalculatorClipboard clipboard,
 | 
					                     @Nonnull CalculatorClipboard clipboard,
 | 
				
			||||||
                     @Nonnull CalculatorNotifier notifier,
 | 
					                     @Nonnull CalculatorNotifier notifier,
 | 
				
			||||||
                     @Nonnull ErrorReporter errorReporter,
 | 
					                     @Nonnull ErrorReporter errorReporter,
 | 
				
			||||||
@@ -67,7 +67,7 @@ public class Locator implements CalculatorLocator {
 | 
				
			|||||||
                     @Nonnull CalculatorPlotter plotter) {
 | 
					                     @Nonnull CalculatorPlotter plotter) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.calculator = calculator;
 | 
					        this.calculator = calculator;
 | 
				
			||||||
        this.calculatorEngine = engine;
 | 
					        this.engine = engine;
 | 
				
			||||||
        this.calculatorClipboard = clipboard;
 | 
					        this.calculatorClipboard = clipboard;
 | 
				
			||||||
        this.calculatorNotifier = notifier;
 | 
					        this.calculatorNotifier = notifier;
 | 
				
			||||||
        this.errorReporter = errorReporter;
 | 
					        this.errorReporter = errorReporter;
 | 
				
			||||||
@@ -79,8 +79,8 @@ public class Locator implements CalculatorLocator {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Nonnull
 | 
					    @Nonnull
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public CalculatorEngine getEngine() {
 | 
					    public Engine getEngine() {
 | 
				
			||||||
        return calculatorEngine;
 | 
					        return engine;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Nonnull
 | 
					    @Nonnull
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -42,7 +42,7 @@ import java.util.List;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
public class NumberBuilder extends BaseNumberBuilder {
 | 
					public class NumberBuilder extends BaseNumberBuilder {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public NumberBuilder(@Nonnull CalculatorEngine engine) {
 | 
					    public NumberBuilder(@Nonnull Engine engine) {
 | 
				
			||||||
        super(engine);
 | 
					        super(engine);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -183,7 +183,7 @@ public class NumberBuilder extends BaseNumberBuilder {
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                // check if number still valid
 | 
					                // check if number still valid
 | 
				
			||||||
                toDouble(number, getNumeralBase(), engine.getEngine());
 | 
					                toDouble(number, getNumeralBase(), engine.getMathEngine());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            } catch (NumberFormatException e) {
 | 
					            } catch (NumberFormatException e) {
 | 
				
			||||||
                // number is not valid => stop
 | 
					                // number is not valid => stop
 | 
				
			||||||
@@ -196,6 +196,6 @@ public class NumberBuilder extends BaseNumberBuilder {
 | 
				
			|||||||
            nb = engine.getNumeralBase();
 | 
					            nb = engine.getNumeralBase();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return replaceNumberInText(sb, number, trimmedChars, localNb, engine.getEngine());
 | 
					        return replaceNumberInText(sb, number, trimmedChars, localNb, engine.getMathEngine());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,14 +24,13 @@ package org.solovyev.android.calculator;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import android.app.Activity;
 | 
					import android.app.Activity;
 | 
				
			||||||
import android.content.SharedPreferences;
 | 
					import android.content.SharedPreferences;
 | 
				
			||||||
 | 
					import jscl.NumeralBase;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.annotation.Nonnull;
 | 
					import javax.annotation.Nonnull;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import jscl.NumeralBase;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import static jscl.NumeralBase.hex;
 | 
					import static jscl.NumeralBase.hex;
 | 
				
			||||||
 | 
					import static org.solovyev.android.calculator.Engine.Preferences.numeralBase;
 | 
				
			||||||
import static org.solovyev.android.calculator.Preferences.Gui.hideNumeralBaseDigits;
 | 
					import static org.solovyev.android.calculator.Preferences.Gui.hideNumeralBaseDigits;
 | 
				
			||||||
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.numeralBase;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * User: serso
 | 
					 * User: serso
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,22 +22,15 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
package org.solovyev.android.calculator;
 | 
					package org.solovyev.android.calculator;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import jscl.math.operator.Operator;
 | 
				
			||||||
import org.solovyev.common.JBuilder;
 | 
					import org.solovyev.common.JBuilder;
 | 
				
			||||||
import org.solovyev.common.math.MathRegistry;
 | 
					import org.solovyev.common.math.MathRegistry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import javax.annotation.Nonnull;
 | 
				
			||||||
import java.util.HashMap;
 | 
					import java.util.HashMap;
 | 
				
			||||||
import java.util.Map;
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.annotation.Nonnull;
 | 
					public class OperatorsRegistry extends BaseEntitiesRegistry<Operator, MathPersistenceEntity> {
 | 
				
			||||||
 | 
					 | 
				
			||||||
import jscl.math.operator.Operator;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * User: serso
 | 
					 | 
				
			||||||
 * Date: 11/17/11
 | 
					 | 
				
			||||||
 * Time: 11:29 PM
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
public class CalculatorOperatorsMathRegistry extends BaseEntitiesRegistry<Operator, MathPersistenceEntity> {
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Nonnull
 | 
					    @Nonnull
 | 
				
			||||||
    private static final Map<String, String> substitutes = new HashMap<String, String>();
 | 
					    private static final Map<String, String> substitutes = new HashMap<String, String>();
 | 
				
			||||||
@@ -53,7 +46,7 @@ public class CalculatorOperatorsMathRegistry extends BaseEntitiesRegistry<Operat
 | 
				
			|||||||
        substitutes.put("Σ", "sum");
 | 
					        substitutes.put("Σ", "sum");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public CalculatorOperatorsMathRegistry(@Nonnull MathRegistry<Operator> functionsRegistry,
 | 
					    public OperatorsRegistry(@Nonnull MathRegistry<Operator> functionsRegistry,
 | 
				
			||||||
                             @Nonnull MathEntityDao<MathPersistenceEntity> mathEntityDao) {
 | 
					                             @Nonnull MathEntityDao<MathPersistenceEntity> mathEntityDao) {
 | 
				
			||||||
        super(functionsRegistry, OPERATOR_DESCRIPTION_PREFIX, mathEntityDao);
 | 
					        super(functionsRegistry, OPERATOR_DESCRIPTION_PREFIX, mathEntityDao);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -22,22 +22,15 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
package org.solovyev.android.calculator;
 | 
					package org.solovyev.android.calculator;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import jscl.math.operator.Operator;
 | 
				
			||||||
import org.solovyev.common.JBuilder;
 | 
					import org.solovyev.common.JBuilder;
 | 
				
			||||||
import org.solovyev.common.math.MathRegistry;
 | 
					import org.solovyev.common.math.MathRegistry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import javax.annotation.Nonnull;
 | 
				
			||||||
import java.util.HashMap;
 | 
					import java.util.HashMap;
 | 
				
			||||||
import java.util.Map;
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.annotation.Nonnull;
 | 
					public class PostfixFunctionsRegistry extends BaseEntitiesRegistry<Operator, MathPersistenceEntity> {
 | 
				
			||||||
 | 
					 | 
				
			||||||
import jscl.math.operator.Operator;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * User: serso
 | 
					 | 
				
			||||||
 * Date: 11/19/11
 | 
					 | 
				
			||||||
 * Time: 1:48 PM
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
public class CalculatorPostfixFunctionsRegistry extends BaseEntitiesRegistry<Operator, MathPersistenceEntity> {
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Nonnull
 | 
					    @Nonnull
 | 
				
			||||||
    private static final Map<String, String> substitutes = new HashMap<String, String>();
 | 
					    private static final Map<String, String> substitutes = new HashMap<String, String>();
 | 
				
			||||||
@@ -51,7 +44,7 @@ public class CalculatorPostfixFunctionsRegistry extends BaseEntitiesRegistry<Ope
 | 
				
			|||||||
        substitutes.put("°", "degree");
 | 
					        substitutes.put("°", "degree");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public CalculatorPostfixFunctionsRegistry(@Nonnull MathRegistry<Operator> functionsRegistry,
 | 
					    public PostfixFunctionsRegistry(@Nonnull MathRegistry<Operator> functionsRegistry,
 | 
				
			||||||
                                    @Nonnull MathEntityDao<MathPersistenceEntity> mathEntityDao) {
 | 
					                                    @Nonnull MathEntityDao<MathPersistenceEntity> mathEntityDao) {
 | 
				
			||||||
        super(functionsRegistry, POSTFIX_FUNCTION_DESCRIPTION_PREFIX, mathEntityDao);
 | 
					        super(functionsRegistry, POSTFIX_FUNCTION_DESCRIPTION_PREFIX, mathEntityDao);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -31,31 +31,22 @@ import android.support.annotation.LayoutRes;
 | 
				
			|||||||
import android.support.annotation.StyleRes;
 | 
					import android.support.annotation.StyleRes;
 | 
				
			||||||
import android.util.SparseArray;
 | 
					import android.util.SparseArray;
 | 
				
			||||||
import android.view.ContextThemeWrapper;
 | 
					import android.view.ContextThemeWrapper;
 | 
				
			||||||
 | 
					import jscl.AngleUnit;
 | 
				
			||||||
 | 
					import jscl.NumeralBase;
 | 
				
			||||||
import org.solovyev.android.Check;
 | 
					import org.solovyev.android.Check;
 | 
				
			||||||
import org.solovyev.android.calculator.language.Languages;
 | 
					import org.solovyev.android.calculator.language.Languages;
 | 
				
			||||||
import org.solovyev.android.calculator.math.MathType;
 | 
					import org.solovyev.android.calculator.math.MathType;
 | 
				
			||||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
 | 
					 | 
				
			||||||
import org.solovyev.android.calculator.preferences.PurchaseDialogActivity;
 | 
					import org.solovyev.android.calculator.preferences.PurchaseDialogActivity;
 | 
				
			||||||
import org.solovyev.android.calculator.wizard.WizardActivity;
 | 
					import org.solovyev.android.calculator.wizard.WizardActivity;
 | 
				
			||||||
import org.solovyev.android.prefs.BooleanPreference;
 | 
					import org.solovyev.android.prefs.*;
 | 
				
			||||||
import org.solovyev.android.prefs.IntegerPreference;
 | 
					 | 
				
			||||||
import org.solovyev.android.prefs.LongPreference;
 | 
					 | 
				
			||||||
import org.solovyev.android.prefs.NumberToStringPreference;
 | 
					 | 
				
			||||||
import org.solovyev.android.prefs.Preference;
 | 
					 | 
				
			||||||
import org.solovyev.android.prefs.StringPreference;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import javax.annotation.Nonnull;
 | 
				
			||||||
 | 
					import javax.annotation.Nullable;
 | 
				
			||||||
import java.text.DecimalFormatSymbols;
 | 
					import java.text.DecimalFormatSymbols;
 | 
				
			||||||
import java.util.EnumMap;
 | 
					import java.util.EnumMap;
 | 
				
			||||||
import java.util.Locale;
 | 
					import java.util.Locale;
 | 
				
			||||||
import java.util.Map;
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.annotation.Nonnull;
 | 
					 | 
				
			||||||
import javax.annotation.Nullable;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import jscl.AngleUnit;
 | 
					 | 
				
			||||||
import jscl.NumeralBase;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import static org.solovyev.android.Android.isPhoneModel;
 | 
					import static org.solovyev.android.Android.isPhoneModel;
 | 
				
			||||||
import static org.solovyev.android.DeviceModel.samsung_galaxy_s;
 | 
					import static org.solovyev.android.DeviceModel.samsung_galaxy_s;
 | 
				
			||||||
import static org.solovyev.android.DeviceModel.samsung_galaxy_s_2;
 | 
					import static org.solovyev.android.DeviceModel.samsung_galaxy_s_2;
 | 
				
			||||||
@@ -70,7 +61,7 @@ public final class Preferences {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    static void setDefaultValues(@Nonnull SharedPreferences preferences) {
 | 
					    static void setDefaultValues(@Nonnull SharedPreferences preferences) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!AndroidCalculatorEngine.Preferences.groupingSeparator.isSet(preferences)) {
 | 
					        if (!Engine.Preferences.groupingSeparator.isSet(preferences)) {
 | 
				
			||||||
            final Locale locale = Locale.getDefault();
 | 
					            final Locale locale = Locale.getDefault();
 | 
				
			||||||
            if (locale != null) {
 | 
					            if (locale != null) {
 | 
				
			||||||
                final DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(locale);
 | 
					                final DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(locale);
 | 
				
			||||||
@@ -82,22 +73,22 @@ public final class Preferences {
 | 
				
			|||||||
                    groupingSeparator = " ";
 | 
					                    groupingSeparator = " ";
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                AndroidCalculatorEngine.Preferences.groupingSeparator.putPreference(preferences, groupingSeparator);
 | 
					                Engine.Preferences.groupingSeparator.putPreference(preferences, groupingSeparator);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!AndroidCalculatorEngine.Preferences.angleUnit.isSet(preferences)) {
 | 
					        if (!Engine.Preferences.angleUnit.isSet(preferences)) {
 | 
				
			||||||
            AndroidCalculatorEngine.Preferences.angleUnit.putDefault(preferences);
 | 
					            Engine.Preferences.angleUnit.putDefault(preferences);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!AndroidCalculatorEngine.Preferences.numeralBase.isSet(preferences)) {
 | 
					        if (!Engine.Preferences.numeralBase.isSet(preferences)) {
 | 
				
			||||||
            AndroidCalculatorEngine.Preferences.numeralBase.putDefault(preferences);
 | 
					            Engine.Preferences.numeralBase.putDefault(preferences);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!AndroidCalculatorEngine.Preferences.multiplicationSign.isSet(preferences)) {
 | 
					        if (!Engine.Preferences.multiplicationSign.isSet(preferences)) {
 | 
				
			||||||
            if (isPhoneModel(samsung_galaxy_s) || isPhoneModel(samsung_galaxy_s_2)) {
 | 
					            if (isPhoneModel(samsung_galaxy_s) || isPhoneModel(samsung_galaxy_s_2)) {
 | 
				
			||||||
                // workaround ofr samsung galaxy s phones
 | 
					                // workaround ofr samsung galaxy s phones
 | 
				
			||||||
                AndroidCalculatorEngine.Preferences.multiplicationSign.putPreference(preferences, "*");
 | 
					                Engine.Preferences.multiplicationSign.putPreference(preferences, "*");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -247,8 +238,8 @@ public final class Preferences {
 | 
				
			|||||||
        public static final Preference<Boolean> calculateOnFly = BooleanPreference.of("calculations_calculate_on_fly", true);
 | 
					        public static final Preference<Boolean> calculateOnFly = BooleanPreference.of("calculations_calculate_on_fly", true);
 | 
				
			||||||
        public static final Preference<Boolean> showCalculationMessagesDialog = BooleanPreference.of("show_calculation_messages_dialog", true);
 | 
					        public static final Preference<Boolean> showCalculationMessagesDialog = BooleanPreference.of("show_calculation_messages_dialog", true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public static final Preference<NumeralBase> preferredNumeralBase = StringPreference.ofEnum("preferred_numeral_base", AndroidCalculatorEngine.Preferences.numeralBase.getDefaultValue(), NumeralBase.class);
 | 
					        public static final Preference<NumeralBase> preferredNumeralBase = StringPreference.ofEnum("preferred_numeral_base", Engine.Preferences.numeralBase.getDefaultValue(), NumeralBase.class);
 | 
				
			||||||
        public static final Preference<AngleUnit> preferredAngleUnits = StringPreference.ofEnum("preferred_angle_units", AndroidCalculatorEngine.Preferences.angleUnit.getDefaultValue(), AngleUnit.class);
 | 
					        public static final Preference<AngleUnit> preferredAngleUnits = StringPreference.ofEnum("preferred_angle_units", Engine.Preferences.angleUnit.getDefaultValue(), AngleUnit.class);
 | 
				
			||||||
        public static final Preference<Long> lastPreferredPreferencesCheck = LongPreference.of("preferred_preferences_check_time", 0L);
 | 
					        public static final Preference<Long> lastPreferredPreferencesCheck = LongPreference.of("preferred_preferences_check_time", 0L);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,6 +22,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
package org.solovyev.android.calculator;
 | 
					package org.solovyev.android.calculator;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import jscl.math.function.IConstant;
 | 
				
			||||||
import org.solovyev.android.calculator.model.MathEntityBuilder;
 | 
					import org.solovyev.android.calculator.model.MathEntityBuilder;
 | 
				
			||||||
import org.solovyev.android.calculator.model.Var;
 | 
					import org.solovyev.android.calculator.model.Var;
 | 
				
			||||||
import org.solovyev.android.calculator.model.Vars;
 | 
					import org.solovyev.android.calculator.model.Vars;
 | 
				
			||||||
@@ -29,20 +30,12 @@ import org.solovyev.common.JBuilder;
 | 
				
			|||||||
import org.solovyev.common.math.MathEntity;
 | 
					import org.solovyev.common.math.MathEntity;
 | 
				
			||||||
import org.solovyev.common.math.MathRegistry;
 | 
					import org.solovyev.common.math.MathRegistry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import javax.annotation.Nonnull;
 | 
				
			||||||
 | 
					import javax.annotation.Nullable;
 | 
				
			||||||
import java.util.HashMap;
 | 
					import java.util.HashMap;
 | 
				
			||||||
import java.util.Map;
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.annotation.Nonnull;
 | 
					public class VarsRegistry extends BaseEntitiesRegistry<IConstant, Var> {
 | 
				
			||||||
import javax.annotation.Nullable;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import jscl.math.function.IConstant;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * User: serso
 | 
					 | 
				
			||||||
 * Date: 9/29/11
 | 
					 | 
				
			||||||
 * Time: 4:57 PM
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
public class CalculatorVarsRegistry extends BaseEntitiesRegistry<IConstant, Var> {
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Nonnull
 | 
					    @Nonnull
 | 
				
			||||||
    public static final String ANS = "ans";
 | 
					    public static final String ANS = "ans";
 | 
				
			||||||
@@ -58,7 +51,7 @@ public class CalculatorVarsRegistry extends BaseEntitiesRegistry<IConstant, Var>
 | 
				
			|||||||
        substitutes.put("NaN", "nan");
 | 
					        substitutes.put("NaN", "nan");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public CalculatorVarsRegistry(@Nonnull MathRegistry<IConstant> mathRegistry,
 | 
					    public VarsRegistry(@Nonnull MathRegistry<IConstant> mathRegistry,
 | 
				
			||||||
                        @Nonnull MathEntityDao<Var> mathEntityDao) {
 | 
					                        @Nonnull MathEntityDao<Var> mathEntityDao) {
 | 
				
			||||||
        super(mathRegistry, "c_var_description_", mathEntityDao);
 | 
					        super(mathRegistry, "c_var_description_", mathEntityDao);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -93,12 +86,6 @@ public class CalculatorVarsRegistry extends BaseEntitiesRegistry<IConstant, Var>
 | 
				
			|||||||
        tryToAddAuxVar("y");
 | 
					        tryToAddAuxVar("y");
 | 
				
			||||||
        tryToAddAuxVar("t");
 | 
					        tryToAddAuxVar("t");
 | 
				
			||||||
        tryToAddAuxVar("j");
 | 
					        tryToAddAuxVar("j");
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		/*Log.d(AndroidVarsRegistry.class.getName(), vars.size() + " variables registered!");
 | 
					 | 
				
			||||||
        for (Var var : vars) {
 | 
					 | 
				
			||||||
			Log.d(AndroidVarsRegistry.class.getName(), var.toString());
 | 
					 | 
				
			||||||
		}*/
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -34,7 +34,7 @@ import org.json.JSONArray;
 | 
				
			|||||||
import org.json.JSONException;
 | 
					import org.json.JSONException;
 | 
				
			||||||
import org.solovyev.android.Check;
 | 
					import org.solovyev.android.Check;
 | 
				
			||||||
import org.solovyev.android.calculator.*;
 | 
					import org.solovyev.android.calculator.*;
 | 
				
			||||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences;
 | 
					import org.solovyev.android.calculator.Engine.Preferences;
 | 
				
			||||||
import org.solovyev.android.io.FileLoader;
 | 
					import org.solovyev.android.io.FileLoader;
 | 
				
			||||||
import org.solovyev.android.io.FileSaver;
 | 
					import org.solovyev.android.io.FileSaver;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,7 +28,7 @@ import jscl.text.Identifier;
 | 
				
			|||||||
import jscl.text.MutableInt;
 | 
					import jscl.text.MutableInt;
 | 
				
			||||||
import jscl.text.ParseException;
 | 
					import jscl.text.ParseException;
 | 
				
			||||||
import jscl.text.Parser;
 | 
					import jscl.text.Parser;
 | 
				
			||||||
import org.solovyev.android.calculator.CalculatorVarsRegistry;
 | 
					import org.solovyev.android.calculator.VarsRegistry;
 | 
				
			||||||
import org.solovyev.android.calculator.EntitiesRegistry;
 | 
					import org.solovyev.android.calculator.EntitiesRegistry;
 | 
				
			||||||
import org.solovyev.android.calculator.Locator;
 | 
					import org.solovyev.android.calculator.Locator;
 | 
				
			||||||
import org.solovyev.android.calculator.R;
 | 
					import org.solovyev.android.calculator.R;
 | 
				
			||||||
@@ -76,7 +76,7 @@ public class VarEditorSaver<T extends MathEntity> implements View.OnClickListene
 | 
				
			|||||||
        if (!Strings.isEmpty(name)) {
 | 
					        if (!Strings.isEmpty(name)) {
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                if (name == null) throw new AssertionError();
 | 
					                if (name == null) throw new AssertionError();
 | 
				
			||||||
                Identifier.parser.parse(Parser.Parameters.newInstance(name, new MutableInt(0), Locator.getInstance().getEngine().getEngine()), null);
 | 
					                Identifier.parser.parse(Parser.Parameters.newInstance(name, new MutableInt(0), Locator.getInstance().getEngine().getMathEngine()), null);
 | 
				
			||||||
                result = true;
 | 
					                result = true;
 | 
				
			||||||
            } catch (ParseException e) {
 | 
					            } catch (ParseException e) {
 | 
				
			||||||
                // not valid name;
 | 
					                // not valid name;
 | 
				
			||||||
@@ -147,7 +147,7 @@ public class VarEditorSaver<T extends MathEntity> implements View.OnClickListene
 | 
				
			|||||||
        if (error != null) {
 | 
					        if (error != null) {
 | 
				
			||||||
            Locator.getInstance().getNotifier().showMessage(error, MessageType.error);
 | 
					            Locator.getInstance().getNotifier().showMessage(error, MessageType.error);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            CalculatorVarsRegistry.saveVariable(mathRegistry, varBuilder, editedInstance, source, true);
 | 
					            VarsRegistry.saveVariable(mathRegistry, varBuilder, editedInstance, source, true);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -59,7 +59,7 @@ import java.util.List;
 | 
				
			|||||||
import java.util.concurrent.Executor;
 | 
					import java.util.concurrent.Executor;
 | 
				
			||||||
import java.util.concurrent.Executors;
 | 
					import java.util.concurrent.Executors;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences;
 | 
					import static org.solovyev.android.calculator.Engine.Preferences;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * User: serso
 | 
					 * User: serso
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,8 +22,8 @@ import javax.annotation.Nonnull;
 | 
				
			|||||||
import javax.annotation.Nullable;
 | 
					import javax.annotation.Nullable;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.precision;
 | 
					import static org.solovyev.android.calculator.Engine.Preferences.precision;
 | 
				
			||||||
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.roundResult;
 | 
					import static org.solovyev.android.calculator.Engine.Preferences.roundResult;
 | 
				
			||||||
import static org.solovyev.android.calculator.wizard.CalculatorWizards.DEFAULT_WIZARD_FLOW;
 | 
					import static org.solovyev.android.calculator.wizard.CalculatorWizards.DEFAULT_WIZARD_FLOW;
 | 
				
			||||||
import static org.solovyev.android.wizard.WizardUi.startWizard;
 | 
					import static org.solovyev.android.wizard.WizardUi.startWizard;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,8 +27,8 @@ import android.content.SharedPreferences;
 | 
				
			|||||||
import android.util.AttributeSet;
 | 
					import android.util.AttributeSet;
 | 
				
			||||||
import android.widget.TextView;
 | 
					import android.widget.TextView;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.solovyev.android.calculator.Engine;
 | 
				
			||||||
import org.solovyev.android.calculator.Locator;
 | 
					import org.solovyev.android.calculator.Locator;
 | 
				
			||||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.annotation.Nonnull;
 | 
					import javax.annotation.Nonnull;
 | 
				
			||||||
import javax.annotation.Nullable;
 | 
					import javax.annotation.Nullable;
 | 
				
			||||||
@@ -58,8 +58,8 @@ public class CalculatorAdditionalTitle extends TextView implements SharedPrefere
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void onSharedPreferenceChanged(SharedPreferences preferences, @Nullable String key) {
 | 
					    public void onSharedPreferenceChanged(SharedPreferences preferences, @Nullable String key) {
 | 
				
			||||||
        setText(((AndroidCalculatorEngine) Locator.getInstance().getEngine()).getNumeralBaseFromPrefs(preferences)
 | 
					        setText(((Engine) Locator.getInstance().getEngine()).getNumeralBaseFromPrefs(preferences)
 | 
				
			||||||
                + " / " +
 | 
					                + " / " +
 | 
				
			||||||
                ((AndroidCalculatorEngine) Locator.getInstance().getEngine()).getAngleUnitsFromPrefs(preferences));
 | 
					                ((Engine) Locator.getInstance().getEngine()).getAngleUnitsFromPrefs(preferences));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -26,24 +26,17 @@ import android.graphics.Typeface;
 | 
				
			|||||||
import android.text.SpannableStringBuilder;
 | 
					import android.text.SpannableStringBuilder;
 | 
				
			||||||
import android.text.style.ForegroundColorSpan;
 | 
					import android.text.style.ForegroundColorSpan;
 | 
				
			||||||
import android.text.style.StyleSpan;
 | 
					import android.text.style.StyleSpan;
 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.google.common.collect.Lists;
 | 
					import com.google.common.collect.Lists;
 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.solovyev.android.Check;
 | 
					import org.solovyev.android.Check;
 | 
				
			||||||
import org.solovyev.android.calculator.BaseNumberBuilder;
 | 
					import org.solovyev.android.calculator.*;
 | 
				
			||||||
import org.solovyev.android.calculator.CalculatorEngine;
 | 
					 | 
				
			||||||
import org.solovyev.android.calculator.LiteNumberBuilder;
 | 
					 | 
				
			||||||
import org.solovyev.android.calculator.Locator;
 | 
					 | 
				
			||||||
import org.solovyev.android.calculator.NumberBuilder;
 | 
					 | 
				
			||||||
import org.solovyev.android.calculator.math.MathType;
 | 
					import org.solovyev.android.calculator.math.MathType;
 | 
				
			||||||
import org.solovyev.android.calculator.text.TextProcessor;
 | 
					import org.solovyev.android.calculator.text.TextProcessor;
 | 
				
			||||||
import org.solovyev.android.calculator.text.TextProcessorEditorResult;
 | 
					import org.solovyev.android.calculator.text.TextProcessorEditorResult;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import javax.annotation.Nonnull;
 | 
				
			||||||
import java.util.ArrayList;
 | 
					import java.util.ArrayList;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.annotation.Nonnull;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class TextHighlighter implements TextProcessor<TextProcessorEditorResult, String> {
 | 
					public class TextHighlighter implements TextProcessor<TextProcessorEditorResult, String> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private final int red;
 | 
					    private final int red;
 | 
				
			||||||
@@ -84,7 +77,7 @@ public class TextHighlighter implements TextProcessor<TextProcessorEditorResult,
 | 
				
			|||||||
    @Nonnull
 | 
					    @Nonnull
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public TextProcessorEditorResult process(@Nonnull String text) {
 | 
					    public TextProcessorEditorResult process(@Nonnull String text) {
 | 
				
			||||||
        final CalculatorEngine engine = Locator.getInstance().getEngine();
 | 
					        final Engine engine = Locator.getInstance().getEngine();
 | 
				
			||||||
        final SpannableStringBuilder sb = new SpannableStringBuilder();
 | 
					        final SpannableStringBuilder sb = new SpannableStringBuilder();
 | 
				
			||||||
        final BaseNumberBuilder nb = !formatNumber ? new LiteNumberBuilder(engine) : new NumberBuilder(engine);
 | 
					        final BaseNumberBuilder nb = !formatNumber ? new LiteNumberBuilder(engine) : new NumberBuilder(engine);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,15 +23,13 @@
 | 
				
			|||||||
package org.solovyev.android.calculator.wizard;
 | 
					package org.solovyev.android.calculator.wizard;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import android.content.SharedPreferences;
 | 
					import android.content.SharedPreferences;
 | 
				
			||||||
 | 
					import jscl.AngleUnit;
 | 
				
			||||||
 | 
					import org.solovyev.android.calculator.Engine;
 | 
				
			||||||
import org.solovyev.android.calculator.Preferences;
 | 
					import org.solovyev.android.calculator.Preferences;
 | 
				
			||||||
import org.solovyev.android.calculator.R;
 | 
					import org.solovyev.android.calculator.R;
 | 
				
			||||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.annotation.Nonnull;
 | 
					import javax.annotation.Nonnull;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import jscl.AngleUnit;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import static org.solovyev.android.calculator.Preferences.Gui.Layout.main_calculator;
 | 
					import static org.solovyev.android.calculator.Preferences.Gui.Layout.main_calculator;
 | 
				
			||||||
import static org.solovyev.android.calculator.Preferences.Gui.Layout.main_calculator_mobile;
 | 
					import static org.solovyev.android.calculator.Preferences.Gui.Layout.main_calculator_mobile;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -52,9 +50,9 @@ enum CalculatorMode {
 | 
				
			|||||||
                Preferences.Gui.layout.putPreference(preferences, Preferences.Gui.Layout.simple_mobile);
 | 
					                Preferences.Gui.layout.putPreference(preferences, Preferences.Gui.Layout.simple_mobile);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            Preferences.Calculations.preferredAngleUnits.putPreference(preferences, AngleUnit.deg);
 | 
					            Preferences.Calculations.preferredAngleUnits.putPreference(preferences, AngleUnit.deg);
 | 
				
			||||||
            AndroidCalculatorEngine.Preferences.angleUnit.putPreference(preferences, AngleUnit.deg);
 | 
					            Engine.Preferences.angleUnit.putPreference(preferences, AngleUnit.deg);
 | 
				
			||||||
            AndroidCalculatorEngine.Preferences.scienceNotation.putPreference(preferences, false);
 | 
					            Engine.Preferences.scienceNotation.putPreference(preferences, false);
 | 
				
			||||||
            AndroidCalculatorEngine.Preferences.roundResult.putPreference(preferences, true);
 | 
					            Engine.Preferences.roundResult.putPreference(preferences, true);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -68,9 +66,9 @@ enum CalculatorMode {
 | 
				
			|||||||
                Preferences.Gui.layout.putPreference(preferences, main_calculator_mobile);
 | 
					                Preferences.Gui.layout.putPreference(preferences, main_calculator_mobile);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            Preferences.Calculations.preferredAngleUnits.putPreference(preferences, AngleUnit.rad);
 | 
					            Preferences.Calculations.preferredAngleUnits.putPreference(preferences, AngleUnit.rad);
 | 
				
			||||||
            AndroidCalculatorEngine.Preferences.angleUnit.putPreference(preferences, AngleUnit.rad);
 | 
					            Engine.Preferences.angleUnit.putPreference(preferences, AngleUnit.rad);
 | 
				
			||||||
            AndroidCalculatorEngine.Preferences.scienceNotation.putPreference(preferences, true);
 | 
					            Engine.Preferences.scienceNotation.putPreference(preferences, true);
 | 
				
			||||||
            AndroidCalculatorEngine.Preferences.roundResult.putPreference(preferences, false);
 | 
					            Engine.Preferences.roundResult.putPreference(preferences, false);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,22 +23,19 @@
 | 
				
			|||||||
package org.solovyev.android.calculator;
 | 
					package org.solovyev.android.calculator;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import android.content.Context;
 | 
					import android.content.Context;
 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.squareup.otto.Bus;
 | 
					import com.squareup.otto.Bus;
 | 
				
			||||||
 | 
					import jscl.JsclMathEngine;
 | 
				
			||||||
import org.junit.Assert;
 | 
					import org.junit.Assert;
 | 
				
			||||||
import org.mockito.Mockito;
 | 
					import org.mockito.Mockito;
 | 
				
			||||||
 | 
					import org.robolectric.RuntimeEnvironment;
 | 
				
			||||||
import org.robolectric.fakes.RoboSharedPreferences;
 | 
					import org.robolectric.fakes.RoboSharedPreferences;
 | 
				
			||||||
import org.solovyev.android.calculator.jscl.JsclOperation;
 | 
					import org.solovyev.android.calculator.jscl.JsclOperation;
 | 
				
			||||||
import org.solovyev.android.calculator.language.Languages;
 | 
					import org.solovyev.android.calculator.language.Languages;
 | 
				
			||||||
import org.solovyev.android.calculator.plot.CalculatorPlotter;
 | 
					import org.solovyev.android.calculator.plot.CalculatorPlotter;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.io.ByteArrayInputStream;
 | 
					import javax.annotation.Nonnull;
 | 
				
			||||||
import java.io.ByteArrayOutputStream;
 | 
					import javax.annotation.Nullable;
 | 
				
			||||||
import java.io.IOException;
 | 
					import java.io.*;
 | 
				
			||||||
import java.io.ObjectInputStream;
 | 
					 | 
				
			||||||
import java.io.ObjectOutputStream;
 | 
					 | 
				
			||||||
import java.io.Serializable;
 | 
					 | 
				
			||||||
import java.text.DecimalFormatSymbols;
 | 
					import java.text.DecimalFormatSymbols;
 | 
				
			||||||
import java.util.HashMap;
 | 
					import java.util.HashMap;
 | 
				
			||||||
import java.util.Map;
 | 
					import java.util.Map;
 | 
				
			||||||
@@ -46,11 +43,6 @@ import java.util.concurrent.CountDownLatch;
 | 
				
			|||||||
import java.util.concurrent.Executor;
 | 
					import java.util.concurrent.Executor;
 | 
				
			||||||
import java.util.concurrent.TimeUnit;
 | 
					import java.util.concurrent.TimeUnit;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.annotation.Nonnull;
 | 
					 | 
				
			||||||
import javax.annotation.Nullable;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import jscl.JsclMathEngine;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * User: serso
 | 
					 * User: serso
 | 
				
			||||||
 * Date: 10/7/12
 | 
					 * Date: 10/7/12
 | 
				
			||||||
@@ -87,17 +79,17 @@ public class CalculatorTestUtils {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Nonnull
 | 
					    @Nonnull
 | 
				
			||||||
    static CalculatorEngineImpl newCalculatorEngine() {
 | 
					    static Engine newCalculatorEngine() {
 | 
				
			||||||
        final MathEntityDao mathEntityDao = Mockito.mock(MathEntityDao.class);
 | 
					        final MathEntityDao mathEntityDao = Mockito.mock(MathEntityDao.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        final JsclMathEngine jsclEngine = JsclMathEngine.getInstance();
 | 
					        final JsclMathEngine jsclEngine = JsclMathEngine.getInstance();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        final CalculatorVarsRegistry varsRegistry = new CalculatorVarsRegistry(jsclEngine.getConstantsRegistry(), mathEntityDao);
 | 
					        final VarsRegistry varsRegistry = new VarsRegistry(jsclEngine.getConstantsRegistry(), mathEntityDao);
 | 
				
			||||||
        final FunctionsRegistry functionsRegistry = new FunctionsRegistry(jsclEngine.getFunctionsRegistry(), mathEntityDao);
 | 
					        final FunctionsRegistry functionsRegistry = new FunctionsRegistry(jsclEngine.getFunctionsRegistry(), mathEntityDao);
 | 
				
			||||||
        final CalculatorOperatorsMathRegistry operatorsRegistry = new CalculatorOperatorsMathRegistry(jsclEngine.getOperatorsRegistry(), mathEntityDao);
 | 
					        final OperatorsRegistry operatorsRegistry = new OperatorsRegistry(jsclEngine.getOperatorsRegistry(), mathEntityDao);
 | 
				
			||||||
        final CalculatorPostfixFunctionsRegistry postfixFunctionsRegistry = new CalculatorPostfixFunctionsRegistry(jsclEngine.getPostfixFunctionsRegistry(), mathEntityDao);
 | 
					        final PostfixFunctionsRegistry postfixFunctionsRegistry = new PostfixFunctionsRegistry(jsclEngine.getPostfixFunctionsRegistry(), mathEntityDao);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return new CalculatorEngineImpl(jsclEngine, varsRegistry, functionsRegistry, operatorsRegistry, postfixFunctionsRegistry, null);
 | 
					        return new Engine(RuntimeEnvironment.application, jsclEngine, varsRegistry, functionsRegistry, operatorsRegistry, postfixFunctionsRegistry);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static void assertEval(@Nonnull String expected, @Nonnull String expression) {
 | 
					    public static void assertEval(@Nonnull String expected, @Nonnull String expression) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,7 +23,8 @@
 | 
				
			|||||||
package org.solovyev.android.calculator;
 | 
					package org.solovyev.android.calculator;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import android.graphics.Color;
 | 
					import android.graphics.Color;
 | 
				
			||||||
 | 
					import jscl.MathEngine;
 | 
				
			||||||
 | 
					import jscl.NumeralBase;
 | 
				
			||||||
import org.junit.Before;
 | 
					import org.junit.Before;
 | 
				
			||||||
import org.junit.Test;
 | 
					import org.junit.Test;
 | 
				
			||||||
import org.solovyev.android.calculator.text.TextProcessor;
 | 
					import org.solovyev.android.calculator.text.TextProcessor;
 | 
				
			||||||
@@ -32,12 +33,7 @@ import org.solovyev.android.calculator.view.TextHighlighter;
 | 
				
			|||||||
import java.util.Date;
 | 
					import java.util.Date;
 | 
				
			||||||
import java.util.Random;
 | 
					import java.util.Random;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import jscl.MathEngine;
 | 
					import static org.junit.Assert.*;
 | 
				
			||||||
import jscl.NumeralBase;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import static org.junit.Assert.assertEquals;
 | 
					 | 
				
			||||||
import static org.junit.Assert.assertFalse;
 | 
					 | 
				
			||||||
import static org.junit.Assert.assertTrue;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * User: serso
 | 
					 * User: serso
 | 
				
			||||||
@@ -119,7 +115,7 @@ public class TextHighlighterTest {
 | 
				
			|||||||
        assertEquals("<b>0x:</b>FF33233FFE", textHighlighter.process("0x:FF33233FFE").toString());
 | 
					        assertEquals("<b>0x:</b>FF33233FFE", textHighlighter.process("0x:FF33233FFE").toString());
 | 
				
			||||||
        assertEquals("<b>0x:</b>FF33 233 FFE", textHighlighter.process("0x:FF33 233 FFE").toString());
 | 
					        assertEquals("<b>0x:</b>FF33 233 FFE", textHighlighter.process("0x:FF33 233 FFE").toString());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        final MathEngine me = Locator.getInstance().getEngine().getMathEngine0();
 | 
					        final MathEngine me = Locator.getInstance().getEngine().getMathEngine();
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            me.setNumeralBase(NumeralBase.hex);
 | 
					            me.setNumeralBase(NumeralBase.hex);
 | 
				
			||||||
            assertEquals("E", textHighlighter.process("E").toString());
 | 
					            assertEquals("E", textHighlighter.process("E").toString());
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,9 +24,7 @@ package org.solovyev.android.calculator.history;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import android.content.SharedPreferences;
 | 
					import android.content.SharedPreferences;
 | 
				
			||||||
import android.os.Handler;
 | 
					import android.os.Handler;
 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.squareup.otto.Bus;
 | 
					import com.squareup.otto.Bus;
 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.junit.Before;
 | 
					import org.junit.Before;
 | 
				
			||||||
import org.junit.Test;
 | 
					import org.junit.Test;
 | 
				
			||||||
import org.junit.runner.RunWith;
 | 
					import org.junit.runner.RunWith;
 | 
				
			||||||
@@ -34,27 +32,17 @@ import org.robolectric.RobolectricGradleTestRunner;
 | 
				
			|||||||
import org.robolectric.RuntimeEnvironment;
 | 
					import org.robolectric.RuntimeEnvironment;
 | 
				
			||||||
import org.robolectric.annotation.Config;
 | 
					import org.robolectric.annotation.Config;
 | 
				
			||||||
import org.solovyev.android.CalculatorTestRunner;
 | 
					import org.solovyev.android.CalculatorTestRunner;
 | 
				
			||||||
import org.solovyev.android.calculator.BuildConfig;
 | 
					import org.solovyev.android.calculator.*;
 | 
				
			||||||
import org.solovyev.android.calculator.Display;
 | 
					 | 
				
			||||||
import org.solovyev.android.calculator.DisplayState;
 | 
					 | 
				
			||||||
import org.solovyev.android.calculator.Editor;
 | 
					 | 
				
			||||||
import org.solovyev.android.calculator.EditorState;
 | 
					 | 
				
			||||||
import org.solovyev.android.calculator.jscl.JsclOperation;
 | 
					import org.solovyev.android.calculator.jscl.JsclOperation;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import javax.annotation.Nonnull;
 | 
				
			||||||
import java.io.File;
 | 
					import java.io.File;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.annotation.Nonnull;
 | 
					import static org.junit.Assert.*;
 | 
				
			||||||
 | 
					 | 
				
			||||||
import static org.junit.Assert.assertEquals;
 | 
					 | 
				
			||||||
import static org.junit.Assert.assertNotNull;
 | 
					 | 
				
			||||||
import static org.junit.Assert.assertNull;
 | 
					 | 
				
			||||||
import static org.junit.Assert.assertSame;
 | 
					 | 
				
			||||||
import static org.mockito.Matchers.eq;
 | 
					import static org.mockito.Matchers.eq;
 | 
				
			||||||
import static org.mockito.Mockito.anyString;
 | 
					import static org.mockito.Mockito.*;
 | 
				
			||||||
import static org.mockito.Mockito.mock;
 | 
					import static org.solovyev.android.calculator.Engine.Preferences.groupingSeparator;
 | 
				
			||||||
import static org.mockito.Mockito.when;
 | 
					 | 
				
			||||||
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.groupingSeparator;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Config(constants = BuildConfig.class, sdk = CalculatorTestRunner.SUPPORTED_SDK)
 | 
					@Config(constants = BuildConfig.class, sdk = CalculatorTestRunner.SUPPORTED_SDK)
 | 
				
			||||||
@RunWith(RobolectricGradleTestRunner.class)
 | 
					@RunWith(RobolectricGradleTestRunner.class)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -53,7 +53,7 @@ import static org.junit.Assert.fail;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@SuppressWarnings("deprecation")
 | 
					@SuppressWarnings("deprecation")
 | 
				
			||||||
public class AndroidCalculatorEngineTest extends AbstractCalculatorTest {
 | 
					public class AndroidEngineTest extends AbstractCalculatorTest {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @BeforeClass
 | 
					    @BeforeClass
 | 
				
			||||||
    public static void staticSetUp() throws Exception {
 | 
					    public static void staticSetUp() throws Exception {
 | 
				
			||||||
@@ -64,7 +64,7 @@ public class AndroidCalculatorEngineTest extends AbstractCalculatorTest {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    public void testDegrees() throws Exception {
 | 
					    public void testDegrees() throws Exception {
 | 
				
			||||||
        final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0();
 | 
					        final MathEngine cm = Locator.getInstance().getEngine().getMathEngine();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        final AngleUnit defaultAngleUnit = cm.getAngleUnits();
 | 
					        final AngleUnit defaultAngleUnit = cm.getAngleUnits();
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
@@ -85,7 +85,7 @@ public class AndroidCalculatorEngineTest extends AbstractCalculatorTest {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    public void testFormatting() throws Exception {
 | 
					    public void testFormatting() throws Exception {
 | 
				
			||||||
        final MathEngine ce = Locator.getInstance().getEngine().getMathEngine0();
 | 
					        final MathEngine ce = Locator.getInstance().getEngine().getMathEngine();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        CalculatorTestUtils.assertEval("12 345", ce.simplify("12345"));
 | 
					        CalculatorTestUtils.assertEval("12 345", ce.simplify("12345"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -93,7 +93,7 @@ public class AndroidCalculatorEngineTest extends AbstractCalculatorTest {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    public void testI() throws ParseException, CalculatorEvalException {
 | 
					    public void testI() throws ParseException, CalculatorEvalException {
 | 
				
			||||||
        final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0();
 | 
					        final MathEngine cm = Locator.getInstance().getEngine().getMathEngine();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        CalculatorTestUtils.assertEval("-i", cm.evaluate("i^3"));
 | 
					        CalculatorTestUtils.assertEval("-i", cm.evaluate("i^3"));
 | 
				
			||||||
        for (int i = 0; i < 1000; i++) {
 | 
					        for (int i = 0; i < 1000; i++) {
 | 
				
			||||||
@@ -118,7 +118,7 @@ public class AndroidCalculatorEngineTest extends AbstractCalculatorTest {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    public void testEmptyFunction() throws Exception {
 | 
					    public void testEmptyFunction() throws Exception {
 | 
				
			||||||
        final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0();
 | 
					        final MathEngine cm = Locator.getInstance().getEngine().getMathEngine();
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            cm.evaluate("cos(cos(cos(cos(acos(acos(acos(acos(acos(acos(acos(acos(cos(cos(cos(cos(cosh(acos(cos(cos(cos(cos(cos(acos(acos(acos(acos(acos(acos(acos(acos(cos(cos(cos(cos(cosh(acos(cos())))))))))))))))))))))))))))))))))))))");
 | 
					            cm.evaluate("cos(cos(cos(cos(acos(acos(acos(acos(acos(acos(acos(acos(cos(cos(cos(cos(cosh(acos(cos(cos(cos(cos(cos(acos(acos(acos(acos(acos(acos(acos(acos(cos(cos(cos(cos(cosh(acos(cos())))))))))))))))))))))))))))))))))))))");
 | 
				
			||||||
            Assert.fail();
 | 
					            Assert.fail();
 | 
				
			||||||
@@ -147,7 +147,7 @@ public class AndroidCalculatorEngineTest extends AbstractCalculatorTest {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    public void testRounding() throws Exception {
 | 
					    public void testRounding() throws Exception {
 | 
				
			||||||
        final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0();
 | 
					        final MathEngine cm = Locator.getInstance().getEngine().getMathEngine();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            DecimalFormatSymbols decimalGroupSymbols = new DecimalFormatSymbols(Locale.getDefault());
 | 
					            DecimalFormatSymbols decimalGroupSymbols = new DecimalFormatSymbols(Locale.getDefault());
 | 
				
			||||||
@@ -171,7 +171,7 @@ public class AndroidCalculatorEngineTest extends AbstractCalculatorTest {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    public void testNumeralSystems() throws Exception {
 | 
					    public void testNumeralSystems() throws Exception {
 | 
				
			||||||
        final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0();
 | 
					        final MathEngine cm = Locator.getInstance().getEngine().getMathEngine();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        CalculatorTestUtils.assertEval("11 259 375", "0x:ABCDEF");
 | 
					        CalculatorTestUtils.assertEval("11 259 375", "0x:ABCDEF");
 | 
				
			||||||
        CalculatorTestUtils.assertEval("30 606 154.462", "0x:ABCDEF*e");
 | 
					        CalculatorTestUtils.assertEval("30 606 154.462", "0x:ABCDEF*e");
 | 
				
			||||||
@@ -200,7 +200,7 @@ public class AndroidCalculatorEngineTest extends AbstractCalculatorTest {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    public void testLog() throws Exception {
 | 
					    public void testLog() throws Exception {
 | 
				
			||||||
        final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0();
 | 
					        final MathEngine cm = Locator.getInstance().getEngine().getMathEngine();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        CalculatorTestUtils.assertEval("∞", Expression.valueOf("1/0").numeric().toString());
 | 
					        CalculatorTestUtils.assertEval("∞", Expression.valueOf("1/0").numeric().toString());
 | 
				
			||||||
        CalculatorTestUtils.assertEval("∞", Expression.valueOf("ln(10)/ln(1)").numeric().toString());
 | 
					        CalculatorTestUtils.assertEval("∞", Expression.valueOf("ln(10)/ln(1)").numeric().toString());
 | 
				
			||||||
@@ -54,7 +54,7 @@ public class EvaluateTest extends AbstractCalculatorTest {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    public void testEvaluate() throws Exception {
 | 
					    public void testEvaluate() throws Exception {
 | 
				
			||||||
        final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0();
 | 
					        final MathEngine cm = Locator.getInstance().getEngine().getMathEngine();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        final AngleUnit defaultAngleUnit = cm.getAngleUnits();
 | 
					        final AngleUnit defaultAngleUnit = cm.getAngleUnits();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -58,11 +58,11 @@ public class NumeralBaseTest extends AbstractCalculatorTest {
 | 
				
			|||||||
        final String bin = "0b:" + line[2].toUpperCase();
 | 
					        final String bin = "0b:" + line[2].toUpperCase();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        final String decExpression = converter.convert(dec);
 | 
					        final String decExpression = converter.convert(dec);
 | 
				
			||||||
        final String decResult = Locator.getInstance().getEngine().getEngine().evaluate(decExpression);
 | 
					        final String decResult = Locator.getInstance().getEngine().getMathEngine().evaluate(decExpression);
 | 
				
			||||||
        final String hexExpression = converter.convert(hex);
 | 
					        final String hexExpression = converter.convert(hex);
 | 
				
			||||||
        final String hexResult = Locator.getInstance().getEngine().getEngine().evaluate(hexExpression);
 | 
					        final String hexResult = Locator.getInstance().getEngine().getMathEngine().evaluate(hexExpression);
 | 
				
			||||||
        final String binExpression = converter.convert(bin);
 | 
					        final String binExpression = converter.convert(bin);
 | 
				
			||||||
        final String binResult = Locator.getInstance().getEngine().getEngine().evaluate(binExpression);
 | 
					        final String binResult = Locator.getInstance().getEngine().getMathEngine().evaluate(binExpression);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Assert.assertEquals("dec-hex: " + decExpression + " : " + hexExpression, decResult, hexResult);
 | 
					        Assert.assertEquals("dec-hex: " + decExpression + " : " + hexExpression, decResult, hexResult);
 | 
				
			||||||
        Assert.assertEquals("dec-bin: " + decExpression + " : " + binExpression, decResult, binResult);
 | 
					        Assert.assertEquals("dec-bin: " + decExpression + " : " + binExpression, decResult, binResult);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user