CalculatorLocatorImpl -> Locator

This commit is contained in:
Sergey Solovyev 2012-11-21 12:05:04 +04:00
parent 9a7bb5dbc1
commit 3dd73efaea
8 changed files with 26 additions and 76 deletions

View File

@ -24,8 +24,8 @@ public class CalculatorTestUtils {
public static final int TIMEOUT = 3; public static final int TIMEOUT = 3;
public static void staticSetUp() throws Exception { public static void staticSetUp() throws Exception {
CalculatorLocatorImpl.getInstance().init(new CalculatorImpl(), 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().init(new CalculatorImpl(), 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().getEngine().init();
} }
@NotNull @NotNull
@ -47,9 +47,9 @@ public class CalculatorTestUtils {
} }
public static void assertEval(@NotNull String expected, @NotNull String expression, @NotNull JsclOperation operation) { public static void assertEval(@NotNull String expected, @NotNull String expression, @NotNull JsclOperation operation) {
final Calculator calculator = CalculatorLocatorImpl.getInstance().getCalculator(); final Calculator calculator = Locator.getInstance().getCalculator();
CalculatorLocatorImpl.getInstance().getDisplay().setViewState(CalculatorDisplayViewStateImpl.newDefaultInstance()); Locator.getInstance().getDisplay().setViewState(CalculatorDisplayViewStateImpl.newDefaultInstance());
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);
final TestCalculatorEventListener calculatorEventListener = new TestCalculatorEventListener(latch); final TestCalculatorEventListener calculatorEventListener = new TestCalculatorEventListener(latch);
@ -146,9 +146,9 @@ public class CalculatorTestUtils {
} }
public static void assertError(@NotNull String expression, @NotNull JsclOperation operation) { public static void assertError(@NotNull String expression, @NotNull JsclOperation operation) {
final Calculator calculator = CalculatorLocatorImpl.getInstance().getCalculator(); final Calculator calculator = Locator.getInstance().getCalculator();
CalculatorLocatorImpl.getInstance().getDisplay().setViewState(CalculatorDisplayViewStateImpl.newDefaultInstance()); Locator.getInstance().getDisplay().setViewState(CalculatorDisplayViewStateImpl.newDefaultInstance());
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);
final TestCalculatorEventListener calculatorEventListener = new TestCalculatorEventListener(latch); final TestCalculatorEventListener calculatorEventListener = new TestCalculatorEventListener(latch);

View File

@ -82,7 +82,7 @@ public class CalculatorApplication extends android.app.Application {
final AndroidCalculator calculator = new AndroidCalculator(this); final AndroidCalculator calculator = new AndroidCalculator(this);
CalculatorLocatorImpl.getInstance().init(calculator, Locator.getInstance().init(calculator,
new AndroidCalculatorEngine(this), new AndroidCalculatorEngine(this),
new AndroidCalculatorClipboard(this), new AndroidCalculatorClipboard(this),
new AndroidCalculatorNotifier(this), new AndroidCalculatorNotifier(this),
@ -92,7 +92,7 @@ public class CalculatorApplication extends android.app.Application {
new AndroidCalculatorKeyboard(this, new CalculatorKeyboardImpl(calculator)), new AndroidCalculatorKeyboard(this, new CalculatorKeyboardImpl(calculator)),
new AndroidExternalListenersContainer(calculator)); new AndroidExternalListenersContainer(calculator));
CalculatorLocatorImpl.getInstance().getCalculator().init(); Locator.getInstance().getCalculator().init();
BillingDB.init(CalculatorApplication.this); BillingDB.init(CalculatorApplication.this);
@ -122,8 +122,8 @@ public class CalculatorApplication extends android.app.Application {
} }
}).start(); }).start();
CalculatorLocatorImpl.getInstance().getLogger().debug(TAG, "Application started!"); Locator.getInstance().getLogger().debug(TAG, "Application started!");
CalculatorLocatorImpl.getInstance().getNotifier().showDebugMessage(TAG, "Application started!"); Locator.getInstance().getNotifier().showDebugMessage(TAG, "Application started!");
} }
private void setTheme(@NotNull SharedPreferences preferences) { private void setTheme(@NotNull SharedPreferences preferences) {

View File

@ -15,7 +15,7 @@ import org.solovyev.android.calculator.CalculatorEventData;
import org.solovyev.android.calculator.CalculatorEventHolder; import org.solovyev.android.calculator.CalculatorEventHolder;
import org.solovyev.android.calculator.CalculatorEventListener; import org.solovyev.android.calculator.CalculatorEventListener;
import org.solovyev.android.calculator.CalculatorEventType; import org.solovyev.android.calculator.CalculatorEventType;
import org.solovyev.android.calculator.CalculatorLocatorImpl; import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.CalculatorUtils; import org.solovyev.android.calculator.CalculatorUtils;
import org.solovyev.android.calculator.ParcelableCalculatorDisplayViewState; import org.solovyev.android.calculator.ParcelableCalculatorDisplayViewState;
import org.solovyev.android.calculator.ParcelableCalculatorEditorViewState; import org.solovyev.android.calculator.ParcelableCalculatorEditorViewState;
@ -64,7 +64,7 @@ public class AndroidExternalListenersContainer implements CalculatorExternalList
intent.putExtra(EVENT_ID_EXTRA, calculatorEventData.getEventId()); intent.putExtra(EVENT_ID_EXTRA, calculatorEventData.getEventId());
intent.putExtra(EDITOR_STATE_EXTRA, (Parcelable) new ParcelableCalculatorEditorViewState(editorViewState)); intent.putExtra(EDITOR_STATE_EXTRA, (Parcelable) new ParcelableCalculatorEditorViewState(editorViewState));
context.sendBroadcast(intent); context.sendBroadcast(intent);
CalculatorLocatorImpl.getInstance().getNotifier().showDebugMessage(TAG, "Editor state changed broadcast sent"); Locator.getInstance().getNotifier().showDebugMessage(TAG, "Editor state changed broadcast sent");
} }
} }
@ -77,7 +77,7 @@ public class AndroidExternalListenersContainer implements CalculatorExternalList
intent.putExtra(EVENT_ID_EXTRA, calculatorEventData.getEventId()); intent.putExtra(EVENT_ID_EXTRA, calculatorEventData.getEventId());
intent.putExtra(DISPLAY_STATE_EXTRA, (Parcelable) new ParcelableCalculatorDisplayViewState(displayViewState)); intent.putExtra(DISPLAY_STATE_EXTRA, (Parcelable) new ParcelableCalculatorDisplayViewState(displayViewState));
context.sendBroadcast(intent); context.sendBroadcast(intent);
CalculatorLocatorImpl.getInstance().getNotifier().showDebugMessage(TAG, "Display state changed broadcast sent"); Locator.getInstance().getNotifier().showDebugMessage(TAG, "Display state changed broadcast sent");
} }
} }
@ -101,7 +101,7 @@ public class AndroidExternalListenersContainer implements CalculatorExternalList
final CalculatorEditorChangeEventData editorChangeData = (CalculatorEditorChangeEventData) data; final CalculatorEditorChangeEventData editorChangeData = (CalculatorEditorChangeEventData) data;
final CalculatorEditorViewState newEditorState = editorChangeData.getNewValue(); final CalculatorEditorViewState newEditorState = editorChangeData.getNewValue();
CalculatorLocatorImpl.getInstance().getNotifier().showDebugMessage(TAG, "Editor state changed: " + newEditorState.getText()); Locator.getInstance().getNotifier().showDebugMessage(TAG, "Editor state changed: " + newEditorState.getText());
onEditorStateChanged(CalculatorApplication.getInstance(), calculatorEventData, newEditorState); onEditorStateChanged(CalculatorApplication.getInstance(), calculatorEventData, newEditorState);
break; break;
@ -110,7 +110,7 @@ public class AndroidExternalListenersContainer implements CalculatorExternalList
final CalculatorDisplayChangeEventData displayChangeData = (CalculatorDisplayChangeEventData) data; final CalculatorDisplayChangeEventData displayChangeData = (CalculatorDisplayChangeEventData) data;
final CalculatorDisplayViewState newDisplayState = displayChangeData.getNewValue(); final CalculatorDisplayViewState newDisplayState = displayChangeData.getNewValue();
CalculatorLocatorImpl.getInstance().getNotifier().showDebugMessage(TAG, "Display state changed: " + newDisplayState.getText()); Locator.getInstance().getNotifier().showDebugMessage(TAG, "Display state changed: " + newDisplayState.getText());
onDisplayStateChanged(CalculatorApplication.getInstance(), calculatorEventData, newDisplayState); onDisplayStateChanged(CalculatorApplication.getInstance(), calculatorEventData, newDisplayState);
break; break;

