registries

This commit is contained in:
Sergey Solovyev 2012-10-07 19:29:37 +04:00
parent d4cff84040
commit 78a1cc4942
32 changed files with 1441 additions and 1290 deletions

View File

@ -1,46 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>org.solovyev.android</groupId> <groupId>org.solovyev.android</groupId>
<artifactId>calculatorpp-parent</artifactId> <artifactId>calculatorpp-parent</artifactId>
<version>1.3.2</version> <version>1.3.2</version>
</parent> </parent>
<groupId>org.solovyev.android</groupId> <groupId>org.solovyev.android</groupId>
<artifactId>calculatorpp-core</artifactId> <artifactId>calculatorpp-core</artifactId>
<version>1.3.2</version> <version>1.3.2</version>
<name>Calculator++ Application Core</name> <name>Calculator++ Application Core</name>
<packaging>jar</packaging> <packaging>jar</packaging>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>org.solovyev</groupId>
<artifactId>junit</artifactId> <artifactId>common-text</artifactId>
<scope>test</scope> </dependency>
</dependency>
<dependency>
<dependency> <groupId>junit</groupId>
<groupId>com.intellij</groupId> <artifactId>junit</artifactId>
<artifactId>annotations</artifactId> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.solovyev</groupId> <groupId>org.mockito</groupId>
<artifactId>jscl</artifactId> <artifactId>mockito-core</artifactId>
</dependency> <version>1.9.0</version>
<scope>test</scope>
<dependency> </dependency>
<groupId>org.simpleframework</groupId>
<artifactId>simple-xml</artifactId> <dependency>
</dependency> <groupId>com.intellij</groupId>
<artifactId>annotations</artifactId>
</dependencies> </dependency>
<dependency>
<groupId>org.solovyev</groupId>
<artifactId>jscl</artifactId>
</dependency>
<dependency>
<groupId>org.simpleframework</groupId>
<artifactId>simple-xml</artifactId>
</dependency>
</dependencies>
</project> </project>

View File

@ -0,0 +1,148 @@
/*
* 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 org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.common.JBuilder;
import org.solovyev.common.math.MathEntity;
import org.solovyev.common.math.MathRegistry;
import java.util.List;
import java.util.Map;
/**
* User: serso
* Date: 10/30/11
* Time: 1:03 AM
*/
public abstract class AbstractCalculatorMathRegistry<T extends MathEntity, P extends MathPersistenceEntity> implements CalculatorMathRegistry<T> {
@NotNull
private final MathRegistry<T> mathRegistry;
@NotNull
private final String prefix;
@NotNull
private final MathEntityDao<P> mathEntityDao;
protected AbstractCalculatorMathRegistry(@NotNull MathRegistry<T> mathRegistry,
@NotNull String prefix,
@NotNull MathEntityDao<P> mathEntityDao) {
this.mathRegistry = mathRegistry;
this.prefix = prefix;
this.mathEntityDao = mathEntityDao;
}
@NotNull
protected abstract Map<String, String> getSubstitutes();
@Nullable
@Override
public String getDescription(@NotNull String mathEntityName) {
final String stringName;
final Map<String, String> substitutes = getSubstitutes();
final String substitute = substitutes.get(mathEntityName);
if (substitute == null) {
stringName = prefix + mathEntityName;
} else {
stringName = prefix + substitute;
}
return mathEntityDao.getDescription(stringName);
}
public synchronized void load() {
final MathEntityPersistenceContainer<P> persistenceContainer = mathEntityDao.load();
if (persistenceContainer != null) {
for (P entity : persistenceContainer.getEntities()) {
if (!contains(entity.getName())) {
add(createBuilder(entity));
}
}
}
/*Log.d(AndroidVarsRegistry.class.getName(), vars.size() + " variables registered!");
for (Var var : vars) {
Log.d(AndroidVarsRegistry.class.getName(), var.toString());
}*/
}
@NotNull
protected abstract JBuilder<? extends T> createBuilder(@NotNull P entity);
@Override
public synchronized void save() {
final MathEntityPersistenceContainer<P> container = createPersistenceContainer();
for (T entity : this.getEntities()) {
if (!entity.isSystem()) {
final P persistenceEntity = transform(entity);
if (persistenceEntity != null) {
container.getEntities().add(persistenceEntity);
}
}
}
this.mathEntityDao.save(container);
}
@Nullable
protected abstract P transform(@NotNull T entity);
@NotNull
protected abstract MathEntityPersistenceContainer<P> createPersistenceContainer();
@NotNull
@Override
public List<T> getEntities() {
return mathRegistry.getEntities();
}
@NotNull
@Override
public List<T> getSystemEntities() {
return mathRegistry.getSystemEntities();
}
@Override
public T add(@NotNull JBuilder<? extends T> JBuilder) {
return mathRegistry.add(JBuilder);
}
@Override
public void remove(@NotNull T var) {
mathRegistry.remove(var);
}
@NotNull
@Override
public List<String> getNames() {
return mathRegistry.getNames();
}
@Override
public boolean contains(@NotNull String name) {
return mathRegistry.contains(name);
}
@Override
public T get(@NotNull String name) {
return mathRegistry.get(name);
}
@Override
public T getById(@NotNull Integer id) {
return mathRegistry.getById(id);
}
}

View File

@ -0,0 +1,20 @@
package org.solovyev.android.calculator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* User: serso
* Date: 10/7/12
* Time: 6:43 PM
*/
public interface MathEntityDao<T extends MathPersistenceEntity> {
void save(@NotNull MathEntityPersistenceContainer<T> container);
@Nullable
MathEntityPersistenceContainer<T> load();
@Nullable
String getDescription(@NotNull String descriptionId);
}

View File

@ -1,4 +1,4 @@
package org.solovyev.android.calculator.model; package org.solovyev.android.calculator;
import java.util.List; import java.util.List;
@ -8,5 +8,7 @@ import java.util.List;
* Time: 5:03 PM * Time: 5:03 PM
*/ */
public interface MathEntityPersistenceContainer<T extends MathPersistenceEntity> { public interface MathEntityPersistenceContainer<T extends MathPersistenceEntity> {
public List<T> getEntities();
public List<T> getEntities();
} }

View File

@ -4,7 +4,7 @@
* or visit http://se.solovyev.org * or visit http://se.solovyev.org
*/ */
package org.solovyev.android.calculator.model; package org.solovyev.android.calculator;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;

View File

