diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/AndroidFunctionsMathRegistry.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorFunctionsMathRegistry.java similarity index 88% rename from calculatorpp/src/main/java/org/solovyev/android/calculator/AndroidFunctionsMathRegistry.java rename to calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorFunctionsMathRegistry.java index bfcc919f..20757ae1 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/AndroidFunctionsMathRegistry.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorFunctionsMathRegistry.java @@ -22,7 +22,7 @@ import java.util.Map; * Date: 11/17/11 * Time: 11:28 PM */ -public class AndroidFunctionsMathRegistry extends AbstractCalculatorMathRegistry { +public class CalculatorFunctionsMathRegistry extends AbstractCalculatorMathRegistry { @NotNull private static final Map substitutes = new HashMap(); @@ -33,8 +33,8 @@ public class AndroidFunctionsMathRegistry extends AbstractCalculatorMathRegistry @NotNull private static final String FUNCTION_DESCRIPTION_PREFIX = "c_fun_description_"; - public AndroidFunctionsMathRegistry(@NotNull MathRegistry functionsRegistry, - @NotNull MathEntityDao mathEntityDao) { + public CalculatorFunctionsMathRegistry(@NotNull MathRegistry functionsRegistry, + @NotNull MathEntityDao mathEntityDao) { super(functionsRegistry, FUNCTION_DESCRIPTION_PREFIX, mathEntityDao); } diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/AndroidOperatorsMathRegistry.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorOperatorsMathRegistry.java similarity index 91% rename from calculatorpp/src/main/java/org/solovyev/android/calculator/AndroidOperatorsMathRegistry.java rename to calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorOperatorsMathRegistry.java index 4882c0fd..58be6e97 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/AndroidOperatorsMathRegistry.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorOperatorsMathRegistry.java @@ -18,7 +18,7 @@ import java.util.*; * Date: 11/17/11 * Time: 11:29 PM */ -public class AndroidOperatorsMathRegistry extends AbstractCalculatorMathRegistry { +public class CalculatorOperatorsMathRegistry extends AbstractCalculatorMathRegistry { @NotNull private static final Map substitutes = new HashMap(); @@ -34,7 +34,7 @@ public class AndroidOperatorsMathRegistry extends AbstractCalculatorMathRegistry @NotNull private static final String OPERATOR_DESCRIPTION_PREFIX = "c_op_description_"; - public AndroidOperatorsMathRegistry(@NotNull MathRegistry functionsRegistry, + public CalculatorOperatorsMathRegistry(@NotNull MathRegistry functionsRegistry, @NotNull MathEntityDao mathEntityDao) { super(functionsRegistry, OPERATOR_DESCRIPTION_PREFIX, mathEntityDao); } diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorVarsActivity.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorVarsActivity.java index c14bc860..177ccb34 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorVarsActivity.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorVarsActivity.java @@ -1,100 +1,107 @@ -/* - * Copyright (c) 2009-2011. Created by serso aka se.solovyev. - * For more information, please, contact se.solovyev@gmail.com - * or visit http://se.solovyev.org - */ - -package org.solovyev.android.calculator.math.edit; - -import android.content.Intent; -import android.os.Bundle; -import com.actionbarsherlock.app.SherlockFragmentActivity; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.solovyev.android.calculator.*; -import org.solovyev.android.calculator.about.CalculatorFragmentType; -import org.solovyev.android.calculator.history.CalculatorHistoryActivity; -import org.solovyev.android.calculator.model.VarCategory; - -/** - * User: serso - * Date: 12/21/11 - * Time: 11:05 PM - */ -public class CalculatorVarsActivity extends SherlockFragmentActivity implements CalculatorEventListener { - - @NotNull - private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryActivity.class.getSimpleName()); - - @Override - public void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - activityHelper.onCreate(this, savedInstanceState); - - final Bundle bundle; - - final Intent intent = getIntent(); - if (intent != null) { - bundle = intent.getExtras(); - } else { - bundle = null; - } - - final CalculatorFragmentType fragmentType = CalculatorFragmentType.variables; - - for (VarCategory category : VarCategory.getCategoriesByTabOrder()) { - - final Bundle fragmentParameters; - - if (category == VarCategory.my && bundle != null) { - AbstractMathEntityListFragment.putCategory(bundle, category.name()); - fragmentParameters = bundle; - } else { - fragmentParameters = AbstractMathEntityListFragment.createBundleFor(category.name()); - } - - - activityHelper.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), fragmentParameters, category.getCaptionId(), R.id.main_layout); - - } - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - - activityHelper.onSaveInstanceState(this, outState); - } - - @Override - protected void onResume() { - super.onResume(); - - activityHelper.onResume(this); - } - - @Override - protected void onPause() { - this.activityHelper.onPause(this); - - super.onPause(); - } - - - @Override - protected void onDestroy() { - super.onDestroy(); - - this.activityHelper.onDestroy(this); - } - - @Override - public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) { - switch (calculatorEventType) { - case use_constant: - this.finish(); - break; - } - } -} +/* + * Copyright (c) 2009-2011. Created by serso aka se.solovyev. + * For more information, please, contact se.solovyev@gmail.com + * or visit http://se.solovyev.org + */ + +package org.solovyev.android.calculator.math.edit; + +import android.content.Intent; +import android.os.Bundle; +import com.actionbarsherlock.app.SherlockFragmentActivity; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.solovyev.android.calculator.*; +import org.solovyev.android.calculator.about.CalculatorFragmentType; +import org.solovyev.android.calculator.history.CalculatorHistoryActivity; +import org.solovyev.android.calculator.model.AndroidVarCategory; +import org.solovyev.android.calculator.model.VarCategory; + +/** + * User: serso + * Date: 12/21/11 + * Time: 11:05 PM + */ +public class CalculatorVarsActivity extends SherlockFragmentActivity implements CalculatorEventListener { + + @NotNull + private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryActivity.class.getSimpleName()); + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + activityHelper.onCreate(this, savedInstanceState); + + final Bundle bundle; + + final Intent intent = getIntent(); + if (intent != null) { + bundle = intent.getExtras(); + } else { + bundle = null; + } + + final CalculatorFragmentType fragmentType = CalculatorFragmentType.variables; + + for (VarCategory category : VarCategory.getCategoriesByTabOrder()) { + + final Bundle fragmentParameters; + + if (category == VarCategory.my && bundle != null) { + AbstractMathEntityListFragment.putCategory(bundle, category.name()); + fragmentParameters = bundle; + } else { + fragmentParameters = AbstractMathEntityListFragment.createBundleFor(category.name()); + } + + + final AndroidVarCategory androidVarCategory = AndroidVarCategory.valueOf(category); + + if (androidVarCategory != null) { + activityHelper.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), fragmentParameters, androidVarCategory.getCaptionId(), R.id.main_layout); + } else { + activityHelper.logError("Unable to find android var category for " + category); + } + + } + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + + activityHelper.onSaveInstanceState(this, outState); + } + + @Override + protected void onResume() { + super.onResume(); + + activityHelper.onResume(this); + } + + @Override + protected void onPause() { + this.activityHelper.onPause(this); + + super.onPause(); + } + + + @Override + protected void onDestroy() { + super.onDestroy(); + + this.activityHelper.onDestroy(this); + } + + @Override + public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) { + switch (calculatorEventType) { + case use_constant: + this.finish(); + break; + } + } +} diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/model/AndroidCalculatorEngine.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/model/AndroidCalculatorEngine.java index 2e5414ed..0cd96f89 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/model/AndroidCalculatorEngine.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/model/AndroidCalculatorEngine.java @@ -108,10 +108,10 @@ public class AndroidCalculatorEngine implements CalculatorEngine, SharedPreferen final JsclMathEngine engine = JsclMathEngine.getInstance(); this.calculatorEngine = new CalculatorEngineImpl(engine, - new AndroidVarsRegistryImpl(engine.getConstantsRegistry(), new AndroidMathEntityDao(R.string.p_calc_vars, application, Vars.class)), - new AndroidFunctionsMathRegistry(engine.getFunctionsRegistry(), new AndroidMathEntityDao(R.string.p_calc_functions, application, Functions.class)), - new AndroidOperatorsMathRegistry(engine.getOperatorsRegistry(), new AndroidMathEntityDao(null, application, null)), - new AndroidPostfixFunctionsRegistry(engine.getPostfixFunctionsRegistry(), new AndroidMathEntityDao(null, application, null)), + new CalculatorVarsRegistry(engine.getConstantsRegistry(), new AndroidMathEntityDao(R.string.p_calc_vars, application, Vars.class)), + new CalculatorFunctionsMathRegistry(engine.getFunctionsRegistry(), new AndroidMathEntityDao(R.string.p_calc_functions, application, Functions.class)), + new CalculatorOperatorsMathRegistry(engine.getOperatorsRegistry(), new AndroidMathEntityDao(null, application, null)), + new CalculatorPostfixFunctionsRegistry(engine.getPostfixFunctionsRegistry(), new AndroidMathEntityDao(null, application, null)), this.lock); } diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/model/AndroidVarCategory.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/model/AndroidVarCategory.java new file mode 100644 index 00000000..eb543853 --- /dev/null +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/model/AndroidVarCategory.java @@ -0,0 +1,37 @@ +package org.solovyev.android.calculator.model; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.solovyev.android.calculator.R; + +/** + * User: serso + * Date: 10/7/12 + * Time: 7:56 PM + */ +public enum AndroidVarCategory { + + system(R.string.c_var_system), + my(R.string.c_var_my); + + private final int captionId; + + AndroidVarCategory(int captionId) { + this.captionId = captionId; + } + + public int getCaptionId() { + return captionId; + } + + @Nullable + public static AndroidVarCategory valueOf(@NotNull VarCategory varCategory) { + for (AndroidVarCategory androidVarCategory : values()) { + if ( androidVarCategory.name().equals(varCategory.name()) ) { + return androidVarCategory; + } + } + + return null; + } +} diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/model/AndroidPostfixFunctionsRegistry.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/model/CalculatorPostfixFunctionsRegistry.java similarity index 86% rename from calculatorpp/src/main/java/org/solovyev/android/calculator/model/AndroidPostfixFunctionsRegistry.java rename to calculatorpp/src/main/java/org/solovyev/android/calculator/model/CalculatorPostfixFunctionsRegistry.java index 89389774..af8adfb0 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/model/AndroidPostfixFunctionsRegistry.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/model/CalculatorPostfixFunctionsRegistry.java @@ -20,7 +20,7 @@ import java.util.Map; * Date: 11/19/11 * Time: 1:48 PM */ -public class AndroidPostfixFunctionsRegistry extends AbstractCalculatorMathRegistry { +public class CalculatorPostfixFunctionsRegistry extends AbstractCalculatorMathRegistry { @NotNull private static final Map substitutes = new HashMap(); @@ -34,8 +34,8 @@ public class AndroidPostfixFunctionsRegistry extends AbstractCalculatorMathRegis @NotNull private static final String POSTFIX_FUNCTION_DESCRIPTION_PREFIX = "c_pf_description_"; - protected AndroidPostfixFunctionsRegistry(@NotNull MathRegistry functionsRegistry, - @NotNull MathEntityDao mathEntityDao) { + protected CalculatorPostfixFunctionsRegistry(@NotNull MathRegistry functionsRegistry, + @NotNull MathEntityDao mathEntityDao) { super(functionsRegistry, POSTFIX_FUNCTION_DESCRIPTION_PREFIX, mathEntityDao); } diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/model/AndroidVarsRegistryImpl.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/model/CalculatorVarsRegistry.java similarity index 91% rename from calculatorpp/src/main/java/org/solovyev/android/calculator/model/AndroidVarsRegistryImpl.java rename to calculatorpp/src/main/java/org/solovyev/android/calculator/model/CalculatorVarsRegistry.java index e69c29da..75b517e7 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/model/AndroidVarsRegistryImpl.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/model/CalculatorVarsRegistry.java @@ -22,7 +22,7 @@ import java.util.Map; * Date: 9/29/11 * Time: 4:57 PM */ -class AndroidVarsRegistryImpl extends AbstractCalculatorMathRegistry { +class CalculatorVarsRegistry extends AbstractCalculatorMathRegistry { @NotNull private static final Map substitutes = new HashMap(); @@ -34,8 +34,8 @@ class AndroidVarsRegistryImpl extends AbstractCalculatorMathRegistry mathRegistry, - @NotNull MathEntityDao mathEntityDao) { + protected CalculatorVarsRegistry(@NotNull MathRegistry mathRegistry, + @NotNull MathEntityDao mathEntityDao) { super(mathRegistry, "c_var_description_", mathEntityDao); } diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/model/VarCategory.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/model/VarCategory.java index 80c5d314..96c74875 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/model/VarCategory.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/model/VarCategory.java @@ -2,7 +2,6 @@ package org.solovyev.android.calculator.model; import jscl.math.function.IConstant; import org.jetbrains.annotations.NotNull; -import org.solovyev.android.calculator.R; import org.solovyev.common.collections.CollectionsUtils; import java.util.Collections; @@ -16,33 +15,26 @@ import java.util.List; */ public enum VarCategory { - system(R.string.c_var_system, 100){ + system(100){ @Override boolean isInCategory(@NotNull IConstant var) { return var.isSystem(); } }, - my(R.string.c_var_my, 0) { + my(0) { @Override boolean isInCategory(@NotNull IConstant var) { return !var.isSystem(); } }; - private final int captionId; - private final int tabOrder; - VarCategory(int captionId, int tabOrder) { - this.captionId = captionId; + VarCategory(int tabOrder) { this.tabOrder = tabOrder; } - public int getCaptionId() { - return captionId; - } - abstract boolean isInCategory(@NotNull IConstant var); @NotNull