From 3dd73efaea66a36a4d9ee2b489e512de471339e0 Mon Sep 17 00:00:00 2001 From: Sergey Solovyev Date: Wed, 21 Nov 2012 12:05:04 +0400 Subject: [PATCH] CalculatorLocatorImpl -> Locator --- .../calculator/CalculatorTestUtils.java | 12 ++--- .../calculator/CalculatorApplication.java | 8 +-- .../AndroidExternalListenersContainer.java | 10 ++-- ...efaultExternalCalculatorIntentHandler.java | 4 +- .../overlay/CalculatorOverlayService.java | 6 +-- .../AbstractCalculatorWidgetProvider.java | 4 +- .../widget/CalculatorWidgetHelper.java | 50 ------------------- .../calculator/CalculatorTestUtils.java | 8 +-- 8 files changed, 26 insertions(+), 76 deletions(-) delete mode 100644 calculatorpp/src/main/java/org/solovyev/android/calculator/widget/CalculatorWidgetHelper.java diff --git a/calculatorpp-core/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java b/calculatorpp-core/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java index 20d4335a..758eba4d 100644 --- a/calculatorpp-core/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java +++ b/calculatorpp-core/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java @@ -24,8 +24,8 @@ public class CalculatorTestUtils { public static final int TIMEOUT = 3; 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)); - CalculatorLocatorImpl.getInstance().getEngine().init(); + 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)); + Locator.getInstance().getEngine().init(); } @NotNull @@ -47,9 +47,9 @@ public class CalculatorTestUtils { } 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 TestCalculatorEventListener calculatorEventListener = new TestCalculatorEventListener(latch); @@ -146,9 +146,9 @@ public class CalculatorTestUtils { } 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 TestCalculatorEventListener calculatorEventListener = new TestCalculatorEventListener(latch); diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java index b16eb04c..7a0f804b 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java @@ -82,7 +82,7 @@ public class CalculatorApplication extends android.app.Application { final AndroidCalculator calculator = new AndroidCalculator(this); - CalculatorLocatorImpl.getInstance().init(calculator, + Locator.getInstance().init(calculator, new AndroidCalculatorEngine(this), new AndroidCalculatorClipboard(this), new AndroidCalculatorNotifier(this), @@ -92,7 +92,7 @@ public class CalculatorApplication extends android.app.Application { new AndroidCalculatorKeyboard(this, new CalculatorKeyboardImpl(calculator)), new AndroidExternalListenersContainer(calculator)); - CalculatorLocatorImpl.getInstance().getCalculator().init(); + Locator.getInstance().getCalculator().init(); BillingDB.init(CalculatorApplication.this); @@ -122,8 +122,8 @@ public class CalculatorApplication extends android.app.Application { } }).start(); - CalculatorLocatorImpl.getInstance().getLogger().debug(TAG, "Application started!"); - CalculatorLocatorImpl.getInstance().getNotifier().showDebugMessage(TAG, "Application started!"); + Locator.getInstance().getLogger().debug(TAG, "Application started!"); + Locator.getInstance().getNotifier().showDebugMessage(TAG, "Application started!"); } private void setTheme(@NotNull SharedPreferences preferences) { diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/external/AndroidExternalListenersContainer.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/external/AndroidExternalListenersContainer.java index 49a25da2..eab02963 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/external/AndroidExternalListenersContainer.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/external/AndroidExternalListenersContainer.java @@ -15,7 +15,7 @@ import org.solovyev.android.calculator.CalculatorEventData; import org.solovyev.android.calculator.CalculatorEventHolder; import org.solovyev.android.calculator.CalculatorEventListener; 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.ParcelableCalculatorDisplayViewState; import org.solovyev.android.calculator.ParcelableCalculatorEditorViewState; @@ -64,7 +64,7 @@ public class AndroidExternalListenersContainer implements CalculatorExternalList intent.putExtra(EVENT_ID_EXTRA, calculatorEventData.getEventId()); intent.putExtra(EDITOR_STATE_EXTRA, (Parcelable) new ParcelableCalculatorEditorViewState(editorViewState)); 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(DISPLAY_STATE_EXTRA, (Parcelable) new ParcelableCalculatorDisplayViewState(displayViewState)); 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 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); break; @@ -110,7 +110,7 @@ public class AndroidExternalListenersContainer implements CalculatorExternalList final CalculatorDisplayChangeEventData displayChangeData = (CalculatorDisplayChangeEventData) data; 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); break; diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/external/DefaultExternalCalculatorIntentHandler.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/external/DefaultExternalCalculatorIntentHandler.java index db237050..a985c12f 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/external/DefaultExternalCalculatorIntentHandler.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/external/DefaultExternalCalculatorIntentHandler.java @@ -35,7 +35,7 @@ public class DefaultExternalCalculatorIntentHandler implements ExternalCalculato public void onIntent(@NotNull Context context, @NotNull Intent intent) { 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); @@ -54,7 +54,7 @@ public class DefaultExternalCalculatorIntentHandler implements ExternalCalculato } } } 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); boolean updateDisplay = false; diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/overlay/CalculatorOverlayService.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/overlay/CalculatorOverlayService.java index ed5b1cb9..db14013d 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/overlay/CalculatorOverlayService.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/overlay/CalculatorOverlayService.java @@ -14,7 +14,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.solovyev.android.calculator.CalculatorDisplayViewState; 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.external.DefaultExternalCalculatorIntentHandler; import org.solovyev.android.calculator.external.ExternalCalculatorIntentHandler; @@ -75,7 +75,7 @@ public class CalculatorOverlayService extends Service implements ExternalCalcula } private void startCalculatorListening() { - CalculatorLocatorImpl.getInstance().getExternalListenersContainer().addExternalListener(getIntentListenerClass()); + Locator.getInstance().getExternalListenersContainer().addExternalListener(getIntentListenerClass()); } @NotNull @@ -84,7 +84,7 @@ public class CalculatorOverlayService extends Service implements ExternalCalcula } private void stopCalculatorListening() { - CalculatorLocatorImpl.getInstance().getExternalListenersContainer().removeExternalListener(getIntentListenerClass()); + Locator.getInstance().getExternalListenersContainer().removeExternalListener(getIntentListenerClass()); } @Override diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/widget/AbstractCalculatorWidgetProvider.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/widget/AbstractCalculatorWidgetProvider.java index 99d9ca72..58d6cffd 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/widget/AbstractCalculatorWidgetProvider.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/widget/AbstractCalculatorWidgetProvider.java @@ -13,7 +13,7 @@ import org.jetbrains.annotations.Nullable; import org.solovyev.android.calculator.CalculatorButtons; import org.solovyev.android.calculator.CalculatorDisplayViewState; 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.external.ExternalCalculatorIntentHandler; import org.solovyev.android.calculator.external.ExternalCalculatorStateUpdater; @@ -56,7 +56,7 @@ abstract class AbstractCalculatorWidgetProvider extends AppWidgetProvider implem protected AbstractCalculatorWidgetProvider() { final Class componentClass = this.getComponentClass(); - CalculatorLocatorImpl.getInstance().getExternalListenersContainer().addExternalListener(componentClass); + Locator.getInstance().getExternalListenersContainer().addExternalListener(componentClass); } /* diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/widget/CalculatorWidgetHelper.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/widget/CalculatorWidgetHelper.java deleted file mode 100644 index b38b27f3..00000000 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/widget/CalculatorWidgetHelper.java +++ /dev/null @@ -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; - } - } - } -} diff --git a/calculatorpp/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java b/calculatorpp/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java index 60010215..739229be 100644 --- a/calculatorpp/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java +++ b/calculatorpp/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java @@ -16,8 +16,8 @@ import org.solovyev.android.calculator.history.CalculatorHistory; public class CalculatorTestUtils { 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)); - CalculatorLocatorImpl.getInstance().getEngine().init(); + 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)); + Locator.getInstance().getEngine().init(); if ( context != null ) { initViews(context); @@ -27,11 +27,11 @@ public class CalculatorTestUtils { public static void initViews(@NotNull Context context) { final AndroidCalculatorEditorView editor = new AndroidCalculatorEditorView(context); editor.init(context); - CalculatorLocatorImpl.getInstance().getEditor().setView(editor); + Locator.getInstance().getEditor().setView(editor); final AndroidCalculatorDisplayView display = new AndroidCalculatorDisplayView(context); display.init(context); - CalculatorLocatorImpl.getInstance().getDisplay().setView(display); + Locator.getInstance().getDisplay().setView(display); } public static void staticSetUp() throws Exception {