@ -354,7 +354,7 @@ public enum MathType {
final String s = CollectionsUtils.find(mathType.getTokens(), startsWithFinder); final String s = CollectionsUtils.find(mathType.getTokens(), startsWithFinder);
if (s != null) { if (s != null) {
if ( s.length() == 1 ) { if ( s.length() == 1 ) {
if (hexMode || JsclMathEngine.instance.getNumeralBase() == NumeralBase.hex) { if (hexMode || JsclMathEngine.getInstance().getNumeralBase() == NumeralBase.hex) {
final Character ch = s.charAt(0); final Character ch = s.charAt(0);
if ( NumeralBase.hex.getAcceptableCharacters().contains(ch) ) { if ( NumeralBase.hex.getAcceptableCharacters().contains(ch) ) {
return new Result(MathType.digit, s); return new Result(MathType.digit, s);

View File

@ -10,6 +10,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.simpleframework.xml.Element; import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root; import org.simpleframework.xml.Root;
import org.solovyev.android.calculator.MathPersistenceEntity;
import org.solovyev.common.collections.CollectionsUtils; import org.solovyev.common.collections.CollectionsUtils;
import org.solovyev.common.text.CollectionTransformations; import org.solovyev.common.text.CollectionTransformations;
import org.solovyev.common.text.StringMapper; import org.solovyev.common.text.StringMapper;

View File

@ -1,10 +1,9 @@
package org.solovyev.android.calculator.model; package org.solovyev.android.calculator.model;
import jscl.math.function.CustomFunction; import jscl.math.function.CustomFunction;
import jscl.math.function.Function;
import jscl.math.function.IConstant;
import org.simpleframework.xml.ElementList; import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root; import org.simpleframework.xml.Root;
import org.solovyev.android.calculator.MathEntityPersistenceContainer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@ -0,0 +1,32 @@
package org.solovyev.android.calculator;
import jscl.JsclMathEngine;
import org.jetbrains.annotations.NotNull;
import org.mockito.Mockito;
import org.solovyev.android.calculator.history.CalculatorHistory;
/**
* User: serso
* Date: 10/7/12
* Time: 6:30 PM
*/
public class AbstractCalculatorTest {
protected static void staticSetUp() throws Exception {
CalculatorLocatorImpl.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class));
}
protected void setUp() throws Exception {
CalculatorLocatorImpl.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class));
}
@NotNull
private static CalculatorEngineImpl newCalculatorEngine() {
final CalculatorMathRegistry varsRegistry = Mockito.mock(CalculatorMathRegistry.class);
//Mockito.when(varsRegistry.get())
final CalculatorEngineImpl result = new CalculatorEngineImpl(JsclMathEngine.getInstance(), varsRegistry, Mockito.mock(CalculatorMathRegistry.class), Mockito.mock(CalculatorMathRegistry.class), Mockito.mock(CalculatorMathRegistry.class), null);
result.init();
return result;
}
}

View File

@ -1,200 +1,201 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import junit.framework.Assert; import junit.framework.Assert;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
/** /**
* User: Solovyev_S * User: Solovyev_S
* Date: 21.09.12 * Date: 21.09.12
* Time: 12:44 * Time: 12:44
*/ */
public class CalculatorEditorImplTest { public class CalculatorEditorImplTest extends AbstractCalculatorTest {
@NotNull @NotNull
private CalculatorEditor calculatorEditor; private CalculatorEditor calculatorEditor;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
this.calculatorEditor = new CalculatorEditorImpl(new CalculatorImpl()); super.setUp();
} this.calculatorEditor = new CalculatorEditorImpl(CalculatorLocatorImpl.getInstance().getCalculator());
}
@Test
public void testInsert() throws Exception { @Test
CalculatorEditorViewState viewState = this.calculatorEditor.getViewState(); public void testInsert() throws Exception {
CalculatorEditorViewState viewState = this.calculatorEditor.getViewState();
Assert.assertEquals("", viewState.getText());
Assert.assertEquals(0, viewState.getSelection()); Assert.assertEquals("", viewState.getText());
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.insert("");
viewState = this.calculatorEditor.insert("");
Assert.assertEquals("", viewState.getText());
Assert.assertEquals(0, viewState.getSelection()); Assert.assertEquals("", viewState.getText());
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.insert("test");
viewState = this.calculatorEditor.insert("test");
Assert.assertEquals("test", viewState.getText());
Assert.assertEquals(4, viewState.getSelection()); Assert.assertEquals("test", viewState.getText());
Assert.assertEquals(4, viewState.getSelection());
viewState = this.calculatorEditor.insert("test");
Assert.assertEquals("testtest", viewState.getText()); viewState = this.calculatorEditor.insert("test");
Assert.assertEquals(8, viewState.getSelection()); Assert.assertEquals("testtest", viewState.getText());
Assert.assertEquals(8, viewState.getSelection());
viewState = this.calculatorEditor.insert("");
Assert.assertEquals("testtest", viewState.getText()); viewState = this.calculatorEditor.insert("");
Assert.assertEquals(8, viewState.getSelection()); Assert.assertEquals("testtest", viewState.getText());
Assert.assertEquals(8, viewState.getSelection());
viewState = this.calculatorEditor.insert("1234567890");
Assert.assertEquals("testtest1234567890", viewState.getText()); viewState = this.calculatorEditor.insert("1234567890");
Assert.assertEquals(18, viewState.getSelection()); Assert.assertEquals("testtest1234567890", viewState.getText());
Assert.assertEquals(18, viewState.getSelection());
viewState = this.calculatorEditor.moveCursorLeft();
viewState = this.calculatorEditor.insert("9"); viewState = this.calculatorEditor.moveCursorLeft();
Assert.assertEquals("testtest12345678990", viewState.getText()); viewState = this.calculatorEditor.insert("9");
Assert.assertEquals(18, viewState.getSelection()); Assert.assertEquals("testtest12345678990", viewState.getText());
Assert.assertEquals(18, viewState.getSelection());
viewState = this.calculatorEditor.setCursorOnStart();
viewState = this.calculatorEditor.insert("9"); viewState = this.calculatorEditor.setCursorOnStart();
Assert.assertEquals("9testtest12345678990", viewState.getText()); viewState = this.calculatorEditor.insert("9");
Assert.assertEquals(1, viewState.getSelection()); Assert.assertEquals("9testtest12345678990", viewState.getText());
Assert.assertEquals(1, viewState.getSelection());
viewState = this.calculatorEditor.erase();
viewState = this.calculatorEditor.insert("9"); viewState = this.calculatorEditor.erase();
Assert.assertEquals("9testtest12345678990", viewState.getText()); viewState = this.calculatorEditor.insert("9");
Assert.assertEquals(1, viewState.getSelection()); Assert.assertEquals("9testtest12345678990", viewState.getText());
} Assert.assertEquals(1, viewState.getSelection());
}
@Test
public void testErase() throws Exception { @Test
this.calculatorEditor.setText(""); public void testErase() throws Exception {
this.calculatorEditor.erase(); this.calculatorEditor.setText("");
this.calculatorEditor.erase();
Assert.assertEquals("", this.calculatorEditor.getViewState().getText());
Assert.assertEquals("", this.calculatorEditor.getViewState().getText());
this.calculatorEditor.setText("test");
this.calculatorEditor.erase(); this.calculatorEditor.setText("test");
Assert.assertEquals("tes", this.calculatorEditor.getViewState().getText()); this.calculatorEditor.erase();
Assert.assertEquals("tes", this.calculatorEditor.getViewState().getText());
this.calculatorEditor.erase();
Assert.assertEquals("te", this.calculatorEditor.getViewState().getText()); this.calculatorEditor.erase();
Assert.assertEquals("te", this.calculatorEditor.getViewState().getText());
this.calculatorEditor.erase();
Assert.assertEquals("t", this.calculatorEditor.getViewState().getText()); this.calculatorEditor.erase();
Assert.assertEquals("t", this.calculatorEditor.getViewState().getText());
this.calculatorEditor.erase();
Assert.assertEquals("", this.calculatorEditor.getViewState().getText()); this.calculatorEditor.erase();
Assert.assertEquals("", this.calculatorEditor.getViewState().getText());
this.calculatorEditor.erase();
Assert.assertEquals("", this.calculatorEditor.getViewState().getText()); this.calculatorEditor.erase();
Assert.assertEquals("", this.calculatorEditor.getViewState().getText());
this.calculatorEditor.setText("1234");
this.calculatorEditor.moveCursorLeft(); this.calculatorEditor.setText("1234");
this.calculatorEditor.erase(); this.calculatorEditor.moveCursorLeft();
Assert.assertEquals("124", this.calculatorEditor.getViewState().getText()); this.calculatorEditor.erase();
Assert.assertEquals("124", this.calculatorEditor.getViewState().getText());
this.calculatorEditor.erase();
Assert.assertEquals("14", this.calculatorEditor.getViewState().getText()); this.calculatorEditor.erase();
Assert.assertEquals("14", this.calculatorEditor.getViewState().getText());
this.calculatorEditor.erase();
Assert.assertEquals("4", this.calculatorEditor.getViewState().getText()); this.calculatorEditor.erase();
Assert.assertEquals("4", this.calculatorEditor.getViewState().getText());
this.calculatorEditor.setText("1");
this.calculatorEditor.moveCursorLeft(); this.calculatorEditor.setText("1");
this.calculatorEditor.erase(); this.calculatorEditor.moveCursorLeft();
Assert.assertEquals("1", this.calculatorEditor.getViewState().getText()); this.calculatorEditor.erase();
} Assert.assertEquals("1", this.calculatorEditor.getViewState().getText());
}
@Test
public void testMoveSelection() throws Exception { @Test
this.calculatorEditor.setText(""); public void testMoveSelection() throws Exception {
this.calculatorEditor.setText("");
CalculatorEditorViewState viewState = this.calculatorEditor.moveSelection(0);
Assert.assertEquals(0, viewState.getSelection()); CalculatorEditorViewState viewState = this.calculatorEditor.moveSelection(0);
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(2);
Assert.assertEquals(0, viewState.getSelection()); viewState = this.calculatorEditor.moveSelection(2);
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(100);
Assert.assertEquals(0, viewState.getSelection()); viewState = this.calculatorEditor.moveSelection(100);
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(-3);
Assert.assertEquals(0, viewState.getSelection()); viewState = this.calculatorEditor.moveSelection(-3);
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(-100);
Assert.assertEquals(0, viewState.getSelection()); viewState = this.calculatorEditor.moveSelection(-100);
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.setText("0123456789");
viewState = this.calculatorEditor.setText("0123456789");
viewState = this.calculatorEditor.moveSelection(0);
Assert.assertEquals(10, viewState.getSelection()); viewState = this.calculatorEditor.moveSelection(0);
Assert.assertEquals(10, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(1);
Assert.assertEquals(10, viewState.getSelection()); viewState = this.calculatorEditor.moveSelection(1);
Assert.assertEquals(10, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(-2);
Assert.assertEquals(8, viewState.getSelection()); viewState = this.calculatorEditor.moveSelection(-2);
Assert.assertEquals(8, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(1);
Assert.assertEquals(9, viewState.getSelection()); viewState = this.calculatorEditor.moveSelection(1);
Assert.assertEquals(9, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(-9);
Assert.assertEquals(0, viewState.getSelection()); viewState = this.calculatorEditor.moveSelection(-9);
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(-10);
Assert.assertEquals(0, viewState.getSelection()); viewState = this.calculatorEditor.moveSelection(-10);
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(2);
Assert.assertEquals(2, viewState.getSelection()); viewState = this.calculatorEditor.moveSelection(2);
Assert.assertEquals(2, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(2);
Assert.assertEquals(4, viewState.getSelection()); viewState = this.calculatorEditor.moveSelection(2);
Assert.assertEquals(4, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(-6);
Assert.assertEquals(0, viewState.getSelection()); viewState = this.calculatorEditor.moveSelection(-6);
} Assert.assertEquals(0, viewState.getSelection());
}
@Test
public void testSetText() throws Exception { @Test
CalculatorEditorViewState viewState = this.calculatorEditor.setText("test"); public void testSetText() throws Exception {
CalculatorEditorViewState viewState = this.calculatorEditor.setText("test");
Assert.assertEquals("test", viewState.getText());
Assert.assertEquals(4, viewState.getSelection()); Assert.assertEquals("test", viewState.getText());
Assert.assertEquals(4, viewState.getSelection());
viewState = this.calculatorEditor.setText("testtest");
Assert.assertEquals("testtest", viewState.getText()); viewState = this.calculatorEditor.setText("testtest");
Assert.assertEquals(8, viewState.getSelection()); Assert.assertEquals("testtest", viewState.getText());
Assert.assertEquals(8, viewState.getSelection());
viewState = this.calculatorEditor.setText("");
Assert.assertEquals("", viewState.getText()); viewState = this.calculatorEditor.setText("");
Assert.assertEquals(0, viewState.getSelection()); Assert.assertEquals("", viewState.getText());
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.setText("testtest", 0);
Assert.assertEquals("testtest", viewState.getText()); viewState = this.calculatorEditor.setText("testtest", 0);
Assert.assertEquals(0, viewState.getSelection()); Assert.assertEquals("testtest", viewState.getText());
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.setText("testtest", 2);
Assert.assertEquals("testtest", viewState.getText()); viewState = this.calculatorEditor.setText("testtest", 2);
Assert.assertEquals(2, viewState.getSelection()); Assert.assertEquals("testtest", viewState.getText());
Assert.assertEquals(2, viewState.getSelection());
viewState = this.calculatorEditor.setText("", 0);
Assert.assertEquals("", viewState.getText()); viewState = this.calculatorEditor.setText("", 0);
Assert.assertEquals(0, viewState.getSelection()); Assert.assertEquals("", viewState.getText());
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.setText("", 3);
Assert.assertEquals("", viewState.getText()); viewState = this.calculatorEditor.setText("", 3);
Assert.assertEquals(0, viewState.getSelection()); Assert.assertEquals("", viewState.getText());
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.setText("", -3);
Assert.assertEquals("", viewState.getText()); viewState = this.calculatorEditor.setText("", -3);
Assert.assertEquals(0, viewState.getSelection()); Assert.assertEquals("", viewState.getText());
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.setText("test");
Assert.assertEquals("test", viewState.getText()); viewState = this.calculatorEditor.setText("test");
Assert.assertEquals(4, viewState.getSelection()); Assert.assertEquals("test", viewState.getText());
Assert.assertEquals(4, viewState.getSelection());
viewState = this.calculatorEditor.setText("", 2);
Assert.assertEquals("", viewState.getText()); viewState = this.calculatorEditor.setText("", 2);
Assert.assertEquals(0, viewState.getSelection()); Assert.assertEquals("", viewState.getText());
} Assert.assertEquals(0, viewState.getSelection());
} }
}

View File

@ -9,18 +9,18 @@ package org.solovyev.android.calculator.math;
import junit.framework.Assert; import junit.framework.Assert;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.solovyev.android.calculator.CalculatorLocatorImpl; import org.solovyev.android.calculator.AbstractCalculatorTest;
/** /**
* User: serso * User: serso
* Date: 10/5/11 * Date: 10/5/11
* Time: 1:25 AM * Time: 1:25 AM
*/ */
public class MathTypeTest { public class MathTypeTest extends AbstractCalculatorTest {
@BeforeClass @BeforeClass
public static void setUp() throws Exception { public static void staticSetUp() throws Exception {
CalculatorLocatorImpl.getInstance().getEngine().init(); AbstractCalculatorTest.staticSetUp();
} }
@Test @Test

View File

@ -156,6 +156,13 @@
<artifactId>annotations</artifactId> <artifactId>annotations</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.pivotallabs</groupId>
<artifactId>robolectric</artifactId>
<version>1.1</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -0,0 +1,39 @@
package org.solovyev.android.calculator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* User: serso
* Date: 10/7/12
* Time: 7:17 PM
*/
public enum AndroidFunctionCategory {
trigonometric(R.string.c_fun_category_trig),
hyperbolic_trigonometric(R.string.c_fun_category_hyper_trig),
comparison(R.string.c_fun_category_comparison),
my(R.string.c_fun_category_my),
common(R.string.c_fun_category_common);
private final int captionId;
AndroidFunctionCategory(int captionId) {
this.captionId = captionId;
}
public int getCaptionId() {
return captionId;
}
@Nullable
public AndroidFunctionCategory valueOf( @NotNull FunctionCategory functionCategory ) {
for (AndroidFunctionCategory androidFunctionCategory : values()) {
if ( androidFunctionCategory.name().equals(functionCategory.name()) ) {
return androidFunctionCategory;
}
}
return null;
}
}

View File

@ -0,0 +1,89 @@
/*
* 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.function.CustomFunction;
import jscl.math.function.Function;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.model.AFunction;
import org.solovyev.android.calculator.model.Functions;
import org.solovyev.common.JBuilder;
import org.solovyev.common.math.MathRegistry;
import java.util.HashMap;
import java.util.Map;
/**
* User: serso
* Date: 11/17/11
* Time: 11:28 PM
*/
public class AndroidFunctionsMathRegistry extends AbstractCalculatorMathRegistry<Function, AFunction> {
@NotNull
private static final Map<String, String> substitutes = new HashMap<String, String>();
static {
substitutes.put("", "sqrt");
}
@NotNull
private static final String FUNCTION_DESCRIPTION_PREFIX = "c_fun_description_";
public AndroidFunctionsMathRegistry(@NotNull MathRegistry<Function> functionsRegistry,
@NotNull MathEntityDao<AFunction> mathEntityDao) {
super(functionsRegistry, FUNCTION_DESCRIPTION_PREFIX, mathEntityDao);
}
@Override
public void load() {
super.load();
add(new CustomFunction.Builder(true, "log", new String[]{"base", "x"}, "ln(x)/ln(base)"));
}
@NotNull
@Override
protected Map<String, String> getSubstitutes() {
return substitutes;
}
@Override
public String getCategory(@NotNull Function function) {
for (FunctionCategory category : FunctionCategory.values()) {
if ( category.isInCategory(function) ) {
return category.name();
}
}
return null;
}
@NotNull
@Override
protected JBuilder<? extends Function> createBuilder(@NotNull AFunction entity) {
return new CustomFunction.Builder(entity.getName(), entity.getParameterNamesAsArray(), entity.getContent());
}
@Override
protected AFunction transform(@NotNull Function entity) {
if (entity instanceof CustomFunction) {
final AFunction result = new AFunction();
result.setName(entity.getName());
result.setContent(((CustomFunction) entity).getContent());
result.setParameterNames(((CustomFunction) entity).getParameterNames());
return result;
} else {
return null;
}
}
@NotNull
@Override
protected MathEntityPersistenceContainer<AFunction> createPersistenceContainer() {
return new Functions();
}
}

View File

@ -0,0 +1,92 @@
package org.solovyev.android.calculator;
import jscl.math.function.ArcTrigonometric;
import jscl.math.function.Comparison;
import jscl.math.function.Function;
import jscl.math.function.Trigonometric;
import org.jetbrains.annotations.NotNull;
import org.solovyev.common.collections.CollectionsUtils;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* User: serso
* Date: 10/7/12
* Time: 7:15 PM
*/
public enum FunctionCategory {
trigonometric(100){
@Override
public boolean isInCategory(@NotNull Function function) {
return (function instanceof Trigonometric || function instanceof ArcTrigonometric) && !hyperbolic_trigonometric.isInCategory(function);
}
},
hyperbolic_trigonometric(300) {
private final List<String> names = Arrays.asList("sinh", "cosh", "tanh", "coth", "asinh", "acosh", "atanh", "acoth");
@Override
public boolean isInCategory(@NotNull Function function) {
return names.contains(function.getName());
}
},
comparison(200) {
@Override
public boolean isInCategory(@NotNull Function function) {
return function instanceof Comparison;
}
},
my(0) {
@Override
public boolean isInCategory(@NotNull Function function) {
return !function.isSystem();
}
},
common(50) {
@Override
public boolean isInCategory(@NotNull Function function) {
for (FunctionCategory category : values()) {
if ( category != this ) {
if ( category.isInCategory(function) ) {
return false;
}
}
}
return true;
}
};
private final int tabOrder;
FunctionCategory(int tabOrder) {
this.tabOrder = tabOrder;
}
public abstract boolean isInCategory(@NotNull Function function);
@NotNull
public static List<FunctionCategory> getCategoriesByTabOrder() {
final List<FunctionCategory> result = CollectionsUtils.asList(FunctionCategory.values());
Collections.sort(result, new Comparator<FunctionCategory>() {
@Override
public int compare(FunctionCategory category, FunctionCategory category1) {
return category.tabOrder - category1.tabOrder;
}
});
// todo serso: current solution (as creating functions is not implemented yet)
result.remove(my);
return result;
}
}

View File

@ -1,79 +1,78 @@
/* /*
* 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.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.AndroidFunctionsMathRegistry;
/**
/** * User: serso
* User: serso * Date: 12/21/11
* Date: 12/21/11 * Time: 10:33 PM
* Time: 10:33 PM */
*/ public class CalculatorFunctionsActivity extends SherlockFragmentActivity implements CalculatorEventListener {
public class CalculatorFunctionsActivity extends SherlockFragmentActivity implements CalculatorEventListener {
@NotNull
@NotNull private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryActivity.class.getSimpleName());
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryActivity.class.getSimpleName());
@Override
@Override public void onCreate(@Nullable Bundle savedInstanceState) {
public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
activityHelper.onCreate(this, savedInstanceState);
activityHelper.onCreate(this, savedInstanceState);
final CalculatorFragmentType fragmentType = CalculatorFragmentType.functions;
final CalculatorFragmentType fragmentType = CalculatorFragmentType.functions;
for (FunctionCategory category : FunctionCategory.getCategoriesByTabOrder()) {
for (AndroidFunctionsMathRegistry.Category category : AndroidFunctionsMathRegistry.Category.getCategoriesByTabOrder()) { activityHelper.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), AbstractMathEntityListFragment.createBundleFor(category.name()), category.getCaptionId(), R.id.main_layout);
activityHelper.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), AbstractMathEntityListFragment.createBundleFor(category.name()), category.getCaptionId(), R.id.main_layout); }
}
}
}
@Override
@Override protected void onSaveInstanceState(Bundle outState) {
protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState);
super.onSaveInstanceState(outState);
activityHelper.onSaveInstanceState(this, outState);
activityHelper.onSaveInstanceState(this, outState); }
}
@Override
@Override protected void onResume() {
protected void onResume() { super.onResume();
super.onResume();
activityHelper.onResume(this);
activityHelper.onResume(this); }
}
@Override
@Override protected void onPause() {
protected void onPause() { this.activityHelper.onPause(this);
this.activityHelper.onPause(this);
super.onPause();
super.onPause(); }
}
@Override
@Override protected void onDestroy() {
protected void onDestroy() { super.onDestroy();
super.onDestroy();
this.activityHelper.onDestroy(this);
this.activityHelper.onDestroy(this); }
}
@Override
@Override public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) { switch (calculatorEventType) {
switch (calculatorEventType) { case use_function:
case use_function: this.finish();
this.finish(); break;
break; }
} }
} }
}