View File

@ -35,7 +35,7 @@ public class DefaultExternalCalculatorIntentHandler implements ExternalCalculato
public void onIntent(@NotNull Context context, @NotNull Intent intent) { public void onIntent(@NotNull Context context, @NotNull Intent intent) {
if (AndroidExternalListenersContainer.EDITOR_STATE_CHANGED_ACTION.equals(intent.getAction())) { if (AndroidExternalListenersContainer.EDITOR_STATE_CHANGED_ACTION.equals(intent.getAction())) {
CalculatorLocatorImpl.getInstance().getNotifier().showDebugMessage(TAG, "Editor state changed broadcast received!"); Locator.getInstance().getNotifier().showDebugMessage(TAG, "Editor state changed broadcast received!");
final Long eventId = intent.getLongExtra(AndroidExternalListenersContainer.EVENT_ID_EXTRA, 0L); final Long eventId = intent.getLongExtra(AndroidExternalListenersContainer.EVENT_ID_EXTRA, 0L);
@ -54,7 +54,7 @@ public class DefaultExternalCalculatorIntentHandler implements ExternalCalculato
} }
} }
} else if (AndroidExternalListenersContainer.DISPLAY_STATE_CHANGED_ACTION.equals(intent.getAction())) { } else if (AndroidExternalListenersContainer.DISPLAY_STATE_CHANGED_ACTION.equals(intent.getAction())) {
CalculatorLocatorImpl.getInstance().getNotifier().showDebugMessage(TAG, "Display state changed broadcast received!"); Locator.getInstance().getNotifier().showDebugMessage(TAG, "Display state changed broadcast received!");
final Long eventId = intent.getLongExtra(AndroidExternalListenersContainer.EVENT_ID_EXTRA, 0L); final Long eventId = intent.getLongExtra(AndroidExternalListenersContainer.EVENT_ID_EXTRA, 0L);
boolean updateDisplay = false; boolean updateDisplay = false;

View File

@ -14,7 +14,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.CalculatorDisplayViewState; import org.solovyev.android.calculator.CalculatorDisplayViewState;
import org.solovyev.android.calculator.CalculatorEditorViewState; import org.solovyev.android.calculator.CalculatorEditorViewState;
import org.solovyev.android.calculator.CalculatorLocatorImpl; import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.external.DefaultExternalCalculatorIntentHandler; import org.solovyev.android.calculator.external.DefaultExternalCalculatorIntentHandler;
import org.solovyev.android.calculator.external.ExternalCalculatorIntentHandler; import org.solovyev.android.calculator.external.ExternalCalculatorIntentHandler;
@ -75,7 +75,7 @@ public class CalculatorOverlayService extends Service implements ExternalCalcula
} }
private void startCalculatorListening() { private void startCalculatorListening() {
CalculatorLocatorImpl.getInstance().getExternalListenersContainer().addExternalListener(getIntentListenerClass()); Locator.getInstance().getExternalListenersContainer().addExternalListener(getIntentListenerClass());
} }
@NotNull @NotNull
@ -84,7 +84,7 @@ public class CalculatorOverlayService extends Service implements ExternalCalcula
} }
private void stopCalculatorListening() { private void stopCalculatorListening() {
CalculatorLocatorImpl.getInstance().getExternalListenersContainer().removeExternalListener(getIntentListenerClass()); Locator.getInstance().getExternalListenersContainer().removeExternalListener(getIntentListenerClass());
} }
@Override @Override

View File

@ -13,7 +13,7 @@ import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.CalculatorButtons; import org.solovyev.android.calculator.CalculatorButtons;
import org.solovyev.android.calculator.CalculatorDisplayViewState; import org.solovyev.android.calculator.CalculatorDisplayViewState;
import org.solovyev.android.calculator.CalculatorEditorViewState; import org.solovyev.android.calculator.CalculatorEditorViewState;
import org.solovyev.android.calculator.CalculatorLocatorImpl; import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.external.ExternalCalculatorIntentHandler; import org.solovyev.android.calculator.external.ExternalCalculatorIntentHandler;
import org.solovyev.android.calculator.external.ExternalCalculatorStateUpdater; import org.solovyev.android.calculator.external.ExternalCalculatorStateUpdater;
@ -56,7 +56,7 @@ abstract class AbstractCalculatorWidgetProvider extends AppWidgetProvider implem
protected AbstractCalculatorWidgetProvider() { protected AbstractCalculatorWidgetProvider() {
final Class<? extends AppWidgetProvider> componentClass = this.getComponentClass(); final Class<? extends AppWidgetProvider> componentClass = this.getComponentClass();
CalculatorLocatorImpl.getInstance().getExternalListenersContainer().addExternalListener(componentClass); Locator.getInstance().getExternalListenersContainer().addExternalListener(componentClass);
} }
/* /*

View File

@ -1,50 +0,0 @@
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

@ -16,8 +16,8 @@ import org.solovyev.android.calculator.history.CalculatorHistory;
public class CalculatorTestUtils { public class CalculatorTestUtils {
public static void staticSetUp(@Nullable Context context) throws Exception { public static void staticSetUp(@Nullable Context context) throws Exception {
CalculatorLocatorImpl.getInstance().init(new CalculatorImpl(), 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().init(new CalculatorImpl(), 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().getEngine().init();
if ( context != null ) { if ( context != null ) {
initViews(context); initViews(context);
@ -27,11 +27,11 @@ public class CalculatorTestUtils {
public static void initViews(@NotNull Context context) { public static void initViews(@NotNull Context context) {
final AndroidCalculatorEditorView editor = new AndroidCalculatorEditorView(context); final AndroidCalculatorEditorView editor = new AndroidCalculatorEditorView(context);
editor.init(context); editor.init(context);
CalculatorLocatorImpl.getInstance().getEditor().setView(editor); Locator.getInstance().getEditor().setView(editor);
final AndroidCalculatorDisplayView display = new AndroidCalculatorDisplayView(context); final AndroidCalculatorDisplayView display = new AndroidCalculatorDisplayView(context);
display.init(context); display.init(context);
CalculatorLocatorImpl.getInstance().getDisplay().setView(display); Locator.getInstance().getDisplay().setView(display);
} }
public static void staticSetUp() throws Exception { public static void staticSetUp() throws Exception {