registries
This commit is contained in:
parent
78a1cc4942
commit
4134204e67
@ -66,6 +66,10 @@ public abstract class AbstractCalculatorHelper implements SharedPreferences.OnSh
|
|||||||
Log.d(logTag, message);
|
Log.d(logTag, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void logError(@NotNull String message) {
|
||||||
|
Log.e(logTag, message);
|
||||||
|
}
|
||||||
|
|
||||||
public void processButtons(@NotNull final Activity activity, @NotNull View root) {
|
public void processButtons(@NotNull final Activity activity, @NotNull View root) {
|
||||||
dpclRegister.clear();
|
dpclRegister.clear();
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ public enum AndroidFunctionCategory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public AndroidFunctionCategory valueOf( @NotNull FunctionCategory functionCategory ) {
|
public static AndroidFunctionCategory valueOf( @NotNull FunctionCategory functionCategory ) {
|
||||||
for (AndroidFunctionCategory androidFunctionCategory : values()) {
|
for (AndroidFunctionCategory androidFunctionCategory : values()) {
|
||||||
if ( androidFunctionCategory.name().equals(functionCategory.name()) ) {
|
if ( androidFunctionCategory.name().equals(functionCategory.name()) ) {
|
||||||
return androidFunctionCategory;
|
return androidFunctionCategory;
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: serso
|
||||||
|
* Date: 10/7/12
|
||||||
|
* Time: 7:41 PM
|
||||||
|
*/
|
||||||
|
public enum AndroidOperatorCategory {
|
||||||
|
|
||||||
|
derivatives(R.string.derivatives),
|
||||||
|
other(R.string.other),
|
||||||
|
my(R.string.c_fun_category_my),
|
||||||
|
common(R.string.c_fun_category_common);
|
||||||
|
|
||||||
|
private final int captionId;
|
||||||
|
|
||||||
|
AndroidOperatorCategory(int captionId) {
|
||||||
|
this.captionId = captionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCaptionId() {
|
||||||
|
return captionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static AndroidOperatorCategory valueOf(@NotNull OperatorCategory operatorCategory) {
|
||||||
|
for (AndroidOperatorCategory androidOperatorCategory : values()) {
|
||||||
|
if ( androidOperatorCategory.name().equals(operatorCategory.name()) ) {
|
||||||
|
return androidOperatorCategory;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import jscl.math.operator.*;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.solovyev.common.JBuilder;
|
||||||
|
import org.solovyev.common.math.MathRegistry;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: serso
|
||||||
|
* Date: 11/17/11
|
||||||
|
* Time: 11:29 PM
|
||||||
|
*/
|
||||||
|
public class AndroidOperatorsMathRegistry extends AbstractCalculatorMathRegistry<Operator, MathPersistenceEntity> {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static final Map<String, String> substitutes = new HashMap<String, String>();
|
||||||
|
static {
|
||||||
|
substitutes.put("Σ", "sum");
|
||||||
|
substitutes.put("∏", "product");
|
||||||
|
substitutes.put("∂", "derivative");
|
||||||
|
substitutes.put("∫ab", "integral_ab");
|
||||||
|
substitutes.put("∫", "integral");
|
||||||
|
substitutes.put("Σ", "sum");
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static final String OPERATOR_DESCRIPTION_PREFIX = "c_op_description_";
|
||||||
|
|
||||||
|
public AndroidOperatorsMathRegistry(@NotNull MathRegistry<Operator> functionsRegistry,
|
||||||
|
@NotNull MathEntityDao<MathPersistenceEntity> mathEntityDao) {
|
||||||
|
super(functionsRegistry, OPERATOR_DESCRIPTION_PREFIX, mathEntityDao);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
protected Map<String, String> getSubstitutes() {
|
||||||
|
return substitutes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCategory(@NotNull Operator operator) {
|
||||||
|
for (OperatorCategory category : OperatorCategory.values()) {
|
||||||
|
if ( category.isInCategory(operator) ) {
|
||||||
|
return category.name();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load() {
|
||||||
|
// not supported yet
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
protected JBuilder<? extends Operator> createBuilder(@NotNull MathPersistenceEntity entity) {
|
||||||
|
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save() {
|
||||||
|
// not supported yet
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected MathPersistenceEntity transform(@NotNull Operator entity) {
|
||||||
|
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
protected MathEntityPersistenceContainer<MathPersistenceEntity> createPersistenceContainer() {
|
||||||
|
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
**********************************************************************
|
||||||
|
*
|
||||||
|
* STATIC
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
@ -58,4 +58,5 @@ public interface CalculatorActivityHelper {
|
|||||||
|
|
||||||
void processButtons(@NotNull Activity activity, @NotNull View root);
|
void processButtons(@NotNull Activity activity, @NotNull View root);
|
||||||
|
|
||||||
|
void logError(@NotNull String message);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,78 @@
|
|||||||
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
|
import jscl.math.operator.*;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.solovyev.common.collections.CollectionsUtils;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: serso
|
||||||
|
* Date: 10/7/12
|
||||||
|
* Time: 7:40 PM
|
||||||
|
*/
|
||||||
|
public enum OperatorCategory {
|
||||||
|
|
||||||
|
derivatives(100){
|
||||||
|
@Override
|
||||||
|
public boolean isInCategory(@NotNull Operator operator) {
|
||||||
|
return operator instanceof Derivative || operator instanceof Integral || operator instanceof IndefiniteIntegral;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
other(200) {
|
||||||
|
@Override
|
||||||
|
public boolean isInCategory(@NotNull Operator operator) {
|
||||||
|
return operator instanceof Sum || operator instanceof Product;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
my(0) {
|
||||||
|
@Override
|
||||||
|
public boolean isInCategory(@NotNull Operator operator) {
|
||||||
|
return !operator.isSystem();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
common(50) {
|
||||||
|
@Override
|
||||||
|
public boolean isInCategory(@NotNull Operator operator) {
|
||||||
|
for (OperatorCategory category : values()) {
|
||||||
|
if ( category != this ) {
|
||||||
|
if ( category.isInCategory(operator) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final int tabOrder;
|
||||||
|
|
||||||
|
OperatorCategory(int tabOrder) {
|
||||||
|
this.tabOrder = tabOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract boolean isInCategory(@NotNull Operator operator);
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static List<OperatorCategory> getCategoriesByTabOrder() {
|
||||||
|
final List<OperatorCategory> result = CollectionsUtils.asList(OperatorCategory.values());
|
||||||
|
|
||||||
|
Collections.sort(result, new Comparator<OperatorCategory>() {
|
||||||
|
@Override
|
||||||
|
public int compare(OperatorCategory category, OperatorCategory category1) {
|
||||||
|
return category.tabOrder - category1.tabOrder;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// todo serso: current solution (as creating operators is not implemented yet)
|
||||||
|
result.remove(my);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,7 @@
|
|||||||
package org.solovyev.android.calculator.math.edit;
|
package org.solovyev.android.calculator.math.edit;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
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;
|
||||||
@ -33,7 +34,12 @@ public class CalculatorFunctionsActivity extends SherlockFragmentActivity implem
|
|||||||
final CalculatorFragmentType fragmentType = CalculatorFragmentType.functions;
|
final CalculatorFragmentType fragmentType = CalculatorFragmentType.functions;
|
||||||
|
|
||||||
for (FunctionCategory category : FunctionCategory.getCategoriesByTabOrder()) {
|
for (FunctionCategory category : FunctionCategory.getCategoriesByTabOrder()) {
|
||||||
activityHelper.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), AbstractMathEntityListFragment.createBundleFor(category.name()), category.getCaptionId(), R.id.main_layout);
|
final AndroidFunctionCategory androidCategory = AndroidFunctionCategory.valueOf(category);
|
||||||
|
if (androidCategory != null) {
|
||||||
|
activityHelper.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), AbstractMathEntityListFragment.createBundleFor(category.name()), androidCategory.getCaptionId(), R.id.main_layout);
|
||||||
|
} else {
|
||||||
|
Log.e(CalculatorFunctionsActivity.class.getSimpleName(), "Unable to find android function category for " + category);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ 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.AndroidOperatorsMathRegistry;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
@ -33,8 +32,13 @@ public class CalculatorOperatorsActivity extends SherlockFragmentActivity implem
|
|||||||
|
|
||||||
final CalculatorFragmentType fragmentType = CalculatorFragmentType.operators;
|
final CalculatorFragmentType fragmentType = CalculatorFragmentType.operators;
|
||||||
|
|
||||||
for (AndroidOperatorsMathRegistry.Category category : AndroidOperatorsMathRegistry.Category.getCategoriesByTabOrder()) {
|
for (OperatorCategory category : OperatorCategory.getCategoriesByTabOrder()) {
|
||||||
activityHelper.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), AbstractMathEntityListFragment.createBundleFor(category.name()), category.getCaptionId(), R.id.main_layout);
|
final AndroidOperatorCategory androidCategory = AndroidOperatorCategory.valueOf(category);
|
||||||
|
if (androidCategory != null) {
|
||||||
|
activityHelper.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), AbstractMathEntityListFragment.createBundleFor(category.name()), androidCategory.getCaptionId(), R.id.main_layout);
|
||||||
|
} else {
|
||||||
|
activityHelper.logError("Unable to find android operator category for " + category);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,165 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
|
||||||
* For more information, please, contact se.solovyev@gmail.com
|
|
||||||
* or visit http://se.solovyev.org
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.solovyev.android.calculator.model;
|
|
||||||
|
|
||||||
import jscl.math.operator.*;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.solovyev.android.calculator.*;
|
|
||||||
import org.solovyev.common.JBuilder;
|
|
||||||
import org.solovyev.common.collections.CollectionsUtils;
|
|
||||||
import org.solovyev.common.math.MathRegistry;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User: serso
|
|
||||||
* Date: 11/17/11
|
|
||||||
* Time: 11:29 PM
|
|
||||||
*/
|
|
||||||
public class AndroidOperatorsMathRegistry extends AbstractCalculatorMathRegistry<Operator, MathPersistenceEntity> {
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private static final Map<String, String> substitutes = new HashMap<String, String>();
|
|
||||||
static {
|
|
||||||
substitutes.put("Σ", "sum");
|
|
||||||
substitutes.put("∏", "product");
|
|
||||||
substitutes.put("∂", "derivative");
|
|
||||||
substitutes.put("∫ab", "integral_ab");
|
|
||||||
substitutes.put("∫", "integral");
|
|
||||||
substitutes.put("Σ", "sum");
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private static final String OPERATOR_DESCRIPTION_PREFIX = "c_op_description_";
|
|
||||||
|
|
||||||
protected AndroidOperatorsMathRegistry(@NotNull MathRegistry<Operator> functionsRegistry,
|
|
||||||
@NotNull MathEntityDao<MathPersistenceEntity> mathEntityDao) {
|
|
||||||
super(functionsRegistry, OPERATOR_DESCRIPTION_PREFIX, mathEntityDao);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
protected Map<String, String> getSubstitutes() {
|
|
||||||
return substitutes;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getCategory(@NotNull Operator operator) {
|
|
||||||
for (Category category : Category.values()) {
|
|
||||||
if ( category.isInCategory(operator) ) {
|
|
||||||
return category.name();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void load() {
|
|
||||||
// not supported yet
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
protected JBuilder<? extends Operator> createBuilder(@NotNull MathPersistenceEntity entity) {
|
|
||||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void save() {
|
|
||||||
// not supported yet
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected MathPersistenceEntity transform(@NotNull Operator entity) {
|
|
||||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
protected MathEntityPersistenceContainer<MathPersistenceEntity> createPersistenceContainer() {
|
|
||||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
**********************************************************************
|
|
||||||
*
|
|
||||||
* STATIC
|
|
||||||
*
|
|
||||||
**********************************************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
public static enum Category {
|
|
||||||
|
|
||||||
derivatives(R.string.derivatives, 100){
|
|
||||||
@Override
|
|
||||||
boolean isInCategory(@NotNull Operator operator) {
|
|
||||||
return operator instanceof Derivative || operator instanceof Integral || operator instanceof IndefiniteIntegral;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
other(R.string.other, 200) {
|
|
||||||
@Override
|
|
||||||
boolean isInCategory(@NotNull Operator operator) {
|
|
||||||
return operator instanceof Sum || operator instanceof Product;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
my(R.string.c_fun_category_my, 0) {
|
|
||||||
@Override
|
|
||||||
boolean isInCategory(@NotNull Operator operator) {
|
|
||||||
return !operator.isSystem();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
common(R.string.c_fun_category_common, 50) {
|
|
||||||
@Override
|
|
||||||
boolean isInCategory(@NotNull Operator operator) {
|
|
||||||
for (Category category : values()) {
|
|
||||||
if ( category != this ) {
|
|
||||||
if ( category.isInCategory(operator) ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final int captionId;
|
|
||||||
|
|
||||||
private final int tabOrder;
|
|
||||||
|
|
||||||
Category(int captionId, int tabOrder) {
|
|
||||||
this.captionId = captionId;
|
|
||||||
this.tabOrder = tabOrder;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCaptionId() {
|
|
||||||
return captionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract boolean isInCategory(@NotNull Operator operator);
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static List<Category> getCategoriesByTabOrder() {
|
|
||||||
final List<Category> result = CollectionsUtils.asList(Category.values());
|
|
||||||
|
|
||||||
Collections.sort(result, new Comparator<Category>() {
|
|
||||||
@Override
|
|
||||||
public int compare(Category category, Category category1) {
|
|
||||||
return category.tabOrder - category1.tabOrder;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// todo serso: current solution (as creating operators is not implemented yet)
|
|
||||||
result.remove(my);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,10 +8,7 @@ package org.solovyev.android.calculator.model;
|
|||||||
|
|
||||||
import jscl.math.operator.Operator;
|
import jscl.math.operator.Operator;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.solovyev.android.calculator.AbstractCalculatorMathRegistry;
|
import org.solovyev.android.calculator.*;
|
||||||
import org.solovyev.android.calculator.MathEntityDao;
|
|
||||||
import org.solovyev.android.calculator.MathEntityPersistenceContainer;
|
|
||||||
import org.solovyev.android.calculator.MathPersistenceEntity;
|
|
||||||
import org.solovyev.common.JBuilder;
|
import org.solovyev.common.JBuilder;
|
||||||
import org.solovyev.common.math.MathRegistry;
|
import org.solovyev.common.math.MathRegistry;
|
||||||
|
|
||||||
@ -51,7 +48,7 @@ public class AndroidPostfixFunctionsRegistry extends AbstractCalculatorMathRegis
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCategory(@NotNull Operator operator) {
|
public String getCategory(@NotNull Operator operator) {
|
||||||
for (AndroidOperatorsMathRegistry.Category category : AndroidOperatorsMathRegistry.Category.values()) {
|
for (OperatorCategory category : OperatorCategory.values()) {
|
||||||
if ( category.isInCategory(operator) ) {
|
if ( category.isInCategory(operator) ) {
|
||||||
return category.name();
|
return category.name();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user