View File

@ -1,198 +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 android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.preference.PreferenceManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
import org.solovyev.android.calculator.CalculatorMathRegistry;
import org.solovyev.android.calculator.R;
import org.solovyev.common.JBuilder;
import org.solovyev.common.math.MathEntity;
import org.solovyev.common.math.MathRegistry;
import java.io.StringWriter;
import java.util.List;
import java.util.Map;
/**
* User: serso
* Date: 10/30/11
* Time: 1:03 AM
*/
public abstract class AbstractAndroidMathRegistry<T extends MathEntity, P extends MathPersistenceEntity> implements CalculatorMathRegistry<T> {
@NotNull
private final MathRegistry<T> mathRegistry;
@NotNull
private final String prefix;
@NotNull
private final Context context;
protected AbstractAndroidMathRegistry(@NotNull MathRegistry<T> mathRegistry,
@NotNull String prefix,
@NotNull Application application) {
this.mathRegistry = mathRegistry;
this.prefix = prefix;
this.context = application;
}
@NotNull
protected abstract Map<String, String> getSubstitutes();
@Nullable
@Override
public String getDescription(@NotNull String mathEntityName) {
final String stringName;
final Map<String, String> substitutes = getSubstitutes();
final String substitute = substitutes.get(mathEntityName);
if (substitute == null) {
stringName = prefix + mathEntityName;
} else {
stringName = prefix + substitute;
}
final Resources resources = context.getResources();
final int stringId = resources.getIdentifier(stringName, "string", R.class.getPackage().getName());
try {
return resources.getString(stringId);
} catch (Resources.NotFoundException e) {
return null;
}
}
public synchronized void load() {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
if (preferences != null) {
final Integer preferenceStringId = getPreferenceStringId();
if (preferenceStringId != null) {
final String value = preferences.getString(context.getString(preferenceStringId), null);
if (value != null) {
final Serializer serializer = new Persister();
try {
final MathEntityPersistenceContainer<P> persistenceContainer = serializer.read(getPersistenceContainerClass(), value);
for (P entity : persistenceContainer.getEntities()) {
if (!contains(entity.getName())) {
add(createBuilder(entity));
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
/*Log.d(AndroidVarsRegistry.class.getName(), vars.size() + " variables registered!");
for (Var var : vars) {
Log.d(AndroidVarsRegistry.class.getName(), var.toString());
}*/
}
@NotNull
protected abstract JBuilder<? extends T> createBuilder(@NotNull P entity);
@NotNull
protected abstract Class<? extends MathEntityPersistenceContainer<P>> getPersistenceContainerClass();
@Nullable
protected abstract Integer getPreferenceStringId();
@Override
public synchronized void save() {
final Integer preferenceStringId = getPreferenceStringId();
if (preferenceStringId != null) {
final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
final SharedPreferences.Editor editor = settings.edit();
final MathEntityPersistenceContainer<P> container = createPersistenceContainer();
for (T entity : this.getEntities()) {
if (!entity.isSystem()) {
final P persistenceEntity = transform(entity);
if (persistenceEntity != null) {
container.getEntities().add(persistenceEntity);
}
}
}
final StringWriter sw = new StringWriter();
final Serializer serializer = new Persister();
try {
serializer.write(container, sw);
} catch (Exception e) {
throw new RuntimeException(e);
}
editor.putString(context.getString(preferenceStringId), sw.toString());
editor.commit();
}
}
@Nullable
protected abstract P transform(@NotNull T entity);
@NotNull
protected abstract MathEntityPersistenceContainer<P> createPersistenceContainer();
@NotNull
@Override
public List<T> getEntities() {
return mathRegistry.getEntities();
}
@NotNull
@Override
public List<T> getSystemEntities() {
return mathRegistry.getSystemEntities();
}
@Override
public T add(@NotNull JBuilder<? extends T> JBuilder) {
return mathRegistry.add(JBuilder);
}
@Override
public void remove(@NotNull T var) {
mathRegistry.remove(var);
}
@NotNull
@Override
public List<String> getNames() {
return mathRegistry.getNames();
}
@Override
public boolean contains(@NotNull String name) {
return mathRegistry.contains(name);
}
@Override
public T get(@NotNull String name) {
return mathRegistry.get(name);
}
@Override
public T getById(@NotNull Integer id) {
return mathRegistry.getById(id);
}
}

View File

@ -17,10 +17,7 @@ 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.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.CalculatorEngine; import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.CalculatorEngineImpl;
import org.solovyev.android.calculator.CalculatorMathEngine;
import org.solovyev.android.calculator.CalculatorMathRegistry;
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;
@ -109,12 +106,12 @@ public class AndroidCalculatorEngine implements CalculatorEngine, SharedPreferen
this.lock = new Object(); this.lock = new Object();
final JsclMathEngine engine = JsclMathEngine.instance; final JsclMathEngine engine = JsclMathEngine.getInstance();
this.calculatorEngine = new CalculatorEngineImpl(engine, this.calculatorEngine = new CalculatorEngineImpl(engine,
new AndroidVarsRegistryImpl(engine.getConstantsRegistry(), application), new AndroidVarsRegistryImpl(engine.getConstantsRegistry(), new AndroidMathEntityDao<Var>(R.string.p_calc_vars, application, Vars.class)),
new AndroidFunctionsMathRegistry(engine.getFunctionsRegistry(), application), new AndroidFunctionsMathRegistry(engine.getFunctionsRegistry(), new AndroidMathEntityDao<AFunction>(R.string.p_calc_functions, application, Functions.class)),
new AndroidOperatorsMathRegistry(engine.getOperatorsRegistry(), application), new AndroidOperatorsMathRegistry(engine.getOperatorsRegistry(), new AndroidMathEntityDao<MathPersistenceEntity>(null, application, null)),
new AndroidPostfixFunctionsRegistry(engine.getPostfixFunctionsRegistry(), application), new AndroidPostfixFunctionsRegistry(engine.getPostfixFunctionsRegistry(), new AndroidMathEntityDao<MathPersistenceEntity>(null, application, null)),
this.lock); this.lock);
} }

View File

@ -1,180 +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 android.app.Application;
import jscl.math.function.*;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.R;
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:28 PM
*/
public class AndroidFunctionsMathRegistry extends AbstractAndroidMathRegistry<Function, AFunction> {
public static enum Category {
trigonometric(R.string.c_fun_category_trig, 100){
@Override
boolean isInCategory(@NotNull Function function) {
return (function instanceof Trigonometric || function instanceof ArcTrigonometric) && !hyperbolic_trigonometric.isInCategory(function);
}
},
hyperbolic_trigonometric(R.string.c_fun_category_hyper_trig, 300) {
private final List<String> names = Arrays.asList("sinh", "cosh", "tanh", "coth", "asinh", "acosh", "atanh", "acoth");
@Override
boolean isInCategory(@NotNull Function function) {
return names.contains(function.getName());
}
},
comparison(R.string.c_fun_category_comparison, 200) {
@Override
boolean isInCategory(@NotNull Function function) {
return function instanceof Comparison;
}
},
my(R.string.c_fun_category_my, 0) {
@Override
boolean isInCategory(@NotNull Function function) {
return !function.isSystem();
}
},
common(R.string.c_fun_category_common, 50) {
@Override
boolean isInCategory(@NotNull Function function) {
for (Category category : values()) {
if ( category != this ) {
if ( category.isInCategory(function) ) {
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 Function function);
@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 functions is not implemented yet)
result.remove(my);
return result;
}
}
@NotNull
private static final Map<String, String> substitutes = new HashMap<String, String>();
static {
substitutes.put("", "sqrt");
}
@NotNull
private static final String FUNCTION_DESCRIPTION_PREFIX = "c_fun_description_";
public AndroidFunctionsMathRegistry(@NotNull MathRegistry<Function> functionsRegistry,
@NotNull Application application) {
super(functionsRegistry, FUNCTION_DESCRIPTION_PREFIX, application);
}
@Override
public void load() {
super.load();
add(new CustomFunction.Builder(true, "log", new String[]{"base", "x"}, "ln(x)/ln(base)"));
}
@NotNull
@Override
protected Map<String, String> getSubstitutes() {
return substitutes;
}
@Override
public String getCategory(@NotNull Function function) {
for (Category category : Category.values()) {
if ( category.isInCategory(function) ) {
return category.name();
}
}
return null;
}
@NotNull
@Override
protected JBuilder<? extends Function> createBuilder(@NotNull AFunction entity) {
return new CustomFunction.Builder(entity.getName(), entity.getParameterNamesAsArray(), entity.getContent());
}
@NotNull
@Override
protected Class<? extends MathEntityPersistenceContainer<AFunction>> getPersistenceContainerClass() {
return Functions.class;
}
@Override
protected Integer getPreferenceStringId() {
return R.string.p_calc_functions;
}
@Override
protected AFunction transform(@NotNull Function entity) {
if (entity instanceof CustomFunction) {
final AFunction result = new AFunction();
result.setName(entity.getName());
result.setContent(((CustomFunction) entity).getContent());
result.setParameterNames(((CustomFunction) entity).getParameterNames());
return result;
} else {
return null;
}
}
@NotNull
@Override
protected MathEntityPersistenceContainer<AFunction> createPersistenceContainer() {
return new Functions();
}
}

View File

@ -0,0 +1,95 @@
package org.solovyev.android.calculator.model;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.preference.PreferenceManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
import org.solovyev.android.calculator.MathEntityDao;
import org.solovyev.android.calculator.MathEntityPersistenceContainer;
import org.solovyev.android.calculator.MathPersistenceEntity;
import org.solovyev.android.calculator.R;
import java.io.StringWriter;
/**
* User: serso
* Date: 10/7/12
* Time: 6:46 PM
*/
public class AndroidMathEntityDao<T extends MathPersistenceEntity> implements MathEntityDao<T> {
@Nullable
private final Integer preferenceStringId;
@NotNull
private final Context context;
@Nullable
private final Class<? extends MathEntityPersistenceContainer<T>> persistenceContainerClass;
public AndroidMathEntityDao(@Nullable Integer preferenceStringId,
@NotNull Application application,
@Nullable Class<? extends MathEntityPersistenceContainer<T>> persistenceContainerClass) {
this.preferenceStringId = preferenceStringId;
this.context = application;
this.persistenceContainerClass = persistenceContainerClass;
}
@Override
public void save(@NotNull MathEntityPersistenceContainer<T> container) {
if (preferenceStringId != null) {
final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
final SharedPreferences.Editor editor = settings.edit();
final StringWriter sw = new StringWriter();
final Serializer serializer = new Persister();
try {
serializer.write(container, sw);
} catch (Exception e) {
throw new RuntimeException(e);
}
editor.putString(context.getString(preferenceStringId), sw.toString());
editor.commit();
}
}
@Nullable
@Override
public MathEntityPersistenceContainer<T> load() {
if (persistenceContainerClass != null && preferenceStringId != null) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
if (preferences != null) {
final String value = preferences.getString(context.getString(preferenceStringId), null);
if (value != null) {
final Serializer serializer = new Persister();
try {
return serializer.read(persistenceContainerClass, value);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
return null;
}
@Nullable
public String getDescription(@NotNull String descriptionId) {
final Resources resources = context.getResources();
final int stringId = resources.getIdentifier(descriptionId, "string", R.class.getPackage().getName());
try {
return resources.getString(stringId);
} catch (Resources.NotFoundException e) {
return null;
}
}
}

View File

@ -1,180 +1,165 @@
/* /*
* 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.model; package org.solovyev.android.calculator.model;
import android.app.Application; import jscl.math.operator.*;
import jscl.math.function.ArcTrigonometric; import org.jetbrains.annotations.NotNull;
import jscl.math.function.Comparison; import org.solovyev.android.calculator.*;
import jscl.math.function.Trigonometric; import org.solovyev.common.JBuilder;
import jscl.math.operator.*; import org.solovyev.common.collections.CollectionsUtils;
import org.jetbrains.annotations.NotNull; import org.solovyev.common.math.MathRegistry;
import org.solovyev.android.calculator.R;
import org.solovyev.common.JBuilder; import java.util.*;
import org.solovyev.common.collections.CollectionsUtils;
import org.solovyev.common.math.MathRegistry; /**
* User: serso
import java.util.*; * Date: 11/17/11
* Time: 11:29 PM
/** */
* User: serso public class AndroidOperatorsMathRegistry extends AbstractCalculatorMathRegistry<Operator, MathPersistenceEntity> {
* Date: 11/17/11
* Time: 11:29 PM @NotNull
*/ private static final Map<String, String> substitutes = new HashMap<String, String>();
public class AndroidOperatorsMathRegistry extends AbstractAndroidMathRegistry<Operator, MathPersistenceEntity> { static {
substitutes.put("Σ", "sum");
@NotNull substitutes.put("", "product");
private static final Map<String, String> substitutes = new HashMap<String, String>(); substitutes.put("", "derivative");
static { substitutes.put("∫ab", "integral_ab");
substitutes.put("Σ", "sum"); substitutes.put("", "integral");
substitutes.put("", "product"); substitutes.put("Σ", "sum");
substitutes.put("", "derivative"); }
substitutes.put("∫ab", "integral_ab");
substitutes.put("", "integral"); @NotNull
substitutes.put("Σ", "sum"); private static final String OPERATOR_DESCRIPTION_PREFIX = "c_op_description_";
}
protected AndroidOperatorsMathRegistry(@NotNull MathRegistry<Operator> functionsRegistry,
@NotNull @NotNull MathEntityDao<MathPersistenceEntity> mathEntityDao) {
private static final String OPERATOR_DESCRIPTION_PREFIX = "c_op_description_"; super(functionsRegistry, OPERATOR_DESCRIPTION_PREFIX, mathEntityDao);
}
protected AndroidOperatorsMathRegistry(@NotNull MathRegistry<Operator> functionsRegistry,
@NotNull Application application) { @NotNull
super(functionsRegistry, OPERATOR_DESCRIPTION_PREFIX, application); @Override
} protected Map<String, String> getSubstitutes() {
return substitutes;
@NotNull }
@Override
protected Map<String, String> getSubstitutes() { @Override
return substitutes; public String getCategory(@NotNull Operator operator) {
} for (Category category : Category.values()) {
if ( category.isInCategory(operator) ) {
@Override return category.name();
public String getCategory(@NotNull Operator operator) { }
for (Category category : Category.values()) { }
if ( category.isInCategory(operator) ) { return null;
return category.name(); }
}
} @Override
return null; public void load() {
} // not supported yet
}
@Override
public void load() { @NotNull
// not supported yet @Override
} protected JBuilder<? extends Operator> createBuilder(@NotNull MathPersistenceEntity entity) {
return null; //To change body of implemented methods use File | Settings | File Templates.
@NotNull }
@Override
protected JBuilder<? extends Operator> createBuilder(@NotNull MathPersistenceEntity entity) { @Override
return null; //To change body of implemented methods use File | Settings | File Templates. public void save() {
} // not supported yet
}
@NotNull
@Override @Override
protected Class<? extends MathEntityPersistenceContainer<MathPersistenceEntity>> getPersistenceContainerClass() { protected MathPersistenceEntity transform(@NotNull Operator entity) {
return null; //To change body of implemented methods use File | Settings | File Templates. return null; //To change body of implemented methods use File | Settings | File Templates.
} }
@Override @NotNull
protected Integer getPreferenceStringId() { @Override
return null; //To change body of implemented methods use File | Settings | File Templates. protected MathEntityPersistenceContainer<MathPersistenceEntity> createPersistenceContainer() {
} return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void save() { /*
// not supported yet **********************************************************************
} *
* STATIC
@Override *
protected MathPersistenceEntity transform(@NotNull Operator entity) { **********************************************************************
return null; //To change body of implemented methods use File | Settings | File Templates. */
}
public static enum Category {
@NotNull
@Override derivatives(R.string.derivatives, 100){
protected MathEntityPersistenceContainer<MathPersistenceEntity> createPersistenceContainer() { @Override
return null; //To change body of implemented methods use File | Settings | File Templates. boolean isInCategory(@NotNull Operator operator) {
} return operator instanceof Derivative || operator instanceof Integral || operator instanceof IndefiniteIntegral;
}
/* },
**********************************************************************
* other(R.string.other, 200) {
* STATIC @Override
* boolean isInCategory(@NotNull Operator operator) {
********************************************************************** return operator instanceof Sum || operator instanceof Product;
*/ }
},
public static enum Category {
my(R.string.c_fun_category_my, 0) {
derivatives(R.string.derivatives, 100){ @Override
@Override boolean isInCategory(@NotNull Operator operator) {
boolean isInCategory(@NotNull Operator operator) { return !operator.isSystem();
return operator instanceof Derivative || operator instanceof Integral || operator instanceof IndefiniteIntegral; }
} },
},
common(R.string.c_fun_category_common, 50) {
other(R.string.other, 200) { @Override
@Override boolean isInCategory(@NotNull Operator operator) {
boolean isInCategory(@NotNull Operator operator) { for (Category category : values()) {
return operator instanceof Sum || operator instanceof Product; if ( category != this ) {
} if ( category.isInCategory(operator) ) {
}, return false;
}
my(R.string.c_fun_category_my, 0) { }
@Override }
boolean isInCategory(@NotNull Operator operator) {
return !operator.isSystem(); return true;
} }
}, };
common(R.string.c_fun_category_common, 50) { private final int captionId;
@Override
boolean isInCategory(@NotNull Operator operator) { private final int tabOrder;
for (Category category : values()) {
if ( category != this ) { Category(int captionId, int tabOrder) {
if ( category.isInCategory(operator) ) { this.captionId = captionId;
return false; this.tabOrder = tabOrder;
} }
}
} public int getCaptionId() {
return captionId;
return true; }
}
}; abstract boolean isInCategory(@NotNull Operator operator);
private final int captionId; @NotNull
public static List<Category> getCategoriesByTabOrder() {
private final int tabOrder; final List<Category> result = CollectionsUtils.asList(Category.values());
Category(int captionId, int tabOrder) { Collections.sort(result, new Comparator<Category>() {
this.captionId = captionId; @Override
this.tabOrder = tabOrder; public int compare(Category category, Category category1) {
} return category.tabOrder - category1.tabOrder;
}
public int getCaptionId() { });
return captionId;
} // todo serso: current solution (as creating operators is not implemented yet)
result.remove(my);
abstract boolean isInCategory(@NotNull Operator operator);
return result;
@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;
}
}
}

View File

@ -1,96 +1,88 @@
/* /*
* 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.model; package org.solovyev.android.calculator.model;
import android.app.Application; 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.common.JBuilder; import org.solovyev.android.calculator.MathEntityDao;
import org.solovyev.common.math.MathRegistry; import org.solovyev.android.calculator.MathEntityPersistenceContainer;
import org.solovyev.android.calculator.MathPersistenceEntity;
import java.util.HashMap; import org.solovyev.common.JBuilder;
import java.util.Map; import org.solovyev.common.math.MathRegistry;
/** import java.util.HashMap;
* User: serso import java.util.Map;
* Date: 11/19/11
* Time: 1:48 PM /**
*/ * User: serso
public class AndroidPostfixFunctionsRegistry extends AbstractAndroidMathRegistry<Operator, MathPersistenceEntity> { * Date: 11/19/11
* Time: 1:48 PM
@NotNull */
private static final Map<String, String> substitutes = new HashMap<String, String>(); public class AndroidPostfixFunctionsRegistry extends AbstractCalculatorMathRegistry<Operator, MathPersistenceEntity> {
static {
substitutes.put("%", "percent"); @NotNull
substitutes.put("!", "factorial"); private static final Map<String, String> substitutes = new HashMap<String, String>();
substitutes.put("!!", "double_factorial"); static {
substitutes.put("°", "degree"); substitutes.put("%", "percent");
} substitutes.put("!", "factorial");
substitutes.put("!!", "double_factorial");
@NotNull substitutes.put("°", "degree");
private static final String POSTFIX_FUNCTION_DESCRIPTION_PREFIX = "c_pf_description_"; }
protected AndroidPostfixFunctionsRegistry(@NotNull MathRegistry<Operator> functionsRegistry, @NotNull
@NotNull Application application) { private static final String POSTFIX_FUNCTION_DESCRIPTION_PREFIX = "c_pf_description_";
super(functionsRegistry, POSTFIX_FUNCTION_DESCRIPTION_PREFIX, application);
} protected AndroidPostfixFunctionsRegistry(@NotNull MathRegistry<Operator> functionsRegistry,
@NotNull MathEntityDao<MathPersistenceEntity> mathEntityDao) {
super(functionsRegistry, POSTFIX_FUNCTION_DESCRIPTION_PREFIX, mathEntityDao);
@NotNull }
@Override
protected Map<String, String> getSubstitutes() {
return substitutes; @NotNull
} @Override
protected Map<String, String> getSubstitutes() {
@Override return substitutes;
public String getCategory(@NotNull Operator operator) { }
for (AndroidOperatorsMathRegistry.Category category : AndroidOperatorsMathRegistry.Category.values()) {
if ( category.isInCategory(operator) ) { @Override
return category.name(); public String getCategory(@NotNull Operator operator) {
} for (AndroidOperatorsMathRegistry.Category category : AndroidOperatorsMathRegistry.Category.values()) {
} if ( category.isInCategory(operator) ) {
return null; return category.name();
} }
}
@Override return null;
public void load() { }
// not supported yet
} @Override
public void load() {
@NotNull // not supported yet
@Override }
protected JBuilder<? extends Operator> createBuilder(@NotNull MathPersistenceEntity entity) {
return null; //To change body of implemented methods use File | Settings | File Templates. @NotNull
} @Override
protected JBuilder<? extends Operator> createBuilder(@NotNull MathPersistenceEntity entity) {
@NotNull return null; //To change body of implemented methods use File | Settings | File Templates.
@Override }
protected Class<? extends MathEntityPersistenceContainer<MathPersistenceEntity>> getPersistenceContainerClass() {
return null; //To change body of implemented methods use File | Settings | File Templates. @Override
} public void save() {
// not supported yet
@Override }
protected Integer getPreferenceStringId() {
return null; //To change body of implemented methods use File | Settings | File Templates. @Override
} protected MathPersistenceEntity transform(@NotNull Operator entity) {
return null; //To change body of implemented methods use File | Settings | File Templates.
@Override }
public void save() {
// not supported yet @NotNull
} @Override
protected MathEntityPersistenceContainer<MathPersistenceEntity> createPersistenceContainer() {
@Override return null; //To change body of implemented methods use File | Settings | File Templates.
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.
}
}

View File

@ -6,10 +6,11 @@
package org.solovyev.android.calculator.model; package org.solovyev.android.calculator.model;
import android.app.Application;
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.android.calculator.AbstractCalculatorMathRegistry;
import org.solovyev.android.calculator.MathEntityDao;
import org.solovyev.android.calculator.MathEntityPersistenceContainer;
import org.solovyev.common.JBuilder; import org.solovyev.common.JBuilder;
import org.solovyev.common.math.MathRegistry; import org.solovyev.common.math.MathRegistry;
@ -21,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 AbstractAndroidMathRegistry<IConstant, Var> { class AndroidVarsRegistryImpl 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 +35,8 @@ class AndroidVarsRegistryImpl extends AbstractAndroidMathRegistry<IConstant, Var
} }
protected AndroidVarsRegistryImpl(@NotNull MathRegistry<IConstant> mathRegistry, protected AndroidVarsRegistryImpl(@NotNull MathRegistry<IConstant> mathRegistry,
@NotNull Application application) { @NotNull MathEntityDao<Var> mathEntityDao) {
super(mathRegistry, "c_var_description_", application); super(mathRegistry, "c_var_description_", mathEntityDao);
} }
@NotNull @NotNull
@ -66,24 +67,13 @@ class AndroidVarsRegistryImpl extends AbstractAndroidMathRegistry<IConstant, Var
return new Var.Builder(entity); return new Var.Builder(entity);
} }
@NotNull @NotNull
@Override
protected Class<? extends MathEntityPersistenceContainer<Var>> getPersistenceContainerClass() {
return Vars.class;
}
@NotNull
@Override @Override
protected MathEntityPersistenceContainer<Var> createPersistenceContainer() { protected MathEntityPersistenceContainer<Var> createPersistenceContainer() {
return new Vars(); return new Vars();
} }
@NotNull private void tryToAddAuxVar(@NotNull String name) {
protected Integer getPreferenceStringId() {
return R.string.p_calc_vars;
}
private void tryToAddAuxVar(@NotNull String name) {
if ( !contains(name) ) { if ( !contains(name) ) {
add(new Var.Builder(name, (String)null)); add(new Var.Builder(name, (String)null));
} }

View File

@ -14,6 +14,7 @@ import org.jetbrains.annotations.Nullable;
import org.simpleframework.xml.Element; import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root; import org.simpleframework.xml.Root;
import org.simpleframework.xml.Transient; import org.simpleframework.xml.Transient;
import org.solovyev.android.calculator.MathPersistenceEntity;
import org.solovyev.common.JBuilder; import org.solovyev.common.JBuilder;
import org.solovyev.common.math.MathEntity; import org.solovyev.common.math.MathEntity;
import org.solovyev.common.text.StringUtils; import org.solovyev.common.text.StringUtils;

View File

@ -1,8 +1,8 @@
package org.solovyev.android.calculator.model; package org.solovyev.android.calculator.model;
import jscl.math.function.IConstant;
import org.simpleframework.xml.ElementList; import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root; import org.simpleframework.xml.Root;
import org.solovyev.android.calculator.MathEntityPersistenceContainer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@ -6,7 +6,6 @@
package org.solovyev.android.calculator.plot; package org.solovyev.android.calculator.plot;
import android.util.Log;
import jscl.math.Expression; import jscl.math.Expression;
import jscl.math.Generic; import jscl.math.Generic;
import jscl.math.JsclInteger; import jscl.math.JsclInteger;
@ -375,7 +374,7 @@ public final class PlotUtils {
// double dydx1 = dy2 / dx1; // double dydx1 = dy2 / dx1;
if ( dy2 > MAX_Y_DIFF && dx2 < MAX_X_DIFF && isDifferentSign(point.getY2(), point.getY1()) && isDifferentSign(point.getDyDx1(), point.getDyDx2())) { if ( dy2 > MAX_Y_DIFF && dx2 < MAX_X_DIFF && isDifferentSign(point.getY2(), point.getY1()) && isDifferentSign(point.getDyDx1(), point.getDyDx2())) {
Log.d(CalculatorPlotActivity.class.getName(), "Singularity: " + point); //Log.d(CalculatorPlotActivity.class.getName(), "Singularity: " + point);
//Log.d(CalculatorPlotActivity.class.getName(), String.valueOf(prevX + Math.abs(x - prevX) / 2) + ", null"); //Log.d(CalculatorPlotActivity.class.getName(), String.valueOf(prevX + Math.abs(x - prevX) / 2) + ", null");
series.add(point.getX1() + point.getAbsDx2() / 2, MathHelper.NULL_VALUE); series.add(point.getX1() + point.getAbsDx2() / 2, MathHelper.NULL_VALUE);
point.clearHistory(); point.clearHistory();

View File

@ -31,7 +31,7 @@ public class FromJsclNumericTextProcessorTest {
public void testCreateResultForComplexNumber() throws Exception { public void testCreateResultForComplexNumber() throws Exception {
final FromJsclNumericTextProcessor cm = new FromJsclNumericTextProcessor(); final FromJsclNumericTextProcessor cm = new FromJsclNumericTextProcessor();
final JsclMathEngine me = JsclMathEngine.instance; final JsclMathEngine me = JsclMathEngine.getInstance();
final AngleUnit defaultAngleUnits = me.getAngleUnits(); final AngleUnit defaultAngleUnits = me.getAngleUnits();
Assert.assertEquals("1.22133+23 123i", cm.process(Expression.valueOf("1.22133232+23123*i").numeric())); Assert.assertEquals("1.22133+23 123i", cm.process(Expression.valueOf("1.22133232+23123*i").numeric()));

View File

@ -36,7 +36,7 @@ public class NumeralBaseTest {
public void testConversion() throws Exception { public void testConversion() throws Exception {
CSVReader reader = null; CSVReader reader = null;
try { try {
final MathEngine me = JsclMathEngine.instance; final MathEngine me = JsclMathEngine.getInstance();
reader = new CSVReader(new InputStreamReader(NumeralBaseTest.class.getResourceAsStream("/org/solovyev/android/calculator/model/nb_table.csv")), '\t'); reader = new CSVReader(new InputStreamReader(NumeralBaseTest.class.getResourceAsStream("/org/solovyev/android/calculator/model/nb_table.csv")), '\t');

View File

@ -152,15 +152,15 @@ public class ToJsclTextProcessorTest {
public void testNumeralBases() throws Exception { public void testNumeralBases() throws Exception {
final TextProcessor<PreparedExpression, String> processor = ToJsclTextProcessor.getInstance(); final TextProcessor<PreparedExpression, String> processor = ToJsclTextProcessor.getInstance();
final NumeralBase defaultNumeralBase = JsclMathEngine.instance.getNumeralBase(); final NumeralBase defaultNumeralBase = JsclMathEngine.getInstance().getNumeralBase();
try{ try{
JsclMathEngine.instance.setNumeralBase(NumeralBase.bin); JsclMathEngine.getInstance().setNumeralBase(NumeralBase.bin);
Assert.assertEquals("101", JsclMathEngine.instance.evaluate("10+11")); Assert.assertEquals("101", JsclMathEngine.getInstance().evaluate("10+11"));
JsclMathEngine.instance.setNumeralBase(NumeralBase.hex); JsclMathEngine.getInstance().setNumeralBase(NumeralBase.hex);
Assert.assertEquals("56CE+CAD", processor.process("56CE+CAD").getExpression()); Assert.assertEquals("56CE+CAD", processor.process("56CE+CAD").getExpression());
} finally { } finally {
JsclMathEngine.instance.setNumeralBase(defaultNumeralBase); JsclMathEngine.getInstance().setNumeralBase(defaultNumeralBase);
} }
} }
} }

View File

@ -0,0 +1,19 @@
package org.solovyev.android.calculator.plot;
import com.xtremelabs.robolectric.RobolectricTestRunner;
import org.jetbrains.annotations.NotNull;
import org.junit.runners.model.InitializationError;
import java.io.File;
/**
* User: serso
* Date: 10/7/12
* Time: 5:36 PM
*/
public class CalculatorppTestRunner extends RobolectricTestRunner {
public CalculatorppTestRunner(@NotNull Class<?> testClass) throws InitializationError {
super(testClass, new File("calculatorpp"));
}
}

View File

@ -12,13 +12,13 @@ import junit.framework.Assert;
import org.achartengine.model.XYSeries; import org.achartengine.model.XYSeries;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
/** /**
* User: serso * User: serso
* Date: 12/5/11 * Date: 12/5/11
* Time: 9:07 PM * Time: 9:07 PM
*/ */
public class PlotUtilsTest { public class PlotUtilsTest {
@Test @Test

538
pom.xml
View File

@ -1,265 +1,275 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.solovyev.android</groupId> <groupId>org.solovyev.android</groupId>
<artifactId>calculatorpp-parent</artifactId> <artifactId>calculatorpp-parent</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>
<version>1.3.2</version> <version>1.3.2</version>
<name>Calculator++</name> <name>Calculator++</name>
<modules> <modules>
<module>calculatorpp</module> <module>calculatorpp</module>
<module>calculatorpp-test</module> <module>calculatorpp-test</module>
<module>calculatorpp-core</module> <module>calculatorpp-core</module>
</modules> </modules>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.solovyev</groupId> <groupId>org.solovyev</groupId>
<artifactId>common-core</artifactId> <artifactId>common-core</artifactId>
<version>1.0.0</version> <version>1.0.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.solovyev</groupId> <groupId>org.solovyev</groupId>
<artifactId>common-text</artifactId> <artifactId>common-text</artifactId>
<version>1.0.1</version> <version>1.0.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.solovyev.android</groupId> <groupId>org.solovyev.android</groupId>
<artifactId>android-common-core</artifactId> <artifactId>android-common-core</artifactId>
<type>apklib</type> <type>apklib</type>
<version>1.0.0</version> <version>1.0.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.solovyev.android</groupId> <groupId>org.solovyev.android</groupId>
<artifactId>android-common-ads</artifactId> <artifactId>android-common-ads</artifactId>
<type>apklib</type> <type>apklib</type>
<version>1.0.0</version> <version>1.0.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.solovyev.android</groupId> <groupId>org.solovyev.android</groupId>
<artifactId>android-common-view</artifactId> <artifactId>android-common-view</artifactId>
<type>apklib</type> <type>apklib</type>
<version>1.0.0</version> <version>1.0.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.solovyev.android</groupId> <groupId>org.solovyev.android</groupId>
<artifactId>android-common-preferences</artifactId> <artifactId>android-common-preferences</artifactId>
<type>apklib</type> <type>apklib</type>
<version>1.0.0</version> <version>1.0.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.solovyev.android</groupId> <groupId>org.solovyev.android</groupId>
<artifactId>android-common-menu</artifactId> <artifactId>android-common-menu</artifactId>
<type>apklib</type> <type>apklib</type>
<version>1.0.0</version> <version>1.0.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.solovyev.android</groupId> <groupId>org.solovyev.android</groupId>
<artifactId>android-common-sherlock</artifactId> <artifactId>android-common-sherlock</artifactId>
<version>1.0.0</version> <version>1.0.0</version>
<type>apklib</type> <type>apklib</type>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.actionbarsherlock</groupId> <groupId>com.actionbarsherlock</groupId>
<artifactId>library</artifactId> <artifactId>library</artifactId>
<version>4.1.0</version> <version>4.1.0</version>
<type>apklib</type> <type>apklib</type>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.solovyev</groupId> <groupId>org.solovyev</groupId>
<artifactId>jscl</artifactId> <artifactId>jscl</artifactId>
<version>0.0.2</version> <version>0.0.3</version>
<exclusions> <exclusions>
<exclusion> <exclusion>
<artifactId>xercesImpl</artifactId> <artifactId>xercesImpl</artifactId>
<groupId>xerces</groupId> <groupId>xerces</groupId>
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.solovyev.android</groupId> <groupId>org.solovyev.android</groupId>
<artifactId>android-common-other</artifactId> <artifactId>android-common-other</artifactId>
<type>apklib</type> <type>apklib</type>
<version>1.0.0</version> <version>1.0.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>4.8.2</version> <version>4.8.2</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.intellij</groupId> <groupId>com.intellij</groupId>
<artifactId>annotations</artifactId> <artifactId>annotations</artifactId>
<version>7.0.3</version> <version>7.0.3</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.google.android</groupId> <groupId>com.google.android</groupId>
<artifactId>android</artifactId> <artifactId>android</artifactId>
<version>4.0.1.2</version> <version>4.0.1.2</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.google.android</groupId> <groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId> <artifactId>support-v4</artifactId>
<version>r7</version> <version>r7</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.google.android</groupId> <groupId>com.google.android</groupId>
<artifactId>android-test</artifactId> <artifactId>android-test</artifactId>
<version>2.3.1</version> <version>2.3.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>
<artifactId>guava</artifactId> <artifactId>guava</artifactId>
<version>11.0.2</version> <version>11.0.2</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.simpleframework</groupId> <groupId>org.simpleframework</groupId>
<artifactId>simple-xml</artifactId> <artifactId>simple-xml</artifactId>
<version>2.6.1</version> <version>2.6.1</version>
<exclusions> <exclusions>
<exclusion> <exclusion>
<artifactId>stax-api</artifactId> <artifactId>stax-api</artifactId>
<groupId>stax</groupId> <groupId>stax</groupId>
</exclusion> </exclusion>
<exclusion> <exclusion>
<artifactId>xpp3</artifactId> <artifactId>xpp3</artifactId>
<groupId>xpp3</groupId> <groupId>xpp3</groupId>
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<groupId>com.electriccloud</groupId> <groupId>com.electriccloud</groupId>
<artifactId>javac2-maven-plugin</artifactId> <artifactId>javac2-maven-plugin</artifactId>
<version>1.0.1</version> <version>1.0.1</version>
<executions> <executions>
<execution> <execution>
<id>@NotNull Instrumentation</id> <id>@NotNull Instrumentation</id>
<goals> <goals>
<goal>instrument</goal> <goal>instrument</goal>
</goals> </goals>
<!--compile phase instead of process-classes because of proguard. <!--compile phase instead of process-classes because of proguard.
@NotNull instrumentation will be done now after compilation and before proguard--> @NotNull instrumentation will be done now after compilation and before proguard-->
<phase>compile</phase> <phase>compile</phase>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
</plugins> </plugins>
<pluginManagement> <pluginManagement>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId> <artifactId>maven-jarsigner-plugin</artifactId>
<version>1.2</version> <version>1.2</version>
</plugin> </plugin>
<plugin> <plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId> <groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId> <artifactId>android-maven-plugin</artifactId>
<version>3.1.1</version> <version>3.1.1</version>
<configuration> <configuration>
<sourceDirectories> <sourceDirectories>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory> <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
</sourceDirectories> </sourceDirectories>
<sdk> <sdk>
<platform>15</platform> <platform>15</platform>
</sdk> </sdk>
<emulator> <emulator>
<avd>23</avd> <avd>23</avd>
<wait>10000</wait> <wait>10000</wait>
<!--<options>-no-skin</options>--> <!--<options>-no-skin</options>-->
</emulator> </emulator>
<zipalign> <zipalign>
<verbose>true</verbose> <verbose>true</verbose>
</zipalign> </zipalign>
<undeployBeforeDeploy>true</undeployBeforeDeploy> <undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
<groupId>com.pyx4me</groupId> <groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId> <artifactId>proguard-maven-plugin</artifactId>
<version>2.0.4</version> <version>2.0.4</version>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.codehaus.mojo</groupId> <groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId> <artifactId>build-helper-maven-plugin</artifactId>
<version>1.5</version> <version>1.5</version>
</plugin> </plugin>
</plugins> <!-- as some classes are singletons we must run each test in separate JVM-->
</pluginManagement> <!-- <plugin>
<groupId>org.apache.maven.plugins</groupId>
</build> <artifactId>maven-surefire-plugin</artifactId>
<version>2.2</version>
<profiles> <configuration>
<forkMode>perTest</forkMode>
<profile> </configuration>
<!-- the standard profile runs instrumentation tests --> </plugin>-->
<id>standard</id>
</profile> </plugins>
</pluginManagement>
<profile>
<!-- the release profile does sign, proguard, zipalign --> </build>
<id>release</id>
<!-- via this activation the profile is automatically used when the release is done with the maven release <profiles>
plugin -->
<activation> <profile>
<property> <!-- the standard profile runs instrumentation tests -->
<name>performRelease</name> <id>standard</id>
<value>true</value> </profile>
</property>
</activation> <profile>
<!-- the release profile does sign, proguard, zipalign -->
</profile> <id>release</id>
</profiles> <!-- via this activation the profile is automatically used when the release is done with the maven release
plugin -->
<activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation>
</profile>
</profiles>
</project> </project>