registries
This commit is contained in:
parent
4134204e67
commit
52e6b4b79d
@ -22,7 +22,7 @@ import java.util.Map;
|
|||||||
* Date: 11/17/11
|
* Date: 11/17/11
|
||||||
* Time: 11:28 PM
|
* Time: 11:28 PM
|
||||||
*/
|
*/
|
||||||
public class AndroidFunctionsMathRegistry extends AbstractCalculatorMathRegistry<Function, AFunction> {
|
public class CalculatorFunctionsMathRegistry extends AbstractCalculatorMathRegistry<Function, AFunction> {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static final Map<String, String> substitutes = new HashMap<String, String>();
|
private static final Map<String, String> substitutes = new HashMap<String, String>();
|
||||||
@ -33,8 +33,8 @@ public class AndroidFunctionsMathRegistry extends AbstractCalculatorMathRegistry
|
|||||||
@NotNull
|
@NotNull
|
||||||
private static final String FUNCTION_DESCRIPTION_PREFIX = "c_fun_description_";
|
private static final String FUNCTION_DESCRIPTION_PREFIX = "c_fun_description_";
|
||||||
|
|
||||||
public AndroidFunctionsMathRegistry(@NotNull MathRegistry<Function> functionsRegistry,
|
public CalculatorFunctionsMathRegistry(@NotNull MathRegistry<Function> functionsRegistry,
|
||||||
@NotNull MathEntityDao<AFunction> mathEntityDao) {
|
@NotNull MathEntityDao<AFunction> mathEntityDao) {
|
||||||
super(functionsRegistry, FUNCTION_DESCRIPTION_PREFIX, mathEntityDao);
|
super(functionsRegistry, FUNCTION_DESCRIPTION_PREFIX, mathEntityDao);
|
||||||
}
|
}
|
||||||
|
|
@ -18,7 +18,7 @@ import java.util.*;
|
|||||||
* Date: 11/17/11
|
* Date: 11/17/11
|
||||||
* Time: 11:29 PM
|
* Time: 11:29 PM
|
||||||
*/
|
*/
|
||||||
public class AndroidOperatorsMathRegistry extends AbstractCalculatorMathRegistry<Operator, MathPersistenceEntity> {
|
public class CalculatorOperatorsMathRegistry extends AbstractCalculatorMathRegistry<Operator, MathPersistenceEntity> {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static final Map<String, String> substitutes = new HashMap<String, String>();
|
private static final Map<String, String> substitutes = new HashMap<String, String>();
|
||||||
@ -34,7 +34,7 @@ public class AndroidOperatorsMathRegistry extends AbstractCalculatorMathRegistry
|
|||||||
@NotNull
|
@NotNull
|
||||||
private static final String OPERATOR_DESCRIPTION_PREFIX = "c_op_description_";
|
private static final String OPERATOR_DESCRIPTION_PREFIX = "c_op_description_";
|
||||||
|
|
||||||
public AndroidOperatorsMathRegistry(@NotNull MathRegistry<Operator> functionsRegistry,
|
public CalculatorOperatorsMathRegistry(@NotNull MathRegistry<Operator> functionsRegistry,
|
||||||
@NotNull MathEntityDao<MathPersistenceEntity> mathEntityDao) {
|
@NotNull MathEntityDao<MathPersistenceEntity> mathEntityDao) {
|
||||||
super(functionsRegistry, OPERATOR_DESCRIPTION_PREFIX, mathEntityDao);
|
super(functionsRegistry, OPERATOR_DESCRIPTION_PREFIX, mathEntityDao);
|
||||||
}
|
}
|
@ -1,100 +1,107 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
* For more information, please, contact se.solovyev@gmail.com
|
* For more information, please, contact se.solovyev@gmail.com
|
||||||
* or visit http://se.solovyev.org
|
* or visit http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.math.edit;
|
package org.solovyev.android.calculator.math.edit;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.*;
|
import org.solovyev.android.calculator.*;
|
||||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistoryActivity;
|
import org.solovyev.android.calculator.history.CalculatorHistoryActivity;
|
||||||
import org.solovyev.android.calculator.model.VarCategory;
|
import org.solovyev.android.calculator.model.AndroidVarCategory;
|
||||||
|
import org.solovyev.android.calculator.model.VarCategory;
|
||||||
/**
|
|
||||||
* User: serso
|
/**
|
||||||
* Date: 12/21/11
|
* User: serso
|
||||||
* Time: 11:05 PM
|
* Date: 12/21/11
|
||||||
*/
|
* Time: 11:05 PM
|
||||||
public class CalculatorVarsActivity extends SherlockFragmentActivity implements CalculatorEventListener {
|
*/
|
||||||
|
public class CalculatorVarsActivity extends SherlockFragmentActivity implements CalculatorEventListener {
|
||||||
@NotNull
|
|
||||||
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryActivity.class.getSimpleName());
|
@NotNull
|
||||||
|
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryActivity.class.getSimpleName());
|
||||||
@Override
|
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
@Override
|
||||||
super.onCreate(savedInstanceState);
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
activityHelper.onCreate(this, savedInstanceState);
|
|
||||||
|
activityHelper.onCreate(this, savedInstanceState);
|
||||||
final Bundle bundle;
|
|
||||||
|
final Bundle bundle;
|
||||||
final Intent intent = getIntent();
|
|
||||||
if (intent != null) {
|
final Intent intent = getIntent();
|
||||||
bundle = intent.getExtras();
|
if (intent != null) {
|
||||||
} else {
|
bundle = intent.getExtras();
|
||||||
bundle = null;
|
} else {
|
||||||
}
|
bundle = null;
|
||||||
|
}
|
||||||
final CalculatorFragmentType fragmentType = CalculatorFragmentType.variables;
|
|
||||||
|
final CalculatorFragmentType fragmentType = CalculatorFragmentType.variables;
|
||||||
for (VarCategory category : VarCategory.getCategoriesByTabOrder()) {
|
|
||||||
|
for (VarCategory category : VarCategory.getCategoriesByTabOrder()) {
|
||||||
final Bundle fragmentParameters;
|
|
||||||
|
final Bundle fragmentParameters;
|
||||||
if (category == VarCategory.my && bundle != null) {
|
|
||||||
AbstractMathEntityListFragment.putCategory(bundle, category.name());
|
if (category == VarCategory.my && bundle != null) {
|
||||||
fragmentParameters = bundle;
|
AbstractMathEntityListFragment.putCategory(bundle, category.name());
|
||||||
} else {
|
fragmentParameters = bundle;
|
||||||
fragmentParameters = AbstractMathEntityListFragment.createBundleFor(category.name());
|
} else {
|
||||||
}
|
fragmentParameters = AbstractMathEntityListFragment.createBundleFor(category.name());
|
||||||
|
}
|
||||||
|
|
||||||
activityHelper.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), fragmentParameters, category.getCaptionId(), R.id.main_layout);
|
|
||||||
|
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);
|
||||||
@Override
|
} else {
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
activityHelper.logError("Unable to find android var category for " + category);
|
||||||
super.onSaveInstanceState(outState);
|
}
|
||||||
|
|
||||||
activityHelper.onSaveInstanceState(this, outState);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
super.onResume();
|
super.onSaveInstanceState(outState);
|
||||||
|
|
||||||
activityHelper.onResume(this);
|
activityHelper.onSaveInstanceState(this, outState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onResume() {
|
||||||
this.activityHelper.onPause(this);
|
super.onResume();
|
||||||
|
|
||||||
super.onPause();
|
activityHelper.onResume(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@Override
|
protected void onPause() {
|
||||||
protected void onDestroy() {
|
this.activityHelper.onPause(this);
|
||||||
super.onDestroy();
|
|
||||||
|
super.onPause();
|
||||||
this.activityHelper.onDestroy(this);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
protected void onDestroy() {
|
||||||
switch (calculatorEventType) {
|
super.onDestroy();
|
||||||
case use_constant:
|
|
||||||
this.finish();
|
this.activityHelper.onDestroy(this);
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
}
|
@Override
|
||||||
}
|
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
||||||
|
switch (calculatorEventType) {
|
||||||
|
case use_constant:
|
||||||
|
this.finish();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -108,10 +108,10 @@ public class AndroidCalculatorEngine implements CalculatorEngine, SharedPreferen
|
|||||||
|
|
||||||
final JsclMathEngine engine = JsclMathEngine.getInstance();
|
final JsclMathEngine engine = JsclMathEngine.getInstance();
|
||||||
this.calculatorEngine = new CalculatorEngineImpl(engine,
|
this.calculatorEngine = new CalculatorEngineImpl(engine,
|
||||||
new AndroidVarsRegistryImpl(engine.getConstantsRegistry(), new AndroidMathEntityDao<Var>(R.string.p_calc_vars, application, Vars.class)),
|
new CalculatorVarsRegistry(engine.getConstantsRegistry(), new AndroidMathEntityDao<Var>(R.string.p_calc_vars, application, Vars.class)),
|
||||||
new AndroidFunctionsMathRegistry(engine.getFunctionsRegistry(), new AndroidMathEntityDao<AFunction>(R.string.p_calc_functions, application, Functions.class)),
|
new CalculatorFunctionsMathRegistry(engine.getFunctionsRegistry(), new AndroidMathEntityDao<AFunction>(R.string.p_calc_functions, application, Functions.class)),
|
||||||
new AndroidOperatorsMathRegistry(engine.getOperatorsRegistry(), new AndroidMathEntityDao<MathPersistenceEntity>(null, application, null)),
|
new CalculatorOperatorsMathRegistry(engine.getOperatorsRegistry(), new AndroidMathEntityDao<MathPersistenceEntity>(null, application, null)),
|
||||||
new AndroidPostfixFunctionsRegistry(engine.getPostfixFunctionsRegistry(), new AndroidMathEntityDao<MathPersistenceEntity>(null, application, null)),
|
new CalculatorPostfixFunctionsRegistry(engine.getPostfixFunctionsRegistry(), new AndroidMathEntityDao<MathPersistenceEntity>(null, application, null)),
|
||||||
this.lock);
|
this.lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -20,7 +20,7 @@ import java.util.Map;
|
|||||||
* Date: 11/19/11
|
* Date: 11/19/11
|
||||||
* Time: 1:48 PM
|
* Time: 1:48 PM
|
||||||
*/
|
*/
|
||||||
public class AndroidPostfixFunctionsRegistry extends AbstractCalculatorMathRegistry<Operator, MathPersistenceEntity> {
|
public class CalculatorPostfixFunctionsRegistry extends AbstractCalculatorMathRegistry<Operator, MathPersistenceEntity> {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static final Map<String, String> substitutes = new HashMap<String, String>();
|
private static final Map<String, String> substitutes = new HashMap<String, String>();
|
||||||
@ -34,8 +34,8 @@ public class AndroidPostfixFunctionsRegistry extends AbstractCalculatorMathRegis
|
|||||||
@NotNull
|
@NotNull
|
||||||
private static final String POSTFIX_FUNCTION_DESCRIPTION_PREFIX = "c_pf_description_";
|
private static final String POSTFIX_FUNCTION_DESCRIPTION_PREFIX = "c_pf_description_";
|
||||||
|
|
||||||
protected AndroidPostfixFunctionsRegistry(@NotNull MathRegistry<Operator> functionsRegistry,
|
protected CalculatorPostfixFunctionsRegistry(@NotNull MathRegistry<Operator> functionsRegistry,
|
||||||
@NotNull MathEntityDao<MathPersistenceEntity> mathEntityDao) {
|
@NotNull MathEntityDao<MathPersistenceEntity> mathEntityDao) {
|
||||||
super(functionsRegistry, POSTFIX_FUNCTION_DESCRIPTION_PREFIX, mathEntityDao);
|
super(functionsRegistry, POSTFIX_FUNCTION_DESCRIPTION_PREFIX, mathEntityDao);
|
||||||
}
|
}
|
||||||
|
|
@ -22,7 +22,7 @@ import java.util.Map;
|
|||||||
* Date: 9/29/11
|
* Date: 9/29/11
|
||||||
* Time: 4:57 PM
|
* Time: 4:57 PM
|
||||||
*/
|
*/
|
||||||
class AndroidVarsRegistryImpl extends AbstractCalculatorMathRegistry<IConstant, Var> {
|
class CalculatorVarsRegistry extends AbstractCalculatorMathRegistry<IConstant, Var> {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static final Map<String, String> substitutes = new HashMap<String, String>();
|
private static final Map<String, String> substitutes = new HashMap<String, String>();
|
||||||
@ -34,8 +34,8 @@ class AndroidVarsRegistryImpl extends AbstractCalculatorMathRegistry<IConstant,
|
|||||||
substitutes.put("NaN", "nan");
|
substitutes.put("NaN", "nan");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AndroidVarsRegistryImpl(@NotNull MathRegistry<IConstant> mathRegistry,
|
protected CalculatorVarsRegistry(@NotNull MathRegistry<IConstant> mathRegistry,
|
||||||
@NotNull MathEntityDao<Var> mathEntityDao) {
|
@NotNull MathEntityDao<Var> mathEntityDao) {
|
||||||
super(mathRegistry, "c_var_description_", mathEntityDao);
|
super(mathRegistry, "c_var_description_", mathEntityDao);
|
||||||
}
|
}
|
||||||
|
|
@ -2,7 +2,6 @@ package org.solovyev.android.calculator.model;
|
|||||||
|
|
||||||
import jscl.math.function.IConstant;
|
import jscl.math.function.IConstant;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.solovyev.android.calculator.R;
|
|
||||||
import org.solovyev.common.collections.CollectionsUtils;
|
import org.solovyev.common.collections.CollectionsUtils;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -16,33 +15,26 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public enum VarCategory {
|
public enum VarCategory {
|
||||||
|
|
||||||
system(R.string.c_var_system, 100){
|
system(100){
|
||||||
@Override
|
@Override
|
||||||
boolean isInCategory(@NotNull IConstant var) {
|
boolean isInCategory(@NotNull IConstant var) {
|
||||||
return var.isSystem();
|
return var.isSystem();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
my(R.string.c_var_my, 0) {
|
my(0) {
|
||||||
@Override
|
@Override
|
||||||
boolean isInCategory(@NotNull IConstant var) {
|
boolean isInCategory(@NotNull IConstant var) {
|
||||||
return !var.isSystem();
|
return !var.isSystem();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final int captionId;
|
|
||||||
|
|
||||||
private final int tabOrder;
|
private final int tabOrder;
|
||||||
|
|
||||||
VarCategory(int captionId, int tabOrder) {
|
VarCategory(int tabOrder) {
|
||||||
this.captionId = captionId;
|
|
||||||
this.tabOrder = tabOrder;
|
this.tabOrder = tabOrder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCaptionId() {
|
|
||||||
return captionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract boolean isInCategory(@NotNull IConstant var);
|
abstract boolean isInCategory(@NotNull IConstant var);
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
Loading…
Reference in New Issue
Block a user