diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 05a7c740..673797b4 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -101,24 +101,6 @@
-
-
-
-
-
viewIds = getViewIds();
for (Integer viewId : viewIds) {
@@ -291,16 +293,6 @@ public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChan
}
}
- @Nonnull
- private Calculator getCalculator() {
- return Locator.getInstance().getCalculator();
- }
-
- @Nonnull
- private Keyboard getKeyboard() {
- return Locator.getInstance().getKeyboard();
- }
-
@Nullable
private V getButton(@Nonnull ViewsCache views, int buttonId) {
//noinspection unchecked
diff --git a/app/src/main/java/org/solovyev/android/calculator/ButtonOnClickListener.java b/app/src/main/java/org/solovyev/android/calculator/ButtonOnClickListener.java
index 8eb10505..62a68e69 100644
--- a/app/src/main/java/org/solovyev/android/calculator/ButtonOnClickListener.java
+++ b/app/src/main/java/org/solovyev/android/calculator/ButtonOnClickListener.java
@@ -11,6 +11,13 @@ import javax.annotation.Nonnull;
final class ButtonOnClickListener implements View.OnClickListener {
+ @Nonnull
+ private final Keyboard keyboard;
+
+ ButtonOnClickListener(@Nonnull Keyboard keyboard) {
+ this.keyboard = keyboard;
+ }
+
@Override
public void onClick(View v) {
switch (v.getId()) {
@@ -72,7 +79,7 @@ final class ButtonOnClickListener implements View.OnClickListener {
}
private void onClick(@Nonnull View v, @Nonnull String s) {
- if (Locator.getInstance().getKeyboard().buttonPressed(s)) {
+ if (keyboard.buttonPressed(s)) {
v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
}
}
diff --git a/app/src/main/java/org/solovyev/android/calculator/Calculator.java b/app/src/main/java/org/solovyev/android/calculator/Calculator.java
index 34874adc..e23fb692 100644
--- a/app/src/main/java/org/solovyev/android/calculator/Calculator.java
+++ b/app/src/main/java/org/solovyev/android/calculator/Calculator.java
@@ -50,12 +50,16 @@ import org.solovyev.common.units.Conversions;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicLong;
+@Singleton
public class Calculator implements CalculatorEventListener, SharedPreferences.OnSharedPreferenceChangeListener {
// one minute
@@ -82,7 +86,11 @@ public class Calculator implements CalculatorEventListener, SharedPreferences.On
private volatile long lastPreferenceCheck = 0L;
- public Calculator(@Nonnull SharedPreferences preferences, @Nonnull Bus bus, @Nonnull Executor eventExecutor) {
+ @Inject
+ PreferredPreferences preferredPreferences;
+
+ @Inject
+ public Calculator(@Nonnull SharedPreferences preferences, @Nonnull Bus bus, @Named(AppModule.THREAD_UI) @Nonnull Executor eventExecutor) {
this.preferences = preferences;
this.eventExecutor = eventExecutor;
bus.register(this);
@@ -237,7 +245,6 @@ public class Calculator implements CalculatorEventListener, SharedPreferences.On
result.toString();
if (messageRegistry.hasMessage()) {
- final ErrorReporter errorReporter = Locator.getInstance().getErrorReporter();
try {
final List messages = new ArrayList();
while (messageRegistry.hasMessage()) {
@@ -281,7 +288,7 @@ public class Calculator implements CalculatorEventListener, SharedPreferences.On
if (currentTime - lastPreferenceCheck > PREFERENCE_CHECK_INTERVAL) {
lastPreferenceCheck = currentTime;
- Locator.getInstance().getPreferenceService().check(false);
+ preferredPreferences.check(false);
}
}
@@ -481,43 +488,43 @@ public class Calculator implements CalculatorEventListener, SharedPreferences.On
FixableErrorsActivity.show(App.getApplication(), (List) data);
break;
case show_history:
- CalculatorActivityLauncher.showHistory(App.getApplication());
+ ActivityLauncher.showHistory(App.getApplication());
break;
case show_history_detached:
- CalculatorActivityLauncher.showHistory(App.getApplication(), true);
+ ActivityLauncher.showHistory(App.getApplication(), true);
break;
case show_functions:
- CalculatorActivityLauncher.showFunctions(App.getApplication());
+ ActivityLauncher.showFunctions(App.getApplication());
break;
case show_functions_detached:
- CalculatorActivityLauncher.showFunctions(App.getApplication(), true);
+ ActivityLauncher.showFunctions(App.getApplication(), true);
break;
case show_operators:
- CalculatorActivityLauncher.showOperators(App.getApplication());
+ ActivityLauncher.showOperators(App.getApplication());
break;
case show_operators_detached:
- CalculatorActivityLauncher.showOperators(App.getApplication(), true);
+ ActivityLauncher.showOperators(App.getApplication(), true);
break;
case show_vars:
- CalculatorActivityLauncher.showVars(App.getApplication());
+ ActivityLauncher.showVars(App.getApplication());
break;
case show_vars_detached:
- CalculatorActivityLauncher.showVars(App.getApplication(), true);
+ ActivityLauncher.showVars(App.getApplication(), true);
break;
case show_settings:
- CalculatorActivityLauncher.showSettings(App.getApplication());
+ ActivityLauncher.showSettings(App.getApplication());
break;
case show_settings_detached:
- CalculatorActivityLauncher.showSettings(App.getApplication(), true);
+ ActivityLauncher.showSettings(App.getApplication(), true);
break;
case show_settings_widget:
- CalculatorActivityLauncher.showWidgetSettings(App.getApplication(), true);
+ ActivityLauncher.showWidgetSettings(App.getApplication(), true);
break;
case show_like_dialog:
- CalculatorActivityLauncher.likeButtonPressed(App.getApplication());
+ ActivityLauncher.likeButtonPressed(App.getApplication());
break;
case open_app:
- CalculatorActivityLauncher.openApp(App.getApplication());
+ ActivityLauncher.openApp(App.getApplication());
break;
}
}
diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java
index 85a11bda..9330b7f3 100644
--- a/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java
+++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java
@@ -32,18 +32,11 @@ import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.ActionBar;
import android.text.method.LinkMovementMethod;
-import android.view.KeyEvent;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewConfiguration;
-import android.view.Window;
+import android.view.*;
import android.widget.TextView;
-
import org.solovyev.android.Activities;
import org.solovyev.android.Android;
-import org.solovyev.android.Threads;
import org.solovyev.android.calculator.history.History;
-import org.solovyev.android.calculator.plot.CalculatorPlotActivity;
import org.solovyev.android.calculator.wizard.CalculatorWizards;
import org.solovyev.android.fragments.FragmentUtils;
import org.solovyev.android.prefs.Preference;
@@ -60,11 +53,9 @@ import static android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH;
import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
import static org.solovyev.android.calculator.Preferences.Gui.preventScreenFromFading;
import static org.solovyev.android.calculator.release.ReleaseNotes.hasReleaseNotes;
-import static org.solovyev.android.wizard.WizardUi.continueWizard;
-import static org.solovyev.android.wizard.WizardUi.createLaunchIntent;
-import static org.solovyev.android.wizard.WizardUi.startWizard;
+import static org.solovyev.android.wizard.WizardUi.*;
-public class CalculatorActivity extends BaseActivity implements SharedPreferences.OnSharedPreferenceChangeListener, CalculatorEventListener {
+public class CalculatorActivity extends BaseActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
@Nonnull
public static final String TAG = CalculatorActivity.class.getSimpleName();
@@ -169,7 +160,6 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
ui.addTab(this, CalculatorFragmentType.variables, null, R.id.main_second_pane);
ui.addTab(this, CalculatorFragmentType.functions, null, R.id.main_second_pane);
ui.addTab(this, CalculatorFragmentType.operators, null, R.id.main_second_pane);
- ui.addTab(this, CalculatorPlotActivity.getPlotterFragmentType(), null, R.id.main_second_pane);
} else {
final ActionBar actionBar = getSupportActionBar();
if (Build.VERSION.SDK_INT <= GINGERBREAD_MR1 || (Build.VERSION.SDK_INT >= ICE_CREAM_SANDWICH && hasPermanentMenuKey())) {
@@ -272,29 +262,4 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
-
- @Override
- public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) {
- switch (calculatorEventType) {
- case plot_graph:
- Threads.tryRunOnUiThread(this, new Runnable() {
- @Override
- public void run() {
- if (isMultiPane()) {
- final ActionBar.Tab selectedTab = getSupportActionBar().getSelectedTab();
- if (selectedTab != null && CalculatorFragmentType.plotter.getFragmentTag().equals(selectedTab.getTag())) {
- // do nothing - fragment shown and already registered for plot updates
- } else {
- // otherwise - open fragment
- ui.selectTab(CalculatorActivity.this, CalculatorFragmentType.plotter);
- }
- } else {
- // start new activity
- CalculatorActivityLauncher.plotGraph(CalculatorActivity.this);
- }
- }
- });
- break;
- }
- }
}
\ No newline at end of file
diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java
index b6b3e201..4671e603 100644
--- a/app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java
+++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java
@@ -94,6 +94,9 @@ public class CalculatorApplication extends android.app.Application implements Sh
@Inject
ErrorReporter errorReporter;
+ @Inject
+ Notifier notifier;
+
@Inject
PreferredPreferences preferredPreferences;
@@ -124,14 +127,11 @@ public class CalculatorApplication extends android.app.Application implements Sh
Locator.getInstance().init(calculator,
engine,
- new AndroidCalculatorNotifier(this),
- errorReporter,
- preferredPreferences,
keyboard,
new AndroidCalculatorPlotter(this, new CalculatorPlotterImpl(calculator))
);
- listeners.add(new CalculatorActivityLauncher());
+ listeners.add(new ActivityLauncher());
for (CalculatorEventListener listener : listeners) {
calculator.addCalculatorEventListener(listener);
}
@@ -189,7 +189,7 @@ public class CalculatorApplication extends android.app.Application implements Sh
if (Preferences.Onscreen.showAppIcon.getKey().equals(key)) {
boolean showAppIcon = Preferences.Onscreen.showAppIcon.getPreference(prefs);
Android.enableComponent(this, CalculatorOnscreenStartActivity.class, showAppIcon);
- Locator.getInstance().getNotifier().showMessage(R.string.cpp_this_change_may_require_reboot, MessageType.info);
+ notifier.showMessage(R.string.cpp_this_change_may_require_reboot, MessageType.info);
}
}
diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java
index 8e52db33..bd69afe2 100644
--- a/app/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java
+++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java
@@ -103,20 +103,22 @@ public final class CalculatorButtons {
}
}
- @Nonnull
- private static Keyboard getKeyboard() {
- return Locator.getInstance().getKeyboard();
- }
-
static class RoundBracketsDragProcessor implements SimpleDragListener.DragProcessor {
@Nonnull
- private final DigitButtonDragProcessor upDownProcessor = new DigitButtonDragProcessor(getKeyboard());
+ private final Keyboard keyboard;
+ @Nonnull
+ private final DigitButtonDragProcessor upDownProcessor;
+
+ RoundBracketsDragProcessor(@Nonnull Keyboard keyboard) {
+ this.keyboard = keyboard;
+ this.upDownProcessor = new DigitButtonDragProcessor(keyboard);
+ }
@Override
public boolean processDragEvent(@Nonnull DragDirection direction, @Nonnull DragButton button, @Nonnull PointF startPoint, @Nonnull MotionEvent motionEvent) {
if (direction == DragDirection.left) {
- getKeyboard().roundBracketsButtonPressed();
+ keyboard.roundBracketsButtonPressed();
return true;
}
@@ -154,10 +156,13 @@ public final class CalculatorButtons {
@Nonnull
private final Context context;
+ @Nonnull
+ private final PreferredPreferences preferredPreferences;
- AngleUnitsChanger(@Nonnull Context context) {
+ AngleUnitsChanger(@Nonnull Context context, @Nonnull Keyboard keyboard, @Nonnull PreferredPreferences preferredPreferences) {
this.context = context;
- this.processor = new DigitButtonDragProcessor(Locator.getInstance().getKeyboard());
+ this.preferredPreferences = preferredPreferences;
+ this.processor = new DigitButtonDragProcessor(keyboard);
}
@Override
@@ -177,7 +182,7 @@ public final class CalculatorButtons {
final AngleUnit oldAngleUnits = Engine.Preferences.angleUnit.getPreference(preferences);
if (oldAngleUnits != angleUnits) {
- Locator.getInstance().getPreferenceService().setAngleUnits(angleUnits);
+ preferredPreferences.setAngleUnits(angleUnits);
}
} catch (IllegalArgumentException e) {
Log.d(this.getClass().getName(), "Unsupported angle units: " + directionText);
@@ -197,9 +202,12 @@ public final class CalculatorButtons {
@Nonnull
private final Context context;
+ @Nonnull
+ private final PreferredPreferences preferredPreferences;
- NumeralBasesChanger(@Nonnull Context context) {
+ NumeralBasesChanger(@Nonnull Context context, @Nonnull PreferredPreferences preferredPreferences) {
this.context = context;
+ this.preferredPreferences = preferredPreferences;
}
@Override
@@ -217,7 +225,7 @@ public final class CalculatorButtons {
final NumeralBase oldNumeralBase = Engine.Preferences.numeralBase.getPreference(preferences);
if (oldNumeralBase != numeralBase) {
- Locator.getInstance().getPreferenceService().setNumeralBase(numeralBase);
+ preferredPreferences.setNumeralBase(numeralBase);
}
} catch (IllegalArgumentException e) {
Log.d(this.getClass().getName(), "Unsupported numeral base: " + directionText);
diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorFragmentType.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorFragmentType.java
index a4456a18..d14e94b2 100644
--- a/app/src/main/java/org/solovyev/android/calculator/CalculatorFragmentType.java
+++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorFragmentType.java
@@ -32,10 +32,6 @@ import org.solovyev.android.calculator.functions.FunctionsFragment;
import org.solovyev.android.calculator.operators.OperatorsFragment;
import org.solovyev.android.calculator.variables.VariablesFragment;
import org.solovyev.android.calculator.matrix.CalculatorMatrixEditFragment;
-import org.solovyev.android.calculator.plot.CalculatorPlotFragment;
-import org.solovyev.android.calculator.plot.CalculatorPlotFunctionSettingsActivity;
-import org.solovyev.android.calculator.plot.CalculatorPlotFunctionsActivity;
-import org.solovyev.android.calculator.plot.CalculatorPlotRangeActivity;
import org.solovyev.android.calculator.preferences.PurchaseDialogActivity;
import javax.annotation.Nonnull;
@@ -55,10 +51,6 @@ public enum CalculatorFragmentType {
variables(VariablesFragment.class, R.layout.fragment_entities, R.string.c_vars),
functions(FunctionsFragment.class, R.layout.fragment_entities, R.string.c_functions),
operators(OperatorsFragment.class, R.layout.fragment_entities, R.string.c_operators),
- plotter(CalculatorPlotFragment.class, R.layout.cpp_plotter_fragment, R.string.c_graph),
- plotter_functions(CalculatorPlotFunctionsActivity.CalculatorPlotFunctionsFragment.class, R.layout.cpp_plot_functions_fragment, R.string.cpp_plot_functions),
- plotter_function_settings(CalculatorPlotFunctionSettingsActivity.CalculatorPlotFunctionSettingsFragment.class, R.layout.cpp_plot_function_settings_fragment, R.string.cpp_plot_function_settings),
- plotter_range(CalculatorPlotRangeActivity.CalculatorPlotRangeFragment.class, R.layout.cpp_plot_range_fragment, R.string.cpp_plot_range),
purchase_dialog(PurchaseDialogActivity.PurchaseDialogFragment.class, R.layout.cpp_purchase_dialog_fragment, R.string.cpp_purchase_title),
diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorLocator.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorLocator.java
index aa00afac..bcb1b3c7 100644
--- a/app/src/main/java/org/solovyev/android/calculator/CalculatorLocator.java
+++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorLocator.java
@@ -30,9 +30,6 @@ public interface CalculatorLocator {
void init(@Nonnull Calculator calculator,
@Nonnull Engine engine,
- @Nonnull CalculatorNotifier notifier,
- @Nonnull ErrorReporter errorReporter,
- @Nonnull PreferredPreferences preferenceService,
@Nonnull Keyboard keyboard,
@Nonnull CalculatorPlotter plotter);
@@ -45,15 +42,6 @@ public interface CalculatorLocator {
@Nonnull
Keyboard getKeyboard();
- @Nonnull
- CalculatorNotifier getNotifier();
-
- @Nonnull
- ErrorReporter getErrorReporter();
-
@Nonnull
CalculatorPlotter getPlotter();
-
- @Nonnull
- PreferredPreferences getPreferenceService();
}
diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorMenu.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorMenu.java
index d8cd1057..e28b047d 100644
--- a/app/src/main/java/org/solovyev/android/calculator/CalculatorMenu.java
+++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorMenu.java
@@ -42,14 +42,14 @@ enum CalculatorMenu implements LabeledMenuItem