diff --git a/app/build.gradle b/app/build.gradle
index 2e662abd..68b2367b 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -23,6 +23,7 @@
apply plugin: 'com.android.application'
apply plugin: 'maven'
apply plugin: 'signing'
+apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 23
@@ -98,6 +99,11 @@ dependencies {
}
compile 'commons-cli:commons-cli:1.2'
compile 'com.squareup:otto:1.3.8'
+
+ compile 'com.google.dagger:dagger:2.0.2'
+ apt "com.google.dagger:dagger-compiler:2.0.2"
+ compile 'javax.annotation:jsr250-api:1.0'
+
testCompile 'junit:junit:4.12'
testCompile 'net.sf.opencsv:opencsv:2.0'
testCompile 'org.mockito:mockito-core:1.9.0'
diff --git a/app/src/main/java/org/solovyev/android/calculator/AndroidCalculator.java b/app/src/main/java/org/solovyev/android/calculator/AndroidCalculator.java
index 76bdf00a..f341570c 100644
--- a/app/src/main/java/org/solovyev/android/calculator/AndroidCalculator.java
+++ b/app/src/main/java/org/solovyev/android/calculator/AndroidCalculator.java
@@ -25,14 +25,20 @@ package org.solovyev.android.calculator;
import android.app.Application;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
-import jscl.NumeralBase;
-import jscl.math.Generic;
+
+import com.squareup.otto.Bus;
+
import org.solovyev.android.calculator.jscl.JsclOperation;
import org.solovyev.common.msg.Message;
+import java.util.List;
+import java.util.concurrent.Executor;
+
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import java.util.List;
+
+import jscl.NumeralBase;
+import jscl.math.Generic;
/**
* User: serso
@@ -42,13 +48,14 @@ import java.util.List;
public class AndroidCalculator implements Calculator, CalculatorEventListener, SharedPreferences.OnSharedPreferenceChangeListener {
@Nonnull
- private final CalculatorImpl calculator = new CalculatorImpl();
+ private final CalculatorImpl calculator;
@Nonnull
private final Application context;
- public AndroidCalculator(@Nonnull Application application) {
+ public AndroidCalculator(@Nonnull Application application, @Nonnull Bus bus, Executor eventExecutor) {
this.context = application;
+ this.calculator = new CalculatorImpl(bus, eventExecutor);
this.calculator.addCalculatorEventListener(this);
PreferenceManager.getDefaultSharedPreferences(application).registerOnSharedPreferenceChangeListener(this);
diff --git a/app/src/main/java/org/solovyev/android/calculator/App.java b/app/src/main/java/org/solovyev/android/calculator/App.java
index 469fcd93..2bf2ad1d 100644
--- a/app/src/main/java/org/solovyev/android/calculator/App.java
+++ b/app/src/main/java/org/solovyev/android/calculator/App.java
@@ -29,8 +29,6 @@ import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Typeface;
import android.os.Build;
-import android.os.Handler;
-import android.os.Looper;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
@@ -40,12 +38,10 @@ import android.support.v4.app.FragmentTransaction;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
-import android.util.Log;
import com.squareup.otto.Bus;
import org.solovyev.android.Check;
-import org.solovyev.android.UiThreadExecutor;
import org.solovyev.android.Views;
import org.solovyev.android.calculator.ga.Ga;
import org.solovyev.android.calculator.language.Languages;
@@ -60,10 +56,6 @@ import org.solovyev.android.checkout.Products;
import org.solovyev.android.checkout.RobotmediaDatabase;
import org.solovyev.android.checkout.RobotmediaInventory;
import org.solovyev.android.wizard.Wizards;
-import org.solovyev.common.listeners.JEvent;
-import org.solovyev.common.listeners.JEventListener;
-import org.solovyev.common.listeners.JEventListeners;
-import org.solovyev.common.listeners.Listeners;
import org.solovyev.common.threads.DelayedExecutor;
import java.util.Arrays;
@@ -75,12 +67,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-/**
- * User: serso
- * Date: 12/1/12
- * Time: 3:58 PM
- */
-
/**
* This class aggregates several useful in any Android application interfaces and provides access to {@link android.app.Application} object from a static context.
* NOTE: use this class only if you don't use and dependency injection library (if you use any you can directly set interfaces through it).
@@ -108,13 +94,9 @@ public final class App {
@Nonnull
private static volatile Application application;
@Nonnull
- private static volatile DelayedExecutor uiThreadExecutor;
- @Nonnull
- private static Bus bus;
+ private static Executor uiThreadExecutor;
private static volatile boolean initialized;
@Nonnull
- private static CalculatorBroadcaster broadcaster;
- @Nonnull
private static SharedPreferences preferences;
@Nonnull
private static volatile Ga ga;
@@ -127,16 +109,13 @@ public final class App {
@Nonnull
private static volatile ScreenMetrics screenMetrics;
@Nonnull
- private static final Handler handler = new Handler(Looper.getMainLooper());
- @Nonnull
private static Wizards wizards;
@Nonnull
- private static final Executor initThread = Executors.newSingleThreadExecutor(new ThreadFactory() {
- @Override
- public Thread newThread(@Nonnull Runnable r) {
- return new Thread(r, "Init");
- }
- });
+ private static Editor editor;
+ @Nonnull
+ private static Bus bus;
+ @Nonnull
+ private static Display display;
@Nonnull
private static final Executor background = Executors.newFixedThreadPool(5, new ThreadFactory() {
@NonNull
@@ -151,22 +130,15 @@ public final class App {
throw new AssertionError();
}
- public static void init(@Nonnull Application application, @Nonnull Languages languages) {
- init(application, new UiThreadExecutor(), Listeners.newEventBus(), languages);
- }
-
- public static void init(@Nonnull Application application,
- @Nonnull UiThreadExecutor uiThreadExecutor,
- @Nonnull JEventListeners, JEvent> eventBus,
+ public static void init(@Nonnull CalculatorApplication application,
@Nonnull Languages languages) {
if (initialized) {
throw new IllegalStateException("Already initialized!");
}
App.application = application;
App.preferences = PreferenceManager.getDefaultSharedPreferences(application);
- App.uiThreadExecutor = uiThreadExecutor;
- App.bus = new MyBus();
- App.ga = new Ga(application, preferences, eventBus);
+ App.uiThreadExecutor = application.uiThread;
+ App.ga = new Ga(application, preferences);
App.billing = new Billing(application, new Billing.DefaultConfiguration() {
@Nonnull
@Override
@@ -184,11 +156,13 @@ public final class App {
}
}
});
- App.broadcaster = new CalculatorBroadcaster(application, preferences, bus);
App.screenMetrics = new ScreenMetrics(application);
App.languages = languages;
App.languages.init();
App.wizards = new CalculatorWizards(application);
+ App.editor = application.editor;
+ App.display = application.display;
+ App.bus = application.bus;
App.initialized = true;
}
@@ -215,33 +189,15 @@ public final class App {
* @return UI thread executor
*/
@Nonnull
- public static DelayedExecutor getUiThreadExecutor() {
+ public static Executor getUiThreadExecutor() {
return uiThreadExecutor;
}
- /**
- * @return application's event bus
- */
- @Nonnull
- public static Bus getBus() {
- return bus;
- }
-
- @Nonnull
- public static CalculatorBroadcaster getBroadcaster() {
- return broadcaster;
- }
-
@Nonnull
public static Wizards getWizards() {
return wizards;
}
- @Nonnull
- public static Handler getHandler() {
- return handler;
- }
-
@Nonnull
public static Ga getGa() {
return ga;
@@ -276,11 +232,6 @@ public final class App {
return Preferences.Widget.getTheme(getPreferences());
}
- @Nonnull
- public static Executor getInitThread() {
- return initThread;
- }
-
@Nonnull
public static Executor getBackground() {
return background;
@@ -363,27 +314,16 @@ public final class App {
@Nonnull
public static Editor getEditor() {
- return Locator.getInstance().getEditor();
+ return editor;
}
@Nonnull
public static Display getDisplay() {
- return Locator.getInstance().getDisplay();
+ return display;
}
- private static class MyBus extends Bus {
- @Override
- public void post(final Object event) {
- if (Looper.myLooper() == Looper.getMainLooper()) {
- super.post(event);
- return;
- }
- handler.post(new Runnable() {
- @Override
- public void run() {
- MyBus.super.post(event);
- }
- });
- }
+ @Nonnull
+ public static Bus getBus() {
+ return bus;
}
}
\ No newline at end of file
diff --git a/app/src/main/java/org/solovyev/android/calculator/AppComponent.java b/app/src/main/java/org/solovyev/android/calculator/AppComponent.java
new file mode 100644
index 00000000..f461ee54
--- /dev/null
+++ b/app/src/main/java/org/solovyev/android/calculator/AppComponent.java
@@ -0,0 +1,16 @@
+package org.solovyev.android.calculator;
+
+import org.solovyev.android.calculator.onscreen.CalculatorOnscreenService;
+
+import javax.inject.Singleton;
+
+import dagger.Component;
+
+@Singleton
+@Component(modules = AppModule.class)
+public interface AppComponent {
+ void inject(CalculatorApplication application);
+ void inject(CalculatorEditorFragment fragment);
+ void inject(BaseUi ui);
+ void inject(CalculatorOnscreenService service);
+}
diff --git a/app/src/main/java/org/solovyev/android/calculator/AppModule.java b/app/src/main/java/org/solovyev/android/calculator/AppModule.java
new file mode 100644
index 00000000..788ac088
--- /dev/null
+++ b/app/src/main/java/org/solovyev/android/calculator/AppModule.java
@@ -0,0 +1,106 @@
+package org.solovyev.android.calculator;
+
+import android.app.Application;
+import android.content.SharedPreferences;
+import android.os.Handler;
+import android.os.Looper;
+import android.preference.PreferenceManager;
+import android.support.annotation.NonNull;
+
+import com.squareup.otto.Bus;
+
+import org.solovyev.android.UiThreadExecutor;
+
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+
+import javax.annotation.Nonnull;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import dagger.Module;
+import dagger.Provides;
+
+@Module
+public class AppModule {
+
+ @NonNull
+ public static final String THREAD_INIT = "thread-init";
+ @NonNull
+ public static final String THREAD_UI = "thread-ui";
+
+ @NonNull
+ private final Application application;
+
+ public AppModule(@NonNull Application application) {
+ this.application = application;
+ }
+
+ @Provides
+ @Singleton
+ Handler provideHandler() {
+ return new Handler(Looper.getMainLooper());
+ }
+
+ @Provides
+ @Singleton
+ Bus provideBus(Handler handler) {
+ return new AppBus(handler);
+ }
+
+ @Provides
+ @Singleton
+ SharedPreferences providePreferences() {
+ return PreferenceManager.getDefaultSharedPreferences(application);
+ }
+
+ @Provides
+ @Singleton
+ Calculator provideCalculator(Bus bus, @Named(THREAD_UI) Executor executor) {
+ return new AndroidCalculator(application, bus, executor);
+ }
+
+ @Provides
+ @Singleton
+ @Named(THREAD_INIT)
+ Executor provideInitThread() {
+ return Executors.newSingleThreadExecutor(new ThreadFactory() {
+ @Override
+ public Thread newThread(@Nonnull Runnable r) {
+ return new Thread(r, "Init");
+ }
+ });
+ }
+
+ @Provides
+ @Singleton
+ @Named(THREAD_UI)
+ Executor provideUiThread() {
+ return new UiThreadExecutor();
+ }
+
+ private static class AppBus extends Bus {
+
+ @NonNull
+ private final Handler handler;
+
+ public AppBus(@Nonnull Handler handler) {
+ this.handler = handler;
+ }
+
+ @Override
+ public void post(final Object event) {
+ if (Looper.myLooper() == Looper.getMainLooper()) {
+ super.post(event);
+ return;
+ }
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ AppBus.super.post(event);
+ }
+ });
+ }
+ }
+}
diff --git a/app/src/main/java/org/solovyev/android/calculator/BaseUi.java b/app/src/main/java/org/solovyev/android/calculator/BaseUi.java
index ff08ee37..b21d4ffb 100644
--- a/app/src/main/java/org/solovyev/android/calculator/BaseUi.java
+++ b/app/src/main/java/org/solovyev/android/calculator/BaseUi.java
@@ -43,6 +43,8 @@ import org.solovyev.android.views.dragbutton.*;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import javax.inject.Inject;
+
import java.util.ArrayList;
import java.util.List;
@@ -110,8 +112,14 @@ public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChan
return viewIds;
}
+ @Inject
+ SharedPreferences preferences;
+
+ @Inject
+ Editor editor;
+
protected void onCreate(@Nonnull Activity activity) {
- final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
+ ((CalculatorApplication) activity.getApplication()).getComponent().inject(this);
layout = Preferences.Gui.layout.getPreferenceNoError(preferences);
theme = Preferences.Gui.theme.getPreferenceNoError(preferences);
@@ -170,7 +178,7 @@ public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChan
minusButton.setOnDragListener(newDragListener(new OperatorsDragProcessor(), activity));
}
- final DragListener toPositionDragListener = new SimpleDragListener(new CursorDragProcessor(), activity);
+ final DragListener toPositionDragListener = new SimpleDragListener(new CursorDragProcessor(editor), activity);
final DragButton rightButton = getButton(views, R.id.cpp_button_right);
if (rightButton != null) {
@@ -278,7 +286,7 @@ public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChan
}
@Nonnull
- private CalculatorKeyboard getKeyboard() {
+ private Keyboard getKeyboard() {
return Locator.getInstance().getKeyboard();
}
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 e1a11bef..b5f21f93 100644
--- a/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java
+++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java
@@ -32,11 +32,17 @@ import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.ActionBar;
import android.text.method.LinkMovementMethod;
-import android.view.*;
+import android.view.KeyEvent;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewConfiguration;
+import android.view.Window;
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;
@@ -47,13 +53,16 @@ import org.solovyev.common.Objects;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import javax.inject.Inject;
import static android.os.Build.VERSION_CODES.GINGERBREAD_MR1;
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.*;
+import static org.solovyev.android.wizard.WizardUi.continueWizard;
+import static org.solovyev.android.wizard.WizardUi.createLaunchIntent;
+import static org.solovyev.android.wizard.WizardUi.startWizard;
public class CalculatorActivity extends BaseActivity implements SharedPreferences.OnSharedPreferenceChangeListener, CalculatorEventListener {
@@ -135,6 +144,9 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
return result;
}
+ @Inject
+ History history;
+
/**
* Called when the activity is first created.
*/
@@ -203,7 +215,7 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (useBackAsPrev) {
- Locator.getInstance().getHistory().undo();
+ history.undo();
return true;
}
}
diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java
index ebf8e216..525d8e58 100644
--- a/app/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java
+++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java
@@ -136,7 +136,7 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener
}
public static void tryCreateVar(@Nonnull final Context context) {
- final Display display = Locator.getInstance().getDisplay();
+ final Display display = App.getDisplay();
final DisplayState viewState = display.getState();
if (viewState.valid) {
final String varValue = viewState.text;
@@ -162,7 +162,7 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener
}
public static void tryCreateFunction(@Nonnull final Context context) {
- final Display display = Locator.getInstance().getDisplay();
+ final Display display = App.getDisplay();
final DisplayState viewState = display.getState();
if (viewState.valid) {
@@ -184,7 +184,7 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener
public static void tryPlot() {
final CalculatorPlotter plotter = Locator.getInstance().getPlotter();
- final Display display = Locator.getInstance().getDisplay();
+ final Display display = App.getDisplay();
final DisplayState viewState = display.getState();
if (viewState.valid) {
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 a547ce48..7e8edfaa 100644
--- a/app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java
+++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java
@@ -23,41 +23,78 @@
package org.solovyev.android.calculator;
import android.content.SharedPreferences;
+import android.os.Handler;
import android.preference.PreferenceManager;
import android.util.Log;
import com.squareup.leakcanary.LeakCanary;
+import com.squareup.otto.Bus;
import org.acra.ACRA;
import org.acra.ACRAConfiguration;
import org.acra.sender.HttpSender;
import org.solovyev.android.Android;
-import org.solovyev.android.calculator.history.History;
import org.solovyev.android.calculator.language.Language;
import org.solovyev.android.calculator.language.Languages;
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
import org.solovyev.android.calculator.onscreen.CalculatorOnscreenStartActivity;
import org.solovyev.android.calculator.plot.AndroidCalculatorPlotter;
import org.solovyev.android.calculator.plot.CalculatorPlotterImpl;
-import org.solovyev.android.calculator.view.EditorTextProcessor;
import org.solovyev.common.msg.MessageType;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
+import java.util.concurrent.Executor;
import javax.annotation.Nonnull;
+import javax.inject.Inject;
+import javax.inject.Named;
public class CalculatorApplication extends android.app.Application implements SharedPreferences.OnSharedPreferenceChangeListener {
+
+ @Inject
+ @Named(AppModule.THREAD_INIT)
+ Executor initThread;
+
+ @Inject
+ Handler handler;
+
@Nonnull
private final List listeners = new ArrayList<>();
+ private AppComponent component;
+
+ @Inject
+ Editor editor;
+
+ @Inject
+ Display display;
+
+ @Inject
+ Bus bus;
+
+ @Inject
+ Calculator calculator;
+
+ @Inject
+ Keyboard keyboard;
+
+ @Inject
+ @Named(AppModule.THREAD_UI)
+ Executor uiThread;
+
@Override
public void onCreate() {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
final Languages languages = new Languages(preferences);
onPreCreate(preferences, languages);
+ component = DaggerAppComponent.builder()
+ .appModule(new AppModule(this))
+ .build();
+ component.inject(this);
+
super.onCreate();
onPostCreate(preferences, languages);
}
@@ -69,22 +106,15 @@ public class CalculatorApplication extends android.app.Application implements Sh
languages.updateContextLocale(this, true);
App.getGa().reportInitially(preferences);
- final AndroidCalculator calculator = new AndroidCalculator(this);
-
- final EditorTextProcessor editorTextProcessor = new EditorTextProcessor();
-
Locator.getInstance().init(calculator,
new AndroidCalculatorEngine(this),
new AndroidCalculatorClipboard(this),
new AndroidCalculatorNotifier(this),
- new History(),
new AndroidCalculatorLogger(),
new AndroidCalculatorPreferenceService(this),
- new CalculatorKeyboard(),
- new AndroidCalculatorPlotter(this, new CalculatorPlotterImpl(calculator)),
- editorTextProcessor);
-
- editorTextProcessor.init(this);
+ keyboard,
+ new AndroidCalculatorPlotter(this, new CalculatorPlotterImpl(calculator))
+ );
listeners.add(new CalculatorActivityLauncher());
for (CalculatorEventListener listener : listeners) {
@@ -93,20 +123,12 @@ public class CalculatorApplication extends android.app.Application implements Sh
Locator.getInstance().getCalculator().init();
- App.getInitThread().execute(new Runnable() {
+ initThread.execute(new Runnable() {
@Override
public void run() {
warmUpEngine();
}
});
-
- App.getHandler().postDelayed(new Runnable() {
- @Override
- public void run() {
- // we must update the widget when app starts
- App.getBroadcaster().sendInitIntent();
- }
- }, 100);
}
private void warmUpEngine() {
@@ -154,4 +176,9 @@ public class CalculatorApplication extends android.app.Application implements Sh
Locator.getInstance().getNotifier().showMessage(R.string.cpp_this_change_may_require_reboot, MessageType.info);
}
}
+
+ @Nonnull
+ public AppComponent getComponent() {
+ return component;
+ }
}
diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorBroadcaster.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorBroadcaster.java
index e4e3e414..9219c974 100644
--- a/app/src/main/java/org/solovyev/android/calculator/CalculatorBroadcaster.java
+++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorBroadcaster.java
@@ -3,13 +3,17 @@ package org.solovyev.android.calculator;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.os.Handler;
+
import com.squareup.otto.Bus;
import com.squareup.otto.Subscribe;
-import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.Map;
+import javax.annotation.Nonnull;
+import javax.inject.Inject;
+
public final class CalculatorBroadcaster implements SharedPreferences.OnSharedPreferenceChangeListener {
public static final String ACTION_INIT = "org.solovyev.android.calculator.INIT";
@@ -21,10 +25,18 @@ public final class CalculatorBroadcaster implements SharedPreferences.OnSharedPr
@Nonnull
private final Intents intents = new Intents();
- public CalculatorBroadcaster(@Nonnull Context context, @Nonnull SharedPreferences preferences, @Nonnull Bus bus) {
+ @Inject
+ public CalculatorBroadcaster(@Nonnull Context context, @Nonnull SharedPreferences preferences, @Nonnull Bus bus, @Nonnull Handler handler) {
this.context = context;
preferences.registerOnSharedPreferenceChangeListener(this);
bus.register(this);
+ handler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ // we must update the widget when app starts
+ sendInitIntent();
+ }
+ }, 100);
}
@Subscribe
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 c67e39f4..c2deb78f 100644
--- a/app/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java
+++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java
@@ -107,7 +107,7 @@ public final class CalculatorButtons {
}
@Nonnull
- private static CalculatorKeyboard getKeyboard() {
+ private static Keyboard getKeyboard() {
return Locator.getInstance().getKeyboard();
}
diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayFragment.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayFragment.java
index 76370790..d9d08612 100644
--- a/app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayFragment.java
+++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayFragment.java
@@ -69,7 +69,7 @@ public class CalculatorDisplayFragment extends Fragment {
super.onViewCreated(root, savedInstanceState);
displayView = (DisplayView) root.findViewById(R.id.calculator_display);
- Locator.getInstance().getDisplay().setView(displayView);
+ App.getDisplay().setView(displayView);
fragmentUi.onViewCreated(this, root);
}
@@ -95,7 +95,7 @@ public class CalculatorDisplayFragment extends Fragment {
@Override
public void onDestroyView() {
- Locator.getInstance().getDisplay().clearView(displayView);
+ App.getDisplay().clearView(displayView);
fragmentUi.onDestroyView(this);
super.onDestroyView();
}
diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayOnClickListener.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayOnClickListener.java
index 8e6b2ac8..9f501ebe 100644
--- a/app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayOnClickListener.java
+++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayOnClickListener.java
@@ -50,7 +50,7 @@ public class CalculatorDisplayOnClickListener implements View.OnClickListener {
@Override
public void onClick(View v) {
if (v instanceof DisplayView) {
- final Display cd = Locator.getInstance().getDisplay();
+ final Display cd = App.getDisplay();
final DisplayState displayViewState = cd.getState();
diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorEditorFragment.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorEditorFragment.java
index 53acaec1..10f907e4 100644
--- a/app/src/main/java/org/solovyev/android/calculator/CalculatorEditorFragment.java
+++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorEditorFragment.java
@@ -25,7 +25,6 @@ package org.solovyev.android.calculator;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
-import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.Menu;
@@ -39,23 +38,23 @@ import org.solovyev.android.menu.AndroidMenuHelper;
import org.solovyev.android.menu.ListActivityMenu;
import javax.annotation.Nonnull;
+import javax.inject.Inject;
-/**
- * User: Solovyev_S
- * Date: 25.09.12
- * Time: 10:49
- */
public class CalculatorEditorFragment extends Fragment {
- @Nonnull
private FragmentUi fragmentUi;
@Nonnull
private ActivityMenu