Merge branch 'dev' into dev-overlay-app

Conflicts:
	calculatorpp-core/src/main/java/org/solovyev/android/calculator/Locator.java
	calculatorpp-core/src/test/java/org/solovyev/android/calculator/AbstractCalculatorTest.java
	calculatorpp-core/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java
	calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java
	calculatorpp/src/main/java/org/solovyev/android/calculator/external/DefaultExternalCalculatorIntentHandler.java
	calculatorpp/src/main/java/org/solovyev/android/calculator/external/ExternalCalculatorHelper.java
	calculatorpp/src/main/java/org/solovyev/android/calculator/widget/CalculatorWidgetHelper.java
	calculatorpp/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java
This commit is contained in:
Sergey Solovyev 2012-11-21 12:03:48 +04:00
commit 9a7bb5dbc1
66 changed files with 290 additions and 242 deletions

View File

@ -70,7 +70,7 @@ public abstract class AbstractCalculatorMathRegistry<T extends MathEntity, P ext
try {
add(createBuilder(entity));
} catch (CustomFunctionCalculationException e) {
CalculatorLocatorImpl.getInstance().getLogger().error(null, e.getMessage(), e);
Locator.getInstance().getLogger().error(null, e.getMessage(), e);
}
}
}

View File

@ -165,7 +165,7 @@ public class CalculatorEngineImpl implements CalculatorEngine {
@Override
public void softReset() {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.engine_preferences_changed, null);
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.engine_preferences_changed, null);
}
/*

View File

@ -18,21 +18,21 @@ public enum CalculatorFixableError {
must_be_rad(Messages.msg_23, Messages.msg_24, Messages.msg_25) {
@Override
public void fix() {
CalculatorLocatorImpl.getInstance().getPreferenceService().setAngleUnits(AngleUnit.rad);
Locator.getInstance().getPreferenceService().setAngleUnits(AngleUnit.rad);
}
},
preferred_numeral_base() {
@Override
public void fix() {
CalculatorLocatorImpl.getInstance().getPreferenceService().setPreferredNumeralBase();
Locator.getInstance().getPreferenceService().setPreferredNumeralBase();
}
},
preferred_angle_units() {
@Override
public void fix() {
CalculatorLocatorImpl.getInstance().getPreferenceService().setPreferredAngleUnits();
Locator.getInstance().getPreferenceService().setPreferredAngleUnits();
}
};

View File

@ -67,9 +67,9 @@ public class CalculatorFunctionsMathRegistry extends AbstractCalculatorMathRegis
}
if (editedInstance == null) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.function_added, addedFunction, source);
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.function_added, addedFunction, source);
} else {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.function_changed, ChangeImpl.newInstance(editedInstance, addedFunction), source);
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.function_changed, ChangeImpl.newInstance(editedInstance, addedFunction), source);
}
}

View File

@ -179,8 +179,8 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
@Override
public void init() {
CalculatorLocatorImpl.getInstance().getEngine().init();
CalculatorLocatorImpl.getInstance().getHistory().load();
Locator.getInstance().getEngine().init();
Locator.getInstance().getHistory().load();
}
public void setCalculateOnFly(boolean calculateOnFly) {
@ -218,10 +218,10 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
try {
final CalculatorMathEngine mathEngine = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine();
final CalculatorMathEngine mathEngine = Locator.getInstance().getEngine().getMathEngine();
final MessageRegistry messageRegistry = new ListMessageRegistry();
CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0().setMessageRegistry(messageRegistry);
Locator.getInstance().getEngine().getMathEngine0().setMessageRegistry(messageRegistry);
final Generic result = operation.evaluateGeneric(jsclExpression, mathEngine);
@ -229,7 +229,7 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
result.toString();
if (messageRegistry.hasMessage()) {
final CalculatorLogger logger = CalculatorLocatorImpl.getInstance().getLogger();
final CalculatorLogger logger = Locator.getInstance().getLogger();
try {
final List<Message> messages = new ArrayList<Message>();
while (messageRegistry.hasMessage()) {
@ -273,7 +273,7 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
if ( currentTime - lastPreferenceCheck > PREFERENCE_CHECK_INTERVAL ) {
lastPreferenceCheck = currentTime;
CalculatorLocatorImpl.getInstance().getPreferenceService().checkPreferredPreferences(false);
Locator.getInstance().getPreferenceService().checkPreferredPreferences(false);
}
}
@ -335,8 +335,8 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
@NotNull final NumeralBase to) {
final CalculatorEventData eventDataId = nextEventData();
final CalculatorDisplayViewState displayViewState = CalculatorLocatorImpl.getInstance().getDisplay().getViewState();
final NumeralBase from = CalculatorLocatorImpl.getInstance().getEngine().getNumeralBase();
final CalculatorDisplayViewState displayViewState = Locator.getInstance().getDisplay().getViewState();
final NumeralBase from = Locator.getInstance().getEngine().getNumeralBase();
calculationsExecutor.execute(new Runnable() {
@Override
@ -511,17 +511,17 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
case use_constant:
final IConstant constant = (IConstant)data;
CalculatorLocatorImpl.getInstance().getKeyboard().buttonPressed(constant.getName());
Locator.getInstance().getKeyboard().buttonPressed(constant.getName());
break;
case use_operator:
final Operator operator = (Operator)data;
CalculatorLocatorImpl.getInstance().getKeyboard().buttonPressed(operator.getName());
Locator.getInstance().getKeyboard().buttonPressed(operator.getName());
break;
case use_function:
final Function function = (Function)data;
CalculatorLocatorImpl.getInstance().getKeyboard().buttonPressed(function.getName());
Locator.getInstance().getKeyboard().buttonPressed(function.getName());
break;
}
@ -532,7 +532,7 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
if (newState.isValid()) {
final String result = newState.getStringResult();
if ( !StringUtils.isEmpty(result) ) {
final CalculatorMathRegistry<IConstant> varsRegistry = CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry();
final CalculatorMathRegistry<IConstant> varsRegistry = Locator.getInstance().getEngine().getVarsRegistry();
final IConstant ansVar = varsRegistry.get(CalculatorVarsRegistry.ANS);
final Var.Builder varBuilder;
@ -561,7 +561,7 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
@Override
public void doHistoryAction(@NotNull HistoryAction historyAction) {
final CalculatorHistory history = CalculatorLocatorImpl.getInstance().getHistory();
final CalculatorHistory history = Locator.getInstance().getHistory();
if (history.isActionAvailable(historyAction)) {
final CalculatorHistoryState newState = history.doAction(historyAction, getCurrentHistoryState());
if (newState != null) {
@ -591,11 +591,11 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
@NotNull
private CalculatorEditor getEditor() {
return CalculatorLocatorImpl.getInstance().getEditor();
return Locator.getInstance().getEditor();
}
@NotNull
private CalculatorDisplay getDisplay() {
return CalculatorLocatorImpl.getInstance().getDisplay();
return Locator.getInstance().getDisplay();
}
}

View File

@ -53,7 +53,7 @@ public class CalculatorKeyboardImpl implements CalculatorKeyboard {
}
}
final CalculatorEditor editor = CalculatorLocatorImpl.getInstance().getEditor();
final CalculatorEditor editor = Locator.getInstance().getEditor();
editor.insert(textToBeInserted.toString(), cursorPositionOffset);
}
}
@ -73,7 +73,7 @@ public class CalculatorKeyboardImpl implements CalculatorKeyboard {
@Override
public void roundBracketsButtonPressed() {
final CalculatorEditor editor = CalculatorLocatorImpl.getInstance().getEditor();
final CalculatorEditor editor = Locator.getInstance().getEditor();
CalculatorEditorViewState viewState = editor.getViewState();
final int cursorPosition = viewState.getSelection();
@ -89,36 +89,36 @@ public class CalculatorKeyboardImpl implements CalculatorKeyboard {
@Override
public void pasteButtonPressed() {
final String text = CalculatorLocatorImpl.getInstance().getClipboard().getText();
final String text = Locator.getInstance().getClipboard().getText();
if (text != null) {
CalculatorLocatorImpl.getInstance().getEditor().insert(text);
Locator.getInstance().getEditor().insert(text);
}
}
@Override
public void clearButtonPressed() {
CalculatorLocatorImpl.getInstance().getEditor().clear();
Locator.getInstance().getEditor().clear();
}
@Override
public void copyButtonPressed() {
final CalculatorDisplayViewState displayViewState = CalculatorLocatorImpl.getInstance().getDisplay().getViewState();
final CalculatorDisplayViewState displayViewState = Locator.getInstance().getDisplay().getViewState();
if (displayViewState.isValid()) {
final CharSequence text = displayViewState.getText();
if (!StringUtils.isEmpty(text)) {
CalculatorLocatorImpl.getInstance().getClipboard().setText(text);
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(CalculatorMessage.newInfoMessage(CalculatorMessages.result_copied));
Locator.getInstance().getClipboard().setText(text);
Locator.getInstance().getNotifier().showMessage(CalculatorMessage.newInfoMessage(CalculatorMessages.result_copied));
}
}
}
@Override
public void moveCursorLeft() {
CalculatorLocatorImpl.getInstance().getEditor().moveCursorLeft();
Locator.getInstance().getEditor().moveCursorLeft();
}
@Override
public void moveCursorRight() {
CalculatorLocatorImpl.getInstance().getEditor().moveCursorRight();
Locator.getInstance().getEditor().moveCursorRight();
}
}

View File

@ -16,13 +16,13 @@ public enum CalculatorSpecialButton {
history("history") {
@Override
public void onClick(@NotNull CalculatorKeyboard keyboard) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_history, null);
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_history, null);
}
},
history_detached("history_detached") {
@Override
public void onClick(@NotNull CalculatorKeyboard keyboard) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_history_detached, null);
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_history_detached, null);
}
},
cursor_right("") {
@ -40,27 +40,27 @@ public enum CalculatorSpecialButton {
settings("settings") {
@Override
public void onClick(@NotNull CalculatorKeyboard keyboard) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_settings, null);
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_settings, null);
}
},
settings_detached("settings_detached") {
@Override
public void onClick(@NotNull CalculatorKeyboard keyboard) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_settings_detached, null);
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_settings_detached, null);
}
},
like("like") {
@Override
public void onClick(@NotNull CalculatorKeyboard keyboard) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_like_dialog, null);
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_like_dialog, null);
}
},
erase("erase") {
@Override
public void onClick(@NotNull CalculatorKeyboard keyboard) {
CalculatorLocatorImpl.getInstance().getEditor().erase();
Locator.getInstance().getEditor().erase();
}
},
paste("paste") {
@ -78,7 +78,7 @@ public enum CalculatorSpecialButton {
equals("=") {
@Override
public void onClick(@NotNull CalculatorKeyboard keyboard) {
CalculatorLocatorImpl.getInstance().getCalculator().evaluate();
Locator.getInstance().getCalculator().evaluate();
}
},
clear("clear") {
@ -90,44 +90,44 @@ public enum CalculatorSpecialButton {
functions("functions") {
@Override
public void onClick(@NotNull CalculatorKeyboard keyboard) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_functions, null);
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_functions, null);
}
},
functions_detached("functions_detached") {
@Override
public void onClick(@NotNull CalculatorKeyboard keyboard) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_functions_detached, null);
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_functions_detached, null);
}
},
open_app("open_app") {
@Override
public void onClick(@NotNull CalculatorKeyboard keyboard) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.open_app, null);
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.open_app, null);
}
},
vars("vars") {
@Override
public void onClick(@NotNull CalculatorKeyboard keyboard) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_vars, null);
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_vars, null);
}
},
vars_detached("vars_detached") {
@Override
public void onClick(@NotNull CalculatorKeyboard keyboard) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_vars_detached, null);
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_vars_detached, null);
}
},
operators("operators") {
@Override
public void onClick(@NotNull CalculatorKeyboard keyboard) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_operators, null);
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_operators, null);
}
},
operators_detached("operators_detached") {
@Override
public void onClick(@NotNull CalculatorKeyboard keyboard) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_operators_detached, null);
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_operators_detached, null);
}
};

View File

@ -32,7 +32,7 @@ public final class CalculatorUtils {
final Set<Constant> notSystemConstants = new HashSet<Constant>();
for (Constant constant : expression.getConstants()) {
IConstant var = CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().get(constant.getName());
IConstant var = Locator.getInstance().getEngine().getVarsRegistry().get(constant.getName());
if (var != null && !var.isSystem() && !var.isDefined()) {
notSystemConstants.add(constant);
}

View File

@ -55,9 +55,9 @@ public class CalculatorVarsRegistry extends AbstractCalculatorMathRegistry<ICons
}
if (editedInstance == null) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.constant_added, addedVar, source);
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.constant_added, addedVar, source);
} else {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.constant_changed, ChangeImpl.newInstance(editedInstance, addedVar), source);
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.constant_changed, ChangeImpl.newInstance(editedInstance, addedVar), source);
}
}

View File

@ -39,10 +39,10 @@ public class ListCalculatorEventContainer implements CalculatorEventContainer {
public void fireCalculatorEvents(@NotNull List<CalculatorEvent> calculatorEvents) {
final List<CalculatorEventListener> listeners = this.listeners.getListeners();
//final CalculatorLogger logger = CalculatorLocatorImpl.getInstance().getLogger();
//final CalculatorLogger logger = Locator.getInstance().getLogger();
for (CalculatorEvent e : calculatorEvents) {
//CalculatorLocatorImpl.getInstance().getLogger().debug(TAG, "Event fired: " + e.getCalculatorEventType());
//Locator.getInstance().getLogger().debug(TAG, "Event fired: " + e.getCalculatorEventType());
for (CalculatorEventListener listener : listeners) {
/*long startTime = System.currentTimeMillis();*/
listener.onCalculatorEvent(e.getCalculatorEventData(), e.getCalculatorEventType(), e.getData());

View File

@ -9,7 +9,7 @@ import org.solovyev.android.calculator.history.CalculatorHistory;
* Date: 20.09.12
* Time: 12:45
*/
public class CalculatorLocatorImpl implements CalculatorLocator {
public class Locator implements CalculatorLocator {
@NotNull
private CalculatorEngine calculatorEngine;
@ -39,7 +39,7 @@ public class CalculatorLocatorImpl implements CalculatorLocator {
private CalculatorClipboard calculatorClipboard = new DummyCalculatorClipboard();
@NotNull
private static final CalculatorLocator instance = new CalculatorLocatorImpl();
private static final CalculatorLocator instance = new Locator();
@NotNull
private CalculatorPreferenceService calculatorPreferenceService;
@ -47,7 +47,7 @@ public class CalculatorLocatorImpl implements CalculatorLocator {
@NotNull
private CalculatorExternalListenersContainer calculatorExternalListenersContainer;
public CalculatorLocatorImpl() {
public Locator() {
}
@Override

View File

@ -53,7 +53,7 @@ public class ToJsclTextProcessor implements TextProcessor<PreparedExpression, St
MathType.Result mathTypeResult = null;
MathType.Result mathTypeBefore;
final LiteNumberBuilder nb = new LiteNumberBuilder(CalculatorLocatorImpl.getInstance().getEngine());
final LiteNumberBuilder nb = new LiteNumberBuilder(Locator.getInstance().getEngine());
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == ' ') continue;
startsWithFinder.setI(i);
@ -77,7 +77,7 @@ public class ToJsclTextProcessor implements TextProcessor<PreparedExpression, St
(mathTypeBefore.getMathType() == MathType.function || mathTypeBefore.getMathType() == MathType.operator) &&
CollectionsUtils.find(MathType.openGroupSymbols, startsWithFinder) != null) {
final String functionName = mathTypeBefore.getMatch();
final Function function = CalculatorLocatorImpl.getInstance().getEngine().getFunctionsRegistry().get(functionName);
final Function function = Locator.getInstance().getEngine().getFunctionsRegistry().get(functionName);
if ( function == null || function.getMinParameters() > 0 ) {
throw new CalculatorParseException(i, s, new CalculatorMessage(CalculatorMessages.msg_005, MessageType.error, mathTypeBefore.getMatch()));
}
@ -107,9 +107,9 @@ public class ToJsclTextProcessor implements TextProcessor<PreparedExpression, St
if (functionName == null) {
String operatorName = CollectionsUtils.find(MathType.operator.getTokens(), startsWithFinder);
if (operatorName == null) {
String varName = CollectionsUtils.find(CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getNames(), startsWithFinder);
String varName = CollectionsUtils.find(Locator.getInstance().getEngine().getVarsRegistry().getNames(), startsWithFinder);
if (varName != null) {
final IConstant var = CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().get(varName);
final IConstant var = Locator.getInstance().getEngine().getVarsRegistry().get(varName);
if (var != null) {
if (!var.isDefined()) {
undefinedVars.add(var);

View File

@ -99,7 +99,7 @@ public class CalculatorHistoryImpl implements CalculatorHistory {
public void addState(@Nullable CalculatorHistoryState currentState) {
synchronized (history) {
history.addState(currentState);
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.history_state_added, currentState);
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.history_state_added, currentState);
}
}

View File

@ -10,7 +10,7 @@ import jscl.NumeralBase;
import jscl.math.function.Constants;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.Locator;
import org.solovyev.common.JPredicate;
import org.solovyev.common.StartsWithFinder;
import org.solovyev.android.calculator.CalculatorParseException;
@ -57,7 +57,7 @@ public enum MathType {
@NotNull
@Override
public List<String> getTokens() {
return CalculatorLocatorImpl.getInstance().getEngine().getPostfixFunctionsRegistry().getNames();
return Locator.getInstance().getEngine().getPostfixFunctionsRegistry().getNames();
}
},
@ -101,7 +101,7 @@ public enum MathType {
@NotNull
@Override
public List<String> getTokens() {
return CalculatorLocatorImpl.getInstance().getEngine().getFunctionsRegistry().getNames();
return Locator.getInstance().getEngine().getFunctionsRegistry().getNames();
}
},
@ -109,7 +109,7 @@ public enum MathType {
@NotNull
@Override
public List<String> getTokens() {
return CalculatorLocatorImpl.getInstance().getEngine().getOperatorsRegistry().getNames();
return Locator.getInstance().getEngine().getOperatorsRegistry().getNames();
}
},
@ -117,7 +117,7 @@ public enum MathType {
@NotNull
@Override
public List<String> getTokens() {
return CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getNames();
return Locator.getInstance().getEngine().getVarsRegistry().getNames();
}
@Override

View File

@ -13,7 +13,7 @@ import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
import org.simpleframework.xml.Transient;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.CalculatorParseException;
import org.solovyev.android.calculator.MathPersistenceEntity;
import org.solovyev.common.math.MathEntity;
@ -268,7 +268,7 @@ public class AFunction implements IFunction, MathPersistenceEntity, Serializable
result.name = name;
try {
result.content = CalculatorLocatorImpl.getInstance().getCalculator().prepareExpression(value).toString();
result.content = Locator.getInstance().getCalculator().prepareExpression(value).toString();
} catch (CalculatorParseException e) {
throw new CreationException(e);
}

View File

@ -3,7 +3,7 @@ package org.solovyev.android.calculator.text;
import jscl.math.Generic;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.math.MathType;
import org.solovyev.android.calculator.CalculatorParseException;
@ -57,7 +57,7 @@ public class FromJsclSimplifyTextProcessor implements TextProcessor<String, Gene
}
if (needMultiplicationSign(mathTypeBefore == null ? null : mathTypeBefore.getMathType(), mathTypeAfter == null ? null : mathTypeAfter.getMathType())) {
sb.append(CalculatorLocatorImpl.getInstance().getEngine().getMultiplicationSign());
sb.append(Locator.getInstance().getEngine().getMultiplicationSign());
}
} else {

View File

@ -12,8 +12,8 @@ import org.solovyev.android.calculator.history.CalculatorHistory;
public class AbstractCalculatorTest {
protected void setUp() throws Exception {
CalculatorLocatorImpl.getInstance().init(new CalculatorImpl(), CalculatorTestUtils.newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class), new SystemOutCalculatorLogger(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(CalculatorKeyboard.class), Mockito.mock(CalculatorExternalListenersContainer.class));
CalculatorLocatorImpl.getInstance().getEngine().init();
Locator.getInstance().init(new CalculatorImpl(), CalculatorTestUtils.newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class), new SystemOutCalculatorLogger(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(CalculatorKeyboard.class), Mockito.mock(CalculatorExternalListenersContainer.class));
Locator.getInstance().getEngine().init();
}
}

View File

@ -18,7 +18,7 @@ public class CalculatorEditorImplTest extends AbstractCalculatorTest {
@Before
public void setUp() throws Exception {
super.setUp();
this.calculatorEditor = new CalculatorEditorImpl(CalculatorLocatorImpl.getInstance().getCalculator());
this.calculatorEditor = new CalculatorEditorImpl(Locator.getInstance().getCalculator());
}
@Test

View File

@ -28,22 +28,22 @@ public class FromJsclSimplifyTextProcessorTest extends AbstractCalculatorTest {
//Assert.assertEquals("((e)(e))", tp.process("((2.718281828459045)*(2.718281828459045))"));
DecimalFormatSymbols decimalGroupSymbols = new DecimalFormatSymbols();
decimalGroupSymbols.setGroupingSeparator(' ');
CalculatorLocatorImpl.getInstance().getEngine().setDecimalGroupSymbols(decimalGroupSymbols);
Locator.getInstance().getEngine().setDecimalGroupSymbols(decimalGroupSymbols);
//Assert.assertEquals("123 456 789e", tp.process("123456789*2.718281828459045"));
//Assert.assertEquals("123 456 789e", tp.process("123 456 789 * 2.718281828459045"));
//Assert.assertEquals("t11e", tp.process("t11*2.718281828459045"));
//Assert.assertEquals("e", tp.process("2.718281828459045"));
//Assert.assertEquals("tee", tp.process("t2.718281828459045*2.718281828459045"));
CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t2.718281828459045", "2"));
CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t", (String)null));
Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t2.718281828459045", "2"));
Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t", (String)null));
//Assert.assertEquals("t2.718281828459045e", tp.process("t2.718281828459045*2.718281828459045"));
//Assert.assertEquals("ee", tp.process("2.718281828459045*2.718281828459045"));
Assert.assertEquals("t×", tp.process("t*"));
Assert.assertEquals("×t", tp.process("*t"));
Assert.assertEquals("t2", tp.process("t*2"));
Assert.assertEquals("2t", tp.process("2*t"));
CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t", (String) null));
Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t", (String) null));
Assert.assertEquals("t×", tp.process("t*"));
Assert.assertEquals("×t", tp.process("*t"));
@ -56,7 +56,7 @@ public class FromJsclSimplifyTextProcessorTest extends AbstractCalculatorTest {
Assert.assertEquals("t^[2×2t]", tp.process("t^[2*2*t]"));
Assert.assertEquals("2t^2[2t]", tp.process("2*t^2[2*t]"));
CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("k", (String) null));
Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("k", (String) null));
Assert.assertEquals("(t+2k)[k+2t]", tp.process("(t+2*k)*[k+2*t]"));
Assert.assertEquals("(te+2k)e[k+2te]", tp.process("(t*e+2*k)*e*[k+2*t*e]"));

View File

@ -6,7 +6,7 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.solovyev.android.calculator.CalculatorDisplayViewStateImpl;
import org.solovyev.android.calculator.CalculatorEditorViewStateImpl;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.CalculatorTestUtils;
import java.util.List;
@ -25,7 +25,7 @@ public class CalculatorHistoryImplTest {
@Test
public void testGetStates() throws Exception {
CalculatorHistory calculatorHistory = new CalculatorHistoryImpl(CalculatorLocatorImpl.getInstance().getCalculator());
CalculatorHistory calculatorHistory = new CalculatorHistoryImpl(Locator.getInstance().getCalculator());
addState(calculatorHistory, "1");
addState(calculatorHistory, "12");

View File

@ -18,8 +18,8 @@ import junit.framework.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.solovyev.android.calculator.AbstractCalculatorTest;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.CalculatorEvalException;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.CalculatorTestUtils;
import org.solovyev.android.calculator.jscl.JsclOperation;
@ -40,13 +40,13 @@ public class AndroidCalculatorEngineTest extends AbstractCalculatorTest {
@BeforeClass
public static void staticSetUp() throws Exception {
CalculatorTestUtils.staticSetUp();
CalculatorLocatorImpl.getInstance().getEngine().setPrecision(3);
Locator.getInstance().getEngine().setPrecision(3);
}
@Test
public void testDegrees() throws Exception {
final MathEngine cm = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0();
final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0();
final AngleUnit defaultAngleUnit = cm.getAngleUnits();
try {
@ -67,7 +67,7 @@ public class AndroidCalculatorEngineTest extends AbstractCalculatorTest {
/* @Test
public void testLongExecution() throws Exception {
final MathEngine cm = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0();
final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0();
try {
cm.evaluate( "3^10^10^10");
@ -110,7 +110,7 @@ public class AndroidCalculatorEngineTest extends AbstractCalculatorTest {
@Test
public void testEvaluate() throws Exception {
final MathEngine cm = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0();
final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0();
CalculatorTestUtils.assertEval("cos(t)+10%", "cos(t)+10%", JsclOperation.simplify);
@ -171,7 +171,7 @@ public class AndroidCalculatorEngineTest extends AbstractCalculatorTest {
CalculatorTestUtils.assertError("(-1)i!");
CalculatorTestUtils.assertEval("24i", "4!i");
CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("si", 5d));
Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("si", 5d));
try {
cm.setAngleUnits(AngleUnit.rad);
@ -185,14 +185,14 @@ public class AndroidCalculatorEngineTest extends AbstractCalculatorTest {
cm.setAngleUnits(defaultAngleUnit);
}
CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("s", 1d));
Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("s", 1d));
CalculatorTestUtils.assertEval("5", cm.evaluate( "si"));
CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("k", 3.5d));
CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("k1", 4d));
Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("k", 3.5d));
Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("k1", 4d));
CalculatorTestUtils.assertEval("4", "k11");
CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t", (String) null));
Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t", (String) null));
CalculatorTestUtils.assertEval("11t", "t11");
CalculatorTestUtils.assertEval("11et", "t11e");
CalculatorTestUtils.assertEval("", "");
@ -238,10 +238,10 @@ public class AndroidCalculatorEngineTest extends AbstractCalculatorTest {
cm.setTimeout(3000);
}*/
CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t", (String) null));
Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t", (String) null));
CalculatorTestUtils.assertEval("2t", "∂(t^2,t)", JsclOperation.simplify);
CalculatorTestUtils.assertEval("2t", "∂(t^2,t)");
CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t", "2"));
Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t", "2"));
CalculatorTestUtils.assertEval("2t", "∂(t^2,t)", JsclOperation.simplify);
CalculatorTestUtils.assertEval("4", "∂(t^2,t)");
@ -256,7 +256,7 @@ public class AndroidCalculatorEngineTest extends AbstractCalculatorTest {
@Test
public void testFormatting() throws Exception {
final MathEngine ce = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0();
final MathEngine ce = Locator.getInstance().getEngine().getMathEngine0();
CalculatorTestUtils.assertEval("12 345", ce.simplify( "12345"));
@ -264,7 +264,7 @@ public class AndroidCalculatorEngineTest extends AbstractCalculatorTest {
@Test
public void testI() throws ParseException, CalculatorEvalException {
final MathEngine cm = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0();
final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0();
CalculatorTestUtils.assertEval("-i", cm.evaluate( "i^3"));
for (int i = 0; i < 1000; i++) {
@ -289,7 +289,7 @@ public class AndroidCalculatorEngineTest extends AbstractCalculatorTest {
@Test
public void testEmptyFunction() throws Exception {
final MathEngine cm = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0();
final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0();
try {
cm.evaluate( "cos(cos(cos(cos(acos(acos(acos(acos(acos(acos(acos(acos(cos(cos(cos(cos(cosh(acos(cos(cos(cos(cos(cos(acos(acos(acos(acos(acos(acos(acos(acos(cos(cos(cos(cos(cosh(acos(cos())))))))))))))))))))))))))))))))))))))");
Assert.fail();
@ -310,7 +310,7 @@ public class AndroidCalculatorEngineTest extends AbstractCalculatorTest {
cm.setAngleUnits(defaultAngleUnit);
}
CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("si", 5d));
Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("si", 5d));
CalculatorTestUtils.assertEval("5", cm.evaluate( "si"));
CalculatorTestUtils.assertError("sin");
@ -318,7 +318,7 @@ public class AndroidCalculatorEngineTest extends AbstractCalculatorTest {
@Test
public void testRounding() throws Exception {
final MathEngine cm = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0();
final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0();
try {
DecimalFormatSymbols decimalGroupSymbols = new DecimalFormatSymbols(Locale.getDefault());
@ -342,7 +342,7 @@ public class AndroidCalculatorEngineTest extends AbstractCalculatorTest {
@Test
public void testComparisonFunction() throws Exception {
final MathEngine cm = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0();
final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0();
CalculatorTestUtils.assertEval("0", "eq(0, 1)");
CalculatorTestUtils.assertEval("1", "eq(1, 1)");
@ -379,7 +379,7 @@ public class AndroidCalculatorEngineTest extends AbstractCalculatorTest {
@Test
public void testNumeralSystems() throws Exception {
final MathEngine cm = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0();
final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0();
CalculatorTestUtils.assertEval("11 259 375", "0x:ABCDEF");
CalculatorTestUtils.assertEval("30 606 154.462", "0x:ABCDEF*e");
@ -408,7 +408,7 @@ public class AndroidCalculatorEngineTest extends AbstractCalculatorTest {
@Test
public void testLog() throws Exception {
final MathEngine cm = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0();
final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0();
CalculatorTestUtils.assertEval("", Expression.valueOf("1/0").numeric().toString());
CalculatorTestUtils.assertEval("", Expression.valueOf("ln(10)/ln(1)").numeric().toString());

View File

@ -27,7 +27,7 @@ public class NumeralBaseTest extends AbstractCalculatorTest {
@BeforeClass
public static void staticSetUp() throws Exception {
CalculatorTestUtils.staticSetUp();
CalculatorLocatorImpl.getInstance().getEngine().setPrecision(3);
Locator.getInstance().getEngine().setPrecision(3);
}
@Test
@ -97,11 +97,11 @@ public class NumeralBaseTest extends AbstractCalculatorTest {
final String bin = "0b:" + line[2].toUpperCase();
final String decExpression = converter.convert(dec);
final String decResult = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine().evaluate(decExpression);
final String decResult = Locator.getInstance().getEngine().getMathEngine().evaluate(decExpression);
final String hexExpression = converter.convert(hex);
final String hexResult = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine().evaluate(hexExpression);
final String hexResult = Locator.getInstance().getEngine().getMathEngine().evaluate(hexExpression);
final String binExpression = converter.convert(bin);
final String binResult = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine().evaluate(binExpression);
final String binResult = Locator.getInstance().getEngine().getMathEngine().evaluate(binExpression);
Assert.assertEquals("dec-hex: " + decExpression + " : " + hexExpression, decResult, hexResult);
Assert.assertEquals("dec-bin: " + decExpression + " : " + binExpression, decResult, binResult);

View File

@ -65,10 +65,10 @@ public class ToJsclTextProcessorTest extends AbstractCalculatorTest {
Assert.assertEquals( "EE", preprocessor.process("EE").toString());
try {
CalculatorLocatorImpl.getInstance().getEngine().setNumeralBase(NumeralBase.hex);
Locator.getInstance().getEngine().setNumeralBase(NumeralBase.hex);
Assert.assertEquals( "22F*exp(F)", preprocessor.process("22Fexp(F)").toString());
} finally {
CalculatorLocatorImpl.getInstance().getEngine().setNumeralBase(NumeralBase.dec);
Locator.getInstance().getEngine().setNumeralBase(NumeralBase.dec);
}
Assert.assertEquals( "0x:ABCDEF", preprocessor.process("0x:ABCDEF").toString());
Assert.assertEquals( "0x:ABCDEF", preprocessor.process("0x:A BC DEF").toString());

View File

@ -90,7 +90,7 @@ public abstract class AbstractCalculatorHelper implements SharedPreferences.OnSh
@Override
public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) {
if (dragDirection == DragDirection.down) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_operators, null);
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_operators, null);
return true;
}
return false;
@ -178,7 +178,7 @@ public abstract class AbstractCalculatorHelper implements SharedPreferences.OnSh
@NotNull
private Calculator getCalculator() {
return CalculatorLocatorImpl.getInstance().getCalculator();
return Locator.getInstance().getCalculator();
}
@ -212,7 +212,7 @@ public abstract class AbstractCalculatorHelper implements SharedPreferences.OnSh
@NotNull
private CalculatorKeyboard getKeyboard() {
return CalculatorLocatorImpl.getInstance().getKeyboard();
return Locator.getInstance().getKeyboard();
}
@Nullable

View File

@ -65,7 +65,7 @@ public class AndroidCalculator implements Calculator, CalculatorEventListener, S
public void setDisplay(@NotNull Context context, @NotNull AndroidCalculatorDisplayView displayView) {
displayView.init(context);
CalculatorLocatorImpl.getInstance().getDisplay().setView(displayView);
Locator.getInstance().getDisplay().setView(displayView);
}
public void setEditor(@NotNull Activity activity) {
@ -75,7 +75,7 @@ public class AndroidCalculator implements Calculator, CalculatorEventListener, S
public void setEditor(@NotNull Context context, @NotNull AndroidCalculatorEditorView editorView) {
editorView.init(context);
CalculatorLocatorImpl.getInstance().getEditor().setView(editorView);
Locator.getInstance().getEditor().setView(editorView);
}

View File

@ -16,7 +16,6 @@ import android.text.Html;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.ContextMenu;
import android.widget.EditText;
import org.jetbrains.annotations.NotNull;
@ -128,7 +127,7 @@ public class AndroidCalculatorEditorView extends EditText implements SharedPrefe
public void setHighlightText(boolean highlightText) {
this.highlightText = highlightText;
CalculatorLocatorImpl.getInstance().getEditor().updateViewState();
Locator.getInstance().getEditor().updateViewState();
}
@Override
@ -186,7 +185,7 @@ public class AndroidCalculatorEditorView extends EditText implements SharedPrefe
if (!viewStateChange) {
// external text change => need to notify editor
super.onSelectionChanged(selStart, selEnd);
CalculatorLocatorImpl.getInstance().getEditor().setSelection(selStart);
Locator.getInstance().getEditor().setSelection(selStart);
}
}
}
@ -197,7 +196,7 @@ public class AndroidCalculatorEditorView extends EditText implements SharedPrefe
synchronized (viewLock) {
if (!viewStateChange) {
// external text change => need to notify editor
CalculatorLocatorImpl.getInstance().getEditor().setText(String.valueOf(s));
Locator.getInstance().getEditor().setText(String.valueOf(s));
}
}
}

View File

@ -75,7 +75,7 @@ public class AndroidCalculatorPreferenceService implements CalculatorPreferenceS
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(application);
AndroidCalculatorEngine.Preferences.angleUnit.putPreference(preferences, angleUnit);
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(new AndroidMessage(R.string.c_angle_units_changed_to, MessageType.info, application, angleUnit.name()));
Locator.getInstance().getNotifier().showMessage(new AndroidMessage(R.string.c_angle_units_changed_to, MessageType.info, application, angleUnit.name()));
}
@Override
@ -89,6 +89,6 @@ public class AndroidCalculatorPreferenceService implements CalculatorPreferenceS
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(application);
AndroidCalculatorEngine.Preferences.numeralBase.putPreference(preferences, numeralBase);
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(new AndroidMessage(R.string.c_numeral_base_changed_to, MessageType.info, application, numeralBase.name()));
Locator.getInstance().getNotifier().showMessage(new AndroidMessage(R.string.c_numeral_base_changed_to, MessageType.info, application, numeralBase.name()));
}
}

View File

@ -80,12 +80,12 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar
preferences.registerOnSharedPreferenceChangeListener(this);
CalculatorLocatorImpl.getInstance().getPreferenceService().checkPreferredPreferences(false);
Locator.getInstance().getPreferenceService().checkPreferredPreferences(false);
}
@NotNull
private AndroidCalculator getCalculator() {
return ((AndroidCalculator) CalculatorLocatorImpl.getInstance().getCalculator());
return ((AndroidCalculator) Locator.getInstance().getCalculator());
}
private static void firstTimeInit(@NotNull SharedPreferences preferences, @NotNull Context context) {
@ -267,7 +267,7 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar
@NotNull
private static CalculatorKeyboard getKeyboard() {
return CalculatorLocatorImpl.getInstance().getKeyboard();
return Locator.getInstance().getKeyboard();
}
@SuppressWarnings({"UnusedDeclaration"})

View File

@ -68,7 +68,7 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
super.onCreate(activity);
if (activity instanceof CalculatorEventListener) {
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener((CalculatorEventListener) activity);
Locator.getInstance().getCalculator().addCalculatorEventListener((CalculatorEventListener) activity);
}
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
@ -172,7 +172,7 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
super.onDestroy(activity);
if (activity instanceof CalculatorEventListener) {
CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener((CalculatorEventListener) activity);
Locator.getInstance().getCalculator().removeCalculatorEventListener((CalculatorEventListener) activity);
}
}

View File

@ -120,13 +120,13 @@ public class CalculatorActivityLauncher {
context.startActivity(intent);
}
} else {
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(R.string.c_value_is_not_a_number, MessageType.error);
Locator.getInstance().getNotifier().showMessage(R.string.c_value_is_not_a_number, MessageType.error);
}
} else {
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(R.string.empty_var_error, MessageType.error);
Locator.getInstance().getNotifier().showMessage(R.string.empty_var_error, MessageType.error);
}
} else {
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(R.string.not_valid_result, MessageType.error);
Locator.getInstance().getNotifier().showMessage(R.string.not_valid_result, MessageType.error);
}
}
@ -140,10 +140,10 @@ public class CalculatorActivityLauncher {
FunctionEditDialogFragment.showDialog(FunctionEditDialogFragment.Input.newFromDisplay(viewState), context);
} else {
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(R.string.empty_function_error, MessageType.error);
Locator.getInstance().getNotifier().showMessage(R.string.empty_function_error, MessageType.error);
}
} else {
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(R.string.not_valid_result, MessageType.error);
Locator.getInstance().getNotifier().showMessage(R.string.not_valid_result, MessageType.error);
}
}

View File

@ -54,12 +54,12 @@ public final class CalculatorButtons {
static void initMultiplicationButton(@NotNull View root) {
final View multiplicationButton = root.findViewById(R.id.multiplicationButton);
if ( multiplicationButton instanceof Button) {
((Button) multiplicationButton).setText(CalculatorLocatorImpl.getInstance().getEngine().getMultiplicationSign());
((Button) multiplicationButton).setText(Locator.getInstance().getEngine().getMultiplicationSign());
}
}
public static void initMultiplicationButton(@NotNull RemoteViews views) {
views.setTextViewText(R.id.multiplicationButton, CalculatorLocatorImpl.getInstance().getEngine().getMultiplicationSign());
views.setTextViewText(R.id.multiplicationButton, Locator.getInstance().getEngine().getMultiplicationSign());
}
@ -112,7 +112,7 @@ public final class CalculatorButtons {
@NotNull
private static CalculatorKeyboard getKeyboard() {
return CalculatorLocatorImpl.getInstance().getKeyboard();
return Locator.getInstance().getKeyboard();
}
static class VarsDragProcessor implements SimpleOnDragListener.DragProcessor {
@ -132,7 +132,7 @@ public final class CalculatorButtons {
boolean result = false;
if (dragDirection == DragDirection.up) {
CalculatorActivityLauncher.createVar(context, CalculatorLocatorImpl.getInstance().getDisplay());
CalculatorActivityLauncher.createVar(context, Locator.getInstance().getDisplay());
result = true;
}
@ -150,7 +150,7 @@ public final class CalculatorButtons {
AngleUnitsChanger(@NotNull Context context) {
this.context = context;
this.processor = new DigitButtonDragProcessor(CalculatorLocatorImpl.getInstance().getKeyboard());
this.processor = new DigitButtonDragProcessor(Locator.getInstance().getKeyboard());
}
@Override
@ -172,7 +172,7 @@ public final class CalculatorButtons {
final AngleUnit oldAngleUnits = AndroidCalculatorEngine.Preferences.angleUnit.getPreference(preferences);
if (oldAngleUnits != angleUnits) {
CalculatorLocatorImpl.getInstance().getPreferenceService().setAngleUnits(angleUnits);
Locator.getInstance().getPreferenceService().setAngleUnits(angleUnits);
}
result = true;
@ -216,7 +216,7 @@ public final class CalculatorButtons {
final NumeralBase oldNumeralBase = AndroidCalculatorEngine.Preferences.numeralBase.getPreference(preferences);
if (oldNumeralBase != numeralBase) {
CalculatorLocatorImpl.getInstance().getPreferenceService().setNumeralBase(numeralBase);
Locator.getInstance().getPreferenceService().setNumeralBase(numeralBase);
}
result = true;
@ -247,7 +247,7 @@ public final class CalculatorButtons {
boolean result = false;
if (dragDirection == DragDirection.up) {
CalculatorActivityLauncher.createFunction(context, CalculatorLocatorImpl.getInstance().getDisplay());
CalculatorActivityLauncher.createFunction(context, Locator.getInstance().getDisplay());
result = true;
}

View File

@ -43,7 +43,7 @@ public class CalculatorDisplayFragment extends SherlockFragment {
public void onViewCreated(View root, Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState);
((AndroidCalculator) CalculatorLocatorImpl.getInstance().getCalculator()).setDisplay(getActivity());
((AndroidCalculator) Locator.getInstance().getCalculator()).setDisplay(getActivity());
fragmentHelper.onViewCreated(this, root);
}

View File

@ -19,7 +19,7 @@ public enum CalculatorDisplayMenuItem implements LabeledMenuItem<CalculatorDispl
copy(R.string.c_copy) {
@Override
public void onClick(@NotNull CalculatorDisplayViewState data, @NotNull Context context) {
CalculatorLocatorImpl.getInstance().getKeyboard().copyButtonPressed();
Locator.getInstance().getKeyboard().copyButtonPressed();
}
},

View File

@ -26,7 +26,7 @@ public class CalculatorDisplayOnClickListener implements View.OnClickListener {
@Override
public void onClick(View v) {
if (v instanceof CalculatorDisplayView) {
final CalculatorDisplay cd = CalculatorLocatorImpl.getInstance().getDisplay();
final CalculatorDisplay cd = Locator.getInstance().getDisplay();
final CalculatorDisplayViewState displayViewState = cd.getViewState();

View File

@ -38,7 +38,7 @@ public class CalculatorEditorFragment extends SherlockFragment {
fragmentHelper.onViewCreated(this, view);
((AndroidCalculator) CalculatorLocatorImpl.getInstance().getCalculator()).setEditor(getActivity());
((AndroidCalculator) Locator.getInstance().getCalculator()).setEditor(getActivity());
}
@Override

View File

@ -63,7 +63,7 @@ public class CalculatorFragmentHelperImpl extends AbstractCalculatorHelper imple
if (listenersOnCreate) {
if ( fragment instanceof CalculatorEventListener ) {
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener((CalculatorEventListener) fragment);
Locator.getInstance().getCalculator().addCalculatorEventListener((CalculatorEventListener) fragment);
}
}
}
@ -72,7 +72,7 @@ public class CalculatorFragmentHelperImpl extends AbstractCalculatorHelper imple
public void onResume(@NotNull Fragment fragment) {
if (!listenersOnCreate) {
if ( fragment instanceof CalculatorEventListener ) {
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener((CalculatorEventListener) fragment);
Locator.getInstance().getCalculator().addCalculatorEventListener((CalculatorEventListener) fragment);
}
}
}
@ -81,7 +81,7 @@ public class CalculatorFragmentHelperImpl extends AbstractCalculatorHelper imple
public void onPause(@NotNull Fragment fragment) {
if (!listenersOnCreate) {
if ( fragment instanceof CalculatorEventListener ) {
CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener((CalculatorEventListener) fragment);
Locator.getInstance().getCalculator().removeCalculatorEventListener((CalculatorEventListener) fragment);
}
}
}
@ -114,7 +114,7 @@ public class CalculatorFragmentHelperImpl extends AbstractCalculatorHelper imple
if (listenersOnCreate) {
if ( fragment instanceof CalculatorEventListener ) {
CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener((CalculatorEventListener) fragment);
Locator.getInstance().getCalculator().removeCalculatorEventListener((CalculatorEventListener) fragment);
}
}

View File

@ -131,17 +131,17 @@ public class CalculatorKeyboardFragment extends SherlockFragment implements Shar
@Nullable
private static AndroidCalculatorDisplayView getCalculatorDisplayView() {
return (AndroidCalculatorDisplayView) CalculatorLocatorImpl.getInstance().getDisplay().getView();
return (AndroidCalculatorDisplayView) Locator.getInstance().getDisplay().getView();
}
@NotNull
private Calculator getCalculator() {
return CalculatorLocatorImpl.getInstance().getCalculator();
return Locator.getInstance().getCalculator();
}
@NotNull
private static CalculatorKeyboard getKeyboard() {
return CalculatorLocatorImpl.getInstance().getKeyboard();
return Locator.getInstance().getKeyboard();
}
}

View File

@ -31,9 +31,9 @@ enum ConversionMenuItem implements AMenuItem<CalculatorDisplayViewState> {
if (operation == JsclOperation.numeric) {
if (generic.getConstants().isEmpty()) {
// conversion possible => return true
final NumeralBase fromNumeralBase = CalculatorLocatorImpl.getInstance().getEngine().getNumeralBase();
final NumeralBase fromNumeralBase = Locator.getInstance().getEngine().getNumeralBase();
if (fromNumeralBase != toNumeralBase) {
result = CalculatorLocatorImpl.getInstance().getCalculator().isConversionPossible(generic, fromNumeralBase, this.toNumeralBase);
result = Locator.getInstance().getCalculator().isConversionPossible(generic, fromNumeralBase, this.toNumeralBase);
}
}
}
@ -46,7 +46,7 @@ enum ConversionMenuItem implements AMenuItem<CalculatorDisplayViewState> {
final Generic result = data.getResult();
if (result != null) {
CalculatorLocatorImpl.getInstance().getCalculator().convert(result, this.toNumeralBase);
Locator.getInstance().getCalculator().convert(result, this.toNumeralBase);
}
}
}

View File

@ -30,10 +30,10 @@ public class CursorDragProcessor implements SimpleOnDragListener.DragProcessor{
if (dragButton instanceof DirectionDragButton) {
String text = ((DirectionDragButton) dragButton).getText(dragDirection);
if ("◀◀".equals(text)) {
CalculatorLocatorImpl.getInstance().getEditor().setCursorOnStart();
Locator.getInstance().getEditor().setCursorOnStart();
result = true;
} else if ("▶▶".equals(text)) {
CalculatorLocatorImpl.getInstance().getEditor().setCursorOnEnd();
Locator.getInstance().getEditor().setCursorOnEnd();
result = true;
}
}

View File

@ -31,7 +31,7 @@ public class EvalDragProcessor implements SimpleOnDragListener.DragProcessor {
if (dragButton instanceof DirectionDragButton) {
String text = ((DirectionDragButton) dragButton).getText(dragDirection);
if ("".equals(text)) {
CalculatorLocatorImpl.getInstance().getCalculator().simplify();
Locator.getInstance().getCalculator().simplify();
result = true;
}
}

View File

@ -4,9 +4,9 @@ import android.content.Context;
import android.content.Intent;
import android.os.Parcelable;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.CalculatorDisplayViewState;
import org.solovyev.android.calculator.CalculatorEditorViewState;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.common.MutableObject;
/**
@ -81,10 +81,10 @@ public class DefaultExternalCalculatorIntentHandler implements ExternalCalculato
}
protected void onDisplayStateChanged(@NotNull Context context, @NotNull CalculatorDisplayViewState displayViewState) {
updateState(context, CalculatorLocatorImpl.getInstance().getEditor().getViewState(), displayViewState);
updateState(context, Locator.getInstance().getEditor().getViewState(), displayViewState);
}
protected void onEditorStateChanged(@NotNull Context context, @NotNull CalculatorEditorViewState editorViewState) {
updateState(context, editorViewState, CalculatorLocatorImpl.getInstance().getDisplay().getViewState());
updateState(context, editorViewState, Locator.getInstance().getDisplay().getViewState());
}
}

View File

@ -103,7 +103,7 @@ public class FunctionEditDialogFragment extends DialogFragment implements Calcul
}
});
root.findViewById(R.id.save_button).setOnClickListener(new FunctionEditorSaver(builder, function, root, CalculatorLocatorImpl.getInstance().getEngine().getFunctionsRegistry(), this));
root.findViewById(R.id.save_button).setOnClickListener(new FunctionEditorSaver(builder, function, root, Locator.getInstance().getEngine().getFunctionsRegistry(), this));
if ( function == null ) {
// CREATE MODE
@ -130,12 +130,12 @@ public class FunctionEditDialogFragment extends DialogFragment implements Calcul
public void onResume() {
super.onResume();
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener(this);
Locator.getInstance().getCalculator().addCalculatorEventListener(this);
}
@Override
public void onPause() {
CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener(this);
Locator.getInstance().getCalculator().removeCalculatorEventListener(this);
super.onPause();
}

View File

@ -8,8 +8,8 @@ import jscl.math.function.Function;
import jscl.math.function.IFunction;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.CalculatorFunctionsMathRegistry;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.CalculatorMathRegistry;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.math.edit.VarEditorSaver;
@ -101,14 +101,14 @@ public class FunctionEditorSaver implements View.OnClickListener {
}
if (error != null) {
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(error, MessageType.error);
Locator.getInstance().getNotifier().showMessage(error, MessageType.error);
} else {
try {
CalculatorFunctionsMathRegistry.saveFunction(mathRegistry, new BuilderAdapter(builder), editedInstance, source, true);
} catch (CustomFunctionCalculationException e) {
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(e);
Locator.getInstance().getNotifier().showMessage(e);
} catch (AFunction.Builder.CreationException e) {
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(e);
Locator.getInstance().getNotifier().showMessage(e);
}
}
}

View File

@ -219,7 +219,7 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
boolean result = false;
try {
historyState.setSaved(true);
if ( CollectionsUtils.contains(historyState, CalculatorLocatorImpl.getInstance().getHistory().getSavedHistory(), new Equalizer<CalculatorHistoryState>() {
if ( CollectionsUtils.contains(historyState, Locator.getInstance().getHistory().getSavedHistory(), new Equalizer<CalculatorHistoryState>() {
@Override
public boolean equals(@Nullable CalculatorHistoryState first, @Nullable CalculatorHistoryState second) {
return first != null && second != null &&
@ -237,7 +237,7 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
}
public static void useHistoryItem(@NotNull final CalculatorHistoryState historyState) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_history_state, historyState);
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_history_state, historyState);
}
@NotNull
@ -339,7 +339,7 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
clear_history(org.solovyev.android.calculator.R.id.history_menu_clear_history) {
@Override
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.clear_history_requested, null);
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.clear_history_requested, null);
}
};

View File

@ -8,7 +8,7 @@ package org.solovyev.android.calculator.history;
import android.preference.PreferenceManager;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.CalculatorPreferences;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.about.CalculatorFragmentType;
@ -36,12 +36,12 @@ public class CalculatorHistoryFragment extends AbstractCalculatorHistoryFragment
@Override
protected List<CalculatorHistoryState> getHistoryItems() {
final boolean showIntermediateCalculations = CalculatorPreferences.History.showIntermediateCalculations.getPreference(PreferenceManager.getDefaultSharedPreferences(getActivity()));
return new ArrayList<CalculatorHistoryState>(CalculatorLocatorImpl.getInstance().getHistory().getStates(showIntermediateCalculations));
return new ArrayList<CalculatorHistoryState>(Locator.getInstance().getHistory().getStates(showIntermediateCalculations));
}
@Override
protected void clearHistory() {
CalculatorLocatorImpl.getInstance().getHistory().clear();
Locator.getInstance().getHistory().clear();
getAdapter().clear();
}
}

View File

@ -7,7 +7,7 @@
package org.solovyev.android.calculator.history;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.about.CalculatorFragmentType;
@ -33,12 +33,12 @@ public class CalculatorSavedHistoryFragment extends AbstractCalculatorHistoryFra
@NotNull
@Override
protected List<CalculatorHistoryState> getHistoryItems() {
return new ArrayList<CalculatorHistoryState>(CalculatorLocatorImpl.getInstance().getHistory().getSavedHistory());
return new ArrayList<CalculatorHistoryState>(Locator.getInstance().getHistory().getSavedHistory());
}
@Override
protected void clearHistory() {
CalculatorLocatorImpl.getInstance().getHistory().clearSavedHistory();
Locator.getInstance().getHistory().clearSavedHistory();
getAdapter().clear();
}
}

View File

@ -11,14 +11,13 @@ import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.text.ClipboardManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.R;
import org.solovyev.android.menu.LabeledMenuItem;
import org.solovyev.common.text.StringUtils;
@ -93,7 +92,7 @@ public enum HistoryItemMenuItem implements LabeledMenuItem<HistoryItemMenuData>
final CalculatorHistoryState historyState = data.getHistoryState();
if (historyState.isSaved()) {
data.getAdapter().remove(historyState);
CalculatorLocatorImpl.getInstance().getHistory().removeSavedHistory(historyState);
Locator.getInstance().getHistory().removeSavedHistory(historyState);
Toast.makeText(context, context.getText(R.string.c_history_was_removed), Toast.LENGTH_LONG).show();
data.getAdapter().notifyDataSetChanged();
}
@ -119,14 +118,14 @@ public enum HistoryItemMenuItem implements LabeledMenuItem<HistoryItemMenuData>
@Override
public void onClick(DialogInterface dialog, int which) {
if (save) {
final CalculatorHistoryState savedHistoryItem = CalculatorLocatorImpl.getInstance().getHistory().addSavedState(historyState);
final CalculatorHistoryState savedHistoryItem = Locator.getInstance().getHistory().addSavedState(historyState);
savedHistoryItem.setComment(comment.getText().toString());
CalculatorLocatorImpl.getInstance().getHistory().save();
Locator.getInstance().getHistory().save();
// we don't need to add element to the adapter as adapter of another activity must be updated and not this
//data.getAdapter().add(savedHistoryItem);
} else {
historyState.setComment(comment.getText().toString());
CalculatorLocatorImpl.getInstance().getHistory().save();
Locator.getInstance().getHistory().save();
}
data.getAdapter().notifyDataSetChanged();
Toast.makeText(context, context.getText(R.string.c_history_saved), Toast.LENGTH_LONG).show();

View File

@ -72,7 +72,7 @@ public class CalculatorFunctionsFragment extends AbstractMathEntityListFragment<
protected List<LabeledMenuItem<Function>> getMenuItemsOnLongClick(@NotNull Function item) {
List<LabeledMenuItem<Function>> result = new ArrayList<LabeledMenuItem<Function>>(Arrays.asList(LongClickMenuItem.values()));
final CalculatorMathRegistry<Function> functionsRegistry = CalculatorLocatorImpl.getInstance().getEngine().getFunctionsRegistry();
final CalculatorMathRegistry<Function> functionsRegistry = Locator.getInstance().getEngine().getFunctionsRegistry();
if ( StringUtils.isEmpty(functionsRegistry.getDescription(item.getName())) ) {
result.remove(LongClickMenuItem.copy_description);
}
@ -88,18 +88,18 @@ public class CalculatorFunctionsFragment extends AbstractMathEntityListFragment<
@NotNull
@Override
protected MathEntityDescriptionGetter getDescriptionGetter() {
return new MathEntityDescriptionGetterImpl(CalculatorLocatorImpl.getInstance().getEngine().getFunctionsRegistry());
return new MathEntityDescriptionGetterImpl(Locator.getInstance().getEngine().getFunctionsRegistry());
}
@NotNull
@Override
protected List<Function> getMathEntities() {
return new ArrayList<Function>(CalculatorLocatorImpl.getInstance().getEngine().getFunctionsRegistry().getEntities());
return new ArrayList<Function>(Locator.getInstance().getEngine().getFunctionsRegistry().getEntities());
}
@Override
protected String getMathEntityCategory(@NotNull Function function) {
return CalculatorLocatorImpl.getInstance().getEngine().getFunctionsRegistry().getCategory(function);
return Locator.getInstance().getEngine().getFunctionsRegistry().getCategory(function);
}
@Override
@ -223,7 +223,7 @@ public class CalculatorFunctionsFragment extends AbstractMathEntityListFragment<
use(R.string.c_use) {
@Override
public void onClick(@NotNull Function function, @NotNull Context context) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_function, function);
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_function, function);
}
},
@ -246,7 +246,7 @@ public class CalculatorFunctionsFragment extends AbstractMathEntityListFragment<
copy_description(R.string.c_copy_description) {
@Override
public void onClick(@NotNull Function function, @NotNull Context context) {
final String text = CalculatorLocatorImpl.getInstance().getEngine().getFunctionsRegistry().getDescription(function.getName());
final String text = Locator.getInstance().getEngine().getFunctionsRegistry().getDescription(function.getName());
if (!StringUtils.isEmpty(text)) {
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
clipboard.setText(text);

View File

@ -5,8 +5,8 @@ import android.content.Context;
import android.text.ClipboardManager;
import jscl.math.operator.Operator;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.CalculatorEventType;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.about.CalculatorFragmentType;
import org.solovyev.android.menu.AMenuItem;
@ -58,17 +58,17 @@ public class CalculatorOperatorsFragment extends AbstractMathEntityListFragment<
protected List<Operator> getMathEntities() {
final List<Operator> result = new ArrayList<Operator>();
result.addAll(CalculatorLocatorImpl.getInstance().getEngine().getOperatorsRegistry().getEntities());
result.addAll(CalculatorLocatorImpl.getInstance().getEngine().getPostfixFunctionsRegistry().getEntities());
result.addAll(Locator.getInstance().getEngine().getOperatorsRegistry().getEntities());
result.addAll(Locator.getInstance().getEngine().getPostfixFunctionsRegistry().getEntities());
return result;
}
@Override
protected String getMathEntityCategory(@NotNull Operator operator) {
String result = CalculatorLocatorImpl.getInstance().getEngine().getOperatorsRegistry().getCategory(operator);
String result = Locator.getInstance().getEngine().getOperatorsRegistry().getCategory(operator);
if (result == null) {
result = CalculatorLocatorImpl.getInstance().getEngine().getPostfixFunctionsRegistry().getCategory(operator);
result = Locator.getInstance().getEngine().getPostfixFunctionsRegistry().getCategory(operator);
}
return result;
@ -80,9 +80,9 @@ public class CalculatorOperatorsFragment extends AbstractMathEntityListFragment<
@Override
public String getDescription(@NotNull Context context, @NotNull String mathEntityName) {
String result = CalculatorLocatorImpl.getInstance().getEngine().getOperatorsRegistry().getDescription(mathEntityName);
String result = Locator.getInstance().getEngine().getOperatorsRegistry().getDescription(mathEntityName);
if (StringUtils.isEmpty(result)) {
result = CalculatorLocatorImpl.getInstance().getEngine().getPostfixFunctionsRegistry().getDescription(mathEntityName);
result = Locator.getInstance().getEngine().getPostfixFunctionsRegistry().getDescription(mathEntityName);
}
return result;
@ -102,7 +102,7 @@ public class CalculatorOperatorsFragment extends AbstractMathEntityListFragment<
use(R.string.c_use) {
@Override
public void onClick(@NotNull Operator data, @NotNull Context context) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_operator, data);
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_operator, data);
}
},

View File

@ -75,7 +75,7 @@ public class CalculatorVarsFragment extends AbstractMathEntityListFragment<ICons
result.remove(LongClickMenuItem.remove);
}
if (StringUtils.isEmpty(CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getDescription(item.getName()))) {
if (StringUtils.isEmpty(Locator.getInstance().getEngine().getVarsRegistry().getDescription(item.getName()))) {
result.remove(LongClickMenuItem.copy_description);
}
@ -89,7 +89,7 @@ public class CalculatorVarsFragment extends AbstractMathEntityListFragment<ICons
@NotNull
@Override
protected MathEntityDescriptionGetter getDescriptionGetter() {
return new MathEntityDescriptionGetterImpl(CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry());
return new MathEntityDescriptionGetterImpl(Locator.getInstance().getEngine().getVarsRegistry());
}
@SuppressWarnings({"UnusedDeclaration"})
@ -100,7 +100,7 @@ public class CalculatorVarsFragment extends AbstractMathEntityListFragment<ICons
@NotNull
@Override
protected List<IConstant> getMathEntities() {
final List<IConstant> result = new ArrayList<IConstant>(CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getEntities());
final List<IConstant> result = new ArrayList<IConstant>(Locator.getInstance().getEngine().getVarsRegistry().getEntities());
CollectionsUtils.removeAll(result, new JPredicate<IConstant>() {
@Override
@ -114,7 +114,7 @@ public class CalculatorVarsFragment extends AbstractMathEntityListFragment<ICons
@Override
protected String getMathEntityCategory(@NotNull IConstant var) {
return CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getCategory(var);
return Locator.getInstance().getEngine().getVarsRegistry().getCategory(var);
}
public static boolean isValidValue(@NotNull String value) {
@ -227,7 +227,7 @@ public class CalculatorVarsFragment extends AbstractMathEntityListFragment<ICons
use(R.string.c_use) {
@Override
public void onClick(@NotNull IConstant data, @NotNull Context context) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_constant, data);
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_constant, data);
}
},
@ -251,7 +251,7 @@ public class CalculatorVarsFragment extends AbstractMathEntityListFragment<ICons
final String text = data.getValue();
if (!StringUtils.isEmpty(text)) {
assert text != null;
CalculatorLocatorImpl.getInstance().getClipboard().setText(text);
Locator.getInstance().getClipboard().setText(text);
}
}
},
@ -259,10 +259,10 @@ public class CalculatorVarsFragment extends AbstractMathEntityListFragment<ICons
copy_description(R.string.c_copy_description) {
@Override
public void onClick(@NotNull IConstant data, @NotNull Context context) {
final String text = CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getDescription(data.getName());
final String text = Locator.getInstance().getEngine().getVarsRegistry().getDescription(data.getName());
if (!StringUtils.isEmpty(text)) {
assert text != null;
CalculatorLocatorImpl.getInstance().getClipboard().setText(text);
Locator.getInstance().getClipboard().setText(text);
}
}
};

View File

@ -16,7 +16,7 @@ import jscl.math.function.IConstant;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.CalculatorEventType;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.CalculatorMathRegistry;
import org.solovyev.android.calculator.R;
import org.solovyev.common.math.MathEntity;
@ -76,14 +76,14 @@ public class MathEntityRemover<T extends MathEntity> implements View.OnClickList
@Nullable DialogInterface.OnClickListener callbackOnCancel,
@NotNull Context context,
@NotNull Object source) {
return new MathEntityRemover<IConstant>(constant, callbackOnCancel, false, CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry(), context, source, Params.newConstantInstance());
return new MathEntityRemover<IConstant>(constant, callbackOnCancel, false, Locator.getInstance().getEngine().getVarsRegistry(), context, source, Params.newConstantInstance());
}
public static MathEntityRemover<Function> newFunctionRemover(@NotNull Function function,
@Nullable DialogInterface.OnClickListener callbackOnCancel,
@NotNull Context context,
@NotNull Object source) {
return new MathEntityRemover<Function>(function, callbackOnCancel, false, CalculatorLocatorImpl.getInstance().getEngine().getFunctionsRegistry(), context, source, Params.newFunctionInstance());
return new MathEntityRemover<Function>(function, callbackOnCancel, false, Locator.getInstance().getEngine().getFunctionsRegistry(), context, source, Params.newFunctionInstance());
}
/*
@ -117,7 +117,7 @@ public class MathEntityRemover<T extends MathEntity> implements View.OnClickList
varsRegistry.remove(mathEntity);
varsRegistry.save();
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(params.getCalculatorEventType(), mathEntity, source);
Locator.getInstance().getCalculator().fireCalculatorEvent(params.getCalculatorEventType(), mathEntity, source);
}
}

View File

@ -45,12 +45,12 @@ public class VarEditDialogFragment extends DialogFragment implements CalculatorE
public void onResume() {
super.onResume();
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener(this);
Locator.getInstance().getCalculator().addCalculatorEventListener(this);
}
@Override
public void onPause() {
CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener(this);
Locator.getInstance().getCalculator().removeCalculatorEventListener(this);
super.onPause();
}
@ -110,7 +110,7 @@ public class VarEditDialogFragment extends DialogFragment implements CalculatorE
}
});
root.findViewById(R.id.save_button).setOnClickListener(new VarEditorSaver<IConstant>(varBuilder, constant, root, CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry(), this));
root.findViewById(R.id.save_button).setOnClickListener(new VarEditorSaver<IConstant>(varBuilder, constant, root, Locator.getInstance().getEngine().getVarsRegistry(), this));
if ( constant == null ) {
// CREATE MODE

View File

@ -14,7 +14,7 @@ import jscl.text.ParseException;
import jscl.text.Parser;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.CalculatorMathRegistry;
import org.solovyev.android.calculator.CalculatorVarsRegistry;
import org.solovyev.android.calculator.R;
@ -117,7 +117,7 @@ public class VarEditorSaver<T extends MathEntity> implements View.OnClickListene
}
if (error != null) {
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(error, MessageType.error);
Locator.getInstance().getNotifier().showMessage(error, MessageType.error);
} else {
CalculatorVarsRegistry.saveVariable(mathRegistry, varBuilder, editedInstance, source, true);
}
@ -129,7 +129,7 @@ public class VarEditorSaver<T extends MathEntity> implements View.OnClickListene
if (!StringUtils.isEmpty(name)) {
try {
assert name != null;
Identifier.parser.parse(Parser.Parameters.newInstance(name, new MutableInt(0), CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0()), null);
Identifier.parser.parse(Parser.Parameters.newInstance(name, new MutableInt(0), Locator.getInstance().getEngine().getMathEngine0()), null);
result = true;
} catch (ParseException e) {
// not valid name;

View File

@ -152,10 +152,10 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
result = PreparedInput.newInstance(input, expression, variable, fromInputArgs, plotBoundaries);
} catch (ParseException e) {
result = PreparedInput.newErrorInstance(fromInputArgs);
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(e);
Locator.getInstance().getNotifier().showMessage(e);
} catch (CalculatorParseException e) {
result = PreparedInput.newErrorInstance(fromInputArgs);
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(e);
Locator.getInstance().getNotifier().showMessage(e);
}
return result;
@ -184,7 +184,7 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
super.onViewCreated(view, savedInstanceState);
if (input == null) {
this.preparedInput = prepareInputFromDisplay(CalculatorLocatorImpl.getInstance().getDisplay().getViewState(), savedInstanceState);
this.preparedInput = prepareInputFromDisplay(Locator.getInstance().getDisplay().getViewState(), savedInstanceState);
} else {
this.preparedInput = prepareInput(input, true, savedInstanceState);
}

View File

@ -25,7 +25,7 @@ import org.achartengine.renderer.XYSeriesRenderer;
import org.achartengine.util.MathHelper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.R;
import org.solovyev.common.msg.MessageType;
import org.solovyev.common.text.StringUtils;
@ -207,7 +207,7 @@ public final class PlotUtils {
if (StringUtils.isEmpty(message)) {
message = e.getMessage();
}
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(R.string.arithmetic_error_while_plot, MessageType.error, Arrays.asList(message));
Locator.getInstance().getNotifier().showMessage(R.string.arithmetic_error_while_plot, MessageType.error, Arrays.asList(message));
calculatorPlotFragment.onError();
}

View File

@ -12,7 +12,7 @@ import android.graphics.Paint;
import android.text.TextPaint;
import android.util.AttributeSet;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.R;
import org.solovyev.android.view.drag.DirectionDragButton;
@ -34,7 +34,7 @@ public class AngleUnitsButton extends DirectionDragButton {
super.initDirectionTextPaint(basePaint, directionTextData, resources);
final TextPaint directionTextPaint = directionTextData.getPaint();
if (CalculatorLocatorImpl.getInstance().getEngine().getAngleUnits().name().equals(directionTextData.getText())) {
if (Locator.getInstance().getEngine().getAngleUnits().name().equals(directionTextData.getText())) {
directionTextPaint.setColor(resources.getColor(R.color.cpp_selected_angle_unit_text_color));
} else {
directionTextPaint.setColor(resources.getColor(R.color.cpp_default_text_color));

View File

@ -12,7 +12,7 @@ import android.util.AttributeSet;
import android.widget.TextView;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
/**
@ -40,8 +40,8 @@ public class CalculatorAdditionalTitle extends TextView implements SharedPrefere
@Override
public void onSharedPreferenceChanged(SharedPreferences preferences, @Nullable String key) {
setText(((AndroidCalculatorEngine) CalculatorLocatorImpl.getInstance().getEngine()).getNumeralBaseFromPrefs(preferences)
setText(((AndroidCalculatorEngine) Locator.getInstance().getEngine()).getNumeralBaseFromPrefs(preferences)
+ " / " +
((AndroidCalculatorEngine) CalculatorLocatorImpl.getInstance().getEngine()).getAngleUnitsFromPrefs(preferences));
((AndroidCalculatorEngine) Locator.getInstance().getEngine()).getAngleUnitsFromPrefs(preferences));
}
}

View File

@ -6,7 +6,7 @@ import android.view.View;
import android.view.WindowManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.CalculatorParseException;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.ToJsclTextProcessor;
@ -41,12 +41,12 @@ public class NumeralBaseConverterDialog {
String value = initialFromValue;
try {
value = ToJsclTextProcessor.getInstance().process(value).getExpression();
b.setFromValue(UnitImpl.newInstance(value, CalculatorNumeralBase.valueOf(CalculatorLocatorImpl.getInstance().getEngine().getNumeralBase())));
b.setFromValue(UnitImpl.newInstance(value, CalculatorNumeralBase.valueOf(Locator.getInstance().getEngine().getNumeralBase())));
} catch (CalculatorParseException e) {
b.setFromValue(UnitImpl.newInstance(value, CalculatorNumeralBase.valueOf(CalculatorLocatorImpl.getInstance().getEngine().getNumeralBase())));
b.setFromValue(UnitImpl.newInstance(value, CalculatorNumeralBase.valueOf(Locator.getInstance().getEngine().getNumeralBase())));
}
} else {
b.setFromValue(UnitImpl.newInstance("", CalculatorNumeralBase.valueOf(CalculatorLocatorImpl.getInstance().getEngine().getNumeralBase())));
b.setFromValue(UnitImpl.newInstance("", CalculatorNumeralBase.valueOf(Locator.getInstance().getEngine().getNumeralBase())));
}
b.setConverter(CalculatorNumeralBase.getConverter());
@ -67,11 +67,11 @@ public class NumeralBaseConverterDialog {
public void onClick(@NotNull Unit<String> fromUnits, @NotNull Unit<String> toUnits) {
String toUnitsValue = toUnits.getValue();
if (!toUnits.getUnitType().equals(CalculatorNumeralBase.valueOf(CalculatorLocatorImpl.getInstance().getEngine().getNumeralBase()))) {
if (!toUnits.getUnitType().equals(CalculatorNumeralBase.valueOf(Locator.getInstance().getEngine().getNumeralBase()))) {
toUnitsValue = ((CalculatorNumeralBase) toUnits.getUnitType()).getNumeralBase().getJsclPrefix() + toUnitsValue;
}
CalculatorLocatorImpl.getInstance().getKeyboard().buttonPressed(toUnitsValue);
Locator.getInstance().getKeyboard().buttonPressed(toUnitsValue);
final AlertDialog alertDialog = alertDialogHolder.getObject();
if (alertDialog != null) {
alertDialog.dismiss();

View File

@ -12,7 +12,7 @@ import android.graphics.Paint;
import android.text.TextPaint;
import android.util.AttributeSet;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.R;
import org.solovyev.android.view.drag.DirectionDragButton;
@ -34,7 +34,7 @@ public class NumeralBasesButton extends DirectionDragButton {
super.initDirectionTextPaint(basePaint, directionTextData, resources);
final TextPaint directionTextPaint = directionTextData.getPaint();
if (CalculatorLocatorImpl.getInstance().getEngine().getNumeralBase().name().equals(directionTextData.getText())) {
if (Locator.getInstance().getEngine().getNumeralBase().name().equals(directionTextData.getText())) {
directionTextPaint.setColor(resources.getColor(R.color.cpp_selected_angle_unit_text_color));
} else {
directionTextPaint.setColor(resources.getColor(R.color.cpp_default_text_color));

View File

@ -108,9 +108,9 @@ public class TextHighlighter implements TextProcessor<TextHighlighter.Result, St
final AbstractNumberBuilder numberBuilder;
if (!formatNumber) {
numberBuilder = new LiteNumberBuilder(CalculatorLocatorImpl.getInstance().getEngine());
numberBuilder = new LiteNumberBuilder(Locator.getInstance().getEngine());
} else {
numberBuilder = new NumberBuilder(CalculatorLocatorImpl.getInstance().getEngine());
numberBuilder = new NumberBuilder(Locator.getInstance().getEngine());
}
for (int i = 0; i < text.length(); i++) {
MathType.Result mathType = MathType.getType(text, i, numberBuilder.isHexMode());

View File

@ -88,7 +88,7 @@ abstract class AbstractCalculatorWidgetProvider extends AppWidgetProvider implem
@NotNull int[] appWidgetIds) {
super.onUpdate(context, appWidgetManager, appWidgetIds);
updateWidget(context, appWidgetManager, appWidgetIds, CalculatorLocatorImpl.getInstance().getEditor().getViewState(), CalculatorLocatorImpl.getInstance().getDisplay().getViewState());
updateWidget(context, appWidgetManager, appWidgetIds, Locator.getInstance().getEditor().getViewState(), Locator.getInstance().getDisplay().getViewState());
}
@Override
@ -158,7 +158,7 @@ abstract class AbstractCalculatorWidgetProvider extends AppWidgetProvider implem
// inject cursor
newText = Html.fromHtml(text.substring(0, selection) + "<font color=\"#" + getCursorColor(context) + "\">|</font>" + text.substring(selection));
}
CalculatorLocatorImpl.getInstance().getNotifier().showDebugMessage(TAG, "New editor state: " + text);
Locator.getInstance().getNotifier().showDebugMessage(TAG, "New editor state: " + text);
views.setTextViewText(R.id.calculator_editor, newText);
}
}

View File

@ -0,0 +1,50 @@
package org.solovyev.android.calculator.widget;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.external.ExternalCalculatorHelper;
/**
* User: serso
* Date: 10/19/12
* Time: 11:11 PM
*/
public class CalculatorWidgetHelper implements CalculatorEventListener {
private static final String TAG = "Calculator++ Widget Helper";
@NotNull
private final CalculatorEventHolder lastEvent = new CalculatorEventHolder(CalculatorUtils.createFirstEventDataId());
public CalculatorWidgetHelper() {
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener(this);
}
@Override
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
final CalculatorEventHolder.Result result = lastEvent.apply(calculatorEventData);
if (result.isNewAfter()) {
switch (calculatorEventType) {
case editor_state_changed_light:
case editor_state_changed:
final CalculatorEditorChangeEventData editorChangeData = (CalculatorEditorChangeEventData) data;
final CalculatorEditorViewState newEditorState = editorChangeData.getNewValue();
CalculatorLocatorImpl.getInstance().getNotifier().showDebugMessage(TAG, "Editor state changed: " + newEditorState.getText());
ExternalCalculatorHelper.onEditorStateChanged(CalculatorApplication.getInstance(), calculatorEventData, newEditorState);
break;
case display_state_changed:
final CalculatorDisplayChangeEventData displayChangeData = (CalculatorDisplayChangeEventData) data;
final CalculatorDisplayViewState newDisplayState = displayChangeData.getNewValue();
CalculatorLocatorImpl.getInstance().getNotifier().showDebugMessage(TAG, "Display state changed: " + newDisplayState.getText());
ExternalCalculatorHelper.onDisplayStateChanged(CalculatorApplication.getInstance(), calculatorEventData, newDisplayState);
break;
}
}
}
}

View File

@ -3,7 +3,7 @@ package org.solovyev.android.calculator.widget;
import android.content.Context;
import android.content.Intent;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.external.DefaultExternalCalculatorIntentHandler;
import org.solovyev.android.calculator.external.ExternalCalculatorStateUpdater;
@ -30,7 +30,7 @@ public class CalculatorWidgetIntentHandler extends DefaultExternalCalculatorInte
button.onClick(context);
}
} else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(intent.getAction())) {
updateState(context, CalculatorLocatorImpl.getInstance().getEditor().getViewState(), CalculatorLocatorImpl.getInstance().getDisplay().getViewState());
updateState(context, Locator.getInstance().getEditor().getViewState(), Locator.getInstance().getDisplay().getViewState());
}
}

View File

@ -3,7 +3,7 @@ package org.solovyev.android.calculator.widget;
import android.content.Context;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.CalculatorSpecialButton;
import org.solovyev.android.calculator.R;
@ -79,8 +79,8 @@ public enum WidgetButton {
}
public void onClick(@NotNull Context context) {
CalculatorLocatorImpl.getInstance().getNotifier().showDebugMessage("Calculator++ Widget", "Button pressed: " + text);
CalculatorLocatorImpl.getInstance().getKeyboard().buttonPressed(text);
Locator.getInstance().getNotifier().showDebugMessage("Calculator++ Widget", "Button pressed: " + text);
Locator.getInstance().getKeyboard().buttonPressed(text);
}
@Nullable

View File

@ -61,7 +61,7 @@ public class AndroidCalculatorEditorViewTest {
for ( int j = 0; j < count; j++ ) {
try {
int textLength = random.nextInt(maxTextLength);
CalculatorLocatorImpl.getInstance().getEditor().insert(StringUtils.generateRandomString(textLength), textLength);
Locator.getInstance().getEditor().insert(StringUtils.generateRandomString(textLength), textLength);
} catch (Throwable e) {
System.out.println(e);
error.set(true);

View File

@ -98,7 +98,7 @@ public class TextHighlighterTest {
Assert.assertEquals("<b>0x:</b>FF33233FFE", textHighlighter.process("0x:FF33233FFE").toString());
Assert.assertEquals("<b>0x:</b>FF33 233 FFE", textHighlighter.process("0x:FF33 233 FFE").toString());
final MathEngine me = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0();
final MathEngine me = Locator.getInstance().getEngine().getMathEngine0();
try {
me.setNumeralBase(NumeralBase.hex);
Assert.assertEquals("E", textHighlighter.process("E").toString());