This commit is contained in:
serso 2016-03-03 17:06:27 +01:00
parent 001888973a
commit ba69cc7096
25 changed files with 129 additions and 323 deletions

View File

@ -88,15 +88,10 @@ public final class ActivityLauncher {
context.startActivity(intent); context.startActivity(intent);
} }
@Nonnull
private static Notifier getNotifier() {
return ((CalculatorApplication) App.getApplication()).notifier;
}
public void plotDisplayedExpression() { public void plotDisplayedExpression() {
final DisplayState state = display.get().getState(); final DisplayState state = display.get().getState();
if (!state.valid) { if (!state.valid) {
getNotifier().showMessage(R.string.not_valid_result, MessageType.error); notifier.showMessage(R.string.not_valid_result, MessageType.error);
return; return;
} }
plot(state.getResult()); plot(state.getResult());

View File

@ -41,114 +41,51 @@ import android.support.v7.view.ContextThemeWrapper;
import android.text.Spannable; import android.text.Spannable;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import android.util.AttributeSet;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.View; import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import com.squareup.otto.Bus;
import org.solovyev.android.Check; import org.solovyev.android.Check;
import org.solovyev.android.calculator.floating.FloatingCalculatorService; import org.solovyev.android.calculator.floating.FloatingCalculatorService;
import org.solovyev.android.calculator.ga.Ga;
import org.solovyev.android.calculator.language.Languages;
import org.solovyev.android.calculator.view.ScreenMetrics;
import org.solovyev.android.calculator.wizard.CalculatorWizards;
import org.solovyev.android.wizard.Wizards;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
/**
* 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). <br/>
* <p/>
* Before first usage this class must be initialized by calling {@link App#init(android.app.Application)} method (for example, from {@link android.app.Application#onCreate()})
*/
public final class App { public final class App {
public static final String TAG = "C++"; public static final String TAG = "C++";
@Nonnull @Nonnull
private static Languages languages; private static Application application;
@Nonnull
private static volatile Application application;
@Nonnull @Nonnull
private static SharedPreferences preferences; private static SharedPreferences preferences;
@Nonnull
private static volatile Ga ga;
@Nonnull
private static volatile ScreenMetrics screenMetrics;
@Nonnull
private static Wizards wizards;
@Nonnull
private static Editor editor;
@Nonnull
private static Bus bus;
@Nonnull
private static Display display;
private App() { private App() {
throw new AssertionError(); throw new AssertionError();
} }
public static void init(@Nonnull CalculatorApplication application, public static void init(@Nonnull CalculatorApplication application) {
@Nonnull Languages languages) {
App.application = application; App.application = application;
App.preferences = PreferenceManager.getDefaultSharedPreferences(application); App.preferences = PreferenceManager.getDefaultSharedPreferences(application);
App.ga = new Ga(application, preferences);
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;
}
/**
* @param <A> real type of application
* @return application instance which was provided in {@link App#init} method
*/
@SuppressWarnings("unchecked")
@Nonnull
public static <A extends Application> A getApplication() {
return (A) application;
}
@Nonnull
public static Wizards getWizards() {
return wizards;
}
@Nonnull
public static Ga getGa() {
return ga;
}
@Nonnull
public static SharedPreferences getPreferences() {
return preferences;
} }
@Nonnull @Nonnull
public static Preferences.Gui.Theme getTheme() { public static Preferences.Gui.Theme getTheme() {
return Preferences.Gui.getTheme(getPreferences()); return Preferences.Gui.getTheme(preferences);
} }
@Nonnull @Nonnull
public static Preferences.SimpleTheme getWidgetTheme() { public static Preferences.SimpleTheme getWidgetTheme() {
return Preferences.Widget.getTheme(getPreferences()); return Preferences.Widget.getTheme(preferences);
} }
@Nonnull @Nonnull
public static Preferences.Gui.Theme getThemeFor(@Nonnull Context context) { public static Preferences.Gui.Theme getThemeFor(@Nonnull Context context) {
if (isFloatingCalculator(context)) { if (isFloatingCalculator(context)) {
final SharedPreferences p = getPreferences(); final SharedPreferences p = preferences;
final Preferences.SimpleTheme onscreenTheme = Preferences.Onscreen.getTheme(p); final Preferences.SimpleTheme onscreenTheme = Preferences.Onscreen.getTheme(p);
final Preferences.Gui.Theme appTheme = Preferences.Gui.getTheme(p); final Preferences.Gui.Theme appTheme = Preferences.Gui.getTheme(p);
return onscreenTheme.resolveThemeFor(appTheme).getAppTheme(); return onscreenTheme.resolveThemeFor(appTheme).getAppTheme();
@ -165,16 +102,6 @@ public final class App {
return context; return context;
} }
@Nonnull
public static Languages getLanguages() {
return languages;
}
@Nonnull
public static ScreenMetrics getScreenMetrics() {
return screenMetrics;
}
public static void showDialog(@Nonnull DialogFragment dialogFragment, public static void showDialog(@Nonnull DialogFragment dialogFragment,
@Nonnull String fragmentTag, @Nonnull String fragmentTag,
@Nonnull FragmentManager fm) { @Nonnull FragmentManager fm) {
@ -201,21 +128,6 @@ public final class App {
return spannable.toString(); return spannable.toString();
} }
@Nonnull
public static Editor getEditor() {
return editor;
}
@Nonnull
public static Display getDisplay() {
return display;
}
@Nonnull
public static Bus getBus() {
return bus;
}
private static final AtomicInteger sNextViewId = new AtomicInteger(1); private static final AtomicInteger sNextViewId = new AtomicInteger(1);
public static int generateViewId() { public static int generateViewId() {
@ -391,14 +303,6 @@ public final class App {
pm.setComponentEnabledSetting(new ComponentName(context, componentClass), componentState, PackageManager.DONT_KILL_APP); pm.setComponentEnabledSetting(new ComponentName(context, componentClass), componentState, PackageManager.DONT_KILL_APP);
} }
public static boolean isComponentEnabled(@Nonnull Context context,
@Nonnull Class<? extends Context> componentClass) {
final PackageManager pm = context.getPackageManager();
int componentEnabledSetting = pm.getComponentEnabledSetting(new ComponentName(context, componentClass));
return componentEnabledSetting == PackageManager.COMPONENT_ENABLED_STATE_ENABLED || componentEnabledSetting == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
}
public static int toPixels(@Nonnull DisplayMetrics dm, float dps) { public static int toPixels(@Nonnull DisplayMetrics dm, float dps) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dps, dm); return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dps, dm);
} }

View File

@ -1,8 +1,10 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import dagger.Component;
import org.solovyev.android.calculator.converter.ConverterFragment; import org.solovyev.android.calculator.converter.ConverterFragment;
import org.solovyev.android.calculator.errors.FixableErrorFragment; import org.solovyev.android.calculator.errors.FixableErrorFragment;
import org.solovyev.android.calculator.errors.FixableErrorsActivity; import org.solovyev.android.calculator.errors.FixableErrorsActivity;
import org.solovyev.android.calculator.floating.FloatingCalculatorBroadcastReceiver;
import org.solovyev.android.calculator.floating.FloatingCalculatorService; import org.solovyev.android.calculator.floating.FloatingCalculatorService;
import org.solovyev.android.calculator.floating.FloatingCalculatorView; import org.solovyev.android.calculator.floating.FloatingCalculatorView;
import org.solovyev.android.calculator.functions.BaseFunctionFragment; import org.solovyev.android.calculator.functions.BaseFunctionFragment;
@ -17,6 +19,7 @@ import org.solovyev.android.calculator.plot.PlotDimensionsFragment;
import org.solovyev.android.calculator.plot.PlotEditFunctionFragment; import org.solovyev.android.calculator.plot.PlotEditFunctionFragment;
import org.solovyev.android.calculator.plot.PlotFunctionsFragment; import org.solovyev.android.calculator.plot.PlotFunctionsFragment;
import org.solovyev.android.calculator.preferences.PreferencesActivity; import org.solovyev.android.calculator.preferences.PreferencesActivity;
import org.solovyev.android.calculator.preferences.PreferencesFragment;
import org.solovyev.android.calculator.preferences.PurchaseDialogActivity; import org.solovyev.android.calculator.preferences.PurchaseDialogActivity;
import org.solovyev.android.calculator.variables.EditVariableFragment; import org.solovyev.android.calculator.variables.EditVariableFragment;
import org.solovyev.android.calculator.variables.VariablesFragment; import org.solovyev.android.calculator.variables.VariablesFragment;
@ -24,11 +27,10 @@ import org.solovyev.android.calculator.view.Tabs;
import org.solovyev.android.calculator.widget.CalculatorWidget; import org.solovyev.android.calculator.widget.CalculatorWidget;
import org.solovyev.android.calculator.wizard.DragButtonWizardStep; import org.solovyev.android.calculator.wizard.DragButtonWizardStep;
import org.solovyev.android.calculator.wizard.WizardActivity; import org.solovyev.android.calculator.wizard.WizardActivity;
import org.solovyev.android.calculator.wizard.WizardFragment;
import javax.inject.Singleton; import javax.inject.Singleton;
import dagger.Component;
@Singleton @Singleton
@Component(modules = AppModule.class) @Component(modules = AppModule.class)
public interface AppComponent { public interface AppComponent {
@ -65,4 +67,7 @@ public interface AppComponent {
void inject(CalculatorWidget widget); void inject(CalculatorWidget widget);
void inject(WizardActivity activity); void inject(WizardActivity activity);
void inject(BaseActivity activity); void inject(BaseActivity activity);
void inject(PreferencesFragment fragment);
void inject(WizardFragment fragment);
void inject(FloatingCalculatorBroadcastReceiver receiver);
} }

View File

@ -15,9 +15,11 @@ import dagger.Module;
import dagger.Provides; import dagger.Provides;
import jscl.JsclMathEngine; import jscl.JsclMathEngine;
import org.solovyev.android.calculator.language.Languages; import org.solovyev.android.calculator.language.Languages;
import org.solovyev.android.calculator.wizard.CalculatorWizards;
import org.solovyev.android.checkout.*; import org.solovyev.android.checkout.*;
import org.solovyev.android.plotter.Plot; import org.solovyev.android.plotter.Plot;
import org.solovyev.android.plotter.Plotter; import org.solovyev.android.plotter.Plotter;
import org.solovyev.android.wizard.Wizards;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -137,6 +139,12 @@ public class AppModule {
return new AcraErrorReporter(); return new AcraErrorReporter();
} }
@Provides
@Singleton
Wizards provideWizards(@Nonnull Application application) {
return new CalculatorWizards(application);
}
@Provides @Provides
@Singleton @Singleton
@Named(THREAD_UI) @Named(THREAD_UI)

View File

@ -1,8 +1,6 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import android.app.Activity; import android.app.Activity;
import android.app.KeyguardManager;
import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.os.Bundle; import android.os.Bundle;
@ -21,6 +19,7 @@ import android.widget.TextView;
import butterknife.Bind; import butterknife.Bind;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import org.solovyev.android.Check; import org.solovyev.android.Check;
import org.solovyev.android.calculator.ga.Ga;
import org.solovyev.android.calculator.history.History; import org.solovyev.android.calculator.history.History;
import org.solovyev.android.calculator.language.Language; import org.solovyev.android.calculator.language.Language;
import org.solovyev.android.calculator.language.Languages; import org.solovyev.android.calculator.language.Languages;
@ -51,6 +50,8 @@ public class BaseActivity extends AppCompatActivity {
@Inject @Inject
Calculator calculator; Calculator calculator;
@Inject @Inject
Ga ga;
@Inject
Typeface typeface; Typeface typeface;
@Bind(R.id.main) @Bind(R.id.main)
ViewGroup mainView; ViewGroup mainView;
@ -77,12 +78,12 @@ public class BaseActivity extends AppCompatActivity {
this.tabs = new Tabs(this); this.tabs = new Tabs(this);
} }
public static void reportActivityStop(@Nonnull Activity activity) { public void reportActivityStop(@Nonnull Activity activity) {
App.getGa().getAnalytics().reportActivityStop(activity); ga.getAnalytics().reportActivityStop(activity);
} }
public static void reportActivityStart(@Nonnull Activity activity) { public void reportActivityStart(@Nonnull Activity activity) {
App.getGa().getAnalytics().reportActivityStart(activity); ga.getAnalytics().reportActivityStart(activity);
} }
public static void setFont(@Nonnull TextView view, @Nonnull Typeface newTypeface) { public static void setFont(@Nonnull TextView view, @Nonnull Typeface newTypeface) {

View File

@ -34,6 +34,7 @@ import org.acra.ACRA;
import org.acra.ACRAConfiguration; import org.acra.ACRAConfiguration;
import org.acra.sender.HttpSender; import org.acra.sender.HttpSender;
import org.solovyev.android.calculator.floating.FloatingCalculatorActivity; import org.solovyev.android.calculator.floating.FloatingCalculatorActivity;
import org.solovyev.android.calculator.ga.Ga;
import org.solovyev.android.calculator.history.History; import org.solovyev.android.calculator.history.History;
import org.solovyev.android.calculator.language.Language; import org.solovyev.android.calculator.language.Language;
import org.solovyev.android.calculator.language.Languages; import org.solovyev.android.calculator.language.Languages;
@ -96,6 +97,9 @@ public class CalculatorApplication extends android.app.Application implements Sh
@Inject @Inject
ActivityLauncher launcher; ActivityLauncher launcher;
@Inject
Ga ga;
@Nonnull @Nonnull
private final TimingLogger timer = new TimingLogger("App", "onCreate"); private final TimingLogger timer = new TimingLogger("App", "onCreate");
@ -104,7 +108,7 @@ public class CalculatorApplication extends android.app.Application implements Sh
timer.reset(); timer.reset();
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
final Languages languages = new Languages(preferences); final Languages languages = new Languages(this, preferences);
timer.addSplit("languages"); timer.addSplit("languages");
onPreCreate(preferences, languages); onPreCreate(preferences, languages);
@ -131,11 +135,12 @@ public class CalculatorApplication extends android.app.Application implements Sh
} }
private void onPostCreate(@Nonnull SharedPreferences preferences, @Nonnull Languages languages) { private void onPostCreate(@Nonnull SharedPreferences preferences, @Nonnull Languages languages) {
App.init(this, languages); App.init(this);
languages.init();
preferences.registerOnSharedPreferenceChangeListener(this); preferences.registerOnSharedPreferenceChangeListener(this);
languages.updateContextLocale(this, true); languages.updateContextLocale(this, true);
App.getGa().reportInitially(preferences); ga.reportInitially(preferences);
calculator.init(initThread); calculator.init(initThread);

View File

@ -22,6 +22,7 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import android.app.Application;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.text.TextUtils; import android.text.TextUtils;
@ -54,8 +55,8 @@ public class Editor {
Bus bus; Bus bus;
@Inject @Inject
public Editor(@Nonnull SharedPreferences preferences, @Nonnull Engine engine) { public Editor(@Nonnull Application application, @Nonnull SharedPreferences preferences, @Nonnull Engine engine) {
textProcessor = new EditorTextProcessor(preferences, engine); textProcessor = new EditorTextProcessor(application, preferences, engine);
} }
public void init() { public void init() {

View File

@ -29,6 +29,7 @@ import com.squareup.otto.Bus;
import dagger.Lazy; import dagger.Lazy;
import org.solovyev.android.Check; import org.solovyev.android.Check;
import org.solovyev.android.calculator.buttons.CppSpecialButton; import org.solovyev.android.calculator.buttons.CppSpecialButton;
import org.solovyev.android.calculator.ga.Ga;
import org.solovyev.android.calculator.math.MathType; import org.solovyev.android.calculator.math.MathType;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -51,6 +52,8 @@ public class Keyboard implements SharedPreferences.OnSharedPreferenceChangeListe
@Inject @Inject
Engine engine; Engine engine;
@Inject @Inject
Ga ga;
@Inject
Lazy<Clipboard> clipboard; Lazy<Clipboard> clipboard;
@Inject @Inject
Lazy<Bus> bus; Lazy<Bus> bus;
@ -72,7 +75,7 @@ public class Keyboard implements SharedPreferences.OnSharedPreferenceChangeListe
if (TextUtils.isEmpty(text)) { if (TextUtils.isEmpty(text)) {
return false; return false;
} }
App.getGa().onButtonPressed(text); ga.onButtonPressed(text);
if (!processSpecialAction(text)) { if (!processSpecialAction(text)) {
processText(prepareText(text)); processText(prepareText(text));
} }

View File

@ -28,6 +28,8 @@ public class StartupHelper {
SharedPreferences uiPreferences; SharedPreferences uiPreferences;
@Inject @Inject
SharedPreferences preferences; SharedPreferences preferences;
@Inject
Wizards wizards;
@Inject @Inject
public StartupHelper() { public StartupHelper() {
@ -44,7 +46,6 @@ public class StartupHelper {
private void handleOnMainActivityOpened(@NonNull final AppCompatActivity activity, @NonNull SharedPreferences.Editor editor, int opened) { private void handleOnMainActivityOpened(@NonNull final AppCompatActivity activity, @NonNull SharedPreferences.Editor editor, int opened) {
final int currentVersion = App.getAppVersionCode(activity); final int currentVersion = App.getAppVersionCode(activity);
final Wizards wizards = App.getWizards();
final Wizard wizard = wizards.getWizard(CalculatorWizards.FIRST_TIME_WIZARD); final Wizard wizard = wizards.getWizard(CalculatorWizards.FIRST_TIME_WIZARD);
if (wizard.isStarted() && !wizard.isFinished()) { if (wizard.isStarted() && !wizard.isFinished()) {
continueWizard(wizards, wizard.getName(), activity); continueWizard(wizards, wizard.getName(), activity);

View File

@ -107,7 +107,7 @@ public abstract class BaseEntitiesRegistry<T extends MathEntity> implements Enti
stringName = prefix + substitute; stringName = prefix + substitute;
} }
return getDescription(App.getApplication(), stringName); return getDescription(application, stringName);
} }
@Override @Override

View File

@ -27,14 +27,21 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.Preferences; import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.ga.Ga;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.inject.Inject;
import static org.solovyev.android.calculator.App.cast;
public final class FloatingCalculatorBroadcastReceiver extends BroadcastReceiver { public final class FloatingCalculatorBroadcastReceiver extends BroadcastReceiver {
@Inject
SharedPreferences preferences;
@Inject
Ga ga;
public FloatingCalculatorBroadcastReceiver() { public FloatingCalculatorBroadcastReceiver() {
} }
@ -42,10 +49,10 @@ public final class FloatingCalculatorBroadcastReceiver extends BroadcastReceiver
public void onReceive(@Nonnull Context context, public void onReceive(@Nonnull Context context,
@Nonnull Intent intent) { @Nonnull Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) { if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); cast(context).getComponent().inject(this);
if (Preferences.Onscreen.startOnBoot.getPreferenceNoError(preferences)) { if (Preferences.Onscreen.startOnBoot.getPreferenceNoError(preferences)) {
FloatingCalculatorService.showNotification(context); FloatingCalculatorService.showNotification(context);
App.getGa().onBootStart(); ga.onBootStart();
} }
} else { } else {
final Intent newIntent = new Intent(intent); final Intent newIntent = new Intent(intent);

View File

@ -32,16 +32,11 @@ import android.os.IBinder;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.view.WindowManager; import android.view.WindowManager;
import com.squareup.otto.Bus; import com.squareup.otto.Bus;
import com.squareup.otto.Subscribe; import com.squareup.otto.Subscribe;
import org.solovyev.android.Check; import org.solovyev.android.Check;
import org.solovyev.android.calculator.App; import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.Display; import org.solovyev.android.calculator.ga.Ga;
import org.solovyev.android.calculator.Editor;
import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.R;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -64,6 +59,8 @@ public class FloatingCalculatorService extends Service implements FloatingViewLi
@Inject @Inject
Display display; Display display;
@Inject @Inject
Ga ga;
@Inject
SharedPreferences preferences; SharedPreferences preferences;
public static void showNotification(@Nonnull Context context) { public static void showNotification(@Nonnull Context context) {
@ -148,7 +145,7 @@ public class FloatingCalculatorService extends Service implements FloatingViewLi
if (isShowWindowIntent(intent)) { if (isShowWindowIntent(intent)) {
hideNotification(); hideNotification();
createView(); createView();
App.getGa().onFloatingCalculatorOpened(); ga.onFloatingCalculatorOpened();
} else if (isShowNotificationIntent(intent)) { } else if (isShowNotificationIntent(intent)) {
showNotification(); showNotification();
} }

View File

@ -1,23 +1,20 @@
package org.solovyev.android.calculator.ga; package org.solovyev.android.calculator.ga;
import android.content.Context; import android.app.Application;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import com.google.android.gms.analytics.GoogleAnalytics; import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.HitBuilders; import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker; import com.google.android.gms.analytics.Tracker;
import org.solovyev.android.calculator.Preferences; import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
@Singleton
public final class Ga implements SharedPreferences.OnSharedPreferenceChangeListener { public final class Ga implements SharedPreferences.OnSharedPreferenceChangeListener {
private static final int LAYOUT = 1; private static final int LAYOUT = 1;
@ -29,24 +26,13 @@ public final class Ga implements SharedPreferences.OnSharedPreferenceChangeListe
@Nonnull @Nonnull
private final Tracker tracker; private final Tracker tracker;
public Ga(@Nonnull Context context, @Nonnull SharedPreferences preferences) { @Inject
analytics = GoogleAnalytics.getInstance(context); public Ga(@Nonnull Application application, @Nonnull SharedPreferences preferences) {
analytics = GoogleAnalytics.getInstance(application);
tracker = analytics.newTracker(R.xml.ga); tracker = analytics.newTracker(R.xml.ga);
preferences.registerOnSharedPreferenceChangeListener(this); preferences.registerOnSharedPreferenceChangeListener(this);
} }
@Nonnull
private String getStackTrace(@Nonnull Exception e) {
try {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
e.printStackTrace(new PrintStream(out));
return new String(out.toByteArray());
} catch (Exception e1) {
Log.e("Ga", e1.getMessage(), e1);
}
return "";
}
private void reportLayout(@Nonnull Preferences.Gui.Layout layout) { private void reportLayout(@Nonnull Preferences.Gui.Layout layout) {
tracker.send(new HitBuilders.EventBuilder().setCustomDimension(LAYOUT, layout.name()).build()); tracker.send(new HitBuilders.EventBuilder().setCustomDimension(LAYOUT, layout.name()).build());
} }
@ -60,11 +46,6 @@ public final class Ga implements SharedPreferences.OnSharedPreferenceChangeListe
return analytics; return analytics;
} }
@Nonnull
public Tracker getTracker() {
return tracker;
}
public void onButtonPressed(@Nullable String text) { public void onButtonPressed(@Nullable String text) {
if (TextUtils.isEmpty(text)) { if (TextUtils.isEmpty(text)) {
return; return;

View File

@ -4,17 +4,16 @@ import android.app.Activity;
import android.app.Application; import android.app.Application;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.util.DisplayMetrics;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.buttons.CppSpecialButton; import org.solovyev.android.calculator.buttons.CppSpecialButton;
import org.solovyev.android.calculator.view.ScreenMetrics;
import org.solovyev.android.views.Adjuster; import org.solovyev.android.views.Adjuster;
import org.solovyev.android.views.dragbutton.DirectionDragButton; import org.solovyev.android.views.dragbutton.DirectionDragButton;
import org.solovyev.android.views.dragbutton.DragButton; import org.solovyev.android.views.dragbutton.DragButton;
@ -26,9 +25,9 @@ import javax.inject.Inject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
import static android.view.HapticFeedbackConstants.*; import static android.view.HapticFeedbackConstants.*;
import static org.solovyev.android.calculator.App.cast; import static org.solovyev.android.calculator.App.cast;
import static org.solovyev.android.calculator.App.getScreenMetrics;
import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple; import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple;
import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple_mobile; import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple_mobile;
@ -59,7 +58,7 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
ActivityLauncher launcher; ActivityLauncher launcher;
@Inject @Inject
PreferredPreferences preferredPreferences; PreferredPreferences preferredPreferences;
protected int orientation = Configuration.ORIENTATION_PORTRAIT; protected int orientation = ORIENTATION_PORTRAIT;
private int textSize; private int textSize;
private Preferences.Gui.Layout layout; private Preferences.Gui.Layout layout;
private final float textScale; private final float textScale;
@ -83,7 +82,7 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
orientation = App.getScreenOrientation(activity); orientation = App.getScreenOrientation(activity);
layout = Preferences.Gui.layout.getPreferenceNoError(preferences); layout = Preferences.Gui.layout.getPreferenceNoError(preferences);
textSize = calculateTextSize(); textSize = calculateTextSize(activity);
} }
protected final void prepareButton(@Nullable ImageView button) { protected final void prepareButton(@Nullable ImageView button) {
@ -141,12 +140,13 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
preferences.unregisterOnSharedPreferenceChangeListener(this); preferences.unregisterOnSharedPreferenceChangeListener(this);
} }
public static int calculateTextSize() { public static int calculateTextSize(@Nonnull Activity activity) {
final ScreenMetrics metrics = getScreenMetrics(); final boolean portrait = App.getScreenOrientation(activity) == ORIENTATION_PORTRAIT;
final boolean portrait = metrics.isInPortraitMode(); final DisplayMetrics metrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
final int buttonsCount = portrait ? 5 : 4; final int buttonsCount = portrait ? 5 : 4;
final int buttonsWeight = portrait ? (2 + 1 + buttonsCount) : (2 + buttonsCount); final int buttonsWeight = portrait ? (2 + 1 + buttonsCount) : (2 + buttonsCount);
final int buttonSize = metrics.getHeightPxs() / buttonsWeight; final int buttonSize = metrics.heightPixels / buttonsWeight;
return 5 * buttonSize / 12; return 5 * buttonSize / 12;
} }

View File

@ -1,5 +1,6 @@
package org.solovyev.android.calculator.language; package org.solovyev.android.calculator.language;
import android.app.Application;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
@ -8,7 +9,6 @@ import android.text.TextUtils;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import org.solovyev.android.Check; import org.solovyev.android.Check;
import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.Preferences; import org.solovyev.android.calculator.Preferences;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -26,9 +26,12 @@ public final class Languages implements SharedPreferences.OnSharedPreferenceChan
@Nonnull @Nonnull
private final List<Language> list = new ArrayList<>(); private final List<Language> list = new ArrayList<>();
@Nonnull @Nonnull
private final Application application;
@Nonnull
private final SharedPreferences preferences; private final SharedPreferences preferences;
public Languages(@Nonnull SharedPreferences preferences) { public Languages(@Nonnull Application application, @Nonnull SharedPreferences preferences) {
this.application = application;
this.preferences = preferences; this.preferences = preferences;
} }
@ -160,7 +163,7 @@ public final class Languages implements SharedPreferences.OnSharedPreferenceChan
@Override @Override
public void onSharedPreferenceChanged(@Nonnull SharedPreferences p, String key) { public void onSharedPreferenceChanged(@Nonnull SharedPreferences p, String key) {
if (Preferences.Gui.language.isSameKey(key)) { if (Preferences.Gui.language.isSameKey(key)) {
updateContextLocale(App.getApplication(), false); updateContextLocale(application, false);
} }
} }

View File

@ -88,7 +88,7 @@ public class PreferencesActivity extends BaseActivity implements SharedPreferenc
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
App.getPreferences().registerOnSharedPreferenceChangeListener(this); preferences.registerOnSharedPreferenceChangeListener(this);
final Intent intent = getIntent(); final Intent intent = getIntent();
final int preferenceTitle = intent.getIntExtra(EXTRA_PREFERENCE_TITLE, 0); final int preferenceTitle = intent.getIntExtra(EXTRA_PREFERENCE_TITLE, 0);
@ -139,7 +139,7 @@ public class PreferencesActivity extends BaseActivity implements SharedPreferenc
@Override @Override
protected void onDestroy() { protected void onDestroy() {
checkout.stop(); checkout.stop();
App.getPreferences().unregisterOnSharedPreferenceChangeListener(this); preferences.unregisterOnSharedPreferenceChangeListener(this);
super.onDestroy(); super.onDestroy();
} }

View File

@ -10,9 +10,7 @@ import android.support.v4.app.FragmentActivity;
import android.util.SparseArray; import android.util.SparseArray;
import android.view.View; import android.view.View;
import android.widget.ListView; import android.widget.ListView;
import org.solovyev.android.calculator.AdView; import org.solovyev.android.calculator.AdView;
import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.Engine; import org.solovyev.android.calculator.Engine;
import org.solovyev.android.calculator.Preferences; import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
@ -22,12 +20,14 @@ import org.solovyev.android.checkout.BillingRequests;
import org.solovyev.android.checkout.Checkout; import org.solovyev.android.checkout.Checkout;
import org.solovyev.android.checkout.ProductTypes; import org.solovyev.android.checkout.ProductTypes;
import org.solovyev.android.checkout.RequestListener; import org.solovyev.android.checkout.RequestListener;
import org.solovyev.android.wizard.Wizards;
import java.util.List;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.inject.Inject;
import java.util.List;
import static org.solovyev.android.calculator.App.cast;
import static org.solovyev.android.calculator.wizard.CalculatorWizards.DEFAULT_WIZARD_FLOW; import static org.solovyev.android.calculator.wizard.CalculatorWizards.DEFAULT_WIZARD_FLOW;
import static org.solovyev.android.wizard.WizardUi.startWizard; import static org.solovyev.android.wizard.WizardUi.startWizard;
@ -38,6 +38,12 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc
private Preference buyPremiumPreference; private Preference buyPremiumPreference;
@Nullable @Nullable
private AdView adView; private AdView adView;
@Inject
SharedPreferences preferences;
@Inject
Languages languages;
@Inject
Wizards wizards;
@Nonnull @Nonnull
public static PreferencesFragment create(int preferencesResId, int layoutResId) { public static PreferencesFragment create(int preferencesResId, int layoutResId) {
@ -49,8 +55,9 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
cast(this).getComponent().inject(this);
App.getPreferences().registerOnSharedPreferenceChangeListener(this); preferences.registerOnSharedPreferenceChangeListener(this);
} }
private void setPreferenceIntent(int xml, @Nonnull PreferencesActivity.PrefDef def) { private void setPreferenceIntent(int xml, @Nonnull PreferencesActivity.PrefDef def) {
@ -80,7 +87,7 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc
restartWizardPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { restartWizardPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
startWizard(App.getWizards(), DEFAULT_WIZARD_FLOW, getActivity()); startWizard(wizards, DEFAULT_WIZARD_FLOW, getActivity());
return true; return true;
} }
}); });
@ -122,7 +129,6 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc
} }
}); });
final SharedPreferences preferences = App.getPreferences();
onSharedPreferenceChanged(preferences, Engine.Preferences.Output.round.getKey()); onSharedPreferenceChanged(preferences, Engine.Preferences.Output.round.getKey());
} }
@ -132,7 +138,6 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc
} }
final ListPreference language = (ListPreference) preferenceManager.findPreference(Preferences.Gui.language.getKey()); final ListPreference language = (ListPreference) preferenceManager.findPreference(Preferences.Gui.language.getKey());
final Languages languages = App.getLanguages();
final List<Language> languagesList = languages.getList(); final List<Language> languagesList = languages.getList();
final CharSequence[] entries = new CharSequence[languagesList.size()]; final CharSequence[] entries = new CharSequence[languagesList.size()];
final CharSequence[] entryValues = new CharSequence[languagesList.size()]; final CharSequence[] entryValues = new CharSequence[languagesList.size()];
@ -195,7 +200,7 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc
@Override @Override
public void onDestroy() { public void onDestroy() {
App.getPreferences().unregisterOnSharedPreferenceChangeListener(this); preferences.unregisterOnSharedPreferenceChangeListener(this);
super.onDestroy(); super.onDestroy();
} }

View File

@ -30,11 +30,10 @@ import android.support.annotation.NonNull;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import org.solovyev.android.calculator.App; import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.BaseActivity;
import org.solovyev.android.calculator.BaseDialogFragment; import org.solovyev.android.calculator.BaseDialogFragment;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.ga.Ga;
import org.solovyev.android.checkout.*; import org.solovyev.android.checkout.*;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -49,6 +48,8 @@ public class PurchaseDialogActivity extends AppCompatActivity implements Request
Billing billing; Billing billing;
@Inject @Inject
Products products; Products products;
@Inject
Ga ga;
ActivityCheckout checkout; ActivityCheckout checkout;
@Override @Override
@ -69,12 +70,12 @@ public class PurchaseDialogActivity extends AppCompatActivity implements Request
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
BaseActivity.reportActivityStart(this); ga.getAnalytics().reportActivityStart(this);
} }
@Override @Override
protected void onStop() { protected void onStop() {
BaseActivity.reportActivityStop(this); ga.getAnalytics().reportActivityStop(this);
super.onStop(); super.onStop();
} }

View File

@ -2,8 +2,6 @@ package org.solovyev.android.calculator.view;
import android.app.Application; import android.app.Application;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.Engine; import org.solovyev.android.calculator.Engine;
import org.solovyev.android.calculator.Preferences; import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.text.TextProcessor; import org.solovyev.android.calculator.text.TextProcessor;
@ -21,11 +19,14 @@ public final class EditorTextProcessor implements TextProcessor<TextProcessorEdi
@Nullable @Nullable
private TextHighlighter textHighlighter; private TextHighlighter textHighlighter;
@Nonnull @Nonnull
private final Application application;
@Nonnull
private final SharedPreferences preferences; private final SharedPreferences preferences;
@Nonnull @Nonnull
private final Engine engine; private final Engine engine;
public EditorTextProcessor(@Nonnull SharedPreferences preferences, @Nonnull Engine engine) { public EditorTextProcessor(@Nonnull Application application, @Nonnull SharedPreferences preferences, @Nonnull Engine engine) {
this.application = application;
this.preferences = preferences; this.preferences = preferences;
this.engine = engine; this.engine = engine;
preferences.registerOnSharedPreferenceChangeListener(this); preferences.registerOnSharedPreferenceChangeListener(this);
@ -66,7 +67,6 @@ public final class EditorTextProcessor implements TextProcessor<TextProcessorEdi
private int getTextColor(@Nonnull SharedPreferences preferences) { private int getTextColor(@Nonnull SharedPreferences preferences) {
final Preferences.Gui.Theme theme = Preferences.Gui.getTheme(preferences); final Preferences.Gui.Theme theme = Preferences.Gui.getTheme(preferences);
final Application application = App.getApplication();
return theme.getTextColorFor(application).normal; return theme.getTextColorFor(application).normal;
} }
} }

View File

@ -1,120 +0,0 @@
package org.solovyev.android.calculator.view;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Build;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import javax.annotation.Nonnull;
public class ScreenMetrics {
@Nonnull
private final android.view.Display display;
@Nonnull
private final DisplayMetrics metrics;
private final int layout;
private float xDpi;
private float yDpi;
private float diagonalIns;
private float widthIns;
private float heightIns;
public ScreenMetrics(@Nonnull Context context) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
display = wm.getDefaultDisplay();
metrics = new DisplayMetrics();
display.getMetrics(metrics);
initDpi();
initDimensions();
layout = context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
}
private void initDpi() {
if ((Build.DEVICE.equals("qsd8250_surf")
|| Build.MODEL.equals("Dell Streak"))) {
xDpi = 190f;
yDpi = 190f;
} else if (Build.MODEL.equals("VTAB1008")) {
xDpi = 160f;
yDpi = 160f;
} else if (Build.MODEL.equals("Dell Streak 7")) {
xDpi = 150f;
yDpi = 150f;
} else if (Build.MODEL.equals("A1_07")) {
xDpi = 127.5f;
yDpi = 100f;
} else if (Build.MODEL.equals("N12GPS")
|| Build.MODEL.equals("MID_Serials")) {
xDpi = 133f;
yDpi = 133f;
} else if (Build.MODEL.startsWith("GT-N710")
|| Build.MODEL.equalsIgnoreCase("SCH-N719")
|| Build.MODEL.startsWith("SHV-E250")) {
xDpi = 267f;
yDpi = 267f;
} else if (metrics.densityDpi - metrics.xdpi >= 79.0
|| metrics.densityDpi - metrics.ydpi >= 79.0
|| Math.abs(metrics.ydpi - metrics.xdpi) > 40.0) {
xDpi = yDpi = metrics.densityDpi;
} else {
xDpi = metrics.xdpi;
yDpi = metrics.ydpi;
}
}
private void initDimensions() {
final float w = getWidthPxs() / xDpi;
final float h = getHeightPxs() / yDpi;
diagonalIns = (float) Math.sqrt(w * w + h * h);
widthIns = w;
heightIns = h;
}
public boolean isInPortraitMode() {
return getWidthPxs() < getHeightPxs();
}
@SuppressWarnings("deprecation")
public int getWidthPxs() {
return display.getWidth();
}
@SuppressWarnings("deprecation")
public int getHeightPxs() {
return display.getHeight();
}
public float getWidthIns() {
return widthIns;
}
public float getHeightIns() {
return heightIns;
}
public int getDensityDpi() {
return metrics.densityDpi;
}
public float getDensity() {
return metrics.density;
}
public float getXDpi() {
return xDpi;
}
public float getYDpi() {
return yDpi;
}
public float getDiagonalIns() {
return diagonalIns;
}
public int getLayout() {
return layout;
}
}

View File

@ -27,7 +27,6 @@ import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.Preferences; import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.android.views.dragbutton.DirectionDragButton; import org.solovyev.android.views.dragbutton.DirectionDragButton;
@ -52,7 +51,7 @@ public class ChooseModeWizardStep extends WizardFragment implements AdapterView.
public void onViewCreated(View root, Bundle savedInstanceState) { public void onViewCreated(View root, Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState); super.onViewCreated(root, savedInstanceState);
final CalculatorMode mode = CalculatorMode.fromGuiLayout(Preferences.Gui.layout.getPreference(App.getPreferences())); final CalculatorMode mode = CalculatorMode.fromGuiLayout(Preferences.Gui.layout.getPreference(preferences));
final Spinner spinner = (Spinner) root.findViewById(R.id.wizard_mode_spinner); final Spinner spinner = (Spinner) root.findViewById(R.id.wizard_mode_spinner);
spinner.setAdapter(WizardArrayAdapter.create(getActivity(), R.array.cpp_modes)); spinner.setAdapter(WizardArrayAdapter.create(getActivity(), R.array.cpp_modes));
spinner.setSelection(mode == simple ? 0 : 1); spinner.setSelection(mode == simple ? 0 : 1);
@ -80,7 +79,7 @@ public class ChooseModeWizardStep extends WizardFragment implements AdapterView.
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
final CalculatorMode mode = position == 0 ? simple : engineer; final CalculatorMode mode = position == 0 ? simple : engineer;
mode.apply(App.getPreferences()); mode.apply(preferences);
updateDescription(mode); updateDescription(mode);
} }

View File

@ -55,7 +55,7 @@ public class ChooseThemeWizardStep extends WizardFragment implements AdapterView
public void onViewCreated(View root, Bundle savedInstanceState) { public void onViewCreated(View root, Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState); super.onViewCreated(root, savedInstanceState);
final Preferences.Gui.Theme theme = Preferences.Gui.getTheme(App.getPreferences()); final Preferences.Gui.Theme theme = Preferences.Gui.getTheme(preferences);
final Spinner spinner = (Spinner) root.findViewById(R.id.wizard_theme_spinner); final Spinner spinner = (Spinner) root.findViewById(R.id.wizard_theme_spinner);
themes.clear(); themes.clear();
themes.add(new ThemeUi(Preferences.Gui.Theme.material_theme, R.string.cpp_theme_dark)); themes.add(new ThemeUi(Preferences.Gui.Theme.material_theme, R.string.cpp_theme_dark));
@ -97,7 +97,7 @@ public class ChooseThemeWizardStep extends WizardFragment implements AdapterView
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
final ThemeUi theme = adapter.getItem(position); final ThemeUi theme = adapter.getItem(position);
Preferences.Gui.theme.putPreference(App.getPreferences(), theme.theme); Preferences.Gui.theme.putPreference(preferences, theme.theme);
updateImage(theme.theme); updateImage(theme.theme);
} }

View File

@ -49,7 +49,7 @@ public class OnScreenCalculatorWizardStep extends WizardFragment implements Comp
public void onViewCreated(View root, Bundle savedInstanceState) { public void onViewCreated(View root, Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState); super.onViewCreated(root, savedInstanceState);
final Boolean enabled = Preferences.Onscreen.showAppIcon.getPreference(App.getPreferences()); final Boolean enabled = Preferences.Onscreen.showAppIcon.getPreference(preferences);
checkbox = (CheckBox) root.findViewById(R.id.wizard_onscreen_app_enabled_checkbox); checkbox = (CheckBox) root.findViewById(R.id.wizard_onscreen_app_enabled_checkbox);
checkbox.setChecked(enabled); checkbox.setChecked(enabled);
checkbox.setOnCheckedChangeListener(this); checkbox.setOnCheckedChangeListener(this);
@ -67,7 +67,7 @@ public class OnScreenCalculatorWizardStep extends WizardFragment implements Comp
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) { public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
Preferences.Onscreen.showAppIcon.putPreference(App.getPreferences(), checked); Preferences.Onscreen.showAppIcon.putPreference(preferences, checked);
} }
} }

View File

@ -38,8 +38,6 @@ public class WizardActivity extends BaseActivity implements WizardsAware, Shared
private ViewPager pager; private ViewPager pager;
@Nonnull @Nonnull
private WizardPagerAdapter pagerAdapter; private WizardPagerAdapter pagerAdapter;
@Nonnull
private Wizards wizards = App.getWizards();
@Nullable @Nullable
private AlertDialog dialog; private AlertDialog dialog;
@ -47,6 +45,8 @@ public class WizardActivity extends BaseActivity implements WizardsAware, Shared
SharedPreferences preferences; SharedPreferences preferences;
@Inject @Inject
Languages languages; Languages languages;
@Inject
Wizards wizards;
public WizardActivity() { public WizardActivity() {
super(R.layout.cpp_activity_wizard, 0); super(R.layout.cpp_activity_wizard, 0);

View File

@ -1,5 +1,6 @@
package org.solovyev.android.calculator.wizard; package org.solovyev.android.calculator.wizard;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.LayoutRes; import android.support.annotation.LayoutRes;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
@ -8,6 +9,7 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import org.solovyev.android.calculator.AppComponent;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.release.ChooseThemeReleaseNoteFragment; import org.solovyev.android.calculator.release.ChooseThemeReleaseNoteFragment;
import org.solovyev.android.calculator.release.ChooseThemeReleaseNoteStep; import org.solovyev.android.calculator.release.ChooseThemeReleaseNoteStep;
@ -20,7 +22,9 @@ import org.solovyev.android.wizard.WizardStep;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.inject.Inject;
import static org.solovyev.android.calculator.App.cast;
import static org.solovyev.android.calculator.App.toPixels; import static org.solovyev.android.calculator.App.toPixels;
public abstract class WizardFragment extends Fragment implements View.OnClickListener { public abstract class WizardFragment extends Fragment implements View.OnClickListener {
@ -30,16 +34,22 @@ public abstract class WizardFragment extends Fragment implements View.OnClickLis
@Nullable @Nullable
protected TextView prevButton; protected TextView prevButton;
@Inject
SharedPreferences preferences;
private WizardStep step; private WizardStep step;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
inject(cast(this).getComponent());
step = findStepByClassName(); step = findStepByClassName();
} }
protected void inject(@Nonnull AppComponent component) {
component.inject(this);
}
@Nonnull @Nonnull
private WizardStep findStepByClassName() { private WizardStep findStepByClassName() {
if (this instanceof ReleaseNoteFragment) { if (this instanceof ReleaseNoteFragment